X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FWatchedItemStoreIntegrationTest.php;h=61b62aa66bb0df516947986fcb12b5adfd2a2bb6;hb=b86ef89dd17f51841a220e8ef9b3b8b2402e2547;hp=0dea461974bf8952d92bacc6fd59fb452966ef32;hpb=64078f2ce68e3679dfa315247d5e70a8a7f0f5d1;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php index 0dea461974..61b62aa66b 100644 --- a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php +++ b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php @@ -1,5 +1,7 @@ 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, @@ -52,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( @@ -59,18 +80,37 @@ 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, $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' ); @@ -81,6 +121,10 @@ 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' ) @@ -102,6 +146,10 @@ 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' ) @@ -124,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