Namespace Mapper

Change-Id: I8a02082466ef39db32ffa7562b02db61929346cd
This commit is contained in:
Reedy 2022-11-02 14:47:04 -06:00
parent e6251eb642
commit c85fe25fe7
25 changed files with 148 additions and 110 deletions

View file

@ -1073,7 +1073,6 @@
"Bundleable": "includes/Bundleable.php",
"Bundler": "includes/Bundler.php",
"EchoAbstractEntity": "includes/model/AbstractEntity.php",
"EchoAbstractMapper": "includes/mapper/AbstractMapper.php",
"EchoArrayList": "includes/EchoArrayList.php",
"EchoAttributeManager": "includes/AttributeManager.php",
"EchoCachedList": "includes/EchoCachedList.php",
@ -1091,7 +1090,6 @@
"EchoEmailFormat": "includes/EmailFormat.php",
"EchoEmailFrequency": "includes/EmailFrequency.php",
"EchoEvent": "includes/model/Event.php",
"EchoEventMapper": "includes/mapper/EventMapper.php",
"EchoEventPresentationModel": "includes/Formatters/EchoEventPresentationModel.php",
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoEventPresentationModel": "includes/Formatters/EchoEventPresentationModel.php",
"EchoForeignNotifications": "includes/ForeignNotifications.php",
@ -1101,7 +1099,8 @@
"EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php",
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php",
"EchoNotification": "includes/model/Notification.php",
"EchoNotificationMapper": "includes/mapper/NotificationMapper.php",
"EchoNotificationMapper": "includes/Mapper/NotificationMapper.php",
"MediaWiki\\Extension\\Notifications\\Mapper\\NotificationMapper": "includes/Mapper/NotificationMapper.php",
"EchoNotifier": "includes/Notifier.php",
"EchoOnWikiList": "includes/EchoOnWikiList.php",
"EchoPresentationModelSection": "includes/Formatters/EchoPresentationModelSection.php",
@ -1111,7 +1110,6 @@
"EchoSummaryParser": "includes/EchoSummaryParser.php",
"EchoSuppressionRowUpdateGenerator": "includes/schemaUpdate.php",
"EchoTargetPage": "includes/model/TargetPage.php",
"EchoTargetPageMapper": "includes/mapper/TargetPageMapper.php",
"EchoUnreadWikis": "includes/UnreadWikis.php",
"EchoUserLocator": "includes/UserLocator.php",
"GenerateSampleNotifications": "maintenance/generateSampleNotifications.php",
@ -1137,8 +1135,8 @@
"MediaWiki\\Extension\\Notifications\\": "includes/"
},
"TestAutoloadClasses": {
"EchoAbstractMapperStub": "tests/phpunit/mapper/EchoAbstractMapperStub.php",
"EchoExecuteFirstArgumentStub": "tests/phpunit/mapper/EchoExecuteFirstArgumentStub.php"
"EchoAbstractMapperStub": "tests/phpunit/Mapper/EchoAbstractMapperStub.php",
"EchoExecuteFirstArgumentStub": "tests/phpunit/Mapper/EchoExecuteFirstArgumentStub.php"
},
"ServiceWiringFiles": [
"ServiceWiring.php"

View file

@ -11,10 +11,10 @@ use EchoAttributeManager;
use EchoDataOutputFormatter;
use EchoForeignNotifications;
use EchoNotification;
use EchoNotificationMapper;
use EchoSeenTime;
use EchoServices;
use MediaWiki\Extension\Notifications\Controller\NotificationController;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MWEchoNotifUser;
use Title;
use User;
@ -241,7 +241,7 @@ class ApiEchoNotifications extends ApiQueryBase {
'continue' => null
];
$notifMapper = new EchoNotificationMapper();
$notifMapper = new NotificationMapper();
// check if we want both read & unread...
if ( in_array( 'read', $filter ) && in_array( '!read', $filter ) ) {

View file

@ -3,8 +3,8 @@
namespace MediaWiki\Extension\Notifications\Controller;
use DeferredUpdates;
use EchoEventMapper;
use EchoNotificationMapper;
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\MediaWikiServices;
use MWEchoNotifUser;
use MWException;
@ -27,8 +27,8 @@ class ModerationController {
return;
}
$eventMapper = new EchoEventMapper();
$notificationMapper = new EchoNotificationMapper();
$eventMapper = new EventMapper();
$notificationMapper = new NotificationMapper();
$affectedUserIds = $notificationMapper->fetchUsersWithNotificationsForEvents( $eventIds );
$eventMapper->toggleDeleted( $eventIds, $moderate );

View file

@ -2,6 +2,7 @@
use MediaWiki\Extension\Notifications\Formatters\EchoHtmlDigestEmailFormatter;
use MediaWiki\Extension\Notifications\Formatters\EchoPlainTextDigestEmailFormatter;
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserOptionsManager;
use Wikimedia\Rdbms\IResultWrapper;
@ -271,7 +272,7 @@ class MWEchoEmailBatch {
*/
public function clearProcessedEvent() {
global $wgUpdateRowsPerQuery;
$eventMapper = new EchoEventMapper();
$eventMapper = new EventMapper();
$dbFactory = MWEchoDbFactory::newFromDefault();
$dbw = $dbFactory->getEchoDb( DB_PRIMARY );
$dbr = $dbFactory->getEchoDb( DB_REPLICA );

View file

@ -12,9 +12,7 @@ use EchoDiscussionParser;
use EchoEmailFormat;
use EchoEmailFrequency;
use EchoEvent;
use EchoEventMapper;
use EchoNotification;
use EchoNotificationMapper;
use EchoSeenTime;
use EchoServices;
use EmailNotification;
@ -30,6 +28,8 @@ use MediaWiki\DAO\WikiAwareEntity;
use MediaWiki\Extension\Notifications\Controller\ModerationController;
use MediaWiki\Extension\Notifications\Controller\NotificationController;
use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel;
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\Push\Api\ApiEchoPushSubscriptions;
use MediaWiki\Hook\AbortTalkPageEmailNotificationHook;
use MediaWiki\Hook\BeforePageDisplayHook;
@ -624,7 +624,7 @@ class Hooks implements
$thresholdCount = self::getEditCount( $userIdentity );
if ( in_array( $thresholdCount, $thresholds ) ) {
DeferredUpdates::addCallableUpdate( static function () use ( $userIdentity, $title, $thresholdCount ) {
$notificationMapper = new EchoNotificationMapper();
$notificationMapper = new NotificationMapper();
$notifications = $notificationMapper->fetchByUser( $userIdentity, 10, null, [ 'thank-you-edit' ] );
/** @var EchoNotification $notification */
foreach ( $notifications as $notification ) {
@ -956,7 +956,7 @@ class Hooks implements
// Attempt to mark a notification as read when visiting a page
$eventIds = [];
if ( $title->getArticleID() ) {
$eventMapper = new EchoEventMapper();
$eventMapper = new EventMapper();
$events = $eventMapper->fetchUnreadByUserAndPage( $user, $title->getArticleID() );
foreach ( $events as $event ) {
@ -982,7 +982,7 @@ class Hooks implements
if ( $eventsToMarkAsRead ) {
// fetch the notifications to adjust the counters
$notifMapper = new EchoNotificationMapper();
$notifMapper = new NotificationMapper();
$notifs = $notifMapper->fetchByUserEvents( $user, $eventsToMarkAsRead );
foreach ( $notifs as $notif ) {
@ -1158,7 +1158,7 @@ class Hooks implements
);
// If there's exactly one new user talk message, then link directly to it from the alert.
$notificationMapper = new EchoNotificationMapper();
$notificationMapper = new NotificationMapper();
$notifications = $notificationMapper->fetchUnreadByUser( $user, 2, null, [ 'edit-user-talk' ] );
if ( count( $notifications ) === 1 ) {
$presModel = EchoEventPresentationModel::factory(
@ -1635,7 +1635,7 @@ class Hooks implements
$archivedRevisionCount
) {
DeferredUpdates::addCallableUpdate( static function () use ( $articleId ) {
$eventMapper = new EchoEventMapper();
$eventMapper = new EventMapper();
$eventIds = $eventMapper->fetchIdsByPage( $articleId );
ModerationController::moderate( $eventIds, true );
} );
@ -1651,7 +1651,7 @@ class Hooks implements
public function onArticleUndelete( $title, $create, $comment, $oldPageId, $restoredPages ) {
if ( $create ) {
DeferredUpdates::addCallableUpdate( static function () use ( $oldPageId ) {
$eventMapper = new EchoEventMapper();
$eventMapper = new EventMapper();
$eventIds = $eventMapper->fetchIdsByPage( $oldPageId );
ModerationController::moderate( $eventIds, false );
} );

View file

@ -2,8 +2,8 @@
namespace MediaWiki\Extension\Notifications\Jobs;
use EchoNotificationMapper;
use Job;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\MediaWikiServices;
use MWEchoNotifUser;
use Title;
@ -47,7 +47,7 @@ class NotificationDeleteJob extends Job {
return true;
}
$notifMapper = new EchoNotificationMapper();
$notifMapper = new NotificationMapper();
// Back-compat for older jobs which used array( $userId => $userId );
$userIds = array_values( $this->params['userIds'] );

View file

@ -2,9 +2,9 @@
namespace MediaWiki\Extension\Notifications\Jobs;
use EchoEventMapper;
use Job;
use MediaWiki\Extension\Notifications\Controller\NotificationController;
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
use Title;
class NotificationJob extends Job {
@ -15,7 +15,7 @@ class NotificationJob extends Job {
}
public function run() {
$eventMapper = new EchoEventMapper();
$eventMapper = new EventMapper();
$event = $eventMapper->fetchById( $this->params['eventId'], true );
NotificationController::notify( $event, false );

View file

@ -1,9 +1,14 @@
<?php
namespace MediaWiki\Extension\Notifications\Mapper;
use MWEchoDbFactory;
use MWException;
/**
* Abstract mapper for model
*/
abstract class EchoAbstractMapper {
abstract class AbstractMapper {
/**
* Echo database factory

View file

@ -1,10 +1,16 @@
<?php
namespace MediaWiki\Extension\Notifications\Mapper;
use EchoEvent;
use MWException;
use User;
/**
* Database mapper for EchoEvent model, which is an immutable class, there should
* not be any update to it
*/
class EchoEventMapper extends EchoAbstractMapper {
class EventMapper extends AbstractMapper {
/**
* Insert an event record

View file

@ -1,13 +1,23 @@
<?php
namespace MediaWiki\Extension\Notifications\Mapper;
use AtomicSectionUpdate;
use BatchRowIterator;
use DeferredUpdates;
use EchoNotification;
use Exception;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserIdentity;
use MWException;
use MWExceptionHandler;
use Title;
use Wikimedia\Rdbms\IDatabase;
/**
* Database mapper for EchoNotification model
*/
class EchoNotificationMapper extends EchoAbstractMapper {
class NotificationMapper extends AbstractMapper {
/**
* Insert a notification record
@ -61,7 +71,7 @@ class EchoNotificationMapper extends EchoAbstractMapper {
/**
* Get unread notifications by user in the amount specified by limit order by
* notification timestamp in descending order. We have an index to retrieve
* unread notifications but it's not optimized for ordering by timestamp. The
* unread notifications, but it's not optimized for ordering by timestamp. The
* descending order is only allowed if we keep the notification in low volume,
* which is done via a deleteJob
* @param UserIdentity $userIdentity
@ -356,7 +366,7 @@ class EchoNotificationMapper extends EchoAbstractMapper {
*/
public function deleteByUserEventOffset( UserIdentity $userIdentity, $eventId ) {
global $wgUpdateRowsPerQuery;
$eventMapper = new EchoEventMapper( $this->dbFactory );
$eventMapper = new EventMapper( $this->dbFactory );
$userId = $userIdentity->getId();
$dbw = $this->dbFactory->getEchoDb( DB_PRIMARY );
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
@ -430,3 +440,5 @@ class EchoNotificationMapper extends EchoAbstractMapper {
}
}
class_alias( NotificationMapper::class, 'EchoNotificationMapper' );

View file

@ -1,9 +1,13 @@
<?php
namespace MediaWiki\Extension\Notifications\Mapper;
use EchoTargetPage;
/**
* Database mapper for EchoTargetPage model
*/
class EchoTargetPageMapper extends EchoAbstractMapper {
class TargetPageMapper extends AbstractMapper {
/**
* List of db fields used to construct an EchoTargetPage model

View file

@ -1,6 +1,8 @@
<?php
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserFactory;
use MediaWiki\User\UserIdentity;
@ -32,13 +34,13 @@ class MWEchoNotifUser {
/**
* Notification mapper
* @var EchoNotificationMapper
* @var NotificationMapper
*/
private $notifMapper;
/**
* Target page mapper
* @var EchoTargetPageMapper
* @var TargetPageMapper
*/
private $targetPageMapper;
@ -91,8 +93,8 @@ class MWEchoNotifUser {
* @param UserIdentity $user
* @param WANObjectCache $cache
* @param UserNotificationGateway $userNotifGateway
* @param EchoNotificationMapper $notifMapper
* @param EchoTargetPageMapper $targetPageMapper
* @param NotificationMapper $notifMapper
* @param TargetPageMapper $targetPageMapper
* @param UserOptionsLookup $userOptionsLookup
* @param UserFactory $userFactory
* @param ReadOnlyMode $readOnlyMode
@ -101,8 +103,8 @@ class MWEchoNotifUser {
UserIdentity $user,
WANObjectCache $cache,
UserNotificationGateway $userNotifGateway,
EchoNotificationMapper $notifMapper,
EchoTargetPageMapper $targetPageMapper,
NotificationMapper $notifMapper,
TargetPageMapper $targetPageMapper,
UserOptionsLookup $userOptionsLookup,
UserFactory $userFactory,
ReadOnlyMode $readOnlyMode
@ -136,8 +138,8 @@ class MWEchoNotifUser {
MWEchoDbFactory::newFromDefault(),
$services->getMainConfig()
),
new EchoNotificationMapper(),
new EchoTargetPageMapper(),
new NotificationMapper(),
new TargetPageMapper(),
$services->getUserOptionsLookup(),
$services->getUserFactory(),
$services->getReadOnlyMode()

View file

@ -2,12 +2,12 @@
namespace MediaWiki\Extension\Notifications\Push;
use EchoAbstractMapper;
use MediaWiki\Extension\Notifications\Mapper\AbstractMapper;
use MediaWiki\Storage\NameTableStore;
use Wikimedia\Rdbms\DBError;
use Wikimedia\Rdbms\IDatabase;
class SubscriptionManager extends EchoAbstractMapper {
class SubscriptionManager extends AbstractMapper {
/** @var IDatabase */
private $dbw;

View file

@ -3,6 +3,8 @@
use MediaWiki\Extension\Notifications\Cache\RevisionLocalCache;
use MediaWiki\Extension\Notifications\Cache\TitleLocalCache;
use MediaWiki\Extension\Notifications\Controller\NotificationController;
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
@ -249,12 +251,12 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
* Inserts the object into the database.
*/
protected function insert() {
$eventMapper = new EchoEventMapper();
$eventMapper = new EventMapper();
$this->id = $eventMapper->insert( $this );
$targetPages = self::resolveTargetPages( $this->getExtraParam( 'target-page' ) );
if ( $targetPages ) {
$targetMapper = new EchoTargetPageMapper();
$targetMapper = new TargetPageMapper();
foreach ( $targetPages as $title ) {
$targetPage = EchoTargetPage::create( $title, $this );
if ( $targetPage ) {
@ -361,7 +363,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
* @return bool Whether it loaded successfully
*/
public function loadFromID( $id, $fromPrimary = false ) {
$eventMapper = new EchoEventMapper();
$eventMapper = new EventMapper();
$event = $eventMapper->fetchById( $id, $fromPrimary );
if ( !$event ) {
return false;

View file

@ -1,5 +1,6 @@
<?php
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\MediaWikiServices;
class EchoNotification extends EchoAbstractEntity implements Bundleable {
@ -96,7 +97,7 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
protected function insert() {
global $wgEchoNotifications;
$notifMapper = new EchoNotificationMapper();
$notifMapper = new NotificationMapper();
// Get the bundle key for this event if web bundling is enabled
$bundleKey = '';

View file

@ -0,0 +1,13 @@
<?php
use MediaWiki\Extension\Notifications\Mapper\AbstractMapper;
/**
* Create a stub class for testing the abstract class
*/
class EchoAbstractMapperStub extends AbstractMapper {
public function testMethod() {
}
}

View file

@ -1,12 +1,13 @@
<?php
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
use Wikimedia\Rdbms\IDatabase;
/**
* @group Database
* @covers \EchoEventMapper
* @covers \MediaWiki\Extension\Notifications\Mapper\EventMapper
*/
class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
class EventMapperTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
@ -35,7 +36,7 @@ class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
*/
public function testInsert( $message, $dbResult, $result ) {
$event = $this->mockEchoEvent();
$eventMapper = new EchoEventMapper( $this->mockMWEchoDbFactory( $dbResult ) );
$eventMapper = new EventMapper( $this->mockMWEchoDbFactory( $dbResult ) );
$this->assertEquals( $result, $eventMapper->insert( $event ), $message );
}
@ -43,7 +44,7 @@ class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
* Successful fetchById()
*/
public function testSuccessfulFetchById() {
$eventMapper = new EchoEventMapper(
$eventMapper = new EventMapper(
$this->mockMWEchoDbFactory(
[
'selectRow' => (object)[
@ -64,7 +65,7 @@ class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
}
public function testUnsuccessfulFetchById() {
$eventMapper = new EchoEventMapper(
$eventMapper = new EventMapper(
$this->mockMWEchoDbFactory(
[
'selectRow' => false
@ -122,9 +123,6 @@ class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
return $db;
}
/**
* @covers \EchoEventMapper::fetchIdsByPage
*/
public function testFetchByPage() {
$user = $this->getTestUser()->getUser();
$page = $this->getExistingTestPage();
@ -149,7 +147,7 @@ class EchoEventMapperTest extends MediaWikiIntegrationTestCase {
'extra' => [ 'target-page' => $page->getId() ]
] );
$eventMapper = new EchoEventMapper();
$eventMapper = new EventMapper();
$this->assertArrayEquals(
[ $eventWithTitle->getId(), $eventWithTargetPage->getId() ],

View file

@ -1,11 +1,12 @@
<?php
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use Wikimedia\Rdbms\IDatabase;
/**
* @covers \EchoNotificationMapper
* @covers \MediaWiki\Extension\Notifications\Mapper\NotificationMapper
*/
class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
class NotificationMapperTest extends MediaWikiIntegrationTestCase {
/**
* @todo write this test
@ -16,7 +17,7 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
public function fetchUnreadByUser( User $user, $limit, array $eventTypes = [] ) {
// Unsuccessful select
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => false ] ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => false ] ) );
$res = $notifMapper->fetchUnreadByUser( $this->mockUser(), 10, null, '' );
$this->assertEmpty( $res );
@ -36,11 +37,11 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
'notification_bundle_hash' => 'testhash',
]
];
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => $dbResult ] ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => $dbResult ] ) );
$res = $notifMapper->fetchUnreadByUser( $this->mockUser(), 10, null, '', [] );
$this->assertEmpty( $res );
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => $dbResult ] ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => $dbResult ] ) );
$res = $notifMapper->fetchUnreadByUser( $this->mockUser(), 10, null, '', [ 'test_event' ] );
$this->assertIsArray( $res );
$this->assertNotEmpty( $res );
@ -51,7 +52,7 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
public function testFetchByUser() {
// Unsuccessful select
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => false ] ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => false ] ) );
$res = $notifMapper->fetchByUser( $this->mockUser(), 10, '' );
$this->assertEmpty( $res );
@ -80,15 +81,12 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
],
];
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => $notifDbResult ] ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'select' => $notifDbResult ] ) );
$res = $notifMapper->fetchByUser( $this->mockUser(), 10, '', [] );
$this->assertEmpty( $res );
$notifMapper = new EchoNotificationMapper(
$this->mockMWEchoDbFactory( [ 'select' => $notifDbResult ] ),
new EchoTargetPageMapper(
$this->mockMWEchoDbFactory( [ 'select' => $tpDbResult ] )
)
$notifMapper = new NotificationMapper(
$this->mockMWEchoDbFactory( [ 'select' => $notifDbResult ] )
);
$res = $notifMapper->fetchByUser( $this->mockUser(), 10, '', [ 'test_event' ] );
$this->assertIsArray( $res );
@ -97,14 +95,14 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
$this->assertInstanceOf( EchoNotification::class, $row );
}
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [] ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [] ) );
$res = $notifMapper->fetchByUser( $this->mockUser(), 10, '' );
$this->assertEmpty( $res );
}
public function testFetchByUserOffset() {
// Unsuccessful select
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'selectRow' => false ] ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'selectRow' => false ] ) );
$res = $notifMapper->fetchByUserOffset( User::newFromId( 1 ), 500 );
$this->assertFalse( $res );
@ -123,7 +121,7 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
'notification_read_timestamp' => '20140616101010',
'notification_bundle_hash' => 'testhash',
];
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'selectRow' => $dbResult ] ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'selectRow' => $dbResult ] ) );
$row = $notifMapper->fetchByUserOffset( User::newFromId( 1 ), 500 );
$this->assertInstanceOf( EchoNotification::class, $row );
}
@ -192,7 +190,7 @@ class EchoNotificationMapperTest extends MediaWikiIntegrationTestCase {
)
->willReturn( true );
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( $mockDb ) );
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( $mockDb ) );
$this->assertTrue( $notifMapper->deleteByUserEventOffset( User::newFromId( 1 ), 500 ) );
}

View file

@ -1,6 +1,8 @@
<?php
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserOptionsLookup;
@ -54,8 +56,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => true ] ),
$this->mockEchoNotificationMapper(),
$this->createMock( EchoTargetPageMapper::class ),
$this->mockNotificationMapper(),
$this->createMock( TargetPageMapper::class ),
$this->createNoOpMock( UserOptionsLookup::class ),
$this->getServiceContainer()->getUserFactory(),
$this->getServiceContainer()->getReadOnlyMode()
@ -67,8 +69,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => false ] ),
$this->mockEchoNotificationMapper(),
$this->createMock( EchoTargetPageMapper::class ),
$this->mockNotificationMapper(),
$this->createMock( TargetPageMapper::class ),
$this->createNoOpMock( UserOptionsLookup::class ),
$this->getServiceContainer()->getUserFactory(),
$this->getServiceContainer()->getReadOnlyMode()
@ -83,8 +85,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => true ] ),
$this->mockEchoNotificationMapper( [ $this->mockEchoNotification() ] ),
$this->createMock( EchoTargetPageMapper::class ),
$this->mockNotificationMapper( [ $this->mockEchoNotification() ] ),
$this->createMock( TargetPageMapper::class ),
$this->createNoOpMock( UserOptionsLookup::class ),
$this->getServiceContainer()->getUserFactory(),
$this->getServiceContainer()->getReadOnlyMode()
@ -96,8 +98,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => false ] ),
$this->mockEchoNotificationMapper( [ $this->mockEchoNotification() ] ),
$this->createMock( EchoTargetPageMapper::class ),
$this->mockNotificationMapper( [ $this->mockEchoNotification() ] ),
$this->createMock( TargetPageMapper::class ),
$this->createNoOpMock( UserOptionsLookup::class ),
$this->getServiceContainer()->getUserFactory(),
$this->getServiceContainer()->getReadOnlyMode()
@ -109,8 +111,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => true ] ),
$this->mockEchoNotificationMapper(),
$this->createMock( EchoTargetPageMapper::class ),
$this->mockNotificationMapper(),
$this->createMock( TargetPageMapper::class ),
$this->createNoOpMock( UserOptionsLookup::class ),
$this->getServiceContainer()->getUserFactory(),
$this->getServiceContainer()->getReadOnlyMode()
@ -122,8 +124,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => false ] ),
$this->mockEchoNotificationMapper(),
$this->createMock( EchoTargetPageMapper::class ),
$this->mockNotificationMapper(),
$this->createMock( TargetPageMapper::class ),
$this->createNoOpMock( UserOptionsLookup::class ),
$this->getServiceContainer()->getUserFactory(),
$this->getServiceContainer()->getReadOnlyMode()
@ -144,8 +146,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
return $gateway;
}
public function mockEchoNotificationMapper( array $result = [] ) {
$mapper = $this->createMock( EchoNotificationMapper::class );
public function mockNotificationMapper( array $result = [] ) {
$mapper = $this->createMock( NotificationMapper::class );
$mapper->method( 'fetchUnreadByUser' )
->willReturn( $result );
@ -173,8 +175,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway(),
$this->mockEchoNotificationMapper(),
$this->createMock( EchoTargetPageMapper::class ),
$this->mockNotificationMapper(),
$this->createMock( TargetPageMapper::class ),
$this->createNoOpMock( UserOptionsLookup::class ),
$this->getServiceContainer()->getUserFactory(),
$this->getServiceContainer()->getReadOnlyMode()

View file

@ -1,5 +1,7 @@
<?php
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
/**
* Tests for the built in notification types
*
@ -21,7 +23,7 @@ class NotificationsTest extends MediaWikiIntegrationTestCase {
* @return EchoEvent
*/
public static function getLatestNotification( $user ) {
$notifMapper = new EchoNotificationMapper();
$notifMapper = new NotificationMapper();
$notifs = $notifMapper->fetchUnreadByUser( $user, 1, '', [ 'user-rights' ] );
$notif = array_pop( $notifs );

View file

@ -1,5 +1,7 @@
<?php
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
/**
* @group Echo
* @group Database
@ -31,7 +33,7 @@ class MWEchoThankYouEditTest extends MediaWikiIntegrationTestCase {
$this->edit( $title, $user, 'this is my first edit' );
// assertions
$notificationMapper = new EchoNotificationMapper();
$notificationMapper = new NotificationMapper();
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
$this->assertCount( 1, $notifications );
@ -60,7 +62,7 @@ class MWEchoThankYouEditTest extends MediaWikiIntegrationTestCase {
}
// assertions
$notificationMapper = new EchoNotificationMapper();
$notificationMapper = new NotificationMapper();
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
$this->assertCount( 2, $notifications );

View file

@ -1,11 +0,0 @@
<?php
/**
* Create a stub class for testing the abstract class
*/
class EchoAbstractMapperStub extends EchoAbstractMapper {
public function testMethod() {
}
}

View file

@ -1,12 +1,14 @@
<?php
use MediaWiki\Extension\Notifications\Mapper\AbstractMapper;
/**
* @covers \EchoAbstractMapper
* @covers \MediaWiki\Extension\Notifications\Mapper\AbstractMapper
*/
class EchoAbstractMapperTest extends MediaWikiUnitTestCase {
class AbstractMapperTest extends MediaWikiUnitTestCase {
/**
* @return array [ 'mapper' => EchoAbstractMapper, 'property' => ReflectionProperty ]
* @return array [ 'mapper' => AbstractMapper, 'property' => ReflectionProperty ]
*/
public function testAttachListener() {
$mapper = new EchoAbstractMapperStub();
@ -36,7 +38,7 @@ class EchoAbstractMapperTest extends MediaWikiUnitTestCase {
* @depends testAttachListener
*/
public function testGetMethodListeners( $data ) {
/** @var EchoAbstractMapper $mapper */
/** @var AbstractMapper $mapper */
$mapper = $data['mapper'];
$listeners = $mapper->getMethodListeners( 'testMethod' );
@ -48,7 +50,7 @@ class EchoAbstractMapperTest extends MediaWikiUnitTestCase {
* @depends testAttachListener
*/
public function testGetMethodListenersWithException( $data ) {
/** @var EchoAbstractMapper $mapper */
/** @var AbstractMapper $mapper */
$mapper = $data['mapper'];
$this->expectException( MWException::class );
@ -59,7 +61,7 @@ class EchoAbstractMapperTest extends MediaWikiUnitTestCase {
* @depends testAttachListener
*/
public function testDetachListener( $data ) {
/** @var EchoAbstractMapper $mapper */
/** @var AbstractMapper $mapper */
$mapper = $data['mapper'];
/** @var ReflectionProperty $property */
$property = $data['property'];

View file

@ -1,11 +1,12 @@
<?php
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
use Wikimedia\Rdbms\IDatabase;
/**
* @covers \EchoTargetPageMapper
* @covers \MediaWiki\Extension\Notifications\Mapper\TargetPageMapper
*/
class EchoTargetPageMapperTest extends MediaWikiUnitTestCase {
class TargetPageMapperTest extends MediaWikiUnitTestCase {
public function provideDataTestInsert() {
return [
@ -27,7 +28,7 @@ class EchoTargetPageMapperTest extends MediaWikiUnitTestCase {
*/
public function testInsert( $message, $dbResult, $result ) {
$target = $this->mockEchoTargetPage();
$targetMapper = new EchoTargetPageMapper( $this->mockMWEchoDbFactory( $dbResult ) );
$targetMapper = new TargetPageMapper( $this->mockMWEchoDbFactory( $dbResult ) );
$this->assertEquals( $result, $targetMapper->insert( $target ), $message );
}
@ -63,7 +64,7 @@ class EchoTargetPageMapperTest extends MediaWikiUnitTestCase {
/**
* Returns a mock database object
* @param array $dbResult
* @return \Wikimedia\Rdbms\IDatabase
* @return IDatabase
*/
protected function mockDb( array $dbResult ) {
$dbResult += [