5use Wikimedia\ScopedCallback;
6use Wikimedia\TestingAccessWrapper;
19 return $this->createMock( IDatabase::class );
27 $expectedConnectionType =
null
29 $mock = $this->getMockBuilder( LoadBalancer::class )
30 ->disableOriginalConstructor()
32 if ( $expectedConnectionType !==
null ) {
33 $mock->expects( $this->any() )
34 ->method(
'getConnectionRef' )
35 ->with( $expectedConnectionType )
36 ->will( $this->returnValue( $mockDb ) );
38 $mock->expects( $this->any() )
39 ->method(
'getConnectionRef' )
40 ->will( $this->returnValue( $mockDb ) );
50 $expectedConnectionType =
null
53 $mock = $this->getMockBuilder( LBFactory::class )
54 ->disableOriginalConstructor()
56 $mock->expects( $this->any() )
57 ->method(
'getMainLB' )
58 ->will( $this->returnValue( $loadBalancer ) );
66 $mock = $this->getMockBuilder( JobQueueGroup::class )
67 ->disableOriginalConstructor()
69 $mock->expects( $this->any() )
71 ->will( $this->returnCallback(
function (
Job $job ) {
74 $mock->expects( $this->any() )
75 ->method(
'lazyPush' )
76 ->will( $this->returnCallback(
function (
Job $job ) {
86 $mock = $this->getMockBuilder( HashBagOStuff::class )
87 ->disableOriginalConstructor()
88 ->setMethods( [
'get',
'set',
'delete',
'makeKey' ] )
90 $mock->expects( $this->any() )
92 ->will( $this->returnCallback(
function () {
93 return implode(
':', func_get_args() );
102 $mock = $this->getMockBuilder( ReadOnlyMode::class )
103 ->disableOriginalConstructor()
105 $mock->expects( $this->any() )
106 ->method(
'isReadOnly' )
107 ->will( $this->returnValue( $readOnly ) );
116 $mock = $this->createMock( User::class );
117 $mock->expects( $this->any() )
119 ->will( $this->returnValue(
false ) );
120 $mock->expects( $this->any() )
122 ->will( $this->returnValue( $id ) );
123 $mock->expects( $this->any() )
124 ->method(
'getUserPage' )
125 ->will( $this->returnValue( Title::makeTitle(
NS_USER,
'MockUser' ) ) );
137 $fakeRow =
new stdClass();
138 foreach ( $rowValues
as $valueName =>
$value ) {
139 $fakeRow->$valueName =
$value;
164 $mockDb->expects( $this->once() )
165 ->method(
'selectField' )
170 'wl_user' =>
$user->getId(),
172 $this->isType(
'string' )
174 ->will( $this->returnValue( 12 ) );
175 $mockDb->expects( $this->once() )
180 $this->isType(
'string' )
184 $mockCache->expects( $this->never() )->method(
'get' );
185 $mockCache->expects( $this->never() )->method(
'set' );
186 $mockCache->expects( $this->once() )
196 TestingAccessWrapper::newFromObject( $store )
197 ->cacheIndex = [ 0 => [
'F' => [ 7 =>
'RM-KEY', 9 =>
'KEEP-KEY' ] ] ];
199 $this->assertTrue( $store->clearUserWatchedItems(
$user ) );
206 $mockDb->expects( $this->once() )
207 ->method(
'selectField' )
212 'wl_user' =>
$user->getId(),
214 $this->isType(
'string' )
216 ->will( $this->returnValue( 99999 ) );
219 $mockCache->expects( $this->never() )->method(
'get' );
220 $mockCache->expects( $this->never() )->method(
'set' );
221 $mockCache->expects( $this->never() )->method(
'delete' );
230 $this->assertFalse( $store->clearUserWatchedItems(
$user ) );
237 $mockDb->expects( $this->exactly( 1 ) )
238 ->method(
'selectField' )
243 'wl_user' =>
$user->getId(),
245 $this->isType(
'string' )
247 ->will( $this->returnValue(
'12' ) );
250 $mockCache->expects( $this->never() )->method(
'get' );
251 $mockCache->expects( $this->never() )->method(
'set' );
252 $mockCache->expects( $this->never() )->method(
'delete' );
261 $this->assertEquals( 12, $store->countWatchedItems(
$user ) );
265 $titleValue =
new TitleValue( 0,
'SomeDbKey' );
268 $mockDb->expects( $this->exactly( 1 ) )
269 ->method(
'selectField' )
274 'wl_namespace' => $titleValue->getNamespace(),
275 'wl_title' => $titleValue->getDBkey(),
277 $this->isType(
'string' )
279 ->will( $this->returnValue(
'7' ) );
282 $mockCache->expects( $this->never() )->method(
'get' );
283 $mockCache->expects( $this->never() )->method(
'set' );
284 $mockCache->expects( $this->never() )->method(
'delete' );
293 $this->assertEquals( 7, $store->countWatchers( $titleValue ) );
306 $this->
getFakeRow( [
'wl_title' =>
'SomeDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'100' ] ),
307 $this->
getFakeRow( [
'wl_title' =>
'OtherDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'300' ] ),
308 $this->
getFakeRow( [
'wl_title' =>
'AnotherDbKey',
'wl_namespace' =>
'1',
'watchers' =>
'500' ]
311 $mockDb->expects( $this->once() )
312 ->method(
'makeWhereFrom2d' )
314 [ [
'SomeDbKey' => 1,
'OtherDbKey' => 1 ], [
'AnotherDbKey' => 1 ] ],
315 $this->isType(
'string' ),
316 $this->isType(
'string' )
318 ->will( $this->returnValue(
'makeWhereFrom2d return value' ) );
319 $mockDb->expects( $this->once() )
323 [
'wl_title',
'wl_namespace',
'watchers' =>
'COUNT(*)' ],
324 [
'makeWhereFrom2d return value' ],
325 $this->isType(
'string' ),
327 'GROUP BY' => [
'wl_namespace',
'wl_title' ],
331 $this->returnValue( $dbResult )
335 $mockCache->expects( $this->never() )->method(
'get' );
336 $mockCache->expects( $this->never() )->method(
'set' );
337 $mockCache->expects( $this->never() )->method(
'delete' );
347 0 => [
'SomeDbKey' => 100,
'OtherDbKey' => 300 ],
348 1 => [
'AnotherDbKey' => 500 ],
350 $this->assertEquals( $expected, $store->countWatchersMultiple( $titleValues ) );
356 [
"50; DROP TABLE watchlist;\n--" ],
373 $this->
getFakeRow( [
'wl_title' =>
'SomeDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'100' ] ),
374 $this->
getFakeRow( [
'wl_title' =>
'OtherDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'300' ] ),
375 $this->
getFakeRow( [
'wl_title' =>
'AnotherDbKey',
'wl_namespace' =>
'1',
'watchers' =>
'500' ]
378 $mockDb->expects( $this->once() )
379 ->method(
'makeWhereFrom2d' )
381 [ [
'SomeDbKey' => 1,
'OtherDbKey' => 1 ], [
'AnotherDbKey' => 1 ] ],
382 $this->isType(
'string' ),
383 $this->isType(
'string' )
385 ->will( $this->returnValue(
'makeWhereFrom2d return value' ) );
386 $mockDb->expects( $this->once() )
390 [
'wl_title',
'wl_namespace',
'watchers' =>
'COUNT(*)' ],
391 [
'makeWhereFrom2d return value' ],
392 $this->isType(
'string' ),
394 'GROUP BY' => [
'wl_namespace',
'wl_title' ],
395 'HAVING' =>
'COUNT(*) >= 50',
399 $this->returnValue( $dbResult )
403 $mockCache->expects( $this->never() )->method(
'get' );
404 $mockCache->expects( $this->never() )->method(
'set' );
405 $mockCache->expects( $this->never() )->method(
'delete' );
415 0 => [
'SomeDbKey' => 100,
'OtherDbKey' => 300 ],
416 1 => [
'AnotherDbKey' => 500 ],
420 $store->countWatchersMultiple( $titleValues, [
'minimumWatchers' => $minWatchers ] )
425 $titleValue =
new TitleValue( 0,
'SomeDbKey' );
428 $mockDb->expects( $this->exactly( 1 ) )
429 ->method(
'selectField' )
434 'wl_namespace' => $titleValue->getNamespace(),
435 'wl_title' => $titleValue->getDBkey(),
436 'wl_notificationtimestamp >= \'TS111TS\' OR wl_notificationtimestamp IS NULL',
438 $this->isType(
'string' )
440 ->will( $this->returnValue(
'7' ) );
441 $mockDb->expects( $this->exactly( 1 ) )
442 ->method(
'addQuotes' )
443 ->will( $this->returnCallback(
function (
$value ) {
446 $mockDb->expects( $this->exactly( 1 ) )
447 ->method(
'timestamp' )
448 ->will( $this->returnCallback(
function (
$value ) {
449 return 'TS' .
$value .
'TS';
453 $mockCache->expects( $this->never() )->method(
'set' );
454 $mockCache->expects( $this->never() )->method(
'get' );
455 $mockCache->expects( $this->never() )->method(
'delete' );
464 $this->assertEquals( 7, $store->countVisitingWatchers( $titleValue,
'111' ) );
468 $titleValuesWithThresholds = [
471 [
new TitleValue( 1,
'AnotherDbKey' ),
'123' ],
475 $this->
getFakeRow( [
'wl_title' =>
'SomeDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'100' ] ),
476 $this->
getFakeRow( [
'wl_title' =>
'OtherDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'300' ] ),
478 [
'wl_title' =>
'AnotherDbKey',
'wl_namespace' =>
'1',
'watchers' =>
'500' ]
482 $mockDb->expects( $this->exactly( 2 * 3 ) )
483 ->method(
'addQuotes' )
484 ->will( $this->returnCallback(
function (
$value ) {
487 $mockDb->expects( $this->exactly( 3 ) )
488 ->method(
'timestamp' )
489 ->will( $this->returnCallback(
function (
$value ) {
490 return 'TS' .
$value .
'TS';
492 $mockDb->expects( $this->any() )
493 ->method(
'makeList' )
495 $this->isType(
'array' ),
496 $this->isType(
'int' )
498 ->will( $this->returnCallback(
function ( $a, $conj ) {
499 $sqlConj = $conj ===
LIST_AND ?
' AND ' :
' OR ';
500 return implode( $sqlConj, array_map(
function (
$s ) {
501 return '(' .
$s .
')';
505 $mockDb->expects( $this->never() )
506 ->method(
'makeWhereFrom2d' );
509 '((wl_namespace = 0) AND (' .
510 "(((wl_title = 'SomeDbKey') AND (" .
511 "(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
513 "(wl_title = 'OtherDbKey') AND (" .
514 "(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
516 ') OR ((wl_namespace = 1) AND (' .
517 "(((wl_title = 'AnotherDbKey') AND (" .
518 "(wl_notificationtimestamp >= 'TS123TS') OR (wl_notificationtimestamp IS NULL)" .
520 $mockDb->expects( $this->once() )
524 [
'wl_namespace',
'wl_title',
'watchers' =>
'COUNT(*)' ],
526 $this->isType(
'string' ),
528 'GROUP BY' => [
'wl_namespace',
'wl_title' ],
532 $this->returnValue( $dbResult )
536 $mockCache->expects( $this->never() )->method(
'get' );
537 $mockCache->expects( $this->never() )->method(
'set' );
538 $mockCache->expects( $this->never() )->method(
'delete' );
548 0 => [
'SomeDbKey' => 100,
'OtherDbKey' => 300 ],
549 1 => [
'AnotherDbKey' => 500 ],
553 $store->countVisitingWatchersMultiple( $titleValuesWithThresholds )
558 $titleValuesWithThresholds = [
561 [
new TitleValue( 1,
'AnotherDbKey' ),
'123' ],
567 $this->
getFakeRow( [
'wl_title' =>
'SomeDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'100' ] ),
568 $this->
getFakeRow( [
'wl_title' =>
'OtherDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'300' ] ),
570 [
'wl_title' =>
'AnotherDbKey',
'wl_namespace' =>
'1',
'watchers' =>
'500' ]
573 [
'wl_title' =>
'SomeNotExisitingDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'100' ]
576 [
'wl_title' =>
'OtherNotExisitingDbKey',
'wl_namespace' =>
'0',
'watchers' =>
'200' ]
580 $mockDb->expects( $this->exactly( 2 * 3 ) )
581 ->method(
'addQuotes' )
582 ->will( $this->returnCallback(
function (
$value ) {
585 $mockDb->expects( $this->exactly( 3 ) )
586 ->method(
'timestamp' )
587 ->will( $this->returnCallback(
function (
$value ) {
588 return 'TS' .
$value .
'TS';
590 $mockDb->expects( $this->any() )
591 ->method(
'makeList' )
593 $this->isType(
'array' ),
594 $this->isType(
'int' )
596 ->will( $this->returnCallback(
function ( $a, $conj ) {
597 $sqlConj = $conj ===
LIST_AND ?
' AND ' :
' OR ';
598 return implode( $sqlConj, array_map(
function (
$s ) {
599 return '(' .
$s .
')';
603 $mockDb->expects( $this->once() )
604 ->method(
'makeWhereFrom2d' )
606 [ [
'SomeNotExisitingDbKey' => 1,
'OtherNotExisitingDbKey' => 1 ] ],
607 $this->isType(
'string' ),
608 $this->isType(
'string' )
610 ->
will( $this->returnValue(
'makeWhereFrom2d return value' ) );
613 '((wl_namespace = 0) AND (' .
614 "(((wl_title = 'SomeDbKey') AND (" .
615 "(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
617 "(wl_title = 'OtherDbKey') AND (" .
618 "(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
620 ') OR ((wl_namespace = 1) AND (' .
621 "(((wl_title = 'AnotherDbKey') AND (" .
622 "(wl_notificationtimestamp >= 'TS123TS') OR (wl_notificationtimestamp IS NULL)" .
625 '(makeWhereFrom2d return value)';
626 $mockDb->expects( $this->once() )
630 [
'wl_namespace',
'wl_title',
'watchers' =>
'COUNT(*)' ],
632 $this->isType(
'string' ),
634 'GROUP BY' => [
'wl_namespace',
'wl_title' ],
638 $this->returnValue( $dbResult )
642 $mockCache->expects( $this->never() )->method(
'get' );
643 $mockCache->expects( $this->never() )->method(
'set' );
644 $mockCache->expects( $this->never() )->method(
'delete' );
655 'SomeDbKey' => 100,
'OtherDbKey' => 300,
656 'SomeNotExisitingDbKey' => 100,
'OtherNotExisitingDbKey' => 200
658 1 => [
'AnotherDbKey' => 500 ],
662 $store->countVisitingWatchersMultiple( $titleValuesWithThresholds )
670 $titleValuesWithThresholds = [
673 [
new TitleValue( 1,
'AnotherDbKey' ),
'123' ],
677 $mockDb->expects( $this->any() )
678 ->method(
'makeList' )
679 ->will( $this->returnValue(
'makeList return value' ) );
680 $mockDb->expects( $this->once() )
684 [
'wl_namespace',
'wl_title',
'watchers' =>
'COUNT(*)' ],
685 'makeList return value',
686 $this->isType(
'string' ),
688 'GROUP BY' => [
'wl_namespace',
'wl_title' ],
689 'HAVING' =>
'COUNT(*) >= 50',
693 $this->returnValue( [] )
697 $mockCache->expects( $this->never() )->method(
'get' );
698 $mockCache->expects( $this->never() )->method(
'set' );
699 $mockCache->expects( $this->never() )->method(
'delete' );
709 0 => [
'SomeDbKey' => 0,
'OtherDbKey' => 0 ],
710 1 => [
'AnotherDbKey' => 0 ],
714 $store->countVisitingWatchersMultiple( $titleValuesWithThresholds, $minWatchers )
722 $mockDb->expects( $this->exactly( 1 ) )
723 ->method(
'selectRowCount' )
728 "wl_notificationtimestamp IS NOT NULL",
731 $this->isType(
'string' )
733 ->will( $this->returnValue(
'9' ) );
736 $mockCache->expects( $this->never() )->method(
'set' );
737 $mockCache->expects( $this->never() )->method(
'get' );
738 $mockCache->expects( $this->never() )->method(
'delete' );
747 $this->assertEquals( 9, $store->countUnreadNotifications(
$user ) );
757 $mockDb->expects( $this->exactly( 1 ) )
758 ->method(
'selectRowCount' )
763 "wl_notificationtimestamp IS NOT NULL",
766 $this->isType(
'string' ),
769 ->will( $this->returnValue(
'50' ) );
772 $mockCache->expects( $this->never() )->method(
'set' );
773 $mockCache->expects( $this->never() )->method(
'get' );
774 $mockCache->expects( $this->never() )->method(
'delete' );
785 $store->countUnreadNotifications(
$user, $limit )
796 $mockDb->expects( $this->exactly( 1 ) )
797 ->method(
'selectRowCount' )
802 "wl_notificationtimestamp IS NOT NULL",
805 $this->isType(
'string' ),
808 ->will( $this->returnValue(
'9' ) );
811 $mockCache->expects( $this->never() )->method(
'set' );
812 $mockCache->expects( $this->never() )->method(
'get' );
813 $mockCache->expects( $this->never() )->method(
'delete' );
824 $store->countUnreadNotifications(
$user, $limit )
830 $mockDb->expects( $this->once() )
836 'wl_notificationtimestamp',
840 'wl_title' =>
'Old_Title',
842 'WatchedItemStore::duplicateEntry',
845 ->will( $this->returnValue(
new FakeResultWrapper( [] ) ) );
854 $store->duplicateEntry(
855 Title::newFromText(
'Old_Title' ),
856 Title::newFromText(
'New_Title' )
862 $this->
getFakeRow( [
'wl_user' =>
'1',
'wl_notificationtimestamp' =>
'20151212010101' ] ),
863 $this->
getFakeRow( [
'wl_user' =>
'2',
'wl_notificationtimestamp' =>
null ] ),
867 $mockDb->expects( $this->at( 0 ) )
873 'wl_notificationtimestamp',
877 'wl_title' =>
'Old_Title',
880 ->will( $this->returnValue(
new FakeResultWrapper( $fakeRows ) ) );
881 $mockDb->expects( $this->at( 1 ) )
882 ->method(
'replace' )
885 [ [
'wl_user',
'wl_namespace',
'wl_title' ] ],
890 'wl_title' =>
'New_Title',
891 'wl_notificationtimestamp' =>
'20151212010101',
896 'wl_title' =>
'New_Title',
897 'wl_notificationtimestamp' =>
null,
900 $this->isType(
'string' )
904 $mockCache->expects( $this->never() )->method(
'get' );
905 $mockCache->expects( $this->never() )->method(
'delete' );
914 $store->duplicateEntry(
915 Title::newFromText(
'Old_Title' ),
916 Title::newFromText(
'New_Title' )
922 $mockDb->expects( $this->at( 0 ) )
928 'wl_notificationtimestamp',
932 'wl_title' =>
'Old_Title',
935 ->will( $this->returnValue(
new FakeResultWrapper( [] ) ) );
936 $mockDb->expects( $this->at( 1 ) )
942 'wl_notificationtimestamp',
946 'wl_title' =>
'Old_Title',
949 ->will( $this->returnValue(
new FakeResultWrapper( [] ) ) );
952 $mockCache->expects( $this->never() )->method(
'get' );
953 $mockCache->expects( $this->never() )->method(
'delete' );
962 $store->duplicateAllAssociatedEntries(
963 Title::newFromText(
'Old_Title' ),
964 Title::newFromText(
'New_Title' )
970 [ Title::newFromText(
'Old_Title' ), Title::newFromText(
'New_Title' ) ],
983 $this->
getFakeRow( [
'wl_user' =>
'1',
'wl_notificationtimestamp' =>
'20151212010101' ] ),
987 $mockDb->expects( $this->at( 0 ) )
993 'wl_notificationtimestamp',
997 'wl_title' => $oldTarget->
getDBkey(),
1000 ->will( $this->returnValue(
new FakeResultWrapper( $fakeRows ) ) );
1001 $mockDb->expects( $this->at( 1 ) )
1002 ->method(
'replace' )
1005 [ [
'wl_user',
'wl_namespace',
'wl_title' ] ],
1010 'wl_title' => $newTarget->
getDBkey(),
1011 'wl_notificationtimestamp' =>
'20151212010101',
1014 $this->isType(
'string' )
1016 $mockDb->expects( $this->at( 2 ) )
1017 ->method(
'select' )
1022 'wl_notificationtimestamp',
1026 'wl_title' => $oldTarget->
getDBkey(),
1029 ->will( $this->returnValue(
new FakeResultWrapper( $fakeRows ) ) );
1030 $mockDb->expects( $this->at( 3 ) )
1031 ->method(
'replace' )
1034 [ [
'wl_user',
'wl_namespace',
'wl_title' ] ],
1039 'wl_title' => $newTarget->
getDBkey(),
1040 'wl_notificationtimestamp' =>
'20151212010101',
1043 $this->isType(
'string' )
1047 $mockCache->expects( $this->never() )->method(
'get' );
1048 $mockCache->expects( $this->never() )->method(
'delete' );
1057 $store->duplicateAllAssociatedEntries(
1065 $mockDb->expects( $this->once() )
1066 ->method(
'insert' )
1072 'wl_namespace' => 0,
1073 'wl_title' =>
'Some_Page',
1074 'wl_notificationtimestamp' =>
null,
1080 $mockCache->expects( $this->once() )
1081 ->method(
'delete' )
1082 ->with(
'0:Some_Page:1' );
1093 Title::newFromText(
'Some_Page' )
1099 $mockDb->expects( $this->never() )
1100 ->method(
'insert' );
1103 $mockCache->expects( $this->never() )
1104 ->method(
'delete' );
1115 Title::newFromText(
'Some_Page' )
1128 $store->addWatchBatchForUser(
1129 $this->getMockNonAnonUserWithId( 1 ),
1137 $mockDb->expects( $this->once() )
1138 ->method(
'insert' )
1144 'wl_namespace' => 0,
1145 'wl_title' =>
'Some_Page',
1146 'wl_notificationtimestamp' =>
null,
1150 'wl_namespace' => 1,
1151 'wl_title' =>
'Some_Page',
1152 'wl_notificationtimestamp' =>
null,
1157 $mockDb->expects( $this->once() )
1158 ->method(
'affectedRows' )
1162 $mockCache->expects( $this->exactly( 2 ) )
1163 ->method(
'delete' );
1164 $mockCache->expects( $this->at( 1 ) )
1165 ->method(
'delete' )
1166 ->with(
'0:Some_Page:1' );
1167 $mockCache->expects( $this->at( 3 ) )
1168 ->method(
'delete' )
1169 ->with(
'1:Some_Page:1' );
1181 $store->addWatchBatchForUser(
1190 $mockDb->expects( $this->never() )
1191 ->method(
'insert' );
1194 $mockCache->expects( $this->never() )
1195 ->method(
'delete' );
1205 $store->addWatchBatchForUser(
1206 $this->getAnonUser(),
1215 $mockDb->expects( $this->never() )
1216 ->method(
'insert' );
1219 $mockCache->expects( $this->never() )
1220 ->method(
'delete' );
1230 $store->addWatchBatchForUser(
$user, [] )
1236 $mockDb->expects( $this->once() )
1237 ->method(
'selectRow' )
1240 'wl_notificationtimestamp',
1243 'wl_namespace' => 0,
1244 'wl_title' =>
'SomeDbKey',
1247 ->will( $this->returnValue(
1248 $this->
getFakeRow( [
'wl_notificationtimestamp' =>
'20151212010101' ] )
1252 $mockCache->expects( $this->once() )
1265 $watchedItem = $store->loadWatchedItem(
1269 $this->assertInstanceOf( WatchedItem::class, $watchedItem );
1270 $this->assertEquals( 1, $watchedItem->getUser()->getId() );
1271 $this->assertEquals(
'SomeDbKey', $watchedItem->getLinkTarget()->getDBkey() );
1272 $this->assertEquals( 0, $watchedItem->getLinkTarget()->getNamespace() );
1277 $mockDb->expects( $this->once() )
1278 ->method(
'selectRow' )
1281 'wl_notificationtimestamp',
1284 'wl_namespace' => 0,
1285 'wl_title' =>
'SomeDbKey',
1288 ->will( $this->returnValue( [] ) );
1291 $mockCache->expects( $this->never() )->method(
'get' );
1292 $mockCache->expects( $this->never() )->method(
'delete' );
1302 $store->loadWatchedItem(
1303 $this->getMockNonAnonUserWithId( 1 ),
1311 $mockDb->expects( $this->never() )
1312 ->method(
'selectRow' );
1315 $mockCache->expects( $this->never() )->method(
'get' );
1316 $mockCache->expects( $this->never() )->method(
'delete' );
1326 $store->loadWatchedItem(
1327 $this->getAnonUser(),
1335 $mockDb->expects( $this->once() )
1336 ->method(
'delete' )
1342 'wl_namespace' => 0,
1343 'wl_title' => [
'SomeDbKey' ],
1350 'wl_namespace' => 1,
1351 'wl_title' => [
'SomeDbKey' ],
1355 $mockDb->expects( $this->exactly( 1 ) )
1356 ->method(
'affectedRows' )
1360 $mockCache->expects( $this->never() )->method(
'get' );
1361 $mockCache->expects( $this->once() )
1362 ->method(
'delete' )
1364 [
'0:SomeDbKey:1' ],
1375 $titleValue =
new TitleValue( 0,
'SomeDbKey' );
1377 $store->removeWatch(
1378 $this->getMockNonAnonUserWithId( 1 ),
1379 Title::newFromTitleValue( $titleValue )
1386 $mockDb->expects( $this->once() )
1387 ->method(
'delete' )
1393 'wl_namespace' => 0,
1394 'wl_title' => [
'SomeDbKey' ],
1401 'wl_namespace' => 1,
1402 'wl_title' => [
'SomeDbKey' ],
1407 $mockDb->expects( $this->once() )
1408 ->method(
'affectedRows' )
1412 $mockCache->expects( $this->never() )->method(
'get' );
1413 $mockCache->expects( $this->once() )
1414 ->method(
'delete' )
1416 [
'0:SomeDbKey:1' ],
1427 $titleValue =
new TitleValue( 0,
'SomeDbKey' );
1429 $store->removeWatch(
1430 $this->getMockNonAnonUserWithId( 1 ),
1431 Title::newFromTitleValue( $titleValue )
1438 $mockDb->expects( $this->never() )
1439 ->method(
'delete' );
1442 $mockCache->expects( $this->never() )->method(
'get' );
1443 $mockCache->expects( $this->never() )
1444 ->method(
'delete' );
1454 $store->removeWatch(
1455 $this->getAnonUser(),
1463 $mockDb->expects( $this->once() )
1464 ->method(
'selectRow' )
1467 'wl_notificationtimestamp',
1470 'wl_namespace' => 0,
1471 'wl_title' =>
'SomeDbKey',
1474 ->will( $this->returnValue(
1475 $this->
getFakeRow( [
'wl_notificationtimestamp' =>
'20151212010101' ] )
1479 $mockCache->expects( $this->never() )->method(
'delete' );
1480 $mockCache->expects( $this->once() )
1485 ->will( $this->returnValue(
null ) );
1486 $mockCache->expects( $this->once() )
1499 $watchedItem = $store->getWatchedItem(
1503 $this->assertInstanceOf( WatchedItem::class, $watchedItem );
1504 $this->assertEquals( 1, $watchedItem->getUser()->getId() );
1505 $this->assertEquals(
'SomeDbKey', $watchedItem->getLinkTarget()->getDBkey() );
1506 $this->assertEquals( 0, $watchedItem->getLinkTarget()->getNamespace() );
1511 $mockDb->expects( $this->never() )
1512 ->method(
'selectRow' );
1515 $linkTarget =
new TitleValue( 0,
'SomeDbKey' );
1516 $cachedItem =
new WatchedItem( $mockUser, $linkTarget,
'20151212010101' );
1519 $mockCache->expects( $this->never() )->method(
'delete' );
1520 $mockCache->expects( $this->never() )->method(
'set' );
1521 $mockCache->expects( $this->once() )
1526 ->will( $this->returnValue( $cachedItem ) );
1535 $this->assertEquals(
1537 $store->getWatchedItem(
1546 $mockDb->expects( $this->once() )
1547 ->method(
'selectRow' )
1550 'wl_notificationtimestamp',
1553 'wl_namespace' => 0,
1554 'wl_title' =>
'SomeDbKey',
1557 ->will( $this->returnValue( [] ) );
1560 $mockCache->expects( $this->never() )->method(
'set' );
1561 $mockCache->expects( $this->never() )->method(
'delete' );
1562 $mockCache->expects( $this->once() )
1564 ->with(
'0:SomeDbKey:1' )
1565 ->will( $this->returnValue(
false ) );
1575 $store->getWatchedItem(
1576 $this->getMockNonAnonUserWithId( 1 ),
1584 $mockDb->expects( $this->never() )
1585 ->method(
'selectRow' );
1588 $mockCache->expects( $this->never() )->method(
'set' );
1589 $mockCache->expects( $this->never() )->method(
'get' );
1590 $mockCache->expects( $this->never() )->method(
'delete' );
1600 $store->getWatchedItem(
1601 $this->getAnonUser(),
1609 $mockDb->expects( $this->once() )
1610 ->method(
'select' )
1613 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
1616 ->will( $this->returnValue( [
1618 'wl_namespace' => 0,
1619 'wl_title' =>
'Foo1',
1620 'wl_notificationtimestamp' =>
'20151212010101',
1623 'wl_namespace' => 1,
1624 'wl_title' =>
'Foo2',
1625 'wl_notificationtimestamp' =>
null,
1630 $mockCache->expects( $this->never() )->method(
'delete' );
1631 $mockCache->expects( $this->never() )->method(
'get' );
1632 $mockCache->expects( $this->never() )->method(
'set' );
1642 $watchedItems = $store->getWatchedItemsForUser(
$user );
1644 $this->assertInternalType(
'array', $watchedItems );
1645 $this->assertCount( 2, $watchedItems );
1646 foreach ( $watchedItems
as $watchedItem ) {
1647 $this->assertInstanceOf( WatchedItem::class, $watchedItem );
1649 $this->assertEquals(
1653 $this->assertEquals(
1675 $mockDb->expects( $this->once() )
1676 ->method(
'select' )
1679 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
1681 $this->isType(
'string' ),
1682 [
'ORDER BY' => [
'wl_namespace ASC',
'wl_title ASC' ] ]
1684 ->will( $this->returnValue( [] ) );
1693 $watchedItems = $store->getWatchedItemsForUser(
1697 $this->assertEquals( [], $watchedItems );
1708 $this->setExpectedException( InvalidArgumentException::class );
1709 $store->getWatchedItemsForUser(
1717 $mockDb->expects( $this->once() )
1718 ->method(
'selectRow' )
1721 'wl_notificationtimestamp',
1724 'wl_namespace' => 0,
1725 'wl_title' =>
'SomeDbKey',
1728 ->will( $this->returnValue(
1729 $this->
getFakeRow( [
'wl_notificationtimestamp' =>
'20151212010101' ] )
1733 $mockCache->expects( $this->never() )->method(
'delete' );
1734 $mockCache->expects( $this->once() )
1736 ->with(
'0:SomeDbKey:1' )
1737 ->will( $this->returnValue(
false ) );
1738 $mockCache->expects( $this->once() )
1753 $this->getMockNonAnonUserWithId( 1 ),
1761 $mockDb->expects( $this->once() )
1762 ->method(
'selectRow' )
1765 'wl_notificationtimestamp',
1768 'wl_namespace' => 0,
1769 'wl_title' =>
'SomeDbKey',
1772 ->will( $this->returnValue( [] ) );
1775 $mockCache->expects( $this->never() )->method(
'set' );
1776 $mockCache->expects( $this->never() )->method(
'delete' );
1777 $mockCache->expects( $this->once() )
1779 ->with(
'0:SomeDbKey:1' )
1780 ->will( $this->returnValue(
false ) );
1791 $this->getMockNonAnonUserWithId( 1 ),
1799 $mockDb->expects( $this->never() )
1800 ->method(
'selectRow' );
1803 $mockCache->expects( $this->never() )->method(
'set' );
1804 $mockCache->expects( $this->never() )->method(
'get' );
1805 $mockCache->expects( $this->never() )->method(
'delete' );
1816 $this->getAnonUser(),
1831 'wl_namespace' =>
'0',
1832 'wl_title' =>
'SomeDbKey',
1833 'wl_notificationtimestamp' =>
'20151212010101',
1837 'wl_namespace' =>
'1',
1838 'wl_title' =>
'AnotherDbKey',
1839 'wl_notificationtimestamp' =>
null,
1844 $mockDb->expects( $this->once() )
1845 ->method(
'makeWhereFrom2d' )
1847 [ [
'SomeDbKey' => 1 ], [
'AnotherDbKey' => 1 ] ],
1848 $this->isType(
'string' ),
1849 $this->isType(
'string' )
1851 ->will( $this->returnValue(
'makeWhereFrom2d return value' ) );
1852 $mockDb->expects( $this->once() )
1853 ->method(
'select' )
1856 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
1858 'makeWhereFrom2d return value',
1861 $this->isType(
'string' )
1863 ->will( $this->returnValue( $dbResult ) );
1866 $mockCache->expects( $this->exactly( 2 ) )
1869 [
'0:SomeDbKey:1' ],
1870 [
'1:AnotherDbKey:1' ]
1872 ->will( $this->returnValue(
null ) );
1873 $mockCache->expects( $this->never() )->method(
'set' );
1874 $mockCache->expects( $this->never() )->method(
'delete' );
1883 $this->assertEquals(
1885 0 => [
'SomeDbKey' =>
'20151212010101', ],
1886 1 => [
'AnotherDbKey' =>
null, ],
1888 $store->getNotificationTimestampsBatch( $this->getMockNonAnonUserWithId( 1 ), $targets )
1899 $mockDb->expects( $this->once() )
1900 ->method(
'makeWhereFrom2d' )
1902 [ [
'OtherDbKey' => 1 ] ],
1903 $this->isType(
'string' ),
1904 $this->isType(
'string' )
1906 ->will( $this->returnValue(
'makeWhereFrom2d return value' ) );
1907 $mockDb->expects( $this->once() )
1908 ->method(
'select' )
1911 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
1913 'makeWhereFrom2d return value',
1916 $this->isType(
'string' )
1918 ->will( $this->returnValue( $this->
getFakeRow( [] ) ) );
1921 $mockCache->expects( $this->once() )
1923 ->with(
'0:OtherDbKey:1' )
1924 ->will( $this->returnValue(
null ) );
1925 $mockCache->expects( $this->never() )->method(
'set' );
1926 $mockCache->expects( $this->never() )->method(
'delete' );
1935 $this->assertEquals(
1937 0 => [
'OtherDbKey' =>
false, ],
1939 $store->getNotificationTimestampsBatch( $this->getMockNonAnonUserWithId( 1 ), $targets )
1954 $mockDb->expects( $this->once() )
1955 ->method(
'makeWhereFrom2d' )
1957 [ 1 => [
'AnotherDbKey' => 1 ] ],
1958 $this->isType(
'string' ),
1959 $this->isType(
'string' )
1961 ->will( $this->returnValue(
'makeWhereFrom2d return value' ) );
1962 $mockDb->expects( $this->once() )
1963 ->method(
'select' )
1966 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
1968 'makeWhereFrom2d return value',
1971 $this->isType(
'string' )
1973 ->will( $this->returnValue( [
1975 [
'wl_namespace' =>
'1',
'wl_title' =>
'AnotherDbKey',
'wl_notificationtimestamp' =>
null, ]
1980 $mockCache->expects( $this->at( 1 ) )
1982 ->with(
'0:SomeDbKey:1' )
1983 ->will( $this->returnValue( $cachedItem ) );
1984 $mockCache->expects( $this->at( 3 ) )
1986 ->with(
'1:AnotherDbKey:1' )
1987 ->will( $this->returnValue(
null ) );
1988 $mockCache->expects( $this->never() )->method(
'set' );
1989 $mockCache->expects( $this->never() )->method(
'delete' );
1998 $this->assertEquals(
2000 0 => [
'SomeDbKey' =>
'20151212010101', ],
2001 1 => [
'AnotherDbKey' =>
null, ],
2003 $store->getNotificationTimestampsBatch(
$user, $targets )
2019 $mockDb->expects( $this->never() )->method( $this->
anything() );
2022 $mockCache->expects( $this->at( 1 ) )
2024 ->with(
'0:SomeDbKey:1' )
2025 ->will( $this->returnValue( $cachedItems[0] ) );
2026 $mockCache->expects( $this->at( 3 ) )
2028 ->with(
'1:AnotherDbKey:1' )
2029 ->will( $this->returnValue( $cachedItems[1] ) );
2030 $mockCache->expects( $this->never() )->method(
'set' );
2031 $mockCache->expects( $this->never() )->method(
'delete' );
2040 $this->assertEquals(
2042 0 => [
'SomeDbKey' =>
'20151212010101', ],
2043 1 => [
'AnotherDbKey' =>
null, ],
2045 $store->getNotificationTimestampsBatch(
$user, $targets )
2056 $mockDb->expects( $this->never() )->method( $this->
anything() );
2059 $mockCache->expects( $this->never() )->method( $this->
anything() );
2068 $this->assertEquals(
2070 0 => [
'SomeDbKey' =>
false, ],
2071 1 => [
'AnotherDbKey' =>
false, ],
2073 $store->getNotificationTimestampsBatch( $this->getAnonUser(), $targets )
2079 $mockDb->expects( $this->never() )
2080 ->method(
'selectRow' );
2083 $mockCache->expects( $this->never() )->method(
'get' );
2084 $mockCache->expects( $this->never() )->method(
'set' );
2085 $mockCache->expects( $this->never() )->method(
'delete' );
2095 $store->resetNotificationTimestamp(
2096 $this->getAnonUser(),
2097 Title::newFromText(
'SomeDbKey' )
2104 $mockDb->expects( $this->once() )
2105 ->method(
'selectRow' )
2108 'wl_notificationtimestamp',
2111 'wl_namespace' => 0,
2112 'wl_title' =>
'SomeDbKey',
2115 ->will( $this->returnValue( [] ) );
2118 $mockCache->expects( $this->never() )->method(
'get' );
2119 $mockCache->expects( $this->never() )->method(
'set' );
2120 $mockCache->expects( $this->never() )->method(
'delete' );
2130 $store->resetNotificationTimestamp(
2131 $this->getMockNonAnonUserWithId( 1 ),
2132 Title::newFromText(
'SomeDbKey' )
2139 $title = Title::newFromText(
'SomeDbKey' );
2142 $mockDb->expects( $this->once() )
2143 ->method(
'selectRow' )
2146 'wl_notificationtimestamp',
2149 'wl_namespace' => 0,
2150 'wl_title' =>
'SomeDbKey',
2153 ->will( $this->returnValue(
2154 $this->
getFakeRow( [
'wl_notificationtimestamp' =>
'20151212010101' ] )
2158 $mockCache->expects( $this->never() )->method(
'get' );
2159 $mockCache->expects( $this->once() )
2163 $this->isInstanceOf( WatchedItem::class )
2165 $mockCache->expects( $this->once() )
2166 ->method(
'delete' )
2167 ->with(
'0:SomeDbKey:1' );
2170 $mockQueueGroup->expects( $this->once() )
2171 ->method(
'lazyPush' )
2184 $store->resetNotificationTimestamp(
2193 $title = Title::newFromText(
'SomeDbKey' );
2196 $mockDb->expects( $this->never() )
2197 ->method(
'selectRow' );
2200 $mockCache->expects( $this->never() )->method(
'get' );
2201 $mockCache->expects( $this->never() )->method(
'set' );
2202 $mockCache->expects( $this->once() )
2203 ->method(
'delete' )
2204 ->with(
'0:SomeDbKey:1' );
2214 $mockQueueGroup->expects( $this->any() )
2215 ->method(
'lazyPush' )
2221 $store->resetNotificationTimestamp(
2236 $title = $this->createMock( Title::class );
2237 $title->expects( $this->any() )
2238 ->method(
'getText' )
2239 ->will( $this->returnValue( str_replace(
'_',
' ', $text ) ) );
2240 $title->expects( $this->any() )
2241 ->method(
'getDbKey' )
2242 ->will( $this->returnValue( str_replace(
'_',
' ', $text ) ) );
2243 $title->expects( $this->any() )
2244 ->method(
'getNamespace' )
2245 ->will( $this->returnValue( $ns ) );
2253 callable $notificationTimestampCondition
2255 $this->assertEquals( $expectedTitle->
getDBkey(),
$job->getTitle()->getDBkey() );
2256 $this->assertEquals( $expectedTitle->
getNamespace(),
$job->getTitle()->getNamespace() );
2258 $jobParams =
$job->getParams();
2259 $this->assertArrayHasKey(
'type', $jobParams );
2260 $this->assertEquals(
'updateWatchlistNotification', $jobParams[
'type'] );
2261 $this->assertArrayHasKey(
'userid', $jobParams );
2262 $this->assertEquals( $expectedUserId, $jobParams[
'userid'] );
2263 $this->assertArrayHasKey(
'notifTime', $jobParams );
2264 $this->assertTrue( $notificationTimestampCondition( $jobParams[
'notifTime'] ) );
2271 $title->expects( $this->once() )
2272 ->method(
'getNextRevisionID' )
2274 ->will( $this->returnValue(
false ) );
2277 $mockDb->expects( $this->never() )
2278 ->method(
'selectRow' );
2281 $mockCache->expects( $this->never() )->method(
'get' );
2282 $mockCache->expects( $this->never() )->method(
'set' );
2283 $mockCache->expects( $this->once() )
2284 ->method(
'delete' )
2285 ->with(
'0:SomeTitle:1' );
2295 $mockQueueGroup->expects( $this->any() )
2296 ->method(
'lazyPush' )
2297 ->will( $this->returnCallback(
2304 return $time ===
null;
2311 $store->resetNotificationTimestamp(
2324 $title->expects( $this->once() )
2325 ->method(
'getNextRevisionID' )
2327 ->will( $this->returnValue( 33 ) );
2330 $mockDb->expects( $this->once() )
2331 ->method(
'selectRow' )
2334 'wl_notificationtimestamp',
2337 'wl_namespace' => 0,
2338 'wl_title' =>
'SomeDbKey',
2341 ->will( $this->returnValue(
2342 $this->
getFakeRow( [
'wl_notificationtimestamp' =>
'20151212010101' ] )
2346 $mockCache->expects( $this->never() )->method(
'get' );
2347 $mockCache->expects( $this->once() )
2349 ->with(
'0:SomeDbKey:1', $this->isType(
'object' ) );
2350 $mockCache->expects( $this->once() )
2351 ->method(
'delete' )
2352 ->with(
'0:SomeDbKey:1' );
2362 $mockQueueGroup->expects( $this->any() )
2363 ->method(
'lazyPush' )
2364 ->will( $this->returnCallback(
2371 return $time !==
null &&
$time >
'20151212010101';
2377 $getTimestampCallCounter = 0;
2378 $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
2379 function ( $titleParam, $oldidParam )
use ( &$getTimestampCallCounter,
$title, $oldid ) {
2380 $getTimestampCallCounter++;
2381 $this->assertEquals(
$title, $titleParam );
2382 $this->assertEquals( $oldid, $oldidParam );
2387 $store->resetNotificationTimestamp(
2394 $this->assertEquals( 2, $getTimestampCallCounter );
2396 ScopedCallback::consume( $scopedOverrideRevision );
2403 $title->expects( $this->once() )
2404 ->method(
'getNextRevisionID' )
2406 ->will( $this->returnValue( 33 ) );
2409 $mockDb->expects( $this->once() )
2410 ->method(
'selectRow' )
2413 'wl_notificationtimestamp',
2416 'wl_namespace' => 0,
2417 'wl_title' =>
'SomeDbKey',
2420 ->will( $this->returnValue(
false ) );
2423 $mockCache->expects( $this->never() )->method(
'get' );
2424 $mockCache->expects( $this->never() )->method(
'set' );
2425 $mockCache->expects( $this->once() )
2426 ->method(
'delete' )
2427 ->with(
'0:SomeDbKey:1' );
2437 $mockQueueGroup->expects( $this->any() )
2438 ->method(
'lazyPush' )
2439 ->will( $this->returnCallback(
2446 return $time ===
null;
2453 $store->resetNotificationTimestamp(
2466 $title->expects( $this->once() )
2467 ->method(
'getNextRevisionID' )
2469 ->will( $this->returnValue( 33 ) );
2472 $mockDb->expects( $this->once() )
2473 ->method(
'selectRow' )
2476 'wl_notificationtimestamp',
2479 'wl_namespace' => 0,
2480 'wl_title' =>
'SomeDbKey',
2483 ->will( $this->returnValue(
2484 $this->
getFakeRow( [
'wl_notificationtimestamp' =>
'30151212010101' ] )
2488 $mockCache->expects( $this->never() )->method(
'get' );
2489 $mockCache->expects( $this->once() )
2491 ->with(
'0:SomeDbKey:1', $this->isType(
'object' ) );
2492 $mockCache->expects( $this->once() )
2493 ->method(
'delete' )
2494 ->with(
'0:SomeDbKey:1' );
2504 $mockQueueGroup->expects( $this->any() )
2505 ->method(
'lazyPush' )
2506 ->will( $this->returnCallback(
2513 return $time ===
'30151212010101';
2519 $getTimestampCallCounter = 0;
2520 $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
2521 function ( $titleParam, $oldidParam )
use ( &$getTimestampCallCounter,
$title, $oldid ) {
2522 $getTimestampCallCounter++;
2523 $this->assertEquals(
$title, $titleParam );
2524 $this->assertEquals( $oldid, $oldidParam );
2529 $store->resetNotificationTimestamp(
2536 $this->assertEquals( 2, $getTimestampCallCounter );
2538 ScopedCallback::consume( $scopedOverrideRevision );
2545 $title->expects( $this->once() )
2546 ->method(
'getNextRevisionID' )
2548 ->will( $this->returnValue( 33 ) );
2551 $mockDb->expects( $this->once() )
2552 ->method(
'selectRow' )
2555 'wl_notificationtimestamp',
2558 'wl_namespace' => 0,
2559 'wl_title' =>
'SomeDbKey',
2562 ->will( $this->returnValue(
2563 $this->
getFakeRow( [
'wl_notificationtimestamp' =>
'30151212010101' ] )
2567 $mockCache->expects( $this->never() )->method(
'get' );
2568 $mockCache->expects( $this->once() )
2570 ->with(
'0:SomeDbKey:1', $this->isType(
'object' ) );
2571 $mockCache->expects( $this->once() )
2572 ->method(
'delete' )
2573 ->with(
'0:SomeDbKey:1' );
2583 $mockQueueGroup->expects( $this->any() )
2584 ->method(
'lazyPush' )
2585 ->will( $this->returnCallback(
2592 return $time ===
false;
2598 $getTimestampCallCounter = 0;
2599 $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
2600 function ( $titleParam, $oldidParam )
use ( &$getTimestampCallCounter,
$title, $oldid ) {
2601 $getTimestampCallCounter++;
2602 $this->assertEquals(
$title, $titleParam );
2603 $this->assertEquals( $oldid, $oldidParam );
2608 $store->resetNotificationTimestamp(
2615 $this->assertEquals( 2, $getTimestampCallCounter );
2617 ScopedCallback::consume( $scopedOverrideRevision );
2627 $this->assertFalse( $store->setNotificationTimestampsForUser( $this->getAnonUser(),
'' ) );
2632 $timestamp =
'20100101010101';
2642 $callableCallCounter = 0;
2643 $mockCallback =
function ( $callable )
use ( &$callableCallCounter ) {
2644 $callableCallCounter++;
2645 $this->assertInternalType(
'callable', $callable );
2647 $scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback( $mockCallback );
2650 $store->setNotificationTimestampsForUser(
$user, $timestamp )
2652 $this->assertEquals( 1, $callableCallCounter );
2667 $callableCallCounter = 0;
2668 $mockCallback =
function ( $callable )
use ( &$callableCallCounter ) {
2669 $callableCallCounter++;
2670 $this->assertInternalType(
'callable', $callable );
2672 $scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback( $mockCallback );
2675 $store->setNotificationTimestampsForUser(
$user, $timestamp )
2681 $timestamp =
'20100101010101';
2685 $mockDb->expects( $this->once() )
2686 ->method(
'update' )
2689 [
'wl_notificationtimestamp' =>
'TS' . $timestamp .
'TS' ],
2690 [
'wl_user' => 1,
'wl_namespace' => 0,
'wl_title' => [
'Foo',
'Bar' ] ]
2692 ->will( $this->returnValue(
true ) );
2693 $mockDb->expects( $this->exactly( 1 ) )
2694 ->method(
'timestamp' )
2695 ->will( $this->returnCallback(
function (
$value ) {
2696 return 'TS' .
$value .
'TS';
2698 $mockDb->expects( $this->once() )
2699 ->method(
'affectedRows' )
2700 ->will( $this->returnValue( 2 ) );
2710 $store->setNotificationTimestampsForUser(
$user, $timestamp, $targets )
2716 $mockDb->expects( $this->once() )
2717 ->method(
'selectFieldValues' )
2723 'wl_namespace' => 0,
2724 'wl_title' =>
'SomeDbKey',
2725 'wl_notificationtimestamp IS NULL'
2728 ->will( $this->returnValue( [
'2',
'3' ] ) );
2729 $mockDb->expects( $this->once() )
2730 ->method(
'update' )
2733 [
'wl_notificationtimestamp' =>
null ],
2735 'wl_user' => [ 2, 3 ],
2736 'wl_namespace' => 0,
2737 'wl_title' =>
'SomeDbKey',
2742 $mockCache->expects( $this->never() )->method(
'set' );
2743 $mockCache->expects( $this->never() )->method(
'get' );
2744 $mockCache->expects( $this->never() )->method(
'delete' );
2753 $this->assertEquals(
2755 $store->updateNotificationTimestamp(
2756 $this->getMockNonAnonUserWithId( 1 ),
2765 $mockDb->expects( $this->once() )
2766 ->method(
'selectFieldValues' )
2772 'wl_namespace' => 0,
2773 'wl_title' =>
'SomeDbKey',
2774 'wl_notificationtimestamp IS NULL'
2778 $this->returnValue( [] )
2780 $mockDb->expects( $this->never() )
2781 ->method(
'update' );
2784 $mockCache->expects( $this->never() )->method(
'set' );
2785 $mockCache->expects( $this->never() )->method(
'get' );
2786 $mockCache->expects( $this->never() )->method(
'delete' );
2795 $watchers = $store->updateNotificationTimestamp(
2800 $this->assertInternalType(
'array', $watchers );
2801 $this->assertEmpty( $watchers );
2806 $titleValue =
new TitleValue( 0,
'SomeDbKey' );
2809 $mockDb->expects( $this->once() )
2810 ->method(
'selectRow' )
2811 ->will( $this->returnValue(
2812 $this->
getFakeRow( [
'wl_notificationtimestamp' =>
'20151212010101' ] )
2814 $mockDb->expects( $this->once() )
2815 ->method(
'selectFieldValues' )
2817 $this->returnValue( [
'2',
'3' ] )
2819 $mockDb->expects( $this->once() )
2820 ->method(
'update' );
2823 $mockCache->expects( $this->once() )
2825 ->with(
'0:SomeDbKey:1', $this->isType(
'object' ) );
2826 $mockCache->expects( $this->once() )
2828 ->with(
'0:SomeDbKey:1' );
2829 $mockCache->expects( $this->once() )
2830 ->method(
'delete' )
2831 ->with(
'0:SomeDbKey:1' );
2841 $store->getWatchedItem(
$user, $titleValue );
2843 $store->updateNotificationTimestamp(
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
Job for updating user activity like "last viewed" timestamps.
Simple store for keeping values in an associative array for the current process.
Class to handle enqueueing of background jobs.
Class to both describe a background job and handle jobs.
A service class for fetching the wiki's current read-only mode.
Represents a page (or page fragment) title within MediaWiki.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
testLoadWatchedItem_anonymousUser()
testLoadWatchedItem_noItem()
testCountWatchersMultiple_withMinimumWatchers( $minWatchers)
provideIntWithDbUnsafeVersion
testDuplicateAllAssociatedEntries_somethingToDuplicate(LinkTarget $oldTarget, LinkTarget $newTarget)
provideLinkTargetPairs
testIsWatchedItem_existingItem()
testGetNotificationTimestampsBatch_cachedItem()
getMockTitle( $text, $ns=0)
testDuplicateEntry_somethingToDuplicate()
testSetNotificationTimestampsForUser_nullTimestamp()
testGetWatchedItem_noItem()
getFakeRow(array $rowValues)
testCountVisitingWatchers()
testGetNotificationTimestampsBatch_anonymousUser()
testCountUnreadNotifications_withUnreadLimit_overLimit( $limit)
provideIntWithDbUnsafeVersion
testCountUnreadNotifications()
testIsWatchedItem_anonymousUser()
testGetWatchedItem_cachedItem()
testCountUnreadNotifications_withUnreadLimit_underLimit( $limit)
provideIntWithDbUnsafeVersion
testGetNotificationTimestampsBatch_notWatchedTarget()
testUpdateNotificationTimestamp_noWatchers()
testAddWatchBatchForUser_nonAnonymousUser()
testAddWatch_anonymousUser()
testCountVisitingWatchersMultiple_withMissingTargets()
testCountWatchersMultiple()
testResetNotificationTimestamp_oldidSpecifiedLatestRevisionForced()
testRemoveWatch_anonymousUser()
newWatchedItemStore(LBFactory $lbFactory, JobQueueGroup $queueGroup, HashBagOStuff $cache, ReadOnlyMode $readOnlyMode)
testSetNotificationTimestampsForUser_allRows()
testResetNotificationTimestamp_item()
testGetNotificationTimestampsBatch_allItemsCached()
testResetNotificationTimestamp_oldidSpecifiedNotLatestRevisionForced()
testDuplicateAllAssociatedEntries_nothingToDuplicate()
testResetNotificationTimestamp_noItem()
testUpdateNotificationTimestamp_watchersExist()
testAddWatchBatchForUser_anonymousUsersAreSkipped()
getMockNonAnonUserWithId( $id)
testAddWatchBatchReturnsTrue_whenGivenEmptyList()
getMockLoadBalancer( $mockDb, $expectedConnectionType=null)
testAddWatch_nonAnonymousUser()
testSetNotificationTimestampsForUser_specificTargets()
testResetNotificationTimestamp_anonymousUser()
testSetNotificationTimestampsForUser_anonUser()
testUpdateNotificationTimestamp_clearsCachedItems()
testGetWatchedItemsForUser_badSortOptionThrowsException()
testResetNotificationTimestamp_notWatchedPageForced()
testGetNotificationTimestampsBatch()
testGetWatchedItemsForUser_optionsAndEmptyResult( $forWrite, $dbType)
provideDbTypes
testClearWatchedItems_tooManyItemsWatched()
testGetWatchedItem_anonymousUser()
getMockReadOnlyMode( $readOnly=false)
testRemoveWatch_existingItem()
testDuplicateEntry_nothingToDuplicate()
testLoadWatchedItem_existingItem()
testCountVisitingWatchersMultiple()
testResetNotificationTimestamp_noItemForced()
testResetNotificationTimestamp_futureNotificationTimestampForced()
testGetWatchedItem_existingItem()
getMockLBFactory( $mockDb, $expectedConnectionType=null)
verifyCallbackJob(ActivityUpdateJob $job, LinkTarget $expectedTitle, $expectedUserId, callable $notificationTimestampCondition)
testResetNotificationTimestamp_futureNotificationTimestampNotForced()
testAddWatchBatchForUser_readOnlyDBReturnsFalse()
testGetWatchedItemsForUser()
provideIntWithDbUnsafeVersion()
testIsWatchedItem_noItem()
testCountVisitingWatchersMultiple_withMinimumWatchers( $minWatchers)
provideIntWithDbUnsafeVersion
Storage layer class for WatchedItems.
Representation of a pair of user and title for watchlist entries.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break anything
see documentation in includes Linker php for Linker::makeImageLink & $time
namespace and then decline to actually register it file or subcat img or subcat $title
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
return true to allow those checks to and false if checking is done & $user
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 function
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(count( $args)< 1) $job