Follow-up r91997, moved newFromTitle() function to WikiPage.php and renamed to factor...
[lhc/web/wiklou.git] / tests / phpunit / includes / ArticleTest.php
1 <?php
2
3 class ArticleTest extends MediaWikiTestCase {
4
5 private $title; // holds a Title object
6 private $article; // holds an article
7
8 /** creates a title object and its article object */
9 function setUp() {
10 $this->title = Title::makeTitle( NS_MAIN, 'somePage' );
11 $this->article = new Article( $this->title );
12
13 }
14
15 /** cleanup title object and its article object */
16 function tearDown() {
17 $this->title = null;
18 $this->article = null;
19
20 }
21
22 function testImplementsGetMagic() {
23 $this->assertEquals( -1, $this->article->mCounter, "Article __get magic" );
24 }
25
26 /**
27 * @depends testImplementsGetMagic
28 */
29 function testImplementsSetMagic() {
30
31 $this->article->mCounter = 2;
32 $this->assertEquals( 2, $this->article->mCounter, "Article __set magic" );
33 }
34
35 /**
36 * @depends testImplementsSetMagic
37 */
38 function testImplementsCallMagic() {
39 $this->article->mCounter = 33;
40 $this->assertEquals( 33, $this->article->getCount(), "Article __call magic" );
41 }
42
43 function testGetOrSetOnNewProperty() {
44 $this->article->ext_someNewProperty = 12;
45 $this->assertEquals( 12, $this->article->ext_someNewProperty,
46 "Article get/set magic on new field" );
47
48 $this->article->ext_someNewProperty = -8;
49 $this->assertEquals( -8, $this->article->ext_someNewProperty,
50 "Article get/set magic on update to new field" );
51 }
52
53 function testStaticFunctions() {
54 $this->assertEquals( WikiPage::selectFields(), Article::selectFields(),
55 "Article static functions" );
56 $this->assertEquals( null, Article::onArticleCreate( $this->title ),
57 "Article static functions" );
58 $this->assertEquals( null, Article::onArticleDelete( $this->title ),
59 "Article static functions" );
60 $this->assertEquals( null, ImagePage::onArticleEdit( $this->title ),
61 "Article static functions" );
62 $this->assertTrue( is_string( CategoryPage::getAutosummary( '', '', 0 ) ),
63 "Article static functions" );
64 }
65
66 function testWikiPageFactory() {
67 $title = Title::makeTitle( NS_FILE, 'Someimage.png' );
68 $page = WikiPage::factory( $title );
69 $this->assertEquals( 'WikiFilePage', get_class( $page ) );
70
71 $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
72 $page = WikiPage::factory( $title );
73 $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
74
75 $title = Title::makeTitle( NS_MAIN, 'SomePage' );
76 $page = WikiPage::factory( $title );
77 $this->assertEquals( 'WikiPage', get_class( $page ) );
78 }
79 }