2 use MediaWiki\Linker\LinkTarget
;
3 use Wikimedia\ScopedCallback
;
8 * @covers WatchedItemStore
10 class WatchedItemStoreUnitTest
extends MediaWikiTestCase
{
13 * @return PHPUnit_Framework_MockObject_MockObject|IDatabase
15 private function getMockDb() {
16 return $this->getMock( IDatabase
::class );
20 * @return PHPUnit_Framework_MockObject_MockObject|LoadBalancer
22 private function getMockLoadBalancer(
24 $expectedConnectionType = null,
25 $readOnlyReason = false
27 $mock = $this->getMockBuilder( LoadBalancer
::class )
28 ->disableOriginalConstructor()
30 if ( $expectedConnectionType !== null ) {
31 $mock->expects( $this->any() )
32 ->method( 'getConnectionRef' )
33 ->with( $expectedConnectionType )
34 ->will( $this->returnValue( $mockDb ) );
36 $mock->expects( $this->any() )
37 ->method( 'getConnectionRef' )
38 ->will( $this->returnValue( $mockDb ) );
40 $mock->expects( $this->any() )
41 ->method( 'getReadOnlyReason' )
42 ->will( $this->returnValue( $readOnlyReason ) );
47 * @return PHPUnit_Framework_MockObject_MockObject|HashBagOStuff
49 private function getMockCache() {
50 $mock = $this->getMockBuilder( HashBagOStuff
::class )
51 ->disableOriginalConstructor()
53 $mock->expects( $this->any() )
55 ->will( $this->returnCallback( function() {
56 return implode( ':', func_get_args() );
63 * @return PHPUnit_Framework_MockObject_MockObject|User
65 private function getMockNonAnonUserWithId( $id ) {
66 $mock = $this->getMock( User
::class );
67 $mock->expects( $this->any() )
69 ->will( $this->returnValue( false ) );
70 $mock->expects( $this->any() )
72 ->will( $this->returnValue( $id ) );
79 private function getAnonUser() {
80 return User
::newFromName( 'Anon_User' );
83 private function getFakeRow( array $rowValues ) {
84 $fakeRow = new stdClass();
85 foreach ( $rowValues as $valueName => $value ) {
86 $fakeRow->$valueName = $value;
91 private function newWatchedItemStore( LoadBalancer
$loadBalancer, HashBagOStuff
$cache ) {
92 return new WatchedItemStore(
98 public function testCountWatchedItems() {
99 $user = $this->getMockNonAnonUserWithId( 1 );
101 $mockDb = $this->getMockDb();
102 $mockDb->expects( $this->exactly( 1 ) )
103 ->method( 'selectField' )
108 'wl_user' => $user->getId(),
110 $this->isType( 'string' )
112 ->will( $this->returnValue( 12 ) );
114 $mockCache = $this->getMockCache();
115 $mockCache->expects( $this->never() )->method( 'get' );
116 $mockCache->expects( $this->never() )->method( 'set' );
117 $mockCache->expects( $this->never() )->method( 'delete' );
119 $store = $this->newWatchedItemStore(
120 $this->getMockLoadBalancer( $mockDb ),
124 $this->assertEquals( 12, $store->countWatchedItems( $user ) );
127 public function testCountWatchers() {
128 $titleValue = new TitleValue( 0, 'SomeDbKey' );
130 $mockDb = $this->getMockDb();
131 $mockDb->expects( $this->exactly( 1 ) )
132 ->method( 'selectField' )
137 'wl_namespace' => $titleValue->getNamespace(),
138 'wl_title' => $titleValue->getDBkey(),
140 $this->isType( 'string' )
142 ->will( $this->returnValue( 7 ) );
144 $mockCache = $this->getMockCache();
145 $mockCache->expects( $this->never() )->method( 'get' );
146 $mockCache->expects( $this->never() )->method( 'set' );
147 $mockCache->expects( $this->never() )->method( 'delete' );
149 $store = $this->newWatchedItemStore(
150 $this->getMockLoadBalancer( $mockDb ),
154 $this->assertEquals( 7, $store->countWatchers( $titleValue ) );
157 public function testCountWatchersMultiple() {
159 new TitleValue( 0, 'SomeDbKey' ),
160 new TitleValue( 0, 'OtherDbKey' ),
161 new TitleValue( 1, 'AnotherDbKey' ),
164 $mockDb = $this->getMockDb();
167 $this->getFakeRow( [ 'wl_title' => 'SomeDbKey', 'wl_namespace' => 0, 'watchers' => 100 ] ),
168 $this->getFakeRow( [ 'wl_title' => 'OtherDbKey', 'wl_namespace' => 0, 'watchers' => 300 ] ),
169 $this->getFakeRow( [ 'wl_title' => 'AnotherDbKey', 'wl_namespace' => 1, 'watchers' => 500 ]
172 $mockDb->expects( $this->once() )
173 ->method( 'makeWhereFrom2d' )
175 [ [ 'SomeDbKey' => 1, 'OtherDbKey' => 1 ], [ 'AnotherDbKey' => 1 ] ],
176 $this->isType( 'string' ),
177 $this->isType( 'string' )
179 ->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
180 $mockDb->expects( $this->once() )
184 [ 'wl_title', 'wl_namespace', 'watchers' => 'COUNT(*)' ],
185 [ 'makeWhereFrom2d return value' ],
186 $this->isType( 'string' ),
188 'GROUP BY' => [ 'wl_namespace', 'wl_title' ],
192 $this->returnValue( $dbResult )
195 $mockCache = $this->getMockCache();
196 $mockCache->expects( $this->never() )->method( 'get' );
197 $mockCache->expects( $this->never() )->method( 'set' );
198 $mockCache->expects( $this->never() )->method( 'delete' );
200 $store = $this->newWatchedItemStore(
201 $this->getMockLoadBalancer( $mockDb ),
206 0 => [ 'SomeDbKey' => 100, 'OtherDbKey' => 300 ],
207 1 => [ 'AnotherDbKey' => 500 ],
209 $this->assertEquals( $expected, $store->countWatchersMultiple( $titleValues ) );
212 public function provideIntWithDbUnsafeVersion() {
215 [ "50; DROP TABLE watchlist;\n--" ],
220 * @dataProvider provideIntWithDbUnsafeVersion
222 public function testCountWatchersMultiple_withMinimumWatchers( $minWatchers ) {
224 new TitleValue( 0, 'SomeDbKey' ),
225 new TitleValue( 0, 'OtherDbKey' ),
226 new TitleValue( 1, 'AnotherDbKey' ),
229 $mockDb = $this->getMockDb();
232 $this->getFakeRow( [ 'wl_title' => 'SomeDbKey', 'wl_namespace' => 0, 'watchers' => 100 ] ),
233 $this->getFakeRow( [ 'wl_title' => 'OtherDbKey', 'wl_namespace' => 0, 'watchers' => 300 ] ),
234 $this->getFakeRow( [ 'wl_title' => 'AnotherDbKey', 'wl_namespace' => 1, 'watchers' => 500 ]
237 $mockDb->expects( $this->once() )
238 ->method( 'makeWhereFrom2d' )
240 [ [ 'SomeDbKey' => 1, 'OtherDbKey' => 1 ], [ 'AnotherDbKey' => 1 ] ],
241 $this->isType( 'string' ),
242 $this->isType( 'string' )
244 ->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
245 $mockDb->expects( $this->once() )
249 [ 'wl_title', 'wl_namespace', 'watchers' => 'COUNT(*)' ],
250 [ 'makeWhereFrom2d return value' ],
251 $this->isType( 'string' ),
253 'GROUP BY' => [ 'wl_namespace', 'wl_title' ],
254 'HAVING' => 'COUNT(*) >= 50',
258 $this->returnValue( $dbResult )
261 $mockCache = $this->getMockCache();
262 $mockCache->expects( $this->never() )->method( 'get' );
263 $mockCache->expects( $this->never() )->method( 'set' );
264 $mockCache->expects( $this->never() )->method( 'delete' );
266 $store = $this->newWatchedItemStore(
267 $this->getMockLoadBalancer( $mockDb ),
272 0 => [ 'SomeDbKey' => 100, 'OtherDbKey' => 300 ],
273 1 => [ 'AnotherDbKey' => 500 ],
277 $store->countWatchersMultiple( $titleValues, [ 'minimumWatchers' => $minWatchers ] )
281 public function testCountVisitingWatchers() {
282 $titleValue = new TitleValue( 0, 'SomeDbKey' );
284 $mockDb = $this->getMockDb();
285 $mockDb->expects( $this->exactly( 1 ) )
286 ->method( 'selectField' )
291 'wl_namespace' => $titleValue->getNamespace(),
292 'wl_title' => $titleValue->getDBkey(),
293 'wl_notificationtimestamp >= \'TS111TS\' OR wl_notificationtimestamp IS NULL',
295 $this->isType( 'string' )
297 ->will( $this->returnValue( 7 ) );
298 $mockDb->expects( $this->exactly( 1 ) )
299 ->method( 'addQuotes' )
300 ->will( $this->returnCallback( function( $value ) {
303 $mockDb->expects( $this->exactly( 1 ) )
304 ->method( 'timestamp' )
305 ->will( $this->returnCallback( function( $value ) {
306 return 'TS' . $value . 'TS';
309 $mockCache = $this->getMockCache();
310 $mockCache->expects( $this->never() )->method( 'set' );
311 $mockCache->expects( $this->never() )->method( 'get' );
312 $mockCache->expects( $this->never() )->method( 'delete' );
314 $store = $this->newWatchedItemStore(
315 $this->getMockLoadBalancer( $mockDb ),
319 $this->assertEquals( 7, $store->countVisitingWatchers( $titleValue, '111' ) );
322 public function testCountVisitingWatchersMultiple() {
323 $titleValuesWithThresholds = [
324 [ new TitleValue( 0, 'SomeDbKey' ), '111' ],
325 [ new TitleValue( 0, 'OtherDbKey' ), '111' ],
326 [ new TitleValue( 1, 'AnotherDbKey' ), '123' ],
330 $this->getFakeRow( [ 'wl_title' => 'SomeDbKey', 'wl_namespace' => 0, 'watchers' => 100 ] ),
331 $this->getFakeRow( [ 'wl_title' => 'OtherDbKey', 'wl_namespace' => 0, 'watchers' => 300 ] ),
332 $this->getFakeRow( [ 'wl_title' => 'AnotherDbKey', 'wl_namespace' => 1, 'watchers' => 500 ] ),
334 $mockDb = $this->getMockDb();
335 $mockDb->expects( $this->exactly( 2 * 3 ) )
336 ->method( 'addQuotes' )
337 ->will( $this->returnCallback( function( $value ) {
340 $mockDb->expects( $this->exactly( 3 ) )
341 ->method( 'timestamp' )
342 ->will( $this->returnCallback( function( $value ) {
343 return 'TS' . $value . 'TS';
345 $mockDb->expects( $this->any() )
346 ->method( 'makeList' )
348 $this->isType( 'array' ),
349 $this->isType( 'int' )
351 ->will( $this->returnCallback( function( $a, $conj ) {
352 $sqlConj = $conj === LIST_AND ?
' AND ' : ' OR ';
353 return join( $sqlConj, array_map( function( $s ) {
354 return '(' . $s . ')';
358 $mockDb->expects( $this->never() )
359 ->method( 'makeWhereFrom2d' );
362 '((wl_namespace = 0) AND (' .
363 "(((wl_title = 'SomeDbKey') AND (" .
364 "(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
366 "(wl_title = 'OtherDbKey') AND (" .
367 "(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
369 ') OR ((wl_namespace = 1) AND (' .
370 "(((wl_title = 'AnotherDbKey') AND (".
371 "(wl_notificationtimestamp >= 'TS123TS') OR (wl_notificationtimestamp IS NULL)" .
373 $mockDb->expects( $this->once() )
377 [ 'wl_namespace', 'wl_title', 'watchers' => 'COUNT(*)' ],
379 $this->isType( 'string' ),
381 'GROUP BY' => [ 'wl_namespace', 'wl_title' ],
385 $this->returnValue( $dbResult )
388 $mockCache = $this->getMockCache();
389 $mockCache->expects( $this->never() )->method( 'get' );
390 $mockCache->expects( $this->never() )->method( 'set' );
391 $mockCache->expects( $this->never() )->method( 'delete' );
393 $store = $this->newWatchedItemStore(
394 $this->getMockLoadBalancer( $mockDb ),
399 0 => [ 'SomeDbKey' => 100, 'OtherDbKey' => 300 ],
400 1 => [ 'AnotherDbKey' => 500 ],
404 $store->countVisitingWatchersMultiple( $titleValuesWithThresholds )
408 public function testCountVisitingWatchersMultiple_withMissingTargets() {
409 $titleValuesWithThresholds = [
410 [ new TitleValue( 0, 'SomeDbKey' ), '111' ],
411 [ new TitleValue( 0, 'OtherDbKey' ), '111' ],
412 [ new TitleValue( 1, 'AnotherDbKey' ), '123' ],
413 [ new TitleValue( 0, 'SomeNotExisitingDbKey' ), null ],
414 [ new TitleValue( 0, 'OtherNotExisitingDbKey' ), null ],
418 $this->getFakeRow( [ 'wl_title' => 'SomeDbKey', 'wl_namespace' => 0, 'watchers' => 100 ] ),
419 $this->getFakeRow( [ 'wl_title' => 'OtherDbKey', 'wl_namespace' => 0, 'watchers' => 300 ] ),
420 $this->getFakeRow( [ 'wl_title' => 'AnotherDbKey', 'wl_namespace' => 1, 'watchers' => 500 ] ),
422 [ 'wl_title' => 'SomeNotExisitingDbKey', 'wl_namespace' => 0, 'watchers' => 100 ]
425 [ 'wl_title' => 'OtherNotExisitingDbKey', 'wl_namespace' => 0, 'watchers' => 200 ]
428 $mockDb = $this->getMockDb();
429 $mockDb->expects( $this->exactly( 2 * 3 ) )
430 ->method( 'addQuotes' )
431 ->will( $this->returnCallback( function( $value ) {
434 $mockDb->expects( $this->exactly( 3 ) )
435 ->method( 'timestamp' )
436 ->will( $this->returnCallback( function( $value ) {
437 return 'TS' . $value . 'TS';
439 $mockDb->expects( $this->any() )
440 ->method( 'makeList' )
442 $this->isType( 'array' ),
443 $this->isType( 'int' )
445 ->will( $this->returnCallback( function( $a, $conj ) {
446 $sqlConj = $conj === LIST_AND ?
' AND ' : ' OR ';
447 return join( $sqlConj, array_map( function( $s ) {
448 return '(' . $s . ')';
452 $mockDb->expects( $this->once() )
453 ->method( 'makeWhereFrom2d' )
455 [ [ 'SomeNotExisitingDbKey' => 1, 'OtherNotExisitingDbKey' => 1 ] ],
456 $this->isType( 'string' ),
457 $this->isType( 'string' )
459 ->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
462 '((wl_namespace = 0) AND (' .
463 "(((wl_title = 'SomeDbKey') AND (" .
464 "(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
466 "(wl_title = 'OtherDbKey') AND (" .
467 "(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
469 ') OR ((wl_namespace = 1) AND (' .
470 "(((wl_title = 'AnotherDbKey') AND (".
471 "(wl_notificationtimestamp >= 'TS123TS') OR (wl_notificationtimestamp IS NULL)" .
474 '(makeWhereFrom2d return value)';
475 $mockDb->expects( $this->once() )
479 [ 'wl_namespace', 'wl_title', 'watchers' => 'COUNT(*)' ],
481 $this->isType( 'string' ),
483 'GROUP BY' => [ 'wl_namespace', 'wl_title' ],
487 $this->returnValue( $dbResult )
490 $mockCache = $this->getMockCache();
491 $mockCache->expects( $this->never() )->method( 'get' );
492 $mockCache->expects( $this->never() )->method( 'set' );
493 $mockCache->expects( $this->never() )->method( 'delete' );
495 $store = $this->newWatchedItemStore(
496 $this->getMockLoadBalancer( $mockDb ),
502 'SomeDbKey' => 100, 'OtherDbKey' => 300,
503 'SomeNotExisitingDbKey' => 100, 'OtherNotExisitingDbKey' => 200
505 1 => [ 'AnotherDbKey' => 500 ],
509 $store->countVisitingWatchersMultiple( $titleValuesWithThresholds )
514 * @dataProvider provideIntWithDbUnsafeVersion
516 public function testCountVisitingWatchersMultiple_withMinimumWatchers( $minWatchers ) {
517 $titleValuesWithThresholds = [
518 [ new TitleValue( 0, 'SomeDbKey' ), '111' ],
519 [ new TitleValue( 0, 'OtherDbKey' ), '111' ],
520 [ new TitleValue( 1, 'AnotherDbKey' ), '123' ],
523 $mockDb = $this->getMockDb();
524 $mockDb->expects( $this->any() )
525 ->method( 'makeList' )
526 ->will( $this->returnValue( 'makeList return value' ) );
527 $mockDb->expects( $this->once() )
531 [ 'wl_namespace', 'wl_title', 'watchers' => 'COUNT(*)' ],
532 'makeList return value',
533 $this->isType( 'string' ),
535 'GROUP BY' => [ 'wl_namespace', 'wl_title' ],
536 'HAVING' => 'COUNT(*) >= 50',
540 $this->returnValue( [] )
543 $mockCache = $this->getMockCache();
544 $mockCache->expects( $this->never() )->method( 'get' );
545 $mockCache->expects( $this->never() )->method( 'set' );
546 $mockCache->expects( $this->never() )->method( 'delete' );
548 $store = $this->newWatchedItemStore(
549 $this->getMockLoadBalancer( $mockDb ),
554 0 => [ 'SomeDbKey' => 0, 'OtherDbKey' => 0 ],
555 1 => [ 'AnotherDbKey' => 0 ],
559 $store->countVisitingWatchersMultiple( $titleValuesWithThresholds, $minWatchers )
563 public function testCountUnreadNotifications() {
564 $user = $this->getMockNonAnonUserWithId( 1 );
566 $mockDb = $this->getMockDb();
567 $mockDb->expects( $this->exactly( 1 ) )
568 ->method( 'selectRowCount' )
573 "wl_notificationtimestamp IS NOT NULL",
576 $this->isType( 'string' )
578 ->will( $this->returnValue( 9 ) );
580 $mockCache = $this->getMockCache();
581 $mockCache->expects( $this->never() )->method( 'set' );
582 $mockCache->expects( $this->never() )->method( 'get' );
583 $mockCache->expects( $this->never() )->method( 'delete' );
585 $store = $this->newWatchedItemStore(
586 $this->getMockLoadBalancer( $mockDb ),
590 $this->assertEquals( 9, $store->countUnreadNotifications( $user ) );
594 * @dataProvider provideIntWithDbUnsafeVersion
596 public function testCountUnreadNotifications_withUnreadLimit_overLimit( $limit ) {
597 $user = $this->getMockNonAnonUserWithId( 1 );
599 $mockDb = $this->getMockDb();
600 $mockDb->expects( $this->exactly( 1 ) )
601 ->method( 'selectRowCount' )
606 "wl_notificationtimestamp IS NOT NULL",
609 $this->isType( 'string' ),
612 ->will( $this->returnValue( 50 ) );
614 $mockCache = $this->getMockCache();
615 $mockCache->expects( $this->never() )->method( 'set' );
616 $mockCache->expects( $this->never() )->method( 'get' );
617 $mockCache->expects( $this->never() )->method( 'delete' );
619 $store = $this->newWatchedItemStore(
620 $this->getMockLoadBalancer( $mockDb ),
626 $store->countUnreadNotifications( $user, $limit )
631 * @dataProvider provideIntWithDbUnsafeVersion
633 public function testCountUnreadNotifications_withUnreadLimit_underLimit( $limit ) {
634 $user = $this->getMockNonAnonUserWithId( 1 );
636 $mockDb = $this->getMockDb();
637 $mockDb->expects( $this->exactly( 1 ) )
638 ->method( 'selectRowCount' )
643 "wl_notificationtimestamp IS NOT NULL",
646 $this->isType( 'string' ),
649 ->will( $this->returnValue( 9 ) );
651 $mockCache = $this->getMockCache();
652 $mockCache->expects( $this->never() )->method( 'set' );
653 $mockCache->expects( $this->never() )->method( 'get' );
654 $mockCache->expects( $this->never() )->method( 'delete' );
656 $store = $this->newWatchedItemStore(
657 $this->getMockLoadBalancer( $mockDb ),
663 $store->countUnreadNotifications( $user, $limit )
667 public function testDuplicateEntry_nothingToDuplicate() {
668 $mockDb = $this->getMockDb();
669 $mockDb->expects( $this->once() )
675 'wl_notificationtimestamp',
679 'wl_title' => 'Old_Title',
681 'WatchedItemStore::duplicateEntry',
684 ->will( $this->returnValue( new FakeResultWrapper( [] ) ) );
686 $store = $this->newWatchedItemStore(
687 $this->getMockLoadBalancer( $mockDb ),
688 $this->getMockCache()
691 $store->duplicateEntry(
692 Title
::newFromText( 'Old_Title' ),
693 Title
::newFromText( 'New_Title' )
697 public function testDuplicateEntry_somethingToDuplicate() {
699 $this->getFakeRow( [ 'wl_user' => 1, 'wl_notificationtimestamp' => '20151212010101' ] ),
700 $this->getFakeRow( [ 'wl_user' => 2, 'wl_notificationtimestamp' => null ] ),
703 $mockDb = $this->getMockDb();
704 $mockDb->expects( $this->at( 0 ) )
710 'wl_notificationtimestamp',
714 'wl_title' => 'Old_Title',
717 ->will( $this->returnValue( new FakeResultWrapper( $fakeRows ) ) );
718 $mockDb->expects( $this->at( 1 ) )
719 ->method( 'replace' )
722 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
727 'wl_title' => 'New_Title',
728 'wl_notificationtimestamp' => '20151212010101',
733 'wl_title' => 'New_Title',
734 'wl_notificationtimestamp' => null,
737 $this->isType( 'string' )
740 $mockCache = $this->getMockCache();
741 $mockCache->expects( $this->never() )->method( 'get' );
742 $mockCache->expects( $this->never() )->method( 'delete' );
744 $store = $this->newWatchedItemStore(
745 $this->getMockLoadBalancer( $mockDb ),
749 $store->duplicateEntry(
750 Title
::newFromText( 'Old_Title' ),
751 Title
::newFromText( 'New_Title' )
755 public function testDuplicateAllAssociatedEntries_nothingToDuplicate() {
756 $mockDb = $this->getMockDb();
757 $mockDb->expects( $this->at( 0 ) )
763 'wl_notificationtimestamp',
767 'wl_title' => 'Old_Title',
770 ->will( $this->returnValue( new FakeResultWrapper( [] ) ) );
771 $mockDb->expects( $this->at( 1 ) )
777 'wl_notificationtimestamp',
781 'wl_title' => 'Old_Title',
784 ->will( $this->returnValue( new FakeResultWrapper( [] ) ) );
786 $mockCache = $this->getMockCache();
787 $mockCache->expects( $this->never() )->method( 'get' );
788 $mockCache->expects( $this->never() )->method( 'delete' );
790 $store = $this->newWatchedItemStore(
791 $this->getMockLoadBalancer( $mockDb ),
795 $store->duplicateAllAssociatedEntries(
796 Title
::newFromText( 'Old_Title' ),
797 Title
::newFromText( 'New_Title' )
801 public function provideLinkTargetPairs() {
803 [ Title
::newFromText( 'Old_Title' ), Title
::newFromText( 'New_Title' ) ],
804 [ new TitleValue( 0, 'Old_Title' ), new TitleValue( 0, 'New_Title' ) ],
809 * @dataProvider provideLinkTargetPairs
811 public function testDuplicateAllAssociatedEntries_somethingToDuplicate(
812 LinkTarget
$oldTarget,
813 LinkTarget
$newTarget
816 $this->getFakeRow( [ 'wl_user' => 1, 'wl_notificationtimestamp' => '20151212010101' ] ),
819 $mockDb = $this->getMockDb();
820 $mockDb->expects( $this->at( 0 ) )
826 'wl_notificationtimestamp',
829 'wl_namespace' => $oldTarget->getNamespace(),
830 'wl_title' => $oldTarget->getDBkey(),
833 ->will( $this->returnValue( new FakeResultWrapper( $fakeRows ) ) );
834 $mockDb->expects( $this->at( 1 ) )
835 ->method( 'replace' )
838 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
842 'wl_namespace' => $newTarget->getNamespace(),
843 'wl_title' => $newTarget->getDBkey(),
844 'wl_notificationtimestamp' => '20151212010101',
847 $this->isType( 'string' )
849 $mockDb->expects( $this->at( 2 ) )
855 'wl_notificationtimestamp',
858 'wl_namespace' => $oldTarget->getNamespace() +
1,
859 'wl_title' => $oldTarget->getDBkey(),
862 ->will( $this->returnValue( new FakeResultWrapper( $fakeRows ) ) );
863 $mockDb->expects( $this->at( 3 ) )
864 ->method( 'replace' )
867 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
871 'wl_namespace' => $newTarget->getNamespace() +
1,
872 'wl_title' => $newTarget->getDBkey(),
873 'wl_notificationtimestamp' => '20151212010101',
876 $this->isType( 'string' )
879 $mockCache = $this->getMockCache();
880 $mockCache->expects( $this->never() )->method( 'get' );
881 $mockCache->expects( $this->never() )->method( 'delete' );
883 $store = $this->newWatchedItemStore(
884 $this->getMockLoadBalancer( $mockDb ),
888 $store->duplicateAllAssociatedEntries(
894 public function testAddWatch_nonAnonymousUser() {
895 $mockDb = $this->getMockDb();
896 $mockDb->expects( $this->once() )
904 'wl_title' => 'Some_Page',
905 'wl_notificationtimestamp' => null,
910 $mockCache = $this->getMockCache();
911 $mockCache->expects( $this->once() )
913 ->with( '0:Some_Page:1' );
915 $store = $this->newWatchedItemStore(
916 $this->getMockLoadBalancer( $mockDb ),
921 $this->getMockNonAnonUserWithId( 1 ),
922 Title
::newFromText( 'Some_Page' )
926 public function testAddWatch_anonymousUser() {
927 $mockDb = $this->getMockDb();
928 $mockDb->expects( $this->never() )
929 ->method( 'insert' );
931 $mockCache = $this->getMockCache();
932 $mockCache->expects( $this->never() )
933 ->method( 'delete' );
935 $store = $this->newWatchedItemStore(
936 $this->getMockLoadBalancer( $mockDb ),
941 $this->getAnonUser(),
942 Title
::newFromText( 'Some_Page' )
946 public function testAddWatchBatchForUser_readOnlyDBReturnsFalse() {
947 $store = $this->newWatchedItemStore(
948 $this->getMockLoadBalancer( $this->getMockDb(), null, 'Some Reason' ),
949 $this->getMockCache()
953 $store->addWatchBatchForUser(
954 $this->getMockNonAnonUserWithId( 1 ),
955 [ new TitleValue( 0, 'Some_Page' ), new TitleValue( 1, 'Some_Page' ) ]
960 public function testAddWatchBatchForUser_nonAnonymousUser() {
961 $mockDb = $this->getMockDb();
962 $mockDb->expects( $this->once() )
970 'wl_title' => 'Some_Page',
971 'wl_notificationtimestamp' => null,
976 'wl_title' => 'Some_Page',
977 'wl_notificationtimestamp' => null,
982 $mockCache = $this->getMockCache();
983 $mockCache->expects( $this->exactly( 2 ) )
984 ->method( 'delete' );
985 $mockCache->expects( $this->at( 1 ) )
987 ->with( '0:Some_Page:1' );
988 $mockCache->expects( $this->at( 3 ) )
990 ->with( '1:Some_Page:1' );
992 $store = $this->newWatchedItemStore(
993 $this->getMockLoadBalancer( $mockDb ),
997 $mockUser = $this->getMockNonAnonUserWithId( 1 );
1000 $store->addWatchBatchForUser(
1002 [ new TitleValue( 0, 'Some_Page' ), new TitleValue( 1, 'Some_Page' ) ]
1007 public function testAddWatchBatchForUser_anonymousUsersAreSkipped() {
1008 $mockDb = $this->getMockDb();
1009 $mockDb->expects( $this->never() )
1010 ->method( 'insert' );
1012 $mockCache = $this->getMockCache();
1013 $mockCache->expects( $this->never() )
1014 ->method( 'delete' );
1016 $store = $this->newWatchedItemStore(
1017 $this->getMockLoadBalancer( $mockDb ),
1022 $store->addWatchBatchForUser(
1023 $this->getAnonUser(),
1024 [ new TitleValue( 0, 'Other_Page' ) ]
1029 public function testAddWatchBatchReturnsTrue_whenGivenEmptyList() {
1030 $user = $this->getMockNonAnonUserWithId( 1 );
1031 $mockDb = $this->getMockDb();
1032 $mockDb->expects( $this->never() )
1033 ->method( 'insert' );
1035 $mockCache = $this->getMockCache();
1036 $mockCache->expects( $this->never() )
1037 ->method( 'delete' );
1039 $store = $this->newWatchedItemStore(
1040 $this->getMockLoadBalancer( $mockDb ),
1045 $store->addWatchBatchForUser( $user, [] )
1049 public function testLoadWatchedItem_existingItem() {
1050 $mockDb = $this->getMockDb();
1051 $mockDb->expects( $this->once() )
1052 ->method( 'selectRow' )
1055 'wl_notificationtimestamp',
1058 'wl_namespace' => 0,
1059 'wl_title' => 'SomeDbKey',
1062 ->will( $this->returnValue(
1063 $this->getFakeRow( [ 'wl_notificationtimestamp' => '20151212010101' ] )
1066 $mockCache = $this->getMockCache();
1067 $mockCache->expects( $this->once() )
1073 $store = $this->newWatchedItemStore(
1074 $this->getMockLoadBalancer( $mockDb ),
1078 $watchedItem = $store->loadWatchedItem(
1079 $this->getMockNonAnonUserWithId( 1 ),
1080 new TitleValue( 0, 'SomeDbKey' )
1082 $this->assertInstanceOf( 'WatchedItem', $watchedItem );
1083 $this->assertEquals( 1, $watchedItem->getUser()->getId() );
1084 $this->assertEquals( 'SomeDbKey', $watchedItem->getLinkTarget()->getDBkey() );
1085 $this->assertEquals( 0, $watchedItem->getLinkTarget()->getNamespace() );
1088 public function testLoadWatchedItem_noItem() {
1089 $mockDb = $this->getMockDb();
1090 $mockDb->expects( $this->once() )
1091 ->method( 'selectRow' )
1094 'wl_notificationtimestamp',
1097 'wl_namespace' => 0,
1098 'wl_title' => 'SomeDbKey',
1101 ->will( $this->returnValue( [] ) );
1103 $mockCache = $this->getMockCache();
1104 $mockCache->expects( $this->never() )->method( 'get' );
1105 $mockCache->expects( $this->never() )->method( 'delete' );
1107 $store = $this->newWatchedItemStore(
1108 $this->getMockLoadBalancer( $mockDb ),
1113 $store->loadWatchedItem(
1114 $this->getMockNonAnonUserWithId( 1 ),
1115 new TitleValue( 0, 'SomeDbKey' )
1120 public function testLoadWatchedItem_anonymousUser() {
1121 $mockDb = $this->getMockDb();
1122 $mockDb->expects( $this->never() )
1123 ->method( 'selectRow' );
1125 $mockCache = $this->getMockCache();
1126 $mockCache->expects( $this->never() )->method( 'get' );
1127 $mockCache->expects( $this->never() )->method( 'delete' );
1129 $store = $this->newWatchedItemStore(
1130 $this->getMockLoadBalancer( $mockDb ),
1135 $store->loadWatchedItem(
1136 $this->getAnonUser(),
1137 new TitleValue( 0, 'SomeDbKey' )
1142 public function testRemoveWatch_existingItem() {
1143 $mockDb = $this->getMockDb();
1144 $mockDb->expects( $this->once() )
1145 ->method( 'delete' )
1150 'wl_namespace' => 0,
1151 'wl_title' => 'SomeDbKey',
1154 $mockDb->expects( $this->once() )
1155 ->method( 'affectedRows' )
1156 ->will( $this->returnValue( 1 ) );
1158 $mockCache = $this->getMockCache();
1159 $mockCache->expects( $this->never() )->method( 'get' );
1160 $mockCache->expects( $this->once() )
1161 ->method( 'delete' )
1162 ->with( '0:SomeDbKey:1' );
1164 $store = $this->newWatchedItemStore(
1165 $this->getMockLoadBalancer( $mockDb ),
1170 $store->removeWatch(
1171 $this->getMockNonAnonUserWithId( 1 ),
1172 new TitleValue( 0, 'SomeDbKey' )
1177 public function testRemoveWatch_noItem() {
1178 $mockDb = $this->getMockDb();
1179 $mockDb->expects( $this->once() )
1180 ->method( 'delete' )
1185 'wl_namespace' => 0,
1186 'wl_title' => 'SomeDbKey',
1189 $mockDb->expects( $this->once() )
1190 ->method( 'affectedRows' )
1191 ->will( $this->returnValue( 0 ) );
1193 $mockCache = $this->getMockCache();
1194 $mockCache->expects( $this->never() )->method( 'get' );
1195 $mockCache->expects( $this->once() )
1196 ->method( 'delete' )
1197 ->with( '0:SomeDbKey:1' );
1199 $store = $this->newWatchedItemStore(
1200 $this->getMockLoadBalancer( $mockDb ),
1205 $store->removeWatch(
1206 $this->getMockNonAnonUserWithId( 1 ),
1207 new TitleValue( 0, 'SomeDbKey' )
1212 public function testRemoveWatch_anonymousUser() {
1213 $mockDb = $this->getMockDb();
1214 $mockDb->expects( $this->never() )
1215 ->method( 'delete' );
1217 $mockCache = $this->getMockCache();
1218 $mockCache->expects( $this->never() )->method( 'get' );
1219 $mockCache->expects( $this->never() )
1220 ->method( 'delete' );
1222 $store = $this->newWatchedItemStore(
1223 $this->getMockLoadBalancer( $mockDb ),
1228 $store->removeWatch(
1229 $this->getAnonUser(),
1230 new TitleValue( 0, 'SomeDbKey' )
1235 public function testGetWatchedItem_existingItem() {
1236 $mockDb = $this->getMockDb();
1237 $mockDb->expects( $this->once() )
1238 ->method( 'selectRow' )
1241 'wl_notificationtimestamp',
1244 'wl_namespace' => 0,
1245 'wl_title' => 'SomeDbKey',
1248 ->will( $this->returnValue(
1249 $this->getFakeRow( [ 'wl_notificationtimestamp' => '20151212010101' ] )
1252 $mockCache = $this->getMockCache();
1253 $mockCache->expects( $this->never() )->method( 'delete' );
1254 $mockCache->expects( $this->once() )
1259 ->will( $this->returnValue( null ) );
1260 $mockCache->expects( $this->once() )
1266 $store = $this->newWatchedItemStore(
1267 $this->getMockLoadBalancer( $mockDb ),
1271 $watchedItem = $store->getWatchedItem(
1272 $this->getMockNonAnonUserWithId( 1 ),
1273 new TitleValue( 0, 'SomeDbKey' )
1275 $this->assertInstanceOf( 'WatchedItem', $watchedItem );
1276 $this->assertEquals( 1, $watchedItem->getUser()->getId() );
1277 $this->assertEquals( 'SomeDbKey', $watchedItem->getLinkTarget()->getDBkey() );
1278 $this->assertEquals( 0, $watchedItem->getLinkTarget()->getNamespace() );
1281 public function testGetWatchedItem_cachedItem() {
1282 $mockDb = $this->getMockDb();
1283 $mockDb->expects( $this->never() )
1284 ->method( 'selectRow' );
1286 $mockUser = $this->getMockNonAnonUserWithId( 1 );
1287 $linkTarget = new TitleValue( 0, 'SomeDbKey' );
1288 $cachedItem = new WatchedItem( $mockUser, $linkTarget, '20151212010101' );
1290 $mockCache = $this->getMockCache();
1291 $mockCache->expects( $this->never() )->method( 'delete' );
1292 $mockCache->expects( $this->never() )->method( 'set' );
1293 $mockCache->expects( $this->once() )
1298 ->will( $this->returnValue( $cachedItem ) );
1300 $store = $this->newWatchedItemStore(
1301 $this->getMockLoadBalancer( $mockDb ),
1305 $this->assertEquals(
1307 $store->getWatchedItem(
1314 public function testGetWatchedItem_noItem() {
1315 $mockDb = $this->getMockDb();
1316 $mockDb->expects( $this->once() )
1317 ->method( 'selectRow' )
1320 'wl_notificationtimestamp',
1323 'wl_namespace' => 0,
1324 'wl_title' => 'SomeDbKey',
1327 ->will( $this->returnValue( [] ) );
1329 $mockCache = $this->getMockCache();
1330 $mockCache->expects( $this->never() )->method( 'set' );
1331 $mockCache->expects( $this->never() )->method( 'delete' );
1332 $mockCache->expects( $this->once() )
1334 ->with( '0:SomeDbKey:1' )
1335 ->will( $this->returnValue( false ) );
1337 $store = $this->newWatchedItemStore(
1338 $this->getMockLoadBalancer( $mockDb ),
1343 $store->getWatchedItem(
1344 $this->getMockNonAnonUserWithId( 1 ),
1345 new TitleValue( 0, 'SomeDbKey' )
1350 public function testGetWatchedItem_anonymousUser() {
1351 $mockDb = $this->getMockDb();
1352 $mockDb->expects( $this->never() )
1353 ->method( 'selectRow' );
1355 $mockCache = $this->getMockCache();
1356 $mockCache->expects( $this->never() )->method( 'set' );
1357 $mockCache->expects( $this->never() )->method( 'get' );
1358 $mockCache->expects( $this->never() )->method( 'delete' );
1360 $store = $this->newWatchedItemStore(
1361 $this->getMockLoadBalancer( $mockDb ),
1366 $store->getWatchedItem(
1367 $this->getAnonUser(),
1368 new TitleValue( 0, 'SomeDbKey' )
1373 public function testGetWatchedItemsForUser() {
1374 $mockDb = $this->getMockDb();
1375 $mockDb->expects( $this->once() )
1376 ->method( 'select' )
1379 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
1382 ->will( $this->returnValue( [
1383 $this->getFakeRow( [
1384 'wl_namespace' => 0,
1385 'wl_title' => 'Foo1',
1386 'wl_notificationtimestamp' => '20151212010101',
1388 $this->getFakeRow( [
1389 'wl_namespace' => 1,
1390 'wl_title' => 'Foo2',
1391 'wl_notificationtimestamp' => null,
1395 $mockCache = $this->getMockCache();
1396 $mockCache->expects( $this->never() )->method( 'delete' );
1397 $mockCache->expects( $this->never() )->method( 'get' );
1398 $mockCache->expects( $this->never() )->method( 'set' );
1400 $store = $this->newWatchedItemStore(
1401 $this->getMockLoadBalancer( $mockDb ),
1404 $user = $this->getMockNonAnonUserWithId( 1 );
1406 $watchedItems = $store->getWatchedItemsForUser( $user );
1408 $this->assertInternalType( 'array', $watchedItems );
1409 $this->assertCount( 2, $watchedItems );
1410 foreach ( $watchedItems as $watchedItem ) {
1411 $this->assertInstanceOf( 'WatchedItem', $watchedItem );
1413 $this->assertEquals(
1414 new WatchedItem( $user, new TitleValue( 0, 'Foo1' ), '20151212010101' ),
1417 $this->assertEquals(
1418 new WatchedItem( $user, new TitleValue( 1, 'Foo2' ), null ),
1423 public function provideDbTypes() {
1425 [ false, DB_SLAVE
],
1426 [ true, DB_MASTER
],
1431 * @dataProvider provideDbTypes
1433 public function testGetWatchedItemsForUser_optionsAndEmptyResult( $forWrite, $dbType ) {
1434 $mockDb = $this->getMockDb();
1435 $mockCache = $this->getMockCache();
1436 $mockLoadBalancer = $this->getMockLoadBalancer( $mockDb, $dbType );
1437 $user = $this->getMockNonAnonUserWithId( 1 );
1439 $mockDb->expects( $this->once() )
1440 ->method( 'select' )
1443 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
1445 $this->isType( 'string' ),
1446 [ 'ORDER BY' => [ 'wl_namespace ASC', 'wl_title ASC' ] ]
1448 ->will( $this->returnValue( [] ) );
1450 $store = $this->newWatchedItemStore(
1455 $watchedItems = $store->getWatchedItemsForUser(
1457 [ 'forWrite' => $forWrite, 'sort' => WatchedItemStore
::SORT_ASC
]
1459 $this->assertEquals( [], $watchedItems );
1462 public function testGetWatchedItemsForUser_badSortOptionThrowsException() {
1463 $store = $this->newWatchedItemStore(
1464 $this->getMockLoadBalancer( $this->getMockDb() ),
1465 $this->getMockCache()
1468 $this->setExpectedException( 'InvalidArgumentException' );
1469 $store->getWatchedItemsForUser(
1470 $this->getMockNonAnonUserWithId( 1 ),
1475 public function testIsWatchedItem_existingItem() {
1476 $mockDb = $this->getMockDb();
1477 $mockDb->expects( $this->once() )
1478 ->method( 'selectRow' )
1481 'wl_notificationtimestamp',
1484 'wl_namespace' => 0,
1485 'wl_title' => 'SomeDbKey',
1488 ->will( $this->returnValue(
1489 $this->getFakeRow( [ 'wl_notificationtimestamp' => '20151212010101' ] )
1492 $mockCache = $this->getMockCache();
1493 $mockCache->expects( $this->never() )->method( 'delete' );
1494 $mockCache->expects( $this->once() )
1496 ->with( '0:SomeDbKey:1' )
1497 ->will( $this->returnValue( false ) );
1498 $mockCache->expects( $this->once() )
1504 $store = $this->newWatchedItemStore(
1505 $this->getMockLoadBalancer( $mockDb ),
1511 $this->getMockNonAnonUserWithId( 1 ),
1512 new TitleValue( 0, 'SomeDbKey' )
1517 public function testIsWatchedItem_noItem() {
1518 $mockDb = $this->getMockDb();
1519 $mockDb->expects( $this->once() )
1520 ->method( 'selectRow' )
1523 'wl_notificationtimestamp',
1526 'wl_namespace' => 0,
1527 'wl_title' => 'SomeDbKey',
1530 ->will( $this->returnValue( [] ) );
1532 $mockCache = $this->getMockCache();
1533 $mockCache->expects( $this->never() )->method( 'set' );
1534 $mockCache->expects( $this->never() )->method( 'delete' );
1535 $mockCache->expects( $this->once() )
1537 ->with( '0:SomeDbKey:1' )
1538 ->will( $this->returnValue( false ) );
1540 $store = $this->newWatchedItemStore(
1541 $this->getMockLoadBalancer( $mockDb ),
1547 $this->getMockNonAnonUserWithId( 1 ),
1548 new TitleValue( 0, 'SomeDbKey' )
1553 public function testIsWatchedItem_anonymousUser() {
1554 $mockDb = $this->getMockDb();
1555 $mockDb->expects( $this->never() )
1556 ->method( 'selectRow' );
1558 $mockCache = $this->getMockCache();
1559 $mockCache->expects( $this->never() )->method( 'set' );
1560 $mockCache->expects( $this->never() )->method( 'get' );
1561 $mockCache->expects( $this->never() )->method( 'delete' );
1563 $store = $this->newWatchedItemStore(
1564 $this->getMockLoadBalancer( $mockDb ),
1570 $this->getAnonUser(),
1571 new TitleValue( 0, 'SomeDbKey' )
1576 public function testGetNotificationTimestampsBatch() {
1578 new TitleValue( 0, 'SomeDbKey' ),
1579 new TitleValue( 1, 'AnotherDbKey' ),
1582 $mockDb = $this->getMockDb();
1584 $this->getFakeRow( [
1585 'wl_namespace' => 0,
1586 'wl_title' => 'SomeDbKey',
1587 'wl_notificationtimestamp' => '20151212010101',
1591 'wl_namespace' => 1,
1592 'wl_title' => 'AnotherDbKey',
1593 'wl_notificationtimestamp' => null,
1598 $mockDb->expects( $this->once() )
1599 ->method( 'makeWhereFrom2d' )
1601 [ [ 'SomeDbKey' => 1 ], [ 'AnotherDbKey' => 1 ] ],
1602 $this->isType( 'string' ),
1603 $this->isType( 'string' )
1605 ->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
1606 $mockDb->expects( $this->once() )
1607 ->method( 'select' )
1610 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
1612 'makeWhereFrom2d return value',
1615 $this->isType( 'string' )
1617 ->will( $this->returnValue( $dbResult ) );
1619 $mockCache = $this->getMockCache();
1620 $mockCache->expects( $this->exactly( 2 ) )
1623 [ '0:SomeDbKey:1' ],
1624 [ '1:AnotherDbKey:1' ]
1626 ->will( $this->returnValue( null ) );
1627 $mockCache->expects( $this->never() )->method( 'set' );
1628 $mockCache->expects( $this->never() )->method( 'delete' );
1630 $store = $this->newWatchedItemStore(
1631 $this->getMockLoadBalancer( $mockDb ),
1635 $this->assertEquals(
1637 0 => [ 'SomeDbKey' => '20151212010101', ],
1638 1 => [ 'AnotherDbKey' => null, ],
1640 $store->getNotificationTimestampsBatch( $this->getMockNonAnonUserWithId( 1 ), $targets )
1644 public function testGetNotificationTimestampsBatch_notWatchedTarget() {
1646 new TitleValue( 0, 'OtherDbKey' ),
1649 $mockDb = $this->getMockDb();
1651 $mockDb->expects( $this->once() )
1652 ->method( 'makeWhereFrom2d' )
1654 [ [ 'OtherDbKey' => 1 ] ],
1655 $this->isType( 'string' ),
1656 $this->isType( 'string' )
1658 ->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
1659 $mockDb->expects( $this->once() )
1660 ->method( 'select' )
1663 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
1665 'makeWhereFrom2d return value',
1668 $this->isType( 'string' )
1670 ->will( $this->returnValue( $this->getFakeRow( [] ) ) );
1672 $mockCache = $this->getMockCache();
1673 $mockCache->expects( $this->once() )
1675 ->with( '0:OtherDbKey:1' )
1676 ->will( $this->returnValue( null ) );
1677 $mockCache->expects( $this->never() )->method( 'set' );
1678 $mockCache->expects( $this->never() )->method( 'delete' );
1680 $store = $this->newWatchedItemStore(
1681 $this->getMockLoadBalancer( $mockDb ),
1685 $this->assertEquals(
1687 0 => [ 'OtherDbKey' => false, ],
1689 $store->getNotificationTimestampsBatch( $this->getMockNonAnonUserWithId( 1 ), $targets )
1693 public function testGetNotificationTimestampsBatch_cachedItem() {
1695 new TitleValue( 0, 'SomeDbKey' ),
1696 new TitleValue( 1, 'AnotherDbKey' ),
1699 $user = $this->getMockNonAnonUserWithId( 1 );
1700 $cachedItem = new WatchedItem( $user, $targets[0], '20151212010101' );
1702 $mockDb = $this->getMockDb();
1704 $mockDb->expects( $this->once() )
1705 ->method( 'makeWhereFrom2d' )
1707 [ 1 => [ 'AnotherDbKey' => 1 ] ],
1708 $this->isType( 'string' ),
1709 $this->isType( 'string' )
1711 ->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
1712 $mockDb->expects( $this->once() )
1713 ->method( 'select' )
1716 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
1718 'makeWhereFrom2d return value',
1721 $this->isType( 'string' )
1723 ->will( $this->returnValue( [
1725 [ 'wl_namespace' => 1, 'wl_title' => 'AnotherDbKey', 'wl_notificationtimestamp' => null, ]
1729 $mockCache = $this->getMockCache();
1730 $mockCache->expects( $this->at( 1 ) )
1732 ->with( '0:SomeDbKey:1' )
1733 ->will( $this->returnValue( $cachedItem ) );
1734 $mockCache->expects( $this->at( 3 ) )
1736 ->with( '1:AnotherDbKey:1' )
1737 ->will( $this->returnValue( null ) );
1738 $mockCache->expects( $this->never() )->method( 'set' );
1739 $mockCache->expects( $this->never() )->method( 'delete' );
1741 $store = $this->newWatchedItemStore(
1742 $this->getMockLoadBalancer( $mockDb ),
1746 $this->assertEquals(
1748 0 => [ 'SomeDbKey' => '20151212010101', ],
1749 1 => [ 'AnotherDbKey' => null, ],
1751 $store->getNotificationTimestampsBatch( $user, $targets )
1755 public function testGetNotificationTimestampsBatch_allItemsCached() {
1757 new TitleValue( 0, 'SomeDbKey' ),
1758 new TitleValue( 1, 'AnotherDbKey' ),
1761 $user = $this->getMockNonAnonUserWithId( 1 );
1763 new WatchedItem( $user, $targets[0], '20151212010101' ),
1764 new WatchedItem( $user, $targets[1], null ),
1766 $mockDb = $this->getMockDb();
1767 $mockDb->expects( $this->never() )->method( $this->anything() );
1769 $mockCache = $this->getMockCache();
1770 $mockCache->expects( $this->at( 1 ) )
1772 ->with( '0:SomeDbKey:1' )
1773 ->will( $this->returnValue( $cachedItems[0] ) );
1774 $mockCache->expects( $this->at( 3 ) )
1776 ->with( '1:AnotherDbKey:1' )
1777 ->will( $this->returnValue( $cachedItems[1] ) );
1778 $mockCache->expects( $this->never() )->method( 'set' );
1779 $mockCache->expects( $this->never() )->method( 'delete' );
1781 $store = $this->newWatchedItemStore(
1782 $this->getMockLoadBalancer( $mockDb ),
1786 $this->assertEquals(
1788 0 => [ 'SomeDbKey' => '20151212010101', ],
1789 1 => [ 'AnotherDbKey' => null, ],
1791 $store->getNotificationTimestampsBatch( $user, $targets )
1795 public function testGetNotificationTimestampsBatch_anonymousUser() {
1797 new TitleValue( 0, 'SomeDbKey' ),
1798 new TitleValue( 1, 'AnotherDbKey' ),
1801 $mockDb = $this->getMockDb();
1802 $mockDb->expects( $this->never() )->method( $this->anything() );
1804 $mockCache = $this->getMockCache();
1805 $mockCache->expects( $this->never() )->method( $this->anything() );
1807 $store = $this->newWatchedItemStore(
1808 $this->getMockLoadBalancer( $mockDb ),
1812 $this->assertEquals(
1814 0 => [ 'SomeDbKey' => false, ],
1815 1 => [ 'AnotherDbKey' => false, ],
1817 $store->getNotificationTimestampsBatch( $this->getAnonUser(), $targets )
1821 public function testResetNotificationTimestamp_anonymousUser() {
1822 $mockDb = $this->getMockDb();
1823 $mockDb->expects( $this->never() )
1824 ->method( 'selectRow' );
1826 $mockCache = $this->getMockCache();
1827 $mockCache->expects( $this->never() )->method( 'get' );
1828 $mockCache->expects( $this->never() )->method( 'set' );
1829 $mockCache->expects( $this->never() )->method( 'delete' );
1831 $store = $this->newWatchedItemStore(
1832 $this->getMockLoadBalancer( $mockDb ),
1837 $store->resetNotificationTimestamp(
1838 $this->getAnonUser(),
1839 Title
::newFromText( 'SomeDbKey' )
1844 public function testResetNotificationTimestamp_noItem() {
1845 $mockDb = $this->getMockDb();
1846 $mockDb->expects( $this->once() )
1847 ->method( 'selectRow' )
1850 'wl_notificationtimestamp',
1853 'wl_namespace' => 0,
1854 'wl_title' => 'SomeDbKey',
1857 ->will( $this->returnValue( [] ) );
1859 $mockCache = $this->getMockCache();
1860 $mockCache->expects( $this->never() )->method( 'get' );
1861 $mockCache->expects( $this->never() )->method( 'set' );
1862 $mockCache->expects( $this->never() )->method( 'delete' );
1864 $store = $this->newWatchedItemStore(
1865 $this->getMockLoadBalancer( $mockDb ),
1870 $store->resetNotificationTimestamp(
1871 $this->getMockNonAnonUserWithId( 1 ),
1872 Title
::newFromText( 'SomeDbKey' )
1877 public function testResetNotificationTimestamp_item() {
1878 $user = $this->getMockNonAnonUserWithId( 1 );
1879 $title = Title
::newFromText( 'SomeDbKey' );
1881 $mockDb = $this->getMockDb();
1882 $mockDb->expects( $this->once() )
1883 ->method( 'selectRow' )
1886 'wl_notificationtimestamp',
1889 'wl_namespace' => 0,
1890 'wl_title' => 'SomeDbKey',
1893 ->will( $this->returnValue(
1894 $this->getFakeRow( [ 'wl_notificationtimestamp' => '20151212010101' ] )
1897 $mockCache = $this->getMockCache();
1898 $mockCache->expects( $this->never() )->method( 'get' );
1899 $mockCache->expects( $this->once() )
1903 $this->isInstanceOf( WatchedItem
::class )
1905 $mockCache->expects( $this->once() )
1906 ->method( 'delete' )
1907 ->with( '0:SomeDbKey:1' );
1909 $store = $this->newWatchedItemStore(
1910 $this->getMockLoadBalancer( $mockDb ),
1914 // Note: This does not actually assert the job is correct
1915 $callableCallCounter = 0;
1916 $mockCallback = function( $callable ) use ( &$callableCallCounter ) {
1917 $callableCallCounter++
;
1918 $this->assertInternalType( 'callable', $callable );
1920 $scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback( $mockCallback );
1923 $store->resetNotificationTimestamp(
1928 $this->assertEquals( 1, $callableCallCounter );
1930 ScopedCallback
::consume( $scopedOverride );
1933 public function testResetNotificationTimestamp_noItemForced() {
1934 $user = $this->getMockNonAnonUserWithId( 1 );
1935 $title = Title
::newFromText( 'SomeDbKey' );
1937 $mockDb = $this->getMockDb();
1938 $mockDb->expects( $this->never() )
1939 ->method( 'selectRow' );
1941 $mockCache = $this->getMockCache();
1942 $mockDb->expects( $this->never() )
1944 $mockDb->expects( $this->never() )
1946 $mockDb->expects( $this->never() )
1947 ->method( 'delete' );
1949 $store = $this->newWatchedItemStore(
1950 $this->getMockLoadBalancer( $mockDb ),
1954 // Note: This does not actually assert the job is correct
1955 $callableCallCounter = 0;
1956 $mockCallback = function( $callable ) use ( &$callableCallCounter ) {
1957 $callableCallCounter++
;
1958 $this->assertInternalType( 'callable', $callable );
1960 $scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback( $mockCallback );
1963 $store->resetNotificationTimestamp(
1969 $this->assertEquals( 1, $callableCallCounter );
1971 ScopedCallback
::consume( $scopedOverride );
1978 * @return PHPUnit_Framework_MockObject_MockObject|Title
1980 private function getMockTitle( $text, $ns = 0 ) {
1981 $title = $this->getMock( Title
::class );
1982 $title->expects( $this->any() )
1983 ->method( 'getText' )
1984 ->will( $this->returnValue( str_replace( '_', ' ', $text ) ) );
1985 $title->expects( $this->any() )
1986 ->method( 'getDbKey' )
1987 ->will( $this->returnValue( str_replace( '_', ' ', $text ) ) );
1988 $title->expects( $this->any() )
1989 ->method( 'getNamespace' )
1990 ->will( $this->returnValue( $ns ) );
1994 private function verifyCallbackJob(
1996 LinkTarget
$expectedTitle,
1998 callable
$notificationTimestampCondition
2000 $this->assertInternalType( 'callable', $callback );
2002 $callbackReflector = new ReflectionFunction( $callback );
2003 $vars = $callbackReflector->getStaticVariables();
2004 $this->assertArrayHasKey( 'job', $vars );
2005 $this->assertInstanceOf( ActivityUpdateJob
::class, $vars['job'] );
2007 /** @var ActivityUpdateJob $job */
2008 $job = $vars['job'];
2009 $this->assertEquals( $expectedTitle->getDBkey(), $job->getTitle()->getDBkey() );
2010 $this->assertEquals( $expectedTitle->getNamespace(), $job->getTitle()->getNamespace() );
2012 $jobParams = $job->getParams();
2013 $this->assertArrayHasKey( 'type', $jobParams );
2014 $this->assertEquals( 'updateWatchlistNotification', $jobParams['type'] );
2015 $this->assertArrayHasKey( 'userid', $jobParams );
2016 $this->assertEquals( $expectedUserId, $jobParams['userid'] );
2017 $this->assertArrayHasKey( 'notifTime', $jobParams );
2018 $this->assertTrue( $notificationTimestampCondition( $jobParams['notifTime'] ) );
2021 public function testResetNotificationTimestamp_oldidSpecifiedLatestRevisionForced() {
2022 $user = $this->getMockNonAnonUserWithId( 1 );
2024 $title = $this->getMockTitle( 'SomeTitle' );
2025 $title->expects( $this->once() )
2026 ->method( 'getNextRevisionID' )
2028 ->will( $this->returnValue( false ) );
2030 $mockDb = $this->getMockDb();
2031 $mockDb->expects( $this->never() )
2032 ->method( 'selectRow' );
2034 $mockCache = $this->getMockCache();
2035 $mockDb->expects( $this->never() )
2037 $mockDb->expects( $this->never() )
2039 $mockDb->expects( $this->never() )
2040 ->method( 'delete' );
2042 $store = $this->newWatchedItemStore(
2043 $this->getMockLoadBalancer( $mockDb ),
2047 $callableCallCounter = 0;
2048 $scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
2049 function( $callable ) use ( &$callableCallCounter, $title, $user ) {
2050 $callableCallCounter++
;
2051 $this->verifyCallbackJob(
2056 return $time === null;
2063 $store->resetNotificationTimestamp(
2070 $this->assertEquals( 1, $callableCallCounter );
2072 ScopedCallback
::consume( $scopedOverride );
2075 public function testResetNotificationTimestamp_oldidSpecifiedNotLatestRevisionForced() {
2076 $user = $this->getMockNonAnonUserWithId( 1 );
2078 $title = $this->getMockTitle( 'SomeDbKey' );
2079 $title->expects( $this->once() )
2080 ->method( 'getNextRevisionID' )
2082 ->will( $this->returnValue( 33 ) );
2084 $mockDb = $this->getMockDb();
2085 $mockDb->expects( $this->once() )
2086 ->method( 'selectRow' )
2089 'wl_notificationtimestamp',
2092 'wl_namespace' => 0,
2093 'wl_title' => 'SomeDbKey',
2096 ->will( $this->returnValue(
2097 $this->getFakeRow( [ 'wl_notificationtimestamp' => '20151212010101' ] )
2100 $mockCache = $this->getMockCache();
2101 $mockDb->expects( $this->never() )
2103 $mockDb->expects( $this->never() )
2105 $mockDb->expects( $this->never() )
2106 ->method( 'delete' );
2108 $store = $this->newWatchedItemStore(
2109 $this->getMockLoadBalancer( $mockDb ),
2113 $addUpdateCallCounter = 0;
2114 $scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
2115 function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
2116 $addUpdateCallCounter++
;
2117 $this->verifyCallbackJob(
2122 return $time !== null && $time > '20151212010101';
2128 $getTimestampCallCounter = 0;
2129 $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
2130 function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
2131 $getTimestampCallCounter++
;
2132 $this->assertEquals( $title, $titleParam );
2133 $this->assertEquals( $oldid, $oldidParam );
2138 $store->resetNotificationTimestamp(
2145 $this->assertEquals( 1, $addUpdateCallCounter );
2146 $this->assertEquals( 1, $getTimestampCallCounter );
2148 ScopedCallback
::consume( $scopedOverrideDeferred );
2149 ScopedCallback
::consume( $scopedOverrideRevision );
2152 public function testResetNotificationTimestamp_notWatchedPageForced() {
2153 $user = $this->getMockNonAnonUserWithId( 1 );
2155 $title = $this->getMockTitle( 'SomeDbKey' );
2156 $title->expects( $this->once() )
2157 ->method( 'getNextRevisionID' )
2159 ->will( $this->returnValue( 33 ) );
2161 $mockDb = $this->getMockDb();
2162 $mockDb->expects( $this->once() )
2163 ->method( 'selectRow' )
2166 'wl_notificationtimestamp',
2169 'wl_namespace' => 0,
2170 'wl_title' => 'SomeDbKey',
2173 ->will( $this->returnValue( false ) );
2175 $mockCache = $this->getMockCache();
2176 $mockDb->expects( $this->never() )
2178 $mockDb->expects( $this->never() )
2180 $mockDb->expects( $this->never() )
2181 ->method( 'delete' );
2183 $store = $this->newWatchedItemStore(
2184 $this->getMockLoadBalancer( $mockDb ),
2188 $callableCallCounter = 0;
2189 $scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
2190 function( $callable ) use ( &$callableCallCounter, $title, $user ) {
2191 $callableCallCounter++
;
2192 $this->verifyCallbackJob(
2197 return $time === null;
2204 $store->resetNotificationTimestamp(
2211 $this->assertEquals( 1, $callableCallCounter );
2213 ScopedCallback
::consume( $scopedOverride );
2216 public function testResetNotificationTimestamp_futureNotificationTimestampForced() {
2217 $user = $this->getMockNonAnonUserWithId( 1 );
2219 $title = $this->getMockTitle( 'SomeDbKey' );
2220 $title->expects( $this->once() )
2221 ->method( 'getNextRevisionID' )
2223 ->will( $this->returnValue( 33 ) );
2225 $mockDb = $this->getMockDb();
2226 $mockDb->expects( $this->once() )
2227 ->method( 'selectRow' )
2230 'wl_notificationtimestamp',
2233 'wl_namespace' => 0,
2234 'wl_title' => 'SomeDbKey',
2237 ->will( $this->returnValue(
2238 $this->getFakeRow( [ 'wl_notificationtimestamp' => '30151212010101' ] )
2241 $mockCache = $this->getMockCache();
2242 $mockDb->expects( $this->never() )
2244 $mockDb->expects( $this->never() )
2246 $mockDb->expects( $this->never() )
2247 ->method( 'delete' );
2249 $store = $this->newWatchedItemStore(
2250 $this->getMockLoadBalancer( $mockDb ),
2254 $addUpdateCallCounter = 0;
2255 $scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
2256 function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
2257 $addUpdateCallCounter++
;
2258 $this->verifyCallbackJob(
2263 return $time === '30151212010101';
2269 $getTimestampCallCounter = 0;
2270 $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
2271 function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
2272 $getTimestampCallCounter++
;
2273 $this->assertEquals( $title, $titleParam );
2274 $this->assertEquals( $oldid, $oldidParam );
2279 $store->resetNotificationTimestamp(
2286 $this->assertEquals( 1, $addUpdateCallCounter );
2287 $this->assertEquals( 1, $getTimestampCallCounter );
2289 ScopedCallback
::consume( $scopedOverrideDeferred );
2290 ScopedCallback
::consume( $scopedOverrideRevision );
2293 public function testResetNotificationTimestamp_futureNotificationTimestampNotForced() {
2294 $user = $this->getMockNonAnonUserWithId( 1 );
2296 $title = $this->getMockTitle( 'SomeDbKey' );
2297 $title->expects( $this->once() )
2298 ->method( 'getNextRevisionID' )
2300 ->will( $this->returnValue( 33 ) );
2302 $mockDb = $this->getMockDb();
2303 $mockDb->expects( $this->once() )
2304 ->method( 'selectRow' )
2307 'wl_notificationtimestamp',
2310 'wl_namespace' => 0,
2311 'wl_title' => 'SomeDbKey',
2314 ->will( $this->returnValue(
2315 $this->getFakeRow( [ 'wl_notificationtimestamp' => '30151212010101' ] )
2318 $mockCache = $this->getMockCache();
2319 $mockDb->expects( $this->never() )
2321 $mockDb->expects( $this->never() )
2323 $mockDb->expects( $this->never() )
2324 ->method( 'delete' );
2326 $store = $this->newWatchedItemStore(
2327 $this->getMockLoadBalancer( $mockDb ),
2331 $addUpdateCallCounter = 0;
2332 $scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
2333 function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
2334 $addUpdateCallCounter++
;
2335 $this->verifyCallbackJob(
2340 return $time === false;
2346 $getTimestampCallCounter = 0;
2347 $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
2348 function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
2349 $getTimestampCallCounter++
;
2350 $this->assertEquals( $title, $titleParam );
2351 $this->assertEquals( $oldid, $oldidParam );
2356 $store->resetNotificationTimestamp(
2363 $this->assertEquals( 1, $addUpdateCallCounter );
2364 $this->assertEquals( 1, $getTimestampCallCounter );
2366 ScopedCallback
::consume( $scopedOverrideDeferred );
2367 ScopedCallback
::consume( $scopedOverrideRevision );
2370 public function testSetNotificationTimestampsForUser_anonUser() {
2371 $store = $this->newWatchedItemStore(
2372 $this->getMockLoadBalancer( $this->getMockDb() ),
2373 $this->getMockCache()
2375 $this->assertFalse( $store->setNotificationTimestampsForUser( $this->getAnonUser(), '' ) );
2378 public function testSetNotificationTimestampsForUser_allRows() {
2379 $user = $this->getMockNonAnonUserWithId( 1 );
2380 $timestamp = '20100101010101';
2382 $mockDb = $this->getMockDb();
2383 $mockDb->expects( $this->once() )
2384 ->method( 'update' )
2387 [ 'wl_notificationtimestamp' => 'TS' . $timestamp . 'TS' ],
2390 ->will( $this->returnValue( true ) );
2391 $mockDb->expects( $this->exactly( 1 ) )
2392 ->method( 'timestamp' )
2393 ->will( $this->returnCallback( function( $value ) {
2394 return 'TS' . $value . 'TS';
2397 $store = $this->newWatchedItemStore(
2398 $this->getMockLoadBalancer( $mockDb ),
2399 $this->getMockCache()
2403 $store->setNotificationTimestampsForUser( $user, $timestamp )
2407 public function testSetNotificationTimestampsForUser_nullTimestamp() {
2408 $user = $this->getMockNonAnonUserWithId( 1 );
2411 $mockDb = $this->getMockDb();
2412 $mockDb->expects( $this->once() )
2413 ->method( 'update' )
2416 [ 'wl_notificationtimestamp' => null ],
2419 ->will( $this->returnValue( true ) );
2420 $mockDb->expects( $this->exactly( 0 ) )
2421 ->method( 'timestamp' )
2422 ->will( $this->returnCallback( function( $value ) {
2423 return 'TS' . $value . 'TS';
2426 $store = $this->newWatchedItemStore(
2427 $this->getMockLoadBalancer( $mockDb ),
2428 $this->getMockCache()
2432 $store->setNotificationTimestampsForUser( $user, $timestamp )
2436 public function testSetNotificationTimestampsForUser_specificTargets() {
2437 $user = $this->getMockNonAnonUserWithId( 1 );
2438 $timestamp = '20100101010101';
2439 $targets = [ new TitleValue( 0, 'Foo' ), new TitleValue( 0, 'Bar' ) ];
2441 $mockDb = $this->getMockDb();
2442 $mockDb->expects( $this->once() )
2443 ->method( 'update' )
2446 [ 'wl_notificationtimestamp' => 'TS' . $timestamp . 'TS' ],
2447 [ 'wl_user' => 1, 0 => 'makeWhereFrom2d return value' ]
2449 ->will( $this->returnValue( true ) );
2450 $mockDb->expects( $this->exactly( 1 ) )
2451 ->method( 'timestamp' )
2452 ->will( $this->returnCallback( function( $value ) {
2453 return 'TS' . $value . 'TS';
2455 $mockDb->expects( $this->once() )
2456 ->method( 'makeWhereFrom2d' )
2458 [ [ 'Foo' => 1, 'Bar' => 1 ] ],
2459 $this->isType( 'string' ),
2460 $this->isType( 'string' )
2462 ->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
2464 $store = $this->newWatchedItemStore(
2465 $this->getMockLoadBalancer( $mockDb ),
2466 $this->getMockCache()
2470 $store->setNotificationTimestampsForUser( $user, $timestamp, $targets )
2474 public function testUpdateNotificationTimestamp_watchersExist() {
2475 $mockDb = $this->getMockDb();
2476 $mockDb->expects( $this->once() )
2477 ->method( 'selectFieldValues' )
2483 'wl_namespace' => 0,
2484 'wl_title' => 'SomeDbKey',
2485 'wl_notificationtimestamp IS NULL'
2488 ->will( $this->returnValue( [ '2', '3' ] ) );
2489 $mockDb->expects( $this->once() )
2490 ->method( 'update' )
2493 [ 'wl_notificationtimestamp' => null ],
2495 'wl_user' => [ 2, 3 ],
2496 'wl_namespace' => 0,
2497 'wl_title' => 'SomeDbKey',
2501 $mockCache = $this->getMockCache();
2502 $mockCache->expects( $this->never() )->method( 'set' );
2503 $mockCache->expects( $this->never() )->method( 'get' );
2504 $mockCache->expects( $this->never() )->method( 'delete' );
2506 $store = $this->newWatchedItemStore(
2507 $this->getMockLoadBalancer( $mockDb ),
2511 $this->assertEquals(
2513 $store->updateNotificationTimestamp(
2514 $this->getMockNonAnonUserWithId( 1 ),
2515 new TitleValue( 0, 'SomeDbKey' ),
2521 public function testUpdateNotificationTimestamp_noWatchers() {
2522 $mockDb = $this->getMockDb();
2523 $mockDb->expects( $this->once() )
2524 ->method( 'selectFieldValues' )
2530 'wl_namespace' => 0,
2531 'wl_title' => 'SomeDbKey',
2532 'wl_notificationtimestamp IS NULL'
2536 $this->returnValue( [] )
2538 $mockDb->expects( $this->never() )
2539 ->method( 'update' );
2541 $mockCache = $this->getMockCache();
2542 $mockCache->expects( $this->never() )->method( 'set' );
2543 $mockCache->expects( $this->never() )->method( 'get' );
2544 $mockCache->expects( $this->never() )->method( 'delete' );
2546 $store = $this->newWatchedItemStore(
2547 $this->getMockLoadBalancer( $mockDb ),
2551 $watchers = $store->updateNotificationTimestamp(
2552 $this->getMockNonAnonUserWithId( 1 ),
2553 new TitleValue( 0, 'SomeDbKey' ),
2556 $this->assertInternalType( 'array', $watchers );
2557 $this->assertEmpty( $watchers );
2560 public function testUpdateNotificationTimestamp_clearsCachedItems() {
2561 $user = $this->getMockNonAnonUserWithId( 1 );
2562 $titleValue = new TitleValue( 0, 'SomeDbKey' );
2564 $mockDb = $this->getMockDb();
2565 $mockDb->expects( $this->once() )
2566 ->method( 'selectRow' )
2567 ->will( $this->returnValue(
2568 $this->getFakeRow( [ 'wl_notificationtimestamp' => '20151212010101' ] )
2570 $mockDb->expects( $this->once() )
2571 ->method( 'selectFieldValues' )
2573 $this->returnValue( [ '2', '3' ] )
2575 $mockDb->expects( $this->once() )
2576 ->method( 'update' );
2578 $mockCache = $this->getMockCache();
2579 $mockCache->expects( $this->once() )
2581 ->with( '0:SomeDbKey:1', $this->isType( 'object' ) );
2582 $mockCache->expects( $this->once() )
2584 ->with( '0:SomeDbKey:1' );
2585 $mockCache->expects( $this->once() )
2586 ->method( 'delete' )
2587 ->with( '0:SomeDbKey:1' );
2589 $store = $this->newWatchedItemStore(
2590 $this->getMockLoadBalancer( $mockDb ),
2594 // This will add the item to the cache
2595 $store->getWatchedItem( $user, $titleValue );
2597 $store->updateNotificationTimestamp(
2598 $this->getMockNonAnonUserWithId( 1 ),