aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/integration/includes/user
diff options
context:
space:
mode:
authorDannyS712 <DannyS712.enwiki@gmail.com>2020-05-23 08:43:34 +0000
committerDannyS712 <DannyS712.enwiki@gmail.com>2020-06-02 23:22:02 +0000
commitc243c1b06eb4aeee0928b85df4d896d3b374879f (patch)
treeaf69897b9085d706ee2d6ea216a5b55052bc8e21 /tests/phpunit/integration/includes/user
parent84390e9887d35d4d2559ab96688611c6a01d496b (diff)
downloadmediawikicore-c243c1b06eb4aeee0928b85df4d896d3b374879f.tar.gz
mediawikicore-c243c1b06eb4aeee0928b85df4d896d3b374879f.zip
Add new WatchlistNotificationManager service
Replaces watchlist notification methods in Title and User classes: * Title::getNotificationTimestamp -> ::getTitleNotificationTimestamp * User::clearNotification -> ::clearTitleUserNotifications * User::clearAllNotifications -> ::clearAllUserNotifications New service has 67.90% code coverage with pure Unit tests; as well as integration tests for the DeferredUpdates part A follow-up patch will deprecate the replaced methods, as well as document that the `UserClearNewTalkNotification` hook now only provides a UserIdentity (typehint added in T253435 but until now a full User was still provided). Bug: T208777 Change-Id: I6f388c04cb9dc65b20ff028ece607c3dc131dfc5
Diffstat (limited to 'tests/phpunit/integration/includes/user')
-rw-r--r--tests/phpunit/integration/includes/user/WatchlistNotificationManagerTest.php93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/phpunit/integration/includes/user/WatchlistNotificationManagerTest.php b/tests/phpunit/integration/includes/user/WatchlistNotificationManagerTest.php
new file mode 100644
index 000000000000..0390ae30e646
--- /dev/null
+++ b/tests/phpunit/integration/includes/user/WatchlistNotificationManagerTest.php
@@ -0,0 +1,93 @@
+<?php
+
+use MediaWiki\Config\ServiceOptions;
+use MediaWiki\HookContainer\HookContainer;
+use MediaWiki\Linker\LinkTarget;
+use MediaWiki\Permissions\PermissionManager;
+use MediaWiki\Revision\RevisionStore;
+use MediaWiki\User\TalkPageNotificationManager;
+use MediaWiki\User\WatchlistNotificationManager;
+
+/**
+ * @covers \MediaWiki\User\WatchlistNotificationManager
+ *
+ * @author DannyS712
+ * @group Database
+ */
+class WatchlistNotificationManagerTest extends MediaWikiIntegrationTestCase {
+
+ public function testClearTitleUserNotifications() {
+ $options = new ServiceOptions(
+ WatchlistNotificationManager::CONSTRUCTOR_OPTIONS,
+ [
+ 'UseEnotif' => false,
+ 'ShowUpdatedMarker' => false
+ ]
+ );
+
+ $revisionLookup = $this->createMock( RevisionStore::class );
+ $talkPageNotificationManager = $this->createMock( TalkPageNotificationManager::class );
+ $watchedItemStore = $this->createNoOpAbstractMock( WatchedItemStoreInterface::class );
+
+ $readOnlyMode = $this->createMock( ReadOnlyMode::class );
+ $readOnlyMode->expects( $this->once() )
+ ->method( 'isReadOnly' )
+ ->willReturn( false );
+
+ $user = $this->createMock( User::class );
+ $user->expects( $this->once() )
+ ->method( 'getName' )
+ ->willReturn( 'UserNameIsAlsoTitle' );
+ $title = $this->getMockBuilder( LinkTarget::class )
+ ->setMethods( [ 'getNamespace', 'getText' ] )
+ ->getMockForAbstractClass();
+ $title->expects( $this->any() )
+ ->method( 'getNamespace' )
+ ->willReturn( NS_USER_TALK );
+ $title->expects( $this->any() )
+ ->method( 'getText' )
+ ->willReturn( 'UserNameIsAlsoTitle' );
+ $permissionManager = $this->createMock( PermissionManager::class );
+ $permissionManager->expects( $this->once() )
+ ->method( 'userHasRight' )
+ ->with(
+ $this->equalTo( $user ),
+ $this->equalTo( 'editmywatchlist' )
+ )
+ ->willReturn( true );
+
+ $hookContainer = $this->createMock( HookContainer::class );
+ $hookContainer->expects( $this->once() )
+ ->method( 'run' )
+ ->with(
+ $this->equalTo( 'UserClearNewTalkNotification' ),
+ $this->equalTo( [
+ $user,
+ 0
+ ] )
+ )
+ ->willReturn( true );
+
+ $manager = new WatchlistNotificationManager(
+ $options,
+ $hookContainer,
+ $permissionManager,
+ $readOnlyMode,
+ $revisionLookup,
+ $talkPageNotificationManager,
+ $watchedItemStore
+ );
+
+ $this->db->startAtomic( __METHOD__ ); // let deferred updates queue up
+
+ $manager->clearTitleUserNotifications( $user, $title );
+
+ $updateCount = DeferredUpdates::pendingUpdatesCount();
+ $this->assertGreaterThan( 0, $updateCount, 'An update should have been queued' );
+
+ $this->db->endAtomic( __METHOD__ ); // run deferred updates
+
+ $this->assertSame( 0, DeferredUpdates::pendingUpdatesCount(), 'No pending updates' );
+ }
+
+}