Fix RevisionStorageTest with non-wikitext NS_MAIN
authordaniel <daniel.kinzler@wikimedia.de>
Fri, 12 Oct 2012 16:30:38 +0000 (18:30 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Fri, 12 Oct 2012 16:30:38 +0000 (18:30 +0200)
Change-Id: I96c2c02a009128c91dfd9fb380aaa8af60311ce7

tests/phpunit/includes/RevisionStorageTest.php
tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php

index e06de7c..8d2a7bd 100644 (file)
@@ -83,8 +83,20 @@ class RevisionStorageTest extends MediaWikiTestCase {
        }
 
        protected function createPage( $page, $text, $model = null ) {
-               if ( is_string( $page ) ) $page = Title::newFromText( $page );
-               if ( $page instanceof Title ) $page = new WikiPage( $page );
+               if ( is_string( $page ) ) {
+                       if ( !preg_match( '/:/', $page ) &&
+                               ( $model === null || $model === CONTENT_MODEL_WIKITEXT ) ) {
+
+                               $ns = $this->getDefaultWikitextNS();
+                               $page = MWNamespace::getCanonicalName( $ns ) . ':' . $page;
+                       }
+
+                       $page = Title::newFromText( $page );
+               }
+
+               if ( $page instanceof Title ) {
+                       $page = new WikiPage( $page );
+               }
 
                if ( $page->exists() ) {
                        $page->doDeleteArticle( "done" );
@@ -223,8 +235,6 @@ class RevisionStorageTest extends MediaWikiTestCase {
                                                                'missing rev_content_model in list of fields');
                        $this->assertTrue( in_array( 'rev_content_format', $fields ),
                                                                'missing rev_content_format in list of fields');
-               } else {
-                       $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
                }
        }
 
@@ -440,11 +450,14 @@ class RevisionStorageTest extends MediaWikiTestCase {
                        $userB = \User::createNew( $userB->getName() );
                }
 
+               $ns = $this->getDefaultWikitextNS();
+
                $dbw = wfGetDB( DB_MASTER );
                $revisions = array();
 
                // create revisions -----------------------------
-               $page = WikiPage::factory( Title::newFromText( 'RevisionStorageTest_testUserWasLastToEdit' ) );
+               $page = WikiPage::factory( Title::newFromText(
+                       'RevisionStorageTest_testUserWasLastToEdit', $ns ) );
 
                # zero
                $revisions[0] = new Revision( array(
index 3dfaa8d..c372c3e 100644 (file)
@@ -43,8 +43,7 @@ class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest {
        /**
         * @covers Revision::selectFields
         */
-       public function testSelectFields()
-       {
+       public function testSelectFields() {
                $fields = Revision::selectFields();
 
                $this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields');
@@ -59,26 +58,38 @@ class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest {
        /**
         * @covers Revision::getContentModel
         */
-       public function testGetContentModel()
-       {
-               $orig = $this->makeRevision( array( 'text' => 'hello hello.', 'content_model' => CONTENT_MODEL_JAVASCRIPT ) );
-               $rev = Revision::newFromId( $orig->getId() );
-
-               //NOTE: database fields for the content_model are disabled, so the model name is not retained.
-               //      We expect to get the default here instead of what was suppleid when creating the revision.
-               $this->assertEquals( CONTENT_MODEL_WIKITEXT, $rev->getContentModel() );
+       public function testGetContentModel() {
+               try {
+                       $this->makeRevision( array( 'text' => 'hello hello.',
+                                                   'content_model' => CONTENT_MODEL_JAVASCRIPT ) );
+
+                       $this->fail( "Creating JavaScript content on a wikitext page should fail with "
+                               . "\$wgContentHandlerUseDB disabled" );
+               } catch ( MWException $ex ) {
+                       $this->assertTrue( true ); // ok
+               }
        }
 
 
        /**
         * @covers Revision::getContentFormat
         */
-       public function testGetContentFormat()
-       {
-               $orig = $this->makeRevision( array( 'text' => 'hello hello.', 'content_model' => CONTENT_MODEL_JAVASCRIPT, 'content_format' => 'text/javascript' ) );
-               $rev = Revision::newFromId( $orig->getId() );
-
-               $this->assertEquals( CONTENT_FORMAT_WIKITEXT, $rev->getContentFormat() );
+       public function testGetContentFormat() {
+               try {
+                       //@todo: change this to test failure on using a non-standard (but supported) format
+                       //       for a content model supported in the given location. As of 1.21, there are
+                       //       no alternative formats for any of the standard content models that could be
+                       //       used for this though.
+
+                       $this->makeRevision( array( 'text' => 'hello hello.',
+                                                   'content_model' => CONTENT_MODEL_JAVASCRIPT,
+                                                   'content_format' => 'text/javascript' ) );
+
+                       $this->fail( "Creating JavaScript content on a wikitext page should fail with "
+                               . "\$wgContentHandlerUseDB disabled" );
+               } catch ( MWException $ex ) {
+                       $this->assertTrue( true ); // ok
+               }
        }
 
 }