Merge "Do not linkify the namespace URI in 'uploadscriptednamespace' error message"
[lhc/web/wiklou.git] / tests / phpunit / includes / WatchedItemStoreIntegrationTest.php
index ad5041c..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 );
@@ -39,6 +41,21 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                        'Page should be watched'
                );
                $this->assertEquals( $initialUserWatchedItems + 1, $store->countWatchedItems( $user ) );
+               $watchedItemsForUser = $store->getWatchedItemsForUser( $user );
+               $this->assertCount( $initialUserWatchedItems + 1, $watchedItemsForUser );
+               $watchedItemsForUserHasExpectedItem = false;
+               foreach ( $watchedItemsForUser as $watchedItem ) {
+                       if (
+                               $watchedItem->getUser()->equals( $user ) &&
+                               $watchedItem->getLinkTarget() == $title->getTitleValue()
+                       ) {
+                               $watchedItemsForUserHasExpectedItem = true;
+                       }
+               }
+               $this->assertTrue(
+                       $watchedItemsForUserHasExpectedItem,
+                       'getWatchedItemsForUser should contain the page'
+               );
                $this->assertEquals( $initialWatchers + 1, $store->countWatchers( $title ) );
                $this->assertEquals(
                        $initialWatchers + 1,
@@ -63,6 +80,21 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                        'Page should be unwatched'
                );
                $this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems( $user ) );
+               $watchedItemsForUser = $store->getWatchedItemsForUser( $user );
+               $this->assertCount( $initialUserWatchedItems, $watchedItemsForUser );
+               $watchedItemsForUserHasExpectedItem = false;
+               foreach ( $watchedItemsForUser as $watchedItem ) {
+                       if (
+                               $watchedItem->getUser()->equals( $user ) &&
+                               $watchedItem->getLinkTarget() == $title->getTitleValue()
+                       ) {
+                               $watchedItemsForUserHasExpectedItem = true;
+                       }
+               }
+               $this->assertFalse(
+                       $watchedItemsForUserHasExpectedItem,
+                       'getWatchedItemsForUser should not contain the page'
+               );
                $this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
                $this->assertEquals(
                        $initialWatchers,
@@ -74,11 +106,11 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                );
        }
 
-       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' );
@@ -140,13 +172,31 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                                [ [ $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