diff --git a/extension.json b/extension.json index 7584c45c9..3ad5ec13a 100644 --- a/extension.json +++ b/extension.json @@ -1123,7 +1123,6 @@ "EchoTitleLocalCache": "includes/cache/TitleLocalCache.php", "EchoUnreadWikis": "includes/UnreadWikis.php", "EchoUserLocator": "includes/UserLocator.php", - "EchoUserNotificationGateway": "includes/gateway/UserNotificationGateway.php", "GenerateSampleNotifications": "maintenance/generateSampleNotifications.php", "MWEchoDbFactory": "includes/EchoDbFactory.php", "MWEchoEmailBatch": "includes/EmailBatch.php", diff --git a/includes/gateway/UserNotificationGateway.php b/includes/Gateway/UserNotificationGateway.php similarity index 97% rename from includes/gateway/UserNotificationGateway.php rename to includes/Gateway/UserNotificationGateway.php index 6685a84d9..ab37ea554 100644 --- a/includes/gateway/UserNotificationGateway.php +++ b/includes/Gateway/UserNotificationGateway.php @@ -1,13 +1,18 @@ getMainWANObjectCache(), - new EchoUserNotificationGateway( + new UserNotificationGateway( $user, MWEchoDbFactory::newFromDefault(), $services->getMainConfig() diff --git a/tests/phpunit/NotifUserTest.php b/tests/phpunit/NotifUserTest.php index cbdfa3bf5..dd05de619 100644 --- a/tests/phpunit/NotifUserTest.php +++ b/tests/phpunit/NotifUserTest.php @@ -1,5 +1,6 @@ cache, - $this->mockEchoUserNotificationGateway( [ 'markRead' => true ] ), + $this->mockUserNotificationGateway( [ 'markRead' => true ] ), $this->mockEchoNotificationMapper(), $this->createMock( EchoTargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), @@ -65,7 +66,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { $notifUser = new MWEchoNotifUser( User::newFromId( 2 ), $this->cache, - $this->mockEchoUserNotificationGateway( [ 'markRead' => false ] ), + $this->mockUserNotificationGateway( [ 'markRead' => false ] ), $this->mockEchoNotificationMapper(), $this->createMock( EchoTargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), @@ -81,7 +82,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { $notifUser = new MWEchoNotifUser( User::newFromId( 2 ), $this->cache, - $this->mockEchoUserNotificationGateway( [ 'markRead' => true ] ), + $this->mockUserNotificationGateway( [ 'markRead' => true ] ), $this->mockEchoNotificationMapper( [ $this->mockEchoNotification() ] ), $this->createMock( EchoTargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), @@ -94,7 +95,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { $notifUser = new MWEchoNotifUser( User::newFromId( 2 ), $this->cache, - $this->mockEchoUserNotificationGateway( [ 'markRead' => false ] ), + $this->mockUserNotificationGateway( [ 'markRead' => false ] ), $this->mockEchoNotificationMapper( [ $this->mockEchoNotification() ] ), $this->createMock( EchoTargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), @@ -107,7 +108,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { $notifUser = new MWEchoNotifUser( User::newFromId( 2 ), $this->cache, - $this->mockEchoUserNotificationGateway( [ 'markRead' => true ] ), + $this->mockUserNotificationGateway( [ 'markRead' => true ] ), $this->mockEchoNotificationMapper(), $this->createMock( EchoTargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), @@ -120,7 +121,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { $notifUser = new MWEchoNotifUser( User::newFromId( 2 ), $this->cache, - $this->mockEchoUserNotificationGateway( [ 'markRead' => false ] ), + $this->mockUserNotificationGateway( [ 'markRead' => false ] ), $this->mockEchoNotificationMapper(), $this->createMock( EchoTargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), @@ -130,11 +131,11 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { $this->assertFalse( $notifUser->markAllRead() ); } - public function mockEchoUserNotificationGateway( array $dbResult = [] ) { + public function mockUserNotificationGateway( array $dbResult = [] ) { $dbResult += [ 'markRead' => true ]; - $gateway = $this->createMock( EchoUserNotificationGateway::class ); + $gateway = $this->createMock( UserNotificationGateway::class ); $gateway->method( 'markRead' ) ->willReturn( $dbResult['markRead'] ); $gateway->method( 'getDB' ) @@ -171,7 +172,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { return new MWEchoNotifUser( User::newFromId( 2 ), $this->cache, - $this->mockEchoUserNotificationGateway(), + $this->mockUserNotificationGateway(), $this->mockEchoNotificationMapper(), $this->createMock( EchoTargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), diff --git a/tests/phpunit/unit/gateway/UserNotificationGatewayTest.php b/tests/phpunit/unit/Gateway/UserNotificationGatewayTest.php similarity index 85% rename from tests/phpunit/unit/gateway/UserNotificationGatewayTest.php rename to tests/phpunit/unit/Gateway/UserNotificationGatewayTest.php index 86d6f58f4..4a7cdace7 100644 --- a/tests/phpunit/unit/gateway/UserNotificationGatewayTest.php +++ b/tests/phpunit/unit/Gateway/UserNotificationGatewayTest.php @@ -1,15 +1,16 @@ mockUser(), $this->mockMWEchoDbFactory(), $this->mockConfig() @@ -17,7 +18,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { $this->assertFalse( $gateway->markRead( [] ) ); // successful update - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'update' => true ] ), $this->mockConfig() @@ -25,7 +26,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { $this->assertTrue( $gateway->markRead( [ 2 ] ) ); // unsuccessful update - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'update' => false ] ), $this->mockConfig() @@ -35,7 +36,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { public function testMarkAllRead() { // successful update - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'update' => true ] ), $this->mockConfig() @@ -43,7 +44,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { $this->assertTrue( $gateway->markAllRead( [ 2 ] ) ); // null update - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'update' => false ] ), $this->mockConfig() @@ -53,7 +54,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { public function testGetNotificationCount() { // unsuccessful select - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'selectRowCount' => 0 ] ), $this->mockConfig() @@ -61,7 +62,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { $this->assertSame( 0, $gateway->getCappedNotificationCount( DB_REPLICA, [ 'event_one' ] ) ); // successful select of alert - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'selectRowCount' => 2 ] ), $this->mockConfig() @@ -69,7 +70,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { $this->assertSame( 2, $gateway->getCappedNotificationCount( DB_REPLICA, [ 'event_one', 'event_two' ] ) ); // there is event, should return 0 - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'selectRowCount' => 2 ] ), $this->mockConfig() @@ -77,7 +78,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { $this->assertSame( 0, $gateway->getCappedNotificationCount( DB_REPLICA, [] ) ); // successful select - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'selectRowCount' => 3 ] ), $this->mockConfig() @@ -86,7 +87,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { } public function testGetUnreadNotifications() { - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'select' => false ] ), $this->mockConfig() @@ -98,7 +99,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase { (object)[ 'notification_event' => 2 ], (object)[ 'notification_event' => 3 ], ]; - $gateway = new EchoUserNotificationGateway( + $gateway = new UserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'select' => $dbResult ] ), $this->mockConfig()