Fix MediaWiki.Commenting.LicenseComment.InvalidLicenseTag errors
[lhc/web/wiklou.git] / tests / phpunit / includes / jobqueue / jobs / ClearUserWatchlistJobTest.php
1 <?php
2 use MediaWiki\MediaWikiServices;
3
4 /**
5 * @covers ClearUserWatchlistJob
6 *
7 * @group JobQueue
8 * @group Database
9 *
10 * @license GPL-2.0-or-later
11 * @author Addshore
12 */
13 class ClearUserWatchlistJobTest extends MediaWikiTestCase {
14
15 public function setUp() {
16 parent::setUp();
17 self::$users['ClearUserWatchlistJobTestUser']
18 = new TestUser( 'ClearUserWatchlistJobTestUser' );
19 $this->runJobs();
20 JobQueueGroup::destroySingletons();
21 }
22
23 private function getUser() {
24 return self::$users['ClearUserWatchlistJobTestUser']->getUser();
25 }
26
27 private function runJobs( $jobLimit = 9999 ) {
28 $runJobs = new RunJobs;
29 $runJobs->loadParamsAndArgs( null, [ 'quiet' => true, 'maxjobs' => $jobLimit ] );
30 $runJobs->execute();
31 }
32
33 private function getWatchedItemStore() {
34 return MediaWikiServices::getInstance()->getWatchedItemStore();
35 }
36
37 public function testRun() {
38 $user = $this->getUser();
39 $watchedItemStore = $this->getWatchedItemStore();
40
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' ) );
45
46 $maxId = $watchedItemStore->getMaxId();
47
48 $watchedItemStore->addWatch( $user, new TitleValue( 0, 'C' ) );
49 $watchedItemStore->addWatch( $user, new TitleValue( 1, 'C' ) );
50
51 $this->setMwGlobals( 'wgUpdateRowsPerQuery', 2 );
52
53 JobQueueGroup::singleton()->push(
54 new ClearUserWatchlistJob(
55 null,
56 [
57 'userId' => $user->getId(),
58 'maxWatchlistId' => $maxId,
59 ]
60 )
61 );
62
63 $this->assertEquals( 1, JobQueueGroup::singleton()->getQueueSizes()['clearUserWatchlist'] );
64 $this->assertEquals( 6, $watchedItemStore->countWatchedItems( $user ) );
65 $this->runJobs( 1 );
66 $this->assertEquals( 1, JobQueueGroup::singleton()->getQueueSizes()['clearUserWatchlist'] );
67 $this->assertEquals( 4, $watchedItemStore->countWatchedItems( $user ) );
68 $this->runJobs( 1 );
69 $this->assertEquals( 1, JobQueueGroup::singleton()->getQueueSizes()['clearUserWatchlist'] );
70 $this->assertEquals( 2, $watchedItemStore->countWatchedItems( $user ) );
71 $this->runJobs( 1 );
72 $this->assertEquals( 0, JobQueueGroup::singleton()->getQueueSizes()['clearUserWatchlist'] );
73 $this->assertEquals( 2, $watchedItemStore->countWatchedItems( $user ) );
74
75 $this->assertTrue( $watchedItemStore->isWatched( $user, new TitleValue( 0, 'C' ) ) );
76 $this->assertTrue( $watchedItemStore->isWatched( $user, new TitleValue( 1, 'C' ) ) );
77 }
78
79 }