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