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