WMDE-leszek has uploaded a new change for review. https://gerrit.wikimedia.org/r/271279
Change subject: Add tests for WatchedItemStore::updateNotificationTimestamp ...................................................................... Add tests for WatchedItemStore::updateNotificationTimestamp Change-Id: Id9c77d2d21b43765b46a3afcf9b9b892ccdd27e9 --- M tests/phpunit/includes/WatchedItemStoreTest.php 1 file changed, 162 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/79/271279/1 diff --git a/tests/phpunit/includes/WatchedItemStoreTest.php b/tests/phpunit/includes/WatchedItemStoreTest.php index 66ec5a2..74ea0a8 100644 --- a/tests/phpunit/includes/WatchedItemStoreTest.php +++ b/tests/phpunit/includes/WatchedItemStoreTest.php @@ -802,4 +802,166 @@ ); } + public function testUpdateNotificationTimestamp_watchersExist() { + $mockDb = $this->getMockDb(); + $mockDb->expects( $this->once() ) + ->method( 'select' ) + ->with( + [ 'watchlist' ], + [ 'wl_user' ], + [ + 'wl_user != 1', + 'wl_namespace' => 0, + 'wl_title' => 'SomeDbKey', + 'wl_notificationtimestamp IS NULL' + ] + ) + ->will( + $this->returnValue( [ + $this->getFakeRow( [ 'wl_user' => '2' ] ), + $this->getFakeRow( [ 'wl_user' => '3' ] ) + ] ) + ); + // Not checking update calls due to it being passed as a callback to IDatabase::onTransactionIdle + + $mockConfig = $this->getMockConfig(); + $mockConfig->expects( $this->once() ) + ->method( 'get' ) + ->with( 'EnotifWatchlist' ) + ->will( $this->returnValue( true ) ); + + $store = new WatchedItemStore( + $this->getMockLoadBalancer( $mockDb ), + new HashBagOStuff( [ 'maxKeys' => 100 ] ), + $mockConfig + ); + + $this->assertEquals( + [ 2, 3 ], + $store->updateNotificationTimestamp( + $this->getMockNonAnonUserWithId( 1 ), + new TitleValue( 0, 'SomeDbKey' ), + '20151212010101' + ) + ); + } + + public function testUpdateNotificationTimestamp_noWatchers() { + $mockDb = $this->getMockDb(); + $mockDb->expects( $this->once() ) + ->method( 'select' ) + ->with( + [ 'watchlist' ], + [ 'wl_user' ], + [ + 'wl_user != 1', + 'wl_namespace' => 0, + 'wl_title' => 'SomeDbKey', + 'wl_notificationtimestamp IS NULL' + ] + ) + ->will( + $this->returnValue( [] ) + ); + // Not checking update calls due to it being passed as a callback to IDatabase::onTransactionIdle + + $mockConfig = $this->getMockConfig(); + $mockConfig->expects( $this->once() ) + ->method( 'get' ) + ->with( 'EnotifWatchlist' ) + ->will( $this->returnValue( true ) ); + + $store = new WatchedItemStore( + $this->getMockLoadBalancer( $mockDb ), + new HashBagOStuff( [ 'maxKeys' => 100 ] ), + $mockConfig + ); + + $watchers = $store->updateNotificationTimestamp( + $this->getMockNonAnonUserWithId( 1 ), + new TitleValue( 0, 'SomeDbKey' ), + '20151212010101' + ); + $this->assertInternalType( 'array', $watchers ); + $this->assertEmpty( $watchers ); + } + + public function testUpdateNotificationTimestamp_allRelevantSettingsAreFalse() { + $mockDb = $this->getMockDb(); + $mockDb->expects( $this->never() ) + ->method( 'select' ); + + $mockConfig = $this->getMockConfig(); + $mockConfig->expects( $this->at( 0 ) ) + ->method( 'get' ) + ->with( 'EnotifWatchlist' ) + ->will( $this->returnValue( false ) ); + $mockConfig->expects( $this->at( 1 ) ) + ->method( 'get' ) + ->with( 'ShowUpdatedMarker' ) + ->will( $this->returnValue( false ) ); + + $store = new WatchedItemStore( + $this->getMockLoadBalancer( $mockDb ), + new HashBagOStuff( [ 'maxKeys' => 100 ] ), + $mockConfig + ); + + $watchers = $store->updateNotificationTimestamp( + $this->getMockNonAnonUserWithId( 1 ), + new TitleValue( 0, 'SomeDbKey' ), + '20151212010101' + ); + $this->assertInternalType( 'array', $watchers ); + $this->assertEmpty( $watchers ); + } + + public function testUpdateNotificationTimestamp_singleSettingIsFalse() { + $mockDb = $this->getMockDb(); + $mockDb->expects( $this->once() ) + ->method( 'select' ) + ->with( + [ 'watchlist' ], + [ 'wl_user' ], + [ + 'wl_user != 1', + 'wl_namespace' => 0, + 'wl_title' => 'SomeDbKey', + 'wl_notificationtimestamp IS NULL' + ] + ) + ->will( + $this->returnValue( [ + $this->getFakeRow( [ 'wl_user' => '2' ] ), + $this->getFakeRow( [ 'wl_user' => '3' ] ) + ] ) + ); + // Not checking update calls due to it being passed as a callback to IDatabase::onTransactionIdle + + $mockConfig = $this->getMockConfig(); + $mockConfig->expects( $this->at( 0 ) ) + ->method( 'get' ) + ->with( 'EnotifWatchlist' ) + ->will( $this->returnValue( false ) ); + $mockConfig->expects( $this->at( 1 ) ) + ->method( 'get' ) + ->with( 'ShowUpdatedMarker' ) + ->will( $this->returnValue( true ) ); + + $store = new WatchedItemStore( + $this->getMockLoadBalancer( $mockDb ), + new HashBagOStuff( [ 'maxKeys' => 100 ] ), + $mockConfig + ); + + $this->assertEquals( + [ 2, 3 ], + $store->updateNotificationTimestamp( + $this->getMockNonAnonUserWithId( 1 ), + new TitleValue( 0, 'SomeDbKey' ), + '20151212010101' + ) + ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/271279 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id9c77d2d21b43765b46a3afcf9b9b892ccdd27e9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: WMDE-leszek <leszek.mani...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits