From fe2e385dd850574008184dd2b37793b4511f6abb Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 12 Oct 2012 18:30:38 +0200 Subject: [PATCH] Fix RevisionStorageTest with non-wikitext NS_MAIN Change-Id: I96c2c02a009128c91dfd9fb380aaa8af60311ce7 --- .../phpunit/includes/RevisionStorageTest.php | 23 +++++++--- ...evisionStorageTest_ContentHandlerUseDB.php | 43 ++++++++++++------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/tests/phpunit/includes/RevisionStorageTest.php b/tests/phpunit/includes/RevisionStorageTest.php index e06de7c52b..8d2a7bde44 100644 --- a/tests/phpunit/includes/RevisionStorageTest.php +++ b/tests/phpunit/includes/RevisionStorageTest.php @@ -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( diff --git a/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php b/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php index 3dfaa8de3f..c372c3eab4 100644 --- a/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php +++ b/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php @@ -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 + } } } -- 2.20.1