Avoid deprecation warnings in test cases.
authordaniel <daniel.kinzler@wikimedia.de>
Tue, 28 Aug 2012 13:58:36 +0000 (15:58 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Tue, 28 Aug 2012 14:00:39 +0000 (16:00 +0200)
a) when testing deprecated functions, use $this->hideDeprecated() to
suppress warnings.

b) use doEditContent() instead of doEdit()

Change-Id: Ifa9e0ef373ed72ef7d4a3c2dd558483af4a3fd55

14 files changed:
includes/ContentHandler.php
includes/WikiPage.php
tests/parser/parserTest.inc
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/ArticleTablesTest.php
tests/phpunit/includes/ArticleTest.php
tests/phpunit/includes/ContentHandlerTest.php
tests/phpunit/includes/RevisionStorageTest.php
tests/phpunit/includes/RevisionTest.php
tests/phpunit/includes/TemplateCategoriesTest.php
tests/phpunit/includes/WikiPageTest.php
tests/phpunit/includes/search/SearchEngineTest.php
tests/phpunit/maintenance/DumpTestCase.php
tests/phpunit/maintenance/fetchTextTest.php

index 1f20682..7d844a4 100644 (file)
@@ -841,15 +841,19 @@ abstract class ContentHandler {
         *
         * @param $event String: event name
         * @param $args Array: parameters passed to hook functions
+        * @param $warn bool: whether to log a warning (default: true). Should generally be true,
+        *                    may be set to false for testing.
         *
         * @return Boolean True if no handler aborted the hook
         */
-       public static function runLegacyHooks( $event, $args = array() ) {
+       public static function runLegacyHooks( $event, $args = array(), $warn = true ) {
                if ( !Hooks::isRegistered( $event ) ) {
                        return true; // nothing to do here
                }
 
-               wfWarn( "Using obsolete hook $event" );
+               if ( $warn ) {
+                       wfWarn( "Using obsolete hook $event" );
+               }
 
                // convert Content objects to text
                $contentObjects = array();
index 0318f2d..333b34b 100644 (file)
@@ -468,7 +468,8 @@ class WikiPage extends Page implements IDBAccessObject {
                        if ( $rev !== null ) {
                                return $rev->getContentModel();
                        } else {
-                               wfWarn( "Page exists but has no revision!" );
+                               $title = $this->mTitle->getPrefixedDBkey();
+                               wfWarn( "Page $title exists but has no (visible) revisions!" );
                        }
                }
 
index cd59833..47d3e71 100644 (file)
@@ -1204,7 +1204,7 @@ class ParserTest {
                        }
                }
 
-               $page->doEdit( $text, '', EDIT_NEW );
+               $page->doEditContent( ContentHandler::makeContent( $text, $title ), '', EDIT_NEW );
 
                $wgCapitalLinks = $oldCapitalLinks;
        }
index c873c51..2fb2d00 100644 (file)
@@ -200,11 +200,12 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                //Make 1 page with 1 revision
                $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
                if ( !$page->getId() == 0 ) {
-                       $page->doEdit( 'UTContent',
-                                                       'UTPageSummary',
-                                                       EDIT_NEW,
-                                                       false,
-                                                       User::newFromName( 'UTSysop' ) );
+                       $page->doEditContent(
+                               new WikitextContent( 'UTContent' ),
+                               'UTPageSummary',
+                               EDIT_NEW,
+                               false,
+                               User::newFromName( 'UTSysop' ) );
                }
        }
 
index 17cee6e..967ffa1 100644 (file)
@@ -16,14 +16,14 @@ class ArticleTablesTest extends MediaWikiLangTestCase {
                $wgContLang = Language::factory( 'es' );
 
                $wgLang = Language::factory( 'fr' );
-               $status = $page->doEdit( '{{:{{int:history}}}}', 'Test code for bug 14404', 0, false, $user );
+               $status = $page->doEditContent( new WikitextContent( '{{:{{int:history}}}}' ), 'Test code for bug 14404', 0, false, $user );
                $templates1 = $title->getTemplateLinksFrom();
 
                $wgLang = Language::factory( 'de' );
                $page->mPreparedEdit = false; // In order to force the rerendering of the same wikitext
 
                // We need an edit, a purge is not enough to regenerate the tables
-               $status = $page->doEdit( '{{:{{int:history}}}}', 'Test code for bug 14404', EDIT_UPDATE, false, $user );
+               $status = $page->doEditContent( new WikitextContent( '{{:{{int:history}}}}' ), 'Test code for bug 14404', EDIT_UPDATE, false, $user );
                $templates2 = $title->getTemplateLinksFrom();
 
                $this->assertEquals( $templates1, $templates2 );
index 846d2b8..744417b 100644 (file)
@@ -54,6 +54,9 @@ class ArticleTest extends MediaWikiTestCase {
         * Checks for the existence of the backwards compatibility static functions (forwarders to WikiPage class)
         */
        function testStaticFunctions() {
+               $this->hideDeprecated( 'Article::getAutosummary' );
+               $this->hideDeprecated( 'WikiPage::getAutosummary' );
+
                $this->assertEquals( WikiPage::selectFields(), Article::selectFields(),
                        "Article static functions" );
                $this->assertEquals( true, is_callable( "Article::onArticleCreate" ),
index 01bba65..0dc1c1b 100644 (file)
@@ -241,7 +241,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
                Hooks::register( 'testRunLegacyHooks', __CLASS__ . '::dummyHookHandler' );
 
                $content = new WikitextContent( 'test text' );
-               $ok = ContentHandler::runLegacyHooks( 'testRunLegacyHooks', array( 'foo', &$content, 'bar' ) );
+               $ok = ContentHandler::runLegacyHooks( 'testRunLegacyHooks', array( 'foo', &$content, 'bar' ), false );
 
                $this->assertTrue( $ok, "runLegacyHooks should have returned true" );
                $this->assertEquals( "TEST TEXT", $content->getNativeData() );
index a98b200..576e781 100644 (file)
@@ -186,7 +186,7 @@ class RevisionStorageTest extends MediaWikiTestCase {
                $page = $this->createPage( 'RevisionStorageTest_testFetchRevision', 'one' );
                $id1 = $page->getRevision()->getId();
 
-               $page->doEdit( 'two', 'second rev' );
+               $page->doEditContent( new WikitextContent( 'two' ), 'second rev' );
                $id2 = $page->getRevision()->getId();
 
                $res = Revision::fetchRevision( $page->getTitle() );
@@ -244,6 +244,8 @@ class RevisionStorageTest extends MediaWikiTestCase {
         */
        public function testGetText()
        {
+               $this->hideDeprecated( 'Revision::getText' );
+
                $orig = $this->makeRevision( array( 'text' => 'hello hello.' ) );
                $rev = Revision::newFromId( $orig->getId() );
 
@@ -266,6 +268,8 @@ class RevisionStorageTest extends MediaWikiTestCase {
         */
        public function testRevText()
        {
+               $this->hideDeprecated( 'Revision::revText' );
+
                $orig = $this->makeRevision( array( 'text' => 'hello hello rev.' ) );
                $rev = Revision::newFromId( $orig->getId() );
 
@@ -277,6 +281,8 @@ class RevisionStorageTest extends MediaWikiTestCase {
         */
        public function testGetRawText()
        {
+               $this->hideDeprecated( 'Revision::getRawText' );
+
                $orig = $this->makeRevision( array( 'text' => 'hello hello raw.' ) );
                $rev = Revision::newFromId( $orig->getId() );
 
index 5a98355..cae320f 100644 (file)
@@ -270,6 +270,8 @@ class RevisionTest extends MediaWikiTestCase {
         * @dataProvider dataGetText
         */
        function testGetText( $text, $title, $model, $format, $audience, $expectedText ) {
+               $this->hideDeprecated( 'Revision::getText' );
+
                $rev = $this->newTestRevision( $text, $title, $model, $format );
 
                $this->assertEquals( $expectedText, $rev->getText( $audience ) );
@@ -280,6 +282,8 @@ class RevisionTest extends MediaWikiTestCase {
         * @dataProvider dataGetText
         */
        function testGetRawText( $text, $title, $model, $format, $audience, $expectedText ) {
+               $this->hideDeprecated( 'Revision::getRawText' );
+
                $rev = $this->newTestRevision( $text, $title, $model, $format );
 
                $this->assertEquals( $expectedText, $rev->getRawText( $audience ) );
index 416ec86..38ca85e 100644 (file)
@@ -13,14 +13,14 @@ class TemplateCategoriesTest extends MediaWikiLangTestCase {
                $user = new User();
                $user->mRights = array( 'createpage', 'edit', 'purge' );
 
-               $status = $page->doEdit( '{{Categorising template}}', 'Create a page with a template', 0, false, $user );
+               $status = $page->doEditContent( new WikitextContent( '{{Categorising template}}' ), 'Create a page with a template', 0, false, $user );
                $this->assertEquals(
                        array()
                        , $title->getParentCategories()
                );
 
                $template = WikiPage::factory( Title::newFromText( 'Template:Categorising template' ) );
-               $status = $template->doEdit( '[[Category:Solved bugs]]', 'Add a category through a template', 0, false, $user );
+               $status = $template->doEditContent( new WikitextContent( '[[Category:Solved bugs]]' ), 'Add a category through a template', 0, false, $user );
 
                // Run the job queue
                $jobs = new RunJobs;
index 02c0677..49b27af 100644 (file)
@@ -145,6 +145,10 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
        
        public function testDoEdit() {
+               $this->hideDeprecated( "WikiPage::doEdit" );
+               $this->hideDeprecated( "WikiPage::getText" );
+               $this->hideDeprecated( "Revision::getText" );
+
                $title = Title::newFromText( "WikiPageTest_testDoEdit" );
 
                $page = $this->newPage( $title );
@@ -199,6 +203,8 @@ class WikiPageTest extends MediaWikiLangTestCase {
        public function testDoQuickEdit() {
                global $wgUser;
 
+               $this->hideDeprecated( "WikiPage::doQuickEdit" );
+
                $page = $this->createPage( "WikiPageTest_testDoQuickEdit", "original text" );
 
                $text = "quick text";
@@ -290,6 +296,8 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        public function testGetText() {
+               $this->hideDeprecated( "WikiPage::getText" );
+
                $page = $this->newPage( "WikiPageTest_testGetText" );
 
                $text = $page->getText();
@@ -303,6 +311,8 @@ class WikiPageTest extends MediaWikiLangTestCase {
        }
 
        public function testGetRawText() {
+               $this->hideDeprecated( "WikiPage::getRawText" );
+
                $page = $this->newPage( "WikiPageTest_testGetRawText" );
 
                $text = $page->getRawText();
@@ -621,6 +631,8 @@ more stuff
         * @dataProvider dataReplaceSection
         */
        public function testReplaceSection( $title, $text, $section, $with, $sectionTitle, $expected ) {
+               $this->hideDeprecated( "WikiPage::replaceSection" );
+
                $page = $this->createPage( $title, $text );
                $text = $page->replaceSection( $section, $with, $sectionTitle );
                $text = trim( $text );
@@ -827,6 +839,8 @@ more stuff
         * @dataProvider dataGetAutoSummary
         */
        public function testGetAutosummary( $old, $new, $flags, $expected ) {
+               $this->hideDeprecated( "WikiPage::getAutosummary" );
+
                $page = $this->newPage( "WikiPageTest_testGetAutosummary" );
 
                $summary = $page->getAutosummary( $old, $new, $flags );
index 957907c..4522e50 100644 (file)
@@ -94,7 +94,7 @@ class SearchEngineTest extends MediaWikiTestCase {
                LinkCache::singleton()->clear();
 
                $page = WikiPage::factory( $title );
-               $page->doEdit( $text, $comment, 0, false, $user );
+               $page->doEditContent( ContentHandler::makeContent( $text, $title ), $comment, 0, false, $user );
 
                $this->pageList[] = array( $title, $page->getId() );
 
index 2554e4a..aceedf9 100644 (file)
@@ -35,7 +35,7 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
         * @throws MWExcepion
         */
        protected function addRevision( Page $page, $text, $summary ) {
-               $status = $page->doEdit( $text, $summary );
+               $status = $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), $summary );
                if ( $status->isGood() ) {
                        $value = $status->getValue();
                        $revision = $value['revision'];
index f0689b6..a6e7fbd 100644 (file)
@@ -111,7 +111,7 @@ class FetchTextTest extends MediaWikiTestCase {
         * @throws MWExcepion
         */
        private function addRevision( $page, $text, $summary ) {
-               $status = $page->doEdit( $text, $summary );
+               $status = $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), $summary );
                if ( $status->isGood() ) {
                        $value = $status->getValue();
                        $revision = $value['revision'];