2021-02-26 22:47:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
2021-04-13 03:28:23 +00:00
|
|
|
use MediaWiki\Watchlist\WatchlistManager;
|
2021-02-26 22:47:13 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group API
|
|
|
|
|
* @covers ApiWatchlistTrait
|
|
|
|
|
*/
|
2021-04-13 03:28:23 +00:00
|
|
|
class ApiWatchlistTraitTest extends MediaWikiIntegrationTestCase {
|
2021-02-26 22:47:13 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideWatchlistValue
|
|
|
|
|
*/
|
|
|
|
|
public function testWatchlistValue( $watchlistValue, $setOption, $isBot, $isWatched, $expect ) {
|
|
|
|
|
$mock = $this->getMockForTrait( ApiWatchlistTrait::class );
|
|
|
|
|
|
|
|
|
|
// TODO we don't currently test any of the logic that depends on if the title exists
|
|
|
|
|
$user = $this->createMock( User::class );
|
|
|
|
|
$user->method( 'isBot' )->willReturn( $isBot );
|
|
|
|
|
$user->method( 'getBoolOption' )->willReturnCallback(
|
2021-04-29 16:24:12 +00:00
|
|
|
static function ( $optionName ) use ( $setOption ) {
|
2021-02-26 22:47:13 +00:00
|
|
|
if ( $optionName === 'watchdefault' ) {
|
|
|
|
|
return (bool)$setOption;
|
|
|
|
|
}
|
|
|
|
|
// watchcreations is not currently tested, by default it is enabled
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-13 03:28:23 +00:00
|
|
|
$watchlistManager = $this->createMock( WatchlistManager::class );
|
|
|
|
|
$watchlistManager->method( 'isWatchable' )->willReturn( true );
|
|
|
|
|
$watchlistManager->method( 'isWatchedIgnoringRights' )->willReturn( $isWatched );
|
|
|
|
|
$this->setService( 'WatchlistManager', $watchlistManager );
|
|
|
|
|
|
2021-02-26 22:47:13 +00:00
|
|
|
$title = $this->createMock( Title::class );
|
|
|
|
|
$title->method( 'exists' )->willReturn( true );
|
|
|
|
|
|
|
|
|
|
$watch = TestingAccessWrapper::newFromObject( $mock )
|
|
|
|
|
->getWatchlistValue( $watchlistValue, $title, $user, 'watchdefault' );
|
|
|
|
|
$this->assertEquals( $expect, $watch );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideWatchlistValue() {
|
|
|
|
|
return [
|
|
|
|
|
'watch option on unwatched page' => [ 'watch', null, false, false, true ],
|
|
|
|
|
'watch option on watched page' => [ 'watch', null, false, true, true ],
|
|
|
|
|
'unwatch option on unwatched page' => [ 'unwatch', null, false, false, false ],
|
|
|
|
|
'unwatch option on watched page' => [ 'unwatch', null, false, true, false ],
|
|
|
|
|
'preferences set to true on unwatched page' => [ 'preferences', true, false, false, true ],
|
|
|
|
|
'preferences set to false on unwatched page' => [ 'preferences', false, false, false, false ],
|
|
|
|
|
'preferences set to true on unwatched page (bot group)' => [ 'preferences', true, true, false, false ],
|
|
|
|
|
'preferences set to true on watched page (bot group)' => [ 'preferences', true, true, true, true ],
|
|
|
|
|
'preferences set to false on unwatched page (bot group)' => [ 'preferences', false, true, false, false ],
|
|
|
|
|
'preferences set to false on watched page (bot group)' => [ 'preferences', false, true, true, true ],
|
|
|
|
|
'nochange option on watched page' => [ 'nochange', null, false, true, true ],
|
|
|
|
|
'nochange option on unwatched page' => [ 'nochange', null, false, false, false ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|