summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/ArticleTest.php
blob: 867c4f007be35f550dd3fc00a98e828a1011e9e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php

class ArticleTest extends MediaWikiTestCase {

	/**
	 * @var Title
	 */
	private $title;
	/**
	 * @var Article
	 */
	private $article;

	/** creates a title object and its article object */
	protected function setUp() {
		parent::setUp();
		$this->title = Title::makeTitle( NS_MAIN, 'SomePage' );
		$this->article = new Article( $this->title );
	}

	/** cleanup title object and its article object */
	protected function tearDown() {
		parent::tearDown();
		$this->title = null;
		$this->article = null;
	}

	function testImplementsGetMagic() {
		$this->assertEquals( false, $this->article->mLatest, "Article __get magic" );
	}

	/**
	 * @depends testImplementsGetMagic
	 */
	function testImplementsSetMagic() {
		$this->article->mLatest = 2;
		$this->assertEquals( 2, $this->article->mLatest, "Article __set magic" );
	}

	/**
	 * @depends testImplementsSetMagic
	 */
	function testImplementsCallMagic() {
		$this->article->mLatest = 33;
		$this->article->mDataLoaded = true;
		$this->assertEquals( 33, $this->article->getLatest(), "Article __call magic" );
	}

	function testGetOrSetOnNewProperty() {
		$this->article->ext_someNewProperty = 12;
		$this->assertEquals( 12, $this->article->ext_someNewProperty,
			"Article get/set magic on new field" );

		$this->article->ext_someNewProperty = -8;
		$this->assertEquals( -8, $this->article->ext_someNewProperty,
			"Article get/set magic on update to new field" );
	}

	/**
	 * Checks for the existence of the backwards compatibility static functions (forwarders to WikiPage class)
	 */
	function testStaticFunctions() {
		$this->hideDeprecated( 'Article::getAutosummary' );
		$this->hideDeprecated( 'WikiPage::getAutosummary' );
		$this->hideDeprecated( 'CategoryPage::getAutosummary' ); // Inherited from Article

		$this->assertEquals( WikiPage::selectFields(), Article::selectFields(),
			"Article static functions" );
		$this->assertEquals( true, is_callable( "Article::onArticleCreate" ),
			"Article static functions" );
		$this->assertEquals( true, is_callable( "Article::onArticleDelete" ),
			"Article static functions" );
		$this->assertEquals( true, is_callable( "ImagePage::onArticleEdit" ),
			"Article static functions" );
		$this->assertTrue( is_string( CategoryPage::getAutosummary( '', '', 0 ) ),
			"Article static functions" );
	}

	function testWikiPageFactory() {
		$title = Title::makeTitle( NS_FILE, 'Someimage.png' );
		$page = WikiPage::factory( $title );
		$this->assertEquals( 'WikiFilePage', get_class( $page ) );

		$title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
		$page = WikiPage::factory( $title );
		$this->assertEquals( 'WikiCategoryPage', get_class( $page ) );

		$title = Title::makeTitle( NS_MAIN, 'SomePage' );
		$page = WikiPage::factory( $title );
		$this->assertEquals( 'WikiPage', get_class( $page ) );
	}
}