wiki.techinc.nl/tests/phpunit/includes/api/ApiWatchlistTraitTest.php
Umherirrender 950f9d308d [API] Ignore watchlist preferences for bot users
Every user matching User::isBot would be affected and not longer adding
pages to the watchlist along to its (default) preferences.
To override this behaviour the bot user must change watch explizit.

The watchlist is mostly not useful for bots doing massive edits or
uploads. This reduce the grow of the watchlist tables at all and avoids
less users with massive entries unable to delete or clear.

Bug: T258108
Change-Id: If76127315767bde70147197c88e93f51ca70edaa
2020-12-22 22:28:28 +01:00

63 lines
2.4 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
/**
* @covers ApiWatchlistTrait
*/
class ApiWatchlistTraitTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideWatchlistValue
*/
public function testWatchlistValue( $watchlistValue, $setOption, $setGroup, $setWatch, $expect ) {
$mock = $this->getMockForTrait( ApiWatchlistTrait::class );
$user = $this->getTestUser( $setGroup ?? [] )->getUser();
$title = Title::newFromText( 'Help:' . ucfirst( __FUNCTION__ ) );
if ( $setOption !== null ) {
MediaWikiServices::getInstance()
->getUserOptionsManager()
->setOption( $user, 'watchdefault', $setOption );
}
$resetPermission = null;
if ( $setGroup !== null ) {
// User::isBot needs the bot permission along with the bot group
$resetPermission = MediaWikiServices::getInstance()
->getPermissionManager()
->addTemporaryUserRights( $user, $setGroup );
}
$store = MediaWikiServices::getInstance()->getWatchedItemStore();
if ( $setWatch ) {
$store->addWatch( $user, $title );
} else {
$store->removeWatch( $user, $title );
}
$watch = TestingAccessWrapper::newFromObject( $mock )
->getWatchlistValue( $watchlistValue, $title, $user, 'watchdefault' );
$this->assertEquals( $expect, $watch );
}
public function provideWatchlistValue() {
return [
'watch option on unwatched page' => [ 'watch', null, null, false, true ],
'watch option on watched page' => [ 'watch', null, null, true, true ],
'unwatch option on unwatched page' => [ 'unwatch', null, null, false, false ],
'unwatch option on watched page' => [ 'unwatch', null, null, true, false ],
'preferences set to true on unwatched page' => [ 'preferences', true, null, false, true ],
'preferences set to false on unwatched page' => [ 'preferences', false, null, false, false ],
'preferences set to true on unwatched page (bot group)' => [ 'preferences', true, 'bot', false, false ],
'preferences set to true on watched page (bot group)' => [ 'preferences', true, 'bot', true, true ],
'preferences set to false on unwatched page (bot group)' => [ 'preferences', false, 'bot', false, false ],
'preferences set to false on watched page (bot group)' => [ 'preferences', false, 'bot', true, true ],
'nochange option on watched page' => [ 'nochange', null, null, true, true ],
'nochange option on unwatched page' => [ 'nochange', null, null, false, false ],
];
}
}