MediaWiki REL1_32
ClearUserWatchlistJobTest.php
Go to the documentation of this file.
1<?php
3
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(
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}
Job to clear a users watchlist in batches.
loadParamsAndArgs( $self=null, $opts=null, $args=null)
Process command line arguments $mOptions becomes an array with keys set to the option names $mArgs be...
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Maintenance script that runs pending jobs.
Definition runJobs.php:36
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition TestUser.php:9
Represents a page (or page fragment) title within MediaWiki.