MediaWiki
REL1_31
ClearUserWatchlistJobTest.php
Go to the documentation of this file.
1
<?php
2
use
MediaWiki\MediaWikiServices
;
3
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
}
ClearUserWatchlistJobTest
ClearUserWatchlistJob.
Definition
ClearUserWatchlistJobTest.php:13
ClearUserWatchlistJobTest\testRun
testRun()
Definition
ClearUserWatchlistJobTest.php:37
ClearUserWatchlistJobTest\getWatchedItemStore
getWatchedItemStore()
Definition
ClearUserWatchlistJobTest.php:33
ClearUserWatchlistJobTest\runJobs
runJobs( $jobLimit=9999)
Definition
ClearUserWatchlistJobTest.php:27
ClearUserWatchlistJobTest\getUser
getUser()
Definition
ClearUserWatchlistJobTest.php:23
ClearUserWatchlistJobTest\setUp
setUp()
Definition
ClearUserWatchlistJobTest.php:15
ClearUserWatchlistJob
Job to clear a users watchlist in batches.
Definition
ClearUserWatchlistJob.php:13
JobQueueGroup\singleton
static singleton( $domain=false)
Definition
JobQueueGroup.php:72
JobQueueGroup\destroySingletons
static destroySingletons()
Destroy the singleton instances.
Definition
JobQueueGroup.php:100
Maintenance\loadParamsAndArgs
loadParamsAndArgs( $self=null, $opts=null, $args=null)
Process command line arguments $mOptions becomes an array with keys set to the option names $mArgs be...
Definition
Maintenance.php:923
MediaWikiTestCase
Definition
MediaWikiTestCase.php:17
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition
MediaWikiTestCase.php:678
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition
MediaWikiServices.php:88
RunJobs
Maintenance script that runs pending jobs.
Definition
runJobs.php:36
TestUser
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition
TestUser.php:7
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition
TitleValue.php:35
tests
phpunit
includes
jobqueue
jobs
ClearUserWatchlistJobTest.php
Generated on Mon Nov 25 2024 15:36:24 for MediaWiki by
1.10.0