Add WatchedItemStore::countVisitingWatchersMultiple
[lhc/web/wiklou.git] / tests / phpunit / includes / WatchedItemStoreIntegrationTest.php
index 9341fb8..0dea461 100644 (file)
@@ -25,21 +25,45 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                $store = WatchedItemStore::getDefaultInstance();
                // Cleanup after previous tests
                $store->removeWatch( $user, $title );
+               $initialWatchers = $store->countWatchers( $title );
+               $initialUserWatchedItems = $store->countWatchedItems( $user );
 
                $this->assertFalse(
                        $store->isWatched( $user, $title ),
                        'Page should not initially be watched'
                );
+
                $store->addWatch( $user, $title );
                $this->assertTrue(
                        $store->isWatched( $user, $title ),
                        'Page should be watched'
                );
+               $this->assertEquals( $initialUserWatchedItems + 1, $store->countWatchedItems( $user ) );
+               $this->assertEquals( $initialWatchers + 1, $store->countWatchers( $title ) );
+               $this->assertEquals(
+                       $initialWatchers + 1,
+                       $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
+               );
+               $this->assertEquals(
+                       [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialWatchers + 1 ] ],
+                       $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 1 ] )
+               );
+               $this->assertEquals(
+                       [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
+                       $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 2 ] )
+               );
+
                $store->removeWatch( $user, $title );
                $this->assertFalse(
                        $store->isWatched( $user, $title ),
                        'Page should be unwatched'
                );
+               $this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems( $user ) );
+               $this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
+               $this->assertEquals(
+                       $initialWatchers,
+                       $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
+               );
        }
 
        public function testUpdateAndResetNotificationTimestamp() {
@@ -49,15 +73,57 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                $store = WatchedItemStore::getDefaultInstance();
                $store->addWatch( $user, $title );
                $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
+               $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
+               $initialUnreadNotifications = $store->countUnreadNotifications( $user );
 
                $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
                $this->assertEquals(
                        '20150202010101',
                        $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
                );
+               $this->assertEquals(
+                       $initialVisitingWatchers - 1,
+                       $store->countVisitingWatchers( $title, '20150202020202' )
+               );
+               $this->assertEquals(
+                       $initialVisitingWatchers - 1,
+                       $store->countVisitingWatchersMultiple(
+                               [ [ $title, '20150202020202' ] ]
+                       )[$title->getNamespace()][$title->getDBkey()]
+               );
+               $this->assertEquals(
+                       $initialUnreadNotifications + 1,
+                       $store->countUnreadNotifications( $user )
+               );
+               $this->assertSame(
+                       true,
+                       $store->countUnreadNotifications( $user, $initialUnreadNotifications + 1 )
+               );
 
                $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
-               $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
+               $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
+               $this->assertEquals(
+                       $initialVisitingWatchers,
+                       $store->countVisitingWatchers( $title, '20150202020202' )
+               );
+               $this->assertEquals(
+                       $initialVisitingWatchers,
+                       $store->countVisitingWatchersMultiple(
+                               [ [ $title, '20150202020202' ] ]
+                       )[$title->getNamespace()][$title->getDBkey()]
+               );
+               $this->assertEquals(
+                       [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialVisitingWatchers ] ],
+                       $store->countVisitingWatchersMultiple(
+                               [ [ $title, '20150202020202' ] ], $initialVisitingWatchers
+                       )
+               );
+               $this->assertEquals(
+                       [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
+                       $store->countVisitingWatchersMultiple(
+                               [ [ $title, '20150202020202' ] ], $initialVisitingWatchers + 1
+                       )
+               );
        }
 
        public function testDuplicateAllAssociatedEntries() {