From 96f7db3f7b28150195817d31d8c6ba1eb3e8d0cf Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 28 Aug 2012 15:58:36 +0200 Subject: [PATCH] Avoid deprecation warnings in test cases. a) when testing deprecated functions, use $this->hideDeprecated() to suppress warnings. b) use doEditContent() instead of doEdit() Change-Id: Ifa9e0ef373ed72ef7d4a3c2dd558483af4a3fd55 --- includes/ContentHandler.php | 8 ++++++-- includes/WikiPage.php | 3 ++- tests/parser/parserTest.inc | 2 +- tests/phpunit/MediaWikiTestCase.php | 11 ++++++----- tests/phpunit/includes/ArticleTablesTest.php | 4 ++-- tests/phpunit/includes/ArticleTest.php | 3 +++ tests/phpunit/includes/ContentHandlerTest.php | 2 +- tests/phpunit/includes/RevisionStorageTest.php | 8 +++++++- tests/phpunit/includes/RevisionTest.php | 4 ++++ tests/phpunit/includes/TemplateCategoriesTest.php | 4 ++-- tests/phpunit/includes/WikiPageTest.php | 14 ++++++++++++++ tests/phpunit/includes/search/SearchEngineTest.php | 2 +- tests/phpunit/maintenance/DumpTestCase.php | 2 +- tests/phpunit/maintenance/fetchTextTest.php | 2 +- 14 files changed, 51 insertions(+), 18 deletions(-) diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index 1f20682189..7d844a4688 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -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(); diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 0318f2d8d9..333b34bf4e 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -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!" ); } } diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index cd5983379c..47d3e71100 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -1204,7 +1204,7 @@ class ParserTest { } } - $page->doEdit( $text, '', EDIT_NEW ); + $page->doEditContent( ContentHandler::makeContent( $text, $title ), '', EDIT_NEW ); $wgCapitalLinks = $oldCapitalLinks; } diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index c873c5165d..2fb2d00cb9 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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' ) ); } } diff --git a/tests/phpunit/includes/ArticleTablesTest.php b/tests/phpunit/includes/ArticleTablesTest.php index 17cee6e808..967ffa17e0 100644 --- a/tests/phpunit/includes/ArticleTablesTest.php +++ b/tests/phpunit/includes/ArticleTablesTest.php @@ -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 ); diff --git a/tests/phpunit/includes/ArticleTest.php b/tests/phpunit/includes/ArticleTest.php index 846d2b86c2..744417b1fc 100644 --- a/tests/phpunit/includes/ArticleTest.php +++ b/tests/phpunit/includes/ArticleTest.php @@ -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" ), diff --git a/tests/phpunit/includes/ContentHandlerTest.php b/tests/phpunit/includes/ContentHandlerTest.php index 01bba65726..0dc1c1bc7b 100644 --- a/tests/phpunit/includes/ContentHandlerTest.php +++ b/tests/phpunit/includes/ContentHandlerTest.php @@ -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() ); diff --git a/tests/phpunit/includes/RevisionStorageTest.php b/tests/phpunit/includes/RevisionStorageTest.php index a98b20032a..576e78175b 100644 --- a/tests/phpunit/includes/RevisionStorageTest.php +++ b/tests/phpunit/includes/RevisionStorageTest.php @@ -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() ); diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index 5a983555c0..cae320ff8c 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -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 ) ); diff --git a/tests/phpunit/includes/TemplateCategoriesTest.php b/tests/phpunit/includes/TemplateCategoriesTest.php index 416ec867b8..38ca85eb0a 100644 --- a/tests/phpunit/includes/TemplateCategoriesTest.php +++ b/tests/phpunit/includes/TemplateCategoriesTest.php @@ -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; diff --git a/tests/phpunit/includes/WikiPageTest.php b/tests/phpunit/includes/WikiPageTest.php index 02c06772dc..49b27af671 100644 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@ -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 ); diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index 957907c73c..4522e50c04 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -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() ); diff --git a/tests/phpunit/maintenance/DumpTestCase.php b/tests/phpunit/maintenance/DumpTestCase.php index 2554e4a56a..aceedf9879 100644 --- a/tests/phpunit/maintenance/DumpTestCase.php +++ b/tests/phpunit/maintenance/DumpTestCase.php @@ -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']; diff --git a/tests/phpunit/maintenance/fetchTextTest.php b/tests/phpunit/maintenance/fetchTextTest.php index f0689b607a..a6e7fbd525 100644 --- a/tests/phpunit/maintenance/fetchTextTest.php +++ b/tests/phpunit/maintenance/fetchTextTest.php @@ -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']; -- 2.20.1