b4d6dca6d49da4da0fce1ba5fcf5d431bfae4189
[lhc/web/wiklou.git] / tests / phpunit / includes / ArticleTest.php
1 <?php
2
3 class ArticleTest extends MediaWikiTestCase {
4
5 /**
6 * @var Title
7 */
8 private $title;
9 /**
10 * @var Article
11 */
12 private $article;
13
14 /** creates a title object and its article object */
15 protected function setUp() {
16 parent::setUp();
17 $this->title = Title::makeTitle( NS_MAIN, 'SomePage' );
18 $this->article = new Article( $this->title );
19 }
20
21 /** cleanup title object and its article object */
22 protected function tearDown() {
23 parent::tearDown();
24 $this->title = null;
25 $this->article = null;
26 }
27
28 public function testImplementsGetMagic() {
29 $this->assertEquals( false, $this->article->mLatest, "Article __get magic" );
30 }
31
32 /**
33 * @depends testImplementsGetMagic
34 */
35 public function testImplementsSetMagic() {
36 $this->article->mLatest = 2;
37 $this->assertEquals( 2, $this->article->mLatest, "Article __set magic" );
38 }
39
40 /**
41 * @depends testImplementsSetMagic
42 */
43 public function testImplementsCallMagic() {
44 $this->article->mLatest = 33;
45 $this->article->mDataLoaded = true;
46 $this->assertEquals( 33, $this->article->getLatest(), "Article __call magic" );
47 }
48
49 public function testGetOrSetOnNewProperty() {
50 $this->article->ext_someNewProperty = 12;
51 $this->assertEquals( 12, $this->article->ext_someNewProperty,
52 "Article get/set magic on new field" );
53
54 $this->article->ext_someNewProperty = -8;
55 $this->assertEquals( -8, $this->article->ext_someNewProperty,
56 "Article get/set magic on update to new field" );
57 }
58
59 /**
60 * Checks for the existence of the backwards compatibility static functions (forwarders to WikiPage class)
61 */
62 public function testStaticFunctions() {
63 $this->hideDeprecated( 'Article::getAutosummary' );
64 $this->hideDeprecated( 'WikiPage::getAutosummary' );
65 $this->hideDeprecated( 'CategoryPage::getAutosummary' ); // Inherited from Article
66
67 $this->assertEquals( WikiPage::selectFields(), Article::selectFields(),
68 "Article static functions" );
69 $this->assertEquals( true, is_callable( "Article::onArticleCreate" ),
70 "Article static functions" );
71 $this->assertEquals( true, is_callable( "Article::onArticleDelete" ),
72 "Article static functions" );
73 $this->assertEquals( true, is_callable( "ImagePage::onArticleEdit" ),
74 "Article static functions" );
75 $this->assertTrue( is_string( CategoryPage::getAutosummary( '', '', 0 ) ),
76 "Article static functions" );
77 }
78
79 public function testWikiPageFactory() {
80 $title = Title::makeTitle( NS_FILE, 'Someimage.png' );
81 $page = WikiPage::factory( $title );
82 $this->assertEquals( 'WikiFilePage', get_class( $page ) );
83
84 $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
85 $page = WikiPage::factory( $title );
86 $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
87
88 $title = Title::makeTitle( NS_MAIN, 'SomePage' );
89 $page = WikiPage::factory( $title );
90 $this->assertEquals( 'WikiPage', get_class( $page ) );
91 }
92 }