Merge "Convert Special:NewFiles to use OOUI."
[lhc/web/wiklou.git] / tests / phpunit / includes / WatchedItemStoreIntegrationTest.php
index 9eaa35a..61b62aa 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @author Addshore
  *
@@ -22,7 +24,7 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
        public function testWatchAndUnWatchItem() {
                $user = $this->getUser();
                $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                // Cleanup after previous tests
                $store->removeWatch( $user, $title );
                $initialWatchers = $store->countWatchers( $title );
@@ -67,6 +69,10 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                        [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
                        $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 2 ] )
                );
+               $this->assertEquals(
+                       [ $title->getNamespace() => [ $title->getDBkey() => null ] ],
+                       $store->getNotificationTimestampsBatch( $user, [ $title ] )
+               );
 
                $store->removeWatch( $user, $title );
                $this->assertFalse(
@@ -94,13 +100,17 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                        $initialWatchers,
                        $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
                );
+               $this->assertEquals(
+                       [ $title->getNamespace() => [ $title->getDBkey() => false ] ],
+                       $store->getNotificationTimestampsBatch( $user, [ $title ] )
+               );
        }
 
-       public function testUpdateAndResetNotificationTimestamp() {
+       public function testUpdateResetAndSetNotificationTimestamp() {
                $user = $this->getUser();
                $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
                $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                $store->addWatch( $user, $title );
                $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
                $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
@@ -111,10 +121,20 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                        '20150202010101',
                        $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
                );
+               $this->assertEquals(
+                       [ $title->getNamespace() => [ $title->getDBkey() => '20150202010101' ] ],
+                       $store->getNotificationTimestampsBatch( $user, [ $title ] )
+               );
                $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 )
@@ -126,17 +146,57 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
 
                $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
                $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
+               $this->assertEquals(
+                       [ $title->getNamespace() => [ $title->getDBkey() => null ] ],
+                       $store->getNotificationTimestampsBatch( $user, [ $title ] )
+               );
                $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
+                       )
+               );
+
+               // setNotificationTimestampsForUser specifying a title
+               $this->assertTrue(
+                       $store->setNotificationTimestampsForUser( $user, '20200202020202', [ $title ] )
+               );
+               $this->assertEquals(
+                       '20200202020202',
+                       $store->getWatchedItem( $user, $title )->getNotificationTimestamp()
+               );
+
+               // setNotificationTimestampsForUser not specifying a title
+               $this->assertTrue(
+                       $store->setNotificationTimestampsForUser( $user, '20210202020202' )
+               );
+               $this->assertEquals(
+                       '20210202020202',
+                       $store->getWatchedItem( $user, $title )->getNotificationTimestamp()
+               );
        }
 
        public function testDuplicateAllAssociatedEntries() {
                $user = $this->getUser();
                $titleOld = Title::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
                $titleNew = Title::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                $store->addWatch( $user, $titleOld->getSubjectPage() );
                $store->addWatch( $user, $titleOld->getTalkPage() );
                // Cleanup after previous tests