wiki.techinc.nl/tests/phpunit/includes/api/ApiRollbackTest.php
MusikAnimal 6a898faed2 Add watchlist expiry support to applicable APIs
This introduces an ApiWatchlistTrait that refactors out common code
across APIs that allow you to watch pages. Some methods have been
migrated from ApiBase and changed completely, but codesearch suggests
they aren't being used outside the API modules in this patch.

Bug: T248512
Bug: T248514
Change-Id: Ia18627b9824dca81f44f0571e8420d89b7626cf6
2020-07-13 18:18:15 -04:00

70 lines
1.7 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
/**
* Tests for Rollback API.
*
* @group API
* @group Database
* @group medium
*
* @covers ApiRollback
*/
class ApiRollbackTest extends ApiTestCase {
protected function setUp(): void {
parent::setUp();
$this->tablesUsed = array_merge(
$this->tablesUsed,
[ 'watchlist', 'watchlist_expiry' ]
);
$this->setMwGlobals( [
'wgWatchlistExpiry' => true,
] );
}
/**
* @covers ApiRollback::execute()
*/
public function testProtectWithWatch(): void {
$name = ucfirst( __FUNCTION__ );
$title = Title::newFromText( $name );
$revLookup = MediaWikiServices::getInstance()
->getRevisionLookup();
$user = $this->getTestUser()->getUser();
$sysop = $this->getTestSysop()->getUser();
// Create page as sysop.
$this->editPage( $name, 'Some text', '', NS_MAIN, $sysop );
// Edit as non-sysop.
$this->editPage( $name, 'Vandalism', '', NS_MAIN, $user );
// Rollback as sysop.
$apiResult = $this->doApiRequestWithToken( [
'action' => 'rollback',
'title' => $name,
'user' => $user->getName(),
'watchlist' => 'watch',
'watchlistexpiry' => '99990123000000',
] )[0];
// Content of latest revision should match the initial.
$latestRev = $revLookup->getRevisionByTitle( $title );
$initialRev = $revLookup->getFirstRevision( $title );
$this->assertTrue( $latestRev->hasSameContent( $initialRev ) );
// ...but have different rev IDs.
$this->assertNotSame( $latestRev->getId(), $initialRev->getId() );
// Make sure the API response looks good.
$this->assertArrayHasKey( 'rollback', $apiResult );
$this->assertSame( $name, $apiResult['rollback']['title'] );
// And that the page was temporarily watched.
$this->assertTrue( $sysop->isTempWatched( $title ) );
}
}