| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Api; |
| 4 |
|
| 5 |
use MediaWiki\MainConfigNames; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class ApiProtectTest extends ApiTestCase { |
| 18 |
|
| 19 |
protected function setUp(): void { |
| 20 |
parent::setUp(); |
| 21 |
|
| 22 |
$this->overrideConfigValue( MainConfigNames::WatchlistExpiry, true ); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function testProtectWithWatch(): void { |
| 29 |
$title = Title::makeTitle( NS_MAIN, 'TestProtectWithWatch' ); |
| 30 |
|
| 31 |
$this->editPage( $title, 'Some text' ); |
| 32 |
|
| 33 |
$apiResult = $this->doApiRequestWithToken( [ |
| 34 |
'action' => 'protect', |
| 35 |
'title' => $title->getPrefixedText(), |
| 36 |
'protections' => 'edit=sysop', |
| 37 |
'expiry' => '55550123000000', |
| 38 |
'watchlist' => 'watch', |
| 39 |
'watchlistexpiry' => '99990123000000', |
| 40 |
] )[0]; |
| 41 |
|
| 42 |
$this->assertArrayHasKey( 'protect', $apiResult ); |
| 43 |
$this->assertSame( $title->getPrefixedText(), $apiResult['protect']['title'] ); |
| 44 |
$this->assertTrue( $this->getServiceContainer()->getRestrictionStore()->isProtected( $title, 'edit' ) ); |
| 45 |
$this->assertTrue( $this->getServiceContainer()->getWatchlistManager()->isTempWatched( |
| 46 |
$this->getTestSysop()->getUser(), |
| 47 |
$title |
| 48 |
) ); |
| 49 |
} |
| 50 |
} |