(bug 37209) Make TextContentTest and WikitextContentTest work in all cases
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Wed, 23 Jan 2013 17:14:35 +0000 (18:14 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Wed, 23 Jan 2013 17:14:35 +0000 (18:14 +0100)
Currently TextContentTest::testDeletionUpdates() and
WikitextContentTest::testGetSecondaryDataUpdates() set a random page ID to
pages that does not exist. This works in most cases, but when a method like
Title::getLatestRevID() is called on these objects, it throws an excpection
"LinkCache doesn't currently knows about this title."
This happens e.g. when SemanticMediaWiki extension is installed.

Intsead of setting a random page ID, really insert the page in the database
before getting table updates so that it won't crash anymore.

Change-Id: I489c406f78897bc38ac41d8d599b778b47b30021

tests/phpunit/includes/content/TextContentTest.php
tests/phpunit/includes/content/WikitextContentTest.php

index 3501aec..ca387a2 100644 (file)
@@ -349,12 +349,15 @@ class TextContentTest extends MediaWikiLangTestCase {
         * @dataProvider dataGetDeletionUpdates
         */
        public function testDeletionUpdates( $title, $model, $text, $expectedStuff ) {
-               $title = Title::newFromText( $title );
-               $title->resetArticleID( 2342 ); //dummy id. fine as long as we don't try to execute the updates!
+               $ns = $this->getDefaultWikitextNS();
+               $title = Title::newFromText( $title, $ns );
 
                $content = ContentHandler::makeContent( $text, $title, $model );
 
-               $updates = $content->getDeletionUpdates( WikiPage::factory( $title ) );
+               $page = WikiPage::factory( $title );
+               $page->doEditContent( $content, '' );
+
+               $updates = $content->getDeletionUpdates( $page );
 
                // make updates accessible by class name
                foreach ( $updates as $update ) {
@@ -377,6 +380,8 @@ class TextContentTest extends MediaWikiLangTestCase {
                                $this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" );
                        }
                }
+
+               $page->doDeleteArticle( '' );
        }
 
        public static function provideConvert() {
index b76e9aa..7cf473e 100644 (file)
@@ -69,11 +69,14 @@ more stuff
         * @group Database
         */
        public function testGetSecondaryDataUpdates( $title, $model, $text, $expectedStuff ) {
-               $title = Title::newFromText( $title );
-               $title->resetArticleID( 2342 ); //dummy id. fine as long as we don't try to execute the updates!
+               $ns = $this->getDefaultWikitextNS();
+               $title = Title::newFromText( $title, $ns );
 
                $content = ContentHandler::makeContent( $text, $title, $model );
 
+               $page = WikiPage::factory( $title );
+               $page->doEditContent( $content, '' );
+
                $updates = $content->getSecondaryDataUpdates( $title );
 
                // make updates accessible by class name
@@ -92,6 +95,8 @@ more stuff
                                $this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" );
                        }
                }
+
+               $page->doDeleteArticle( '' );
        }
 
        public static function dataGetSection() {