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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37