X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiParseTest.php;h=028d3b413536f7c4f7ce636ae2e570782c6fdaed;hb=57428a7c8ce44670fb7c8cff311874c42ee9ea20;hp=f01a670b711590bf37d816aa5012f3cb5a49ce77;hpb=b26ad1ac3f9477dcf7a04705b641d5e42fbec3a4;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiParseTest.php b/tests/phpunit/includes/api/ApiParseTest.php index f01a670b71..028d3b4135 100644 --- a/tests/phpunit/includes/api/ApiParseTest.php +++ b/tests/phpunit/includes/api/ApiParseTest.php @@ -9,18 +9,117 @@ */ class ApiParseTest extends ApiTestCase { - protected function setUp() { - parent::setUp(); - $this->doLogin(); + protected static $pageId; + protected static $revIds = []; + + public function addDBDataOnce() { + $user = static::getTestSysop()->getUser(); + $title = Title::newFromText( __CLASS__ ); + $page = WikiPage::factory( $title ); + + $status = $page->doEditContent( + ContentHandler::makeContent( 'Test for revdel', $title, CONTENT_MODEL_WIKITEXT ), + __METHOD__ . ' Test for revdel', 0, false, $user + ); + if ( !$status->isOk() ) { + $this->fail( "Failed to create $title: " . $status->getWikiText( false, false, 'en' ) ); + } + self::$pageId = $status->value['revision']->getPage(); + self::$revIds['revdel'] = $status->value['revision']->getId(); + + $status = $page->doEditContent( + ContentHandler::makeContent( 'Test for oldid', $title, CONTENT_MODEL_WIKITEXT ), + __METHOD__ . ' Test for oldid', 0, false, $user + ); + if ( !$status->isOk() ) { + $this->fail( "Failed to edit $title: " . $status->getWikiText( false, false, 'en' ) ); + } + self::$revIds['oldid'] = $status->value['revision']->getId(); + + $status = $page->doEditContent( + ContentHandler::makeContent( 'Test for latest', $title, CONTENT_MODEL_WIKITEXT ), + __METHOD__ . ' Test for latest', 0, false, $user + ); + if ( !$status->isOk() ) { + $this->fail( "Failed to edit $title: " . $status->getWikiText( false, false, 'en' ) ); + } + self::$revIds['latest'] = $status->value['revision']->getId(); + + RevisionDeleter::createList( + 'revision', RequestContext::getMain(), $title, [ self::$revIds['revdel'] ] + )->setVisibility( [ + 'value' => [ + Revision::DELETED_TEXT => 1, + ], + 'comment' => 'Test for revdel', + ] ); + + Title::clearCaches(); // Otherwise it has the wrong latest revision for some reason } - public function testParseNonexistentPage() { - $somePage = mt_rand(); + public function testParseByName() { + $res = $this->doApiRequest( [ + 'action' => 'parse', + 'page' => __CLASS__, + ] ); + $this->assertContains( 'Test for latest', $res[0]['parse']['text'] ); + + $res = $this->doApiRequest( [ + 'action' => 'parse', + 'page' => __CLASS__, + 'disablelimitreport' => 1, + ] ); + $this->assertContains( 'Test for latest', $res[0]['parse']['text'] ); + } + + public function testParseById() { + $res = $this->doApiRequest( [ + 'action' => 'parse', + 'pageid' => self::$pageId, + ] ); + $this->assertContains( 'Test for latest', $res[0]['parse']['text'] ); + } + + public function testParseByOldId() { + $res = $this->doApiRequest( [ + 'action' => 'parse', + 'oldid' => self::$revIds['oldid'], + ] ); + $this->assertContains( 'Test for oldid', $res[0]['parse']['text'] ); + $this->assertArrayNotHasKey( 'textdeleted', $res[0]['parse'] ); + $this->assertArrayNotHasKey( 'textsuppressed', $res[0]['parse'] ); + } + + public function testParseRevDel() { + $user = static::getTestUser()->getUser(); + $sysop = static::getTestSysop()->getUser(); try { $this->doApiRequest( [ 'action' => 'parse', - 'page' => $somePage ] ); + 'oldid' => self::$revIds['revdel'], + ], null, null, $user ); + $this->fail( "API did not return an error as expected" ); + } catch ( ApiUsageException $ex ) { + $this->assertTrue( ApiTestCase::apiExceptionHasCode( $ex, 'permissiondenied' ), + "API failed with error 'permissiondenied'" ); + } + + $res = $this->doApiRequest( [ + 'action' => 'parse', + 'oldid' => self::$revIds['revdel'], + ], null, null, $sysop ); + $this->assertContains( 'Test for revdel', $res[0]['parse']['text'] ); + $this->assertArrayHasKey( 'textdeleted', $res[0]['parse'] ); + $this->assertArrayNotHasKey( 'textsuppressed', $res[0]['parse'] ); + } + + public function testParseNonexistentPage() { + try { + $this->doApiRequest( [ + 'action' => 'parse', + 'page' => 'DoesNotExist', + ] ); $this->fail( "API did not return an error when parsing a nonexistent page" ); } catch ( ApiUsageException $ex ) {