16 self::$users[
'WatchedItemStoreIntegrationTestUser']
17 =
new TestUser(
'WatchedItemStoreIntegrationTestUser' );
21 return self::$users[
'WatchedItemStoreIntegrationTestUser']->getUser();
27 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
30 $initialWatchers = $store->countWatchers(
$title );
31 $initialUserWatchedItems = $store->countWatchedItems(
$user );
35 'Page should not initially be watched'
41 'Page should be watched'
43 $this->assertEquals( $initialUserWatchedItems + 1, $store->countWatchedItems(
$user ) );
44 $watchedItemsForUser = $store->getWatchedItemsForUser(
$user );
45 $this->assertCount( $initialUserWatchedItems + 1, $watchedItemsForUser );
46 $watchedItemsForUserHasExpectedItem =
false;
47 foreach ( $watchedItemsForUser
as $watchedItem ) {
49 $watchedItem->getUser()->equals(
$user ) &&
50 $watchedItem->getLinkTarget() ==
$title->getTitleValue()
52 $watchedItemsForUserHasExpectedItem =
true;
56 $watchedItemsForUserHasExpectedItem,
57 'getWatchedItemsForUser should contain the page'
59 $this->assertEquals( $initialWatchers + 1, $store->countWatchers(
$title ) );
62 $store->countWatchersMultiple( [
$title ] )[
$title->getNamespace()][
$title->getDBkey()]
65 [ 0 => [
'WatchedItemStoreIntegrationTestPage' => $initialWatchers + 1 ] ],
66 $store->countWatchersMultiple( [
$title ], [
'minimumWatchers' => $initialWatchers + 1 ] )
69 [ 0 => [
'WatchedItemStoreIntegrationTestPage' => 0 ] ],
70 $store->countWatchersMultiple( [
$title ], [
'minimumWatchers' => $initialWatchers + 2 ] )
73 [
$title->getNamespace() => [
$title->getDBkey() => null ] ],
74 $store->getNotificationTimestampsBatch(
$user, [
$title ] )
80 'Page should be unwatched'
82 $this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems(
$user ) );
83 $watchedItemsForUser = $store->getWatchedItemsForUser(
$user );
84 $this->assertCount( $initialUserWatchedItems, $watchedItemsForUser );
85 $watchedItemsForUserHasExpectedItem =
false;
86 foreach ( $watchedItemsForUser
as $watchedItem ) {
88 $watchedItem->getUser()->equals(
$user ) &&
89 $watchedItem->getLinkTarget() ==
$title->getTitleValue()
91 $watchedItemsForUserHasExpectedItem =
true;
95 $watchedItemsForUserHasExpectedItem,
96 'getWatchedItemsForUser should not contain the page'
98 $this->assertEquals( $initialWatchers, $store->countWatchers(
$title ) );
101 $store->countWatchersMultiple( [
$title ] )[
$title->getNamespace()][
$title->getDBkey()]
105 $store->getNotificationTimestampsBatch(
$user, [
$title ] )
113 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
115 $store->addWatchBatchForUser(
$user, [ $title1, $title2 ] );
117 $this->assertTrue( $store->isWatched(
$user, $title1 ) );
118 $this->assertTrue( $store->isWatched(
$user, $title2 ) );
120 $store->clearUserWatchedItems(
$user );
122 $this->assertFalse( $store->isWatched(
$user, $title1 ) );
123 $this->assertFalse( $store->isWatched(
$user, $title2 ) );
128 $otherUser = (
new TestUser(
'WatchedItemStoreIntegrationTestUser_otherUser' ) )->
getUser();
130 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
132 $this->assertNull( $store->loadWatchedItem(
$user,
$title )->getNotificationTimestamp() );
133 $initialVisitingWatchers = $store->countVisitingWatchers(
$title,
'20150202020202' );
134 $initialUnreadNotifications = $store->countUnreadNotifications(
$user );
136 $store->updateNotificationTimestamp( $otherUser,
$title,
'20150202010101' );
139 $store->loadWatchedItem(
$user,
$title )->getNotificationTimestamp()
142 [
$title->getNamespace() => [
$title->getDBkey() =>
'20150202010101' ] ],
143 $store->getNotificationTimestampsBatch(
$user, [
$title ] )
146 $initialVisitingWatchers - 1,
147 $store->countVisitingWatchers(
$title,
'20150202020202' )
150 $initialVisitingWatchers - 1,
151 $store->countVisitingWatchersMultiple(
152 [ [
$title,
'20150202020202' ] ]
156 $initialUnreadNotifications + 1,
157 $store->countUnreadNotifications(
$user )
161 $store->countUnreadNotifications(
$user, $initialUnreadNotifications + 1 )
164 $this->assertTrue( $store->resetNotificationTimestamp(
$user,
$title ) );
165 $this->assertNull( $store->getWatchedItem(
$user,
$title )->getNotificationTimestamp() );
167 [
$title->getNamespace() => [
$title->getDBkey() => null ] ],
168 $store->getNotificationTimestampsBatch(
$user, [
$title ] )
171 $initialVisitingWatchers,
172 $store->countVisitingWatchers(
$title,
'20150202020202' )
175 $initialVisitingWatchers,
176 $store->countVisitingWatchersMultiple(
177 [ [
$title,
'20150202020202' ] ]
181 [ 0 => [
'WatchedItemStoreIntegrationTestPage' => $initialVisitingWatchers ] ],
182 $store->countVisitingWatchersMultiple(
183 [ [
$title,
'20150202020202' ] ], $initialVisitingWatchers
187 [ 0 => [
'WatchedItemStoreIntegrationTestPage' => 0 ] ],
188 $store->countVisitingWatchersMultiple(
189 [ [
$title,
'20150202020202' ] ], $initialVisitingWatchers + 1
195 $store->setNotificationTimestampsForUser(
$user,
'20200202020202', [
$title ] )
199 $store->getWatchedItem(
$user,
$title )->getNotificationTimestamp()
204 $store->setNotificationTimestampsForUser(
$user,
'20210202020202' )
208 $store->getWatchedItem(
$user,
$title )->getNotificationTimestamp()
216 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
217 $store->addWatch(
$user, $titleOld->getSubjectPage() );
218 $store->addWatch(
$user, $titleOld->getTalkPage() );
220 $store->removeWatch(
$user, $titleNew->getSubjectPage() );
221 $store->removeWatch(
$user, $titleNew->getTalkPage() );
223 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
225 $this->assertTrue( $store->isWatched(
$user, $titleOld->getSubjectPage() ) );
226 $this->assertTrue( $store->isWatched(
$user, $titleOld->getTalkPage() ) );
227 $this->assertTrue( $store->isWatched(
$user, $titleNew->getSubjectPage() ) );
228 $this->assertTrue( $store->isWatched(
$user, $titleNew->getTalkPage() ) );