X-Git-Url: http://git.cyclocoop.org/fichier?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FWatchedItemStoreIntegrationTest.php;h=f34af6113d00e00162757d622e6074c3ab69974b;hb=6f5751aa3a3a2ec981d7aebd45791a18dbd8b4e3;hp=91dd1aae24b17157c885cad6e5f2018316139b09;hpb=427d098717e17b86a26dd27ee739a951a672ef4a;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php index 91dd1aae24..f34af6113d 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() { $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,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 ) @@ -96,17 +146,39 @@ 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 + ) + ); } 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