rv r96424, Roan had his fun
[lhc/web/wiklou.git] / tests / phpunit / includes / ArticleTest.php
index 4a84692..56384cf 100644 (file)
@@ -1,34 +1,82 @@
 <?php
 
 class ArticleTest extends MediaWikiTestCase {
-       function testBCMagic() {
-               $title = Title::makeTitle( NS_MAIN, 'somePage' );
-               $article = new Article( $title );
-               
-               $this->assertEquals( -1, $article->mCounter, "Article __get magic" );
 
-               $article->mCounter = 2;
-               $this->assertEquals( 2, $article->mCounter, "Article __set magic" );
+       private $title; // holds a Title object
+       private $article; // holds an article
+
+       /** creates a title object and its article object */
+       function setUp() {
+               $this->title   = Title::makeTitle( NS_MAIN, 'somePage' );
+               $this->article = new Article( $this->title );
+
+       }
+
+       /** cleanup title object and its article object */
+       function tearDown() {
+               $this->title   = null;
+               $this->article = null;
+
+       }
+
+       function testImplementsGetMagic() {             
+               $this->assertEquals( -1, $this->article->mCounter, "Article __get magic" );
+       }
+
+       /**
+        * @depends testImplementsGetMagic
+        */
+       function testImplementsSetMagic() {
+
+               $this->article->mCounter = 2;
+               $this->assertEquals( 2, $this->article->mCounter, "Article __set magic" );
+       }
 
-               $this->assertEquals( 2, $article->getCount(), "Article __call magic" );
+       /**
+        * @depends testImplementsSetMagic
+        */
+       function testImplementsCallMagic() {
+               $this->article->mCounter = 33;
+               $this->assertEquals( 33, $this->article->getCount(), "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->assertEquals( WikiPage::selectFields(), Article::selectFields(),
                        "Article static functions" );
-               $this->assertEquals( null, Article::onArticleCreate( $title ),
+               $this->assertEquals( true, is_callable( "Article::onArticleCreate" ),
                        "Article static functions" );
-               $this->assertEquals( null, Article::onArticleDelete( $title ),
+               $this->assertEquals( true, is_callable( "Article::onArticleDelete" ),
                        "Article static functions" );
-               $this->assertEquals( null, ImagePage::onArticleEdit( $title ),
+               $this->assertEquals( true, is_callable( "ImagePage::onArticleEdit" ),
                        "Article static functions" );
                $this->assertTrue( is_string( CategoryPage::getAutosummary( '', '', 0 ) ),
                        "Article static functions" );
+       }
 
-               $article->ext_someNewProperty = 12;
-               $this->assertEquals( 12, $article->ext_someNewProperty,
-                       "Article get/set magic on new field" );
+       function testWikiPageFactory() {
+               $title = Title::makeTitle( NS_FILE, 'Someimage.png' );
+               $page = WikiPage::factory( $title );
+               $this->assertEquals( 'WikiFilePage', get_class( $page ) );
                
-               $article->ext_someNewProperty = -8;
-               $this->assertEquals( -8, $article->ext_someNewProperty,
-                       "Article get/set magic on update to new field" );
+               $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 ) );
        }
 }