From: Aryeh Gregor Date: Tue, 24 Jul 2018 14:50:03 +0000 (+0300) Subject: Move utility methods from ApiTestCase to MediaWikiTestCase X-Git-Tag: 1.34.0-rc.0~4627^2~1 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=05d78a6c7108c8ea85792ef0b34f44297c5adb67 Move utility methods from ApiTestCase to MediaWikiTestCase Change-Id: I79c4e37092958c63a693194b27a9eafae70cb2f8 --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 82739a70d2..db75bc0b58 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -2215,4 +2215,41 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { } self::assertEquals( file_get_contents( $fileName ), $actualData, $msg ); } + + /** + * Edits or creates a page/revision + * @param string $pageName Page title + * @param string $text Content of the page + * @param string $summary Optional summary string for the revision + * @param int $defaultNs Optional namespace id + * @return array Array as returned by WikiPage::doEditContent() + */ + protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) { + $title = Title::newFromText( $pageName, $defaultNs ); + $page = WikiPage::factory( $title ); + + return $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary ); + } + + /** + * Revision-deletes a revision. + * + * @param Revision|int $rev Revision to delete + * @param array $value Keys are Revision::DELETED_* flags. Values are 1 to set the bit, 0 to + * clear, -1 to leave alone. (All other values also clear the bit.) + * @param string $comment Deletion comment + */ + protected function revisionDelete( + $rev, array $value = [ Revision::DELETED_TEXT => 1 ], $comment = '' + ) { + if ( is_int( $rev ) ) { + $rev = Revision::newFromId( $rev ); + } + RevisionDeleter::createList( + 'revision', RequestContext::getMain(), $rev->getTitle(), [ $rev->getId() ] + )->setVisibility( [ + 'value' => $value, + 'comment' => $comment, + ] ); + } } diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index a5ee7ddb8c..0fce35abec 100644 --- a/tests/phpunit/includes/api/ApiTestCase.php +++ b/tests/phpunit/includes/api/ApiTestCase.php @@ -41,43 +41,6 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { parent::tearDown(); } - /** - * Edits or creates a page/revision - * @param string $pageName Page title - * @param string $text Content of the page - * @param string $summary Optional summary string for the revision - * @param int $defaultNs Optional namespace id - * @return array Array as returned by WikiPage::doEditContent() - */ - protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) { - $title = Title::newFromText( $pageName, $defaultNs ); - $page = WikiPage::factory( $title ); - - return $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary ); - } - - /** - * Revision-deletes a revision. - * - * @param Revision|int $rev Revision to delete - * @param array $value Keys are Revision::DELETED_* flags. Values are 1 to set the bit, 0 to - * clear, -1 to leave alone. (All other values also clear the bit.) - * @param string $comment Deletion comment - */ - protected function revisionDelete( - $rev, array $value = [ Revision::DELETED_TEXT => 1 ], $comment = '' - ) { - if ( is_int( $rev ) ) { - $rev = Revision::newFromId( $rev ); - } - RevisionDeleter::createList( - 'revision', RequestContext::getMain(), $rev->getTitle(), [ $rev->getId() ] - )->setVisibility( [ - 'value' => $value, - 'comment' => $comment, - ] ); - } - /** * Does the API request and returns the result. * diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index c1f5cf8835..2b275715a2 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -315,7 +315,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { $availableResults[] = $title; // pages not created must be filtered if ( $i % 2 == 0 ) { - $this->editPage( $title ); + $this->editSearchResultPage( $title ); } } MockCompletionSearchEngine::addMockResults( 'foo', $availableResults ); @@ -332,7 +332,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { $this->assertFalse( $results->hasMoreResults() ); } - private function editPage( $title ) { + private function editSearchResultPage( $title ) { $page = WikiPage::factory( Title::newFromText( $title ) ); $page->doEditContent( new WikitextContent( 'UTContent' ),