8 * @covers WatchedItemStore
10 class WatchedItemStoreIntegrationTest
extends MediaWikiTestCase
{
12 public function setUp() {
14 self
::$users['WatchedItemStoreIntegrationTestUser']
15 = new TestUser( 'WatchedItemStoreIntegrationTestUser' );
18 private function getUser() {
19 return self
::$users['WatchedItemStoreIntegrationTestUser']->getUser();
22 public function testWatchAndUnWatchItem() {
23 $user = $this->getUser();
24 $title = Title
::newFromText( 'WatchedItemStoreIntegrationTestPage' );
25 $store = WatchedItemStore
::getDefaultInstance();
26 // Cleanup after previous tests
27 $store->removeWatch( $user, $title );
28 $initialWatchers = $store->countWatchers( $title );
29 $initialUserWatchedItems = $store->countWatchedItems( $user );
32 $store->isWatched( $user, $title ),
33 'Page should not initially be watched'
36 $store->addWatch( $user, $title );
38 $store->isWatched( $user, $title ),
39 'Page should be watched'
41 $this->assertEquals( $initialUserWatchedItems +
1, $store->countWatchedItems( $user ) );
42 $this->assertEquals( $initialWatchers +
1, $store->countWatchers( $title ) );
45 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
48 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialWatchers +
1 ] ],
49 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers +
1 ] )
52 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
53 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers +
2 ] )
56 [ $title->getNamespace() => [ $title->getDBkey() => null ] ],
57 $store->getNotificationTimestampsBatch( $user, [ $title ] )
60 $store->removeWatch( $user, $title );
62 $store->isWatched( $user, $title ),
63 'Page should be unwatched'
65 $this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems( $user ) );
66 $this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
69 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
72 [ $title->getNamespace() => [ $title->getDBkey() => false ] ],
73 $store->getNotificationTimestampsBatch( $user, [ $title ] )
77 public function testUpdateAndResetNotificationTimestamp() {
78 $user = $this->getUser();
79 $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
80 $title = Title
::newFromText( 'WatchedItemStoreIntegrationTestPage' );
81 $store = WatchedItemStore
::getDefaultInstance();
82 $store->addWatch( $user, $title );
83 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
84 $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
85 $initialUnreadNotifications = $store->countUnreadNotifications( $user );
87 $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
90 $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
93 [ $title->getNamespace() => [ $title->getDBkey() => '20150202010101' ] ],
94 $store->getNotificationTimestampsBatch( $user, [ $title ] )
97 $initialVisitingWatchers - 1,
98 $store->countVisitingWatchers( $title, '20150202020202' )
101 $initialVisitingWatchers - 1,
102 $store->countVisitingWatchersMultiple(
103 [ [ $title, '20150202020202' ] ]
104 )[$title->getNamespace()][$title->getDBkey()]
107 $initialUnreadNotifications +
1,
108 $store->countUnreadNotifications( $user )
112 $store->countUnreadNotifications( $user, $initialUnreadNotifications +
1 )
115 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
116 $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
118 [ $title->getNamespace() => [ $title->getDBkey() => null ] ],
119 $store->getNotificationTimestampsBatch( $user, [ $title ] )
122 $initialVisitingWatchers,
123 $store->countVisitingWatchers( $title, '20150202020202' )
126 $initialVisitingWatchers,
127 $store->countVisitingWatchersMultiple(
128 [ [ $title, '20150202020202' ] ]
129 )[$title->getNamespace()][$title->getDBkey()]
132 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialVisitingWatchers ] ],
133 $store->countVisitingWatchersMultiple(
134 [ [ $title, '20150202020202' ] ], $initialVisitingWatchers
138 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
139 $store->countVisitingWatchersMultiple(
140 [ [ $title, '20150202020202' ] ], $initialVisitingWatchers +
1
145 public function testDuplicateAllAssociatedEntries() {
146 $user = $this->getUser();
147 $titleOld = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
148 $titleNew = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
149 $store = WatchedItemStore
::getDefaultInstance();
150 $store->addWatch( $user, $titleOld->getSubjectPage() );
151 $store->addWatch( $user, $titleOld->getTalkPage() );
152 // Cleanup after previous tests
153 $store->removeWatch( $user, $titleNew->getSubjectPage() );
154 $store->removeWatch( $user, $titleNew->getTalkPage() );
156 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
158 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
159 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
160 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
161 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );