X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiTestCase.php;h=9a27cf11768a223318de34c73bf3d4076df0e5aa;hb=81cbe34e4d519c62ac441197fe070709e4324304;hp=a5ee7ddb8c9f4c84ab83bd4273524e1f2072d727;hpb=092450edfaa1ff48cc5d1dc78fc89f3486db18e2;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index a5ee7ddb8c..9a27cf1176 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. * @@ -244,4 +207,17 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { 'ApiTestCase::setUp can be slow, tests must be "medium" or "large"' ); } + + /** + * Expect an ApiUsageException to be thrown with the given parameters, which are the same as + * ApiUsageException::newWithMessage()'s parameters. This allows checking for an exception + * whose text is given by a message key instead of text, so as not to hard-code the message's + * text into test code. + */ + protected function setExpectedApiException( + $msg, $code = null, array $data = null, $httpCode = 0 + ) { + $expected = ApiUsageException::newWithMessage( null, $msg, $code, $data, $httpCode ); + $this->setExpectedException( ApiUsageException::class, $expected->getMessage() ); + } }