2 use MediaWiki\MediaWikiServices
;
5 * @covers ClearUserWatchlistJob
10 * @licence GNU GPL v2+
13 class ClearUserWatchlistJobTest
extends MediaWikiTestCase
{
15 public function setUp() {
17 self
::$users['ClearUserWatchlistJobTestUser']
18 = new TestUser( 'ClearUserWatchlistJobTestUser' );
20 JobQueueGroup
::destroySingletons();
23 private function getUser() {
24 return self
::$users['ClearUserWatchlistJobTestUser']->getUser();
27 private function runJobs( $jobLimit = 9999 ) {
28 $runJobs = new RunJobs
;
29 $runJobs->loadParamsAndArgs( null, [ 'quiet' => true, 'maxjobs' => $jobLimit ] );
33 private function getWatchedItemStore() {
34 return MediaWikiServices
::getInstance()->getWatchedItemStore();
37 public function testRun() {
38 $user = $this->getUser();
39 $watchedItemStore = $this->getWatchedItemStore();
41 $watchedItemStore->addWatch( $user, new TitleValue( 0, 'A' ) );
42 $watchedItemStore->addWatch( $user, new TitleValue( 1, 'A' ) );
43 $watchedItemStore->addWatch( $user, new TitleValue( 0, 'B' ) );
44 $watchedItemStore->addWatch( $user, new TitleValue( 1, 'B' ) );
46 $maxId = $watchedItemStore->getMaxId();
48 $watchedItemStore->addWatch( $user, new TitleValue( 0, 'C' ) );
49 $watchedItemStore->addWatch( $user, new TitleValue( 1, 'C' ) );
51 $this->setMwGlobals( 'wgUpdateRowsPerQuery', 2 );
53 JobQueueGroup
::singleton()->push(
54 new ClearUserWatchlistJob(
57 'userId' => $user->getId(),
58 'maxWatchlistId' => $maxId,
63 $this->assertEquals( 1, JobQueueGroup
::singleton()->getQueueSizes()['clearUserWatchlist'] );
64 $this->assertEquals( 6, $watchedItemStore->countWatchedItems( $user ) );
66 $this->assertEquals( 1, JobQueueGroup
::singleton()->getQueueSizes()['clearUserWatchlist'] );
67 $this->assertEquals( 4, $watchedItemStore->countWatchedItems( $user ) );
69 $this->assertEquals( 1, JobQueueGroup
::singleton()->getQueueSizes()['clearUserWatchlist'] );
70 $this->assertEquals( 2, $watchedItemStore->countWatchedItems( $user ) );
72 $this->assertEquals( 0, JobQueueGroup
::singleton()->getQueueSizes()['clearUserWatchlist'] );
73 $this->assertEquals( 2, $watchedItemStore->countWatchedItems( $user ) );
75 $this->assertTrue( $watchedItemStore->isWatched( $user, new TitleValue( 0, 'C' ) ) );
76 $this->assertTrue( $watchedItemStore->isWatched( $user, new TitleValue( 1, 'C' ) ) );