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
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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->setMwGlobals( [
|
|
'wgWatchlistExpiry' => true,
|
|
] );
|
|
}
|
|
|
|
/**
|
|
* @covers ApiProtect::execute()
|
|
*/
|
|
public function testProtectWithWatch(): void {
|
|
$name = ucfirst( __FUNCTION__ );
|
|
$title = Title::newFromText( $name );
|
|
|
|
$this->editPage( $name, 'Some text' );
|
|
|
|
$apiResult = $this->doApiRequestWithToken( [
|
|
'action' => 'protect',
|
|
'title' => $name,
|
|
'protections' => 'edit=sysop',
|
|
'expiry' => '55550123000000',
|
|
'watchlist' => 'watch',
|
|
'watchlistexpiry' => '99990123000000',
|
|
] )[0];
|
|
|
|
$this->assertArrayHasKey( 'protect', $apiResult );
|
|
$this->assertSame( $name, $apiResult['protect']['title'] );
|
|
$this->assertTrue( $title->isProtected( 'edit' ) );
|
|
$this->assertTrue( $this->getTestSysop()->getUser()->isTempWatched( $title ) );
|
|
}
|
|
}
|