mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
Namespace Gateway
Change-Id: I7501be6e57cec92b2b4175b8772d213c7fd031d4
This commit is contained in:
parent
8aa42e0946
commit
fb4478454d
|
@ -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",
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Notifications\Gateway;
|
||||
|
||||
use Config;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MWEchoDbFactory;
|
||||
use MWEchoNotifUser;
|
||||
|
||||
/**
|
||||
* Database gateway which handles direct database interaction with the
|
||||
* echo_notification & echo_event for a user, that wouldn't require
|
||||
* loading data into models
|
||||
*/
|
||||
class EchoUserNotificationGateway {
|
||||
class UserNotificationGateway {
|
||||
|
||||
/**
|
||||
* @var MWEchoDbFactory
|
||||
|
@ -32,6 +37,7 @@ class EchoUserNotificationGateway {
|
|||
* @var string
|
||||
*/
|
||||
protected static $notificationTable = 'echo_notification';
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserFactory;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
|
@ -25,7 +26,7 @@ class MWEchoNotifUser {
|
|||
|
||||
/**
|
||||
* Database access gateway
|
||||
* @var EchoUserNotificationGateway
|
||||
* @var UserNotificationGateway
|
||||
*/
|
||||
private $userNotifGateway;
|
||||
|
||||
|
@ -89,7 +90,7 @@ class MWEchoNotifUser {
|
|||
* because it could be obtained from factory method newFromUser()
|
||||
* @param UserIdentity $user
|
||||
* @param WANObjectCache $cache
|
||||
* @param EchoUserNotificationGateway $userNotifGateway
|
||||
* @param UserNotificationGateway $userNotifGateway
|
||||
* @param EchoNotificationMapper $notifMapper
|
||||
* @param EchoTargetPageMapper $targetPageMapper
|
||||
* @param UserOptionsLookup $userOptionsLookup
|
||||
|
@ -99,7 +100,7 @@ class MWEchoNotifUser {
|
|||
public function __construct(
|
||||
UserIdentity $user,
|
||||
WANObjectCache $cache,
|
||||
EchoUserNotificationGateway $userNotifGateway,
|
||||
UserNotificationGateway $userNotifGateway,
|
||||
EchoNotificationMapper $notifMapper,
|
||||
EchoTargetPageMapper $targetPageMapper,
|
||||
UserOptionsLookup $userOptionsLookup,
|
||||
|
@ -130,7 +131,7 @@ class MWEchoNotifUser {
|
|||
return new MWEchoNotifUser(
|
||||
$user,
|
||||
$services->getMainWANObjectCache(),
|
||||
new EchoUserNotificationGateway(
|
||||
new UserNotificationGateway(
|
||||
$user,
|
||||
MWEchoDbFactory::newFromDefault(),
|
||||
$services->getMainConfig()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserOptionsLookup;
|
||||
|
||||
|
@ -52,7 +53,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 ),
|
||||
|
@ -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 ),
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
/**
|
||||
* @covers \EchoUserNotificationGateway
|
||||
* @covers \MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway
|
||||
*/
|
||||
class EchoUserNotificationGatewayTest extends MediaWikiUnitTestCase {
|
||||
class UserNotificationGatewayTest extends MediaWikiUnitTestCase {
|
||||
|
||||
public function testMarkRead() {
|
||||
// no event ids to mark
|
||||
$gateway = new EchoUserNotificationGateway(
|
||||
$gateway = new UserNotificationGateway(
|
||||
$this->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()
|
Loading…
Reference in a new issue