Parsing titles is expensive, it happens in the test function itself via Title::newFromText and also the called editPage() needs to parse the title, better to pass the title object there. Title::newFromText has a cache, that share the title object between the api code and the test code. Use independent title objects for testing. This requires some Title::READ_LATEST to ensure the changed database after the api call is used. Change-Id: I00c14e270a5f4078f80d78696ca2e39acf138e95
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MainConfigNames;
|
|
use MediaWiki\Title\Title;
|
|
|
|
/**
|
|
* Tests for protect API.
|
|
*
|
|
* @group API
|
|
* @group Database
|
|
* @group medium
|
|
*
|
|
* @covers ApiProtect
|
|
*/
|
|
class ApiProtectTest extends ApiTestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
$this->tablesUsed = array_merge(
|
|
$this->tablesUsed,
|
|
[ 'page_restrictions', 'logging', 'watchlist', 'watchlist_expiry' ]
|
|
);
|
|
|
|
$this->overrideConfigValue( MainConfigNames::WatchlistExpiry, true );
|
|
}
|
|
|
|
/**
|
|
* @covers ApiProtect::execute()
|
|
*/
|
|
public function testProtectWithWatch(): void {
|
|
$title = Title::makeTitle( NS_MAIN, 'TestProtectWithWatch' );
|
|
|
|
$this->editPage( $title, 'Some text' );
|
|
|
|
$apiResult = $this->doApiRequestWithToken( [
|
|
'action' => 'protect',
|
|
'title' => $title->getPrefixedText(),
|
|
'protections' => 'edit=sysop',
|
|
'expiry' => '55550123000000',
|
|
'watchlist' => 'watch',
|
|
'watchlistexpiry' => '99990123000000',
|
|
] )[0];
|
|
|
|
$this->assertArrayHasKey( 'protect', $apiResult );
|
|
$this->assertSame( $title->getPrefixedText(), $apiResult['protect']['title'] );
|
|
$this->assertTrue( $this->getServiceContainer()->getRestrictionStore()->isProtected( $title, 'edit' ) );
|
|
$this->assertTrue( $this->getServiceContainer()->getWatchlistManager()->isTempWatched(
|
|
$this->getTestSysop()->getUser(),
|
|
$title
|
|
) );
|
|
}
|
|
}
|