2014-07-29 23:54:00 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-22 15:31:00 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Test\Controller;
|
|
|
|
|
|
|
|
use MapCacheLRU;
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\AttributeManager;
|
2022-11-02 03:51:15 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\UserLocator;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-11-29 12:38:49 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsLookup;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\User;
|
|
|
|
use MediaWiki\Utils\MWTimestamp;
|
2024-02-22 15:31:00 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2021-12-01 18:29:00 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
2018-01-24 00:31:53 +00:00
|
|
|
/**
|
2022-11-02 03:51:15 +00:00
|
|
|
* @covers \MediaWiki\Extension\Notifications\Controller\NotificationController
|
2018-01-24 00:31:53 +00:00
|
|
|
*/
|
2021-10-11 22:42:10 +00:00
|
|
|
class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
2014-07-29 23:54:00 +00:00
|
|
|
|
2023-05-20 18:35:53 +00:00
|
|
|
public static function evaluateUserLocatorsProvider() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
|
|
|
[
|
2014-07-29 23:54:00 +00:00
|
|
|
'With no options no users are notified',
|
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[],
|
2014-07-29 23:54:00 +00:00
|
|
|
// event user locator config
|
2016-12-05 18:51:07 +00:00
|
|
|
[],
|
|
|
|
],
|
2014-07-29 23:54:00 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2014-07-29 23:54:00 +00:00
|
|
|
'Does not error when given non-existant user-locator',
|
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[],
|
2014-07-29 23:54:00 +00:00
|
|
|
// event user locator config
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'not-callable' ],
|
|
|
|
],
|
2014-07-29 23:54:00 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2014-07-29 23:54:00 +00:00
|
|
|
'Calls selected locator and returns result',
|
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[ [ 123 ] ],
|
2014-07-29 23:54:00 +00:00
|
|
|
// event user locator config
|
2021-05-04 16:06:42 +00:00
|
|
|
static function () {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ 123 => 123 ];
|
2015-10-01 13:48:52 +00:00
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2014-07-29 23:54:00 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2014-07-30 03:18:48 +00:00
|
|
|
'evaluates multiple locators',
|
2014-07-29 23:54:00 +00:00
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[ [ 123 ], [ 456 ] ],
|
2014-07-29 23:54:00 +00:00
|
|
|
// event user locator config
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2021-05-04 16:06:42 +00:00
|
|
|
static function () {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ 123 => 123 ];
|
2015-10-01 13:48:52 +00:00
|
|
|
},
|
2021-05-04 16:06:42 +00:00
|
|
|
static function () {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ 456 => 456 ];
|
2015-10-01 13:48:52 +00:00
|
|
|
},
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
],
|
2014-07-29 23:54:00 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2014-07-30 03:18:48 +00:00
|
|
|
'Passes parameters to locateFromEventExtra in expected manner',
|
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[ [ 123 ] ],
|
2014-07-30 03:18:48 +00:00
|
|
|
// event user locator config
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2022-11-12 07:19:00 +00:00
|
|
|
[ [ UserLocator::class, 'locateFromEventExtra' ], [ 'other-user' ] ],
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2014-07-30 03:18:48 +00:00
|
|
|
// additional setup
|
2021-05-04 16:06:42 +00:00
|
|
|
static function ( $test, $event ) {
|
2014-07-30 03:18:48 +00:00
|
|
|
$event->expects( $test->any() )
|
|
|
|
->method( 'getExtraParam' )
|
|
|
|
->with( 'other-user' )
|
2022-11-12 07:19:00 +00:00
|
|
|
->willReturn( 123 );
|
2014-07-30 03:18:48 +00:00
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
];
|
2014-07-29 23:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-30 03:18:48 +00:00
|
|
|
* @dataProvider evaluateUserLocatorsProvider
|
2014-07-29 23:54:00 +00:00
|
|
|
*/
|
2014-07-30 03:18:48 +00:00
|
|
|
public function testEvaluateUserLocators( $message, $expect, $locatorConfigForEventType, $setup = null ) {
|
2024-07-26 12:45:47 +00:00
|
|
|
$this->overrideConfigValue( 'EchoNotifications', [
|
|
|
|
'unit-test' => [
|
|
|
|
AttributeManager::ATTR_LOCATORS => $locatorConfigForEventType
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
] );
|
2014-07-29 23:54:00 +00:00
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
$event = $this->createMock( Event::class );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->method( 'getType' )
|
|
|
|
->willReturn( 'unit-test' );
|
2014-07-29 23:54:00 +00:00
|
|
|
|
2014-07-30 03:18:48 +00:00
|
|
|
if ( $setup !== null ) {
|
|
|
|
$setup( $this, $event );
|
|
|
|
}
|
|
|
|
|
2022-11-12 07:19:00 +00:00
|
|
|
$result = NotificationController::evaluateUserCallable( $event, AttributeManager::ATTR_LOCATORS );
|
2014-07-30 03:18:48 +00:00
|
|
|
$this->assertEquals( $expect, array_map( 'array_keys', $result ), $message );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEvaluateUserLocatorPassesParameters() {
|
2021-05-14 23:58:55 +00:00
|
|
|
$callback = function ( $event, $firstOption, $secondOption ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
$this->assertInstanceOf( Event::class, $event );
|
2021-05-14 23:58:55 +00:00
|
|
|
$this->assertEquals( 'first', $firstOption );
|
|
|
|
$this->assertEquals( 'second', $secondOption );
|
2014-07-30 03:18:48 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [];
|
2014-07-30 03:18:48 +00:00
|
|
|
};
|
|
|
|
|
2022-11-12 07:19:00 +00:00
|
|
|
$this->testEvaluateUserLocators(
|
2014-07-30 03:18:48 +00:00
|
|
|
__FUNCTION__,
|
2016-12-05 18:51:07 +00:00
|
|
|
[ [] ],
|
|
|
|
[ [ $callback, 'first', 'second' ] ]
|
2014-07-30 03:18:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-20 18:35:53 +00:00
|
|
|
public static function getUsersToNotifyForEventProvider() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
|
|
|
[
|
2014-07-30 03:18:48 +00:00
|
|
|
'Filters anonymous users',
|
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[],
|
2014-07-30 03:18:48 +00:00
|
|
|
// users returned from locator
|
2016-12-05 18:51:07 +00:00
|
|
|
[ User::newFromName( '4.5.6.7', false ) ],
|
|
|
|
],
|
2014-07-30 03:18:48 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2014-07-30 03:18:48 +00:00
|
|
|
'Filters duplicate users',
|
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 123 ],
|
2014-07-30 03:18:48 +00:00
|
|
|
// users returned from locator
|
2016-12-05 18:51:07 +00:00
|
|
|
[ User::newFromId( 123 ), User::newFromId( 123 ) ],
|
|
|
|
],
|
2014-07-30 03:18:48 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2014-07-30 03:18:48 +00:00
|
|
|
'Filters non-user objects',
|
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 123 ],
|
2014-07-30 03:18:48 +00:00
|
|
|
// users returned from locator
|
2020-08-10 10:55:36 +00:00
|
|
|
[ null, 'foo', User::newFromId( 123 ), (object)[], 456 ],
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
];
|
2014-07-30 03:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getUsersToNotifyForEventProvider
|
|
|
|
*/
|
|
|
|
public function testGetUsersToNotifyForEvent(
|
|
|
|
$message,
|
|
|
|
$expect,
|
|
|
|
$users
|
|
|
|
) {
|
2024-07-26 12:45:47 +00:00
|
|
|
$this->overrideConfigValue( 'EchoNotifications', [
|
|
|
|
'unit-test' => [
|
|
|
|
AttributeManager::ATTR_LOCATORS => static function () use ( $users ) {
|
|
|
|
return $users;
|
|
|
|
},
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
] );
|
2014-07-30 03:18:48 +00:00
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
$event = $this->createMock( Event::class );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->method( 'getType' )
|
|
|
|
->willReturn( 'unit-test' );
|
2014-07-30 03:18:48 +00:00
|
|
|
|
2022-11-02 03:51:15 +00:00
|
|
|
$result = NotificationController::getUsersToNotifyForEvent( $event );
|
2016-12-05 18:51:07 +00:00
|
|
|
$ids = [];
|
2014-07-30 03:18:48 +00:00
|
|
|
foreach ( $result as $user ) {
|
|
|
|
$ids[] = $user->getId();
|
|
|
|
}
|
|
|
|
$this->assertEquals( $expect, $ids, $message );
|
2014-07-29 23:54:00 +00:00
|
|
|
}
|
2014-08-02 06:52:16 +00:00
|
|
|
|
|
|
|
public function testDoesNotDeliverDisabledEvent() {
|
2022-11-02 21:34:17 +00:00
|
|
|
$event = $this->createMock( Event::class );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->method( 'isEnabledEvent' )
|
|
|
|
->willReturn( false );
|
2014-08-02 06:52:16 +00:00
|
|
|
// Assume it would have to check the event type to
|
|
|
|
// determine how to deliver
|
|
|
|
$event->expects( $this->never() )
|
|
|
|
->method( 'getType' );
|
|
|
|
|
2022-11-02 03:51:15 +00:00
|
|
|
NotificationController::notify( $event, false );
|
2014-08-02 06:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getEventNotifyTypesProvider() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
|
|
|
[
|
2014-08-02 06:52:16 +00:00
|
|
|
'Selects the `all` configuration by default',
|
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'web' ],
|
2014-08-02 06:52:16 +00:00
|
|
|
// event type
|
|
|
|
'bar',
|
|
|
|
// default notification types configuration
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'web' => true ],
|
2019-04-22 22:35:31 +00:00
|
|
|
// per-category notification type availability
|
|
|
|
[
|
|
|
|
'f' => [ 'email' => true ]
|
|
|
|
],
|
|
|
|
// event types
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
|
|
|
'foo' => [
|
2019-04-22 22:35:31 +00:00
|
|
|
'category' => 'f',
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2019-04-22 22:35:31 +00:00
|
|
|
'bar' => [
|
|
|
|
'category' => 'b',
|
|
|
|
]
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
2019-04-22 22:35:31 +00:00
|
|
|
'Overrides `all` configuration with event category configuration',
|
2014-08-02 06:52:16 +00:00
|
|
|
// expected result
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'web' ],
|
2014-08-02 06:52:16 +00:00
|
|
|
// event type
|
|
|
|
'foo',
|
|
|
|
// default notification types configuration
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'web' => true, 'email' => true ],
|
2019-04-22 22:35:31 +00:00
|
|
|
// per-category notification type availability
|
|
|
|
[
|
|
|
|
'f' => [ 'email' => false ],
|
|
|
|
'b' => [ 'sms' => true ],
|
|
|
|
],
|
|
|
|
// event types
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
|
|
|
'foo' => [
|
2019-04-22 22:35:31 +00:00
|
|
|
'category' => 'f',
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
'bar' => [
|
2019-04-22 22:35:31 +00:00
|
|
|
'category' => 'b',
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
];
|
2014-08-02 06:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getEventNotifyTypesProvider
|
|
|
|
*/
|
2019-04-22 22:35:31 +00:00
|
|
|
public function testGetEventNotifyTypes(
|
2020-06-27 10:05:03 +00:00
|
|
|
$message,
|
|
|
|
$expect,
|
|
|
|
$type,
|
|
|
|
array $defaultNotifyTypeAvailability,
|
|
|
|
array $notifyTypeAvailabilityByCategory,
|
|
|
|
array $notifications
|
2019-04-22 22:35:31 +00:00
|
|
|
) {
|
2024-07-26 12:45:47 +00:00
|
|
|
$this->overrideConfigValues( [
|
|
|
|
'DefaultNotifyTypeAvailability' => $defaultNotifyTypeAvailability,
|
|
|
|
'NotifyTypeAvailabilityByCategory' => $notifyTypeAvailabilityByCategory,
|
|
|
|
'EchoNotifications' => $notifications,
|
|
|
|
'EchoNotificationCategories' => array_fill_keys(
|
2020-06-27 10:05:03 +00:00
|
|
|
array_keys( $notifyTypeAvailabilityByCategory ),
|
|
|
|
[ 'priority' => 4 ]
|
|
|
|
),
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2022-11-02 03:51:15 +00:00
|
|
|
$result = NotificationController::getEventNotifyTypes( $type );
|
2014-08-02 06:52:16 +00:00
|
|
|
$this->assertEquals( $expect, $result, $message );
|
|
|
|
}
|
2020-10-09 14:09:21 +00:00
|
|
|
|
|
|
|
public function testEnqueueEvent() {
|
2022-11-02 21:34:17 +00:00
|
|
|
$event = $this->createMock( Event::class );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->method( 'getExtraParam' )
|
|
|
|
->willReturn( null );
|
|
|
|
$event->expects( $this->once() )
|
2020-10-09 14:09:21 +00:00
|
|
|
->method( 'getTitle' )
|
2022-09-29 13:41:35 +00:00
|
|
|
->willReturn( Title::newFromText( 'test-title' ) );
|
|
|
|
$event->expects( $this->once() )
|
2020-10-09 14:09:21 +00:00
|
|
|
->method( 'getId' )
|
2022-09-29 13:41:35 +00:00
|
|
|
->willReturn( 42 );
|
2022-11-02 03:51:15 +00:00
|
|
|
NotificationController::enqueueEvent( $event );
|
2022-01-25 21:24:53 +00:00
|
|
|
$jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
|
|
|
|
$queues = $jobQueueGroup->getQueuesWithJobs();
|
2020-10-09 14:09:21 +00:00
|
|
|
$this->assertCount( 1, $queues );
|
|
|
|
$this->assertEquals( 'EchoNotificationJob', $queues[0] );
|
2022-01-25 21:24:53 +00:00
|
|
|
$job = $jobQueueGroup->pop( 'EchoNotificationJob' );
|
2020-10-09 14:09:21 +00:00
|
|
|
$this->assertEquals( 'Test-title', $job->params[ 'title' ] );
|
|
|
|
$this->assertEquals( 42, $job->params[ 'eventId' ] );
|
|
|
|
}
|
|
|
|
|
2020-10-29 13:27:20 +00:00
|
|
|
public function testNotSupportedDelay() {
|
2022-01-25 21:24:53 +00:00
|
|
|
$queueGroup = $this->getServiceContainer()->getJobQueueGroup();
|
2020-10-29 13:27:20 +00:00
|
|
|
$this->assertCount( 0, $queueGroup->getQueuesWithJobs() );
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
$event = $this->createMock( Event::class );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->method( 'getExtraParam' )
|
2022-11-12 07:19:00 +00:00
|
|
|
->willReturnMap( [
|
|
|
|
[ 'delay', null, 120 ],
|
|
|
|
[ 'rootJobSignature', null, 'test-signature' ],
|
|
|
|
[ 'rootJobTimestamp', null, wfTimestamp() ]
|
|
|
|
] );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->expects( $this->once() )
|
2020-10-29 13:27:20 +00:00
|
|
|
->method( 'getTitle' )
|
2022-09-29 13:41:35 +00:00
|
|
|
->willReturn( Title::newFromText( 'test-title' ) );
|
|
|
|
$event->method( 'getId' )
|
|
|
|
->willReturn( 42 );
|
2022-11-02 03:51:15 +00:00
|
|
|
NotificationController::enqueueEvent( $event );
|
2020-10-29 13:27:20 +00:00
|
|
|
|
|
|
|
$this->assertCount( 0, $queueGroup->getQueuesWithJobs() );
|
|
|
|
}
|
|
|
|
|
2020-10-09 14:09:21 +00:00
|
|
|
public function testEventParams() {
|
|
|
|
$rootJobTimestamp = wfTimestamp();
|
|
|
|
MWTimestamp::setFakeTime( 0 );
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
$event = $this->createMock( Event::class );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->method( 'getExtraParam' )
|
2022-11-12 07:19:00 +00:00
|
|
|
->willReturnMap( [
|
|
|
|
[ 'delay', null, 10 ],
|
|
|
|
[ 'rootJobSignature', null, 'test-signature' ],
|
|
|
|
[ 'rootJobTimestamp', null, $rootJobTimestamp ]
|
|
|
|
] );
|
2022-09-29 13:41:35 +00:00
|
|
|
$event->expects( $this->once() )
|
2020-10-09 14:09:21 +00:00
|
|
|
->method( 'getId' )
|
2022-09-29 13:41:35 +00:00
|
|
|
->willReturn( 42 );
|
2020-10-09 14:09:21 +00:00
|
|
|
|
2022-11-02 03:51:15 +00:00
|
|
|
$params = NotificationController::getEventParams( $event );
|
2020-10-09 14:09:21 +00:00
|
|
|
$expectedParams = [
|
|
|
|
'eventId' => 42,
|
|
|
|
'rootJobSignature' => 'test-signature',
|
|
|
|
'rootJobTimestamp' => $rootJobTimestamp,
|
|
|
|
'jobReleaseTimestamp' => 10
|
|
|
|
];
|
|
|
|
$this->assertArrayEquals( $expectedParams, $params );
|
|
|
|
}
|
2021-12-01 18:29:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider PageLinkedTitleMutedByUserDataProvider
|
2023-05-20 18:35:53 +00:00
|
|
|
* @param int $mockArticleID
|
|
|
|
* @param int[] $mockMutedTitlePreferences
|
2021-12-01 18:29:00 +00:00
|
|
|
* @param bool $expected
|
|
|
|
*/
|
|
|
|
public function testIsPageLinkedTitleMutedByUser(
|
2023-05-20 18:35:53 +00:00
|
|
|
int $mockArticleID, array $mockMutedTitlePreferences, $expected ): void {
|
|
|
|
$title = $this->getMockTitle( $mockArticleID );
|
|
|
|
$user = $this->getMockUser();
|
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $mockMutedTitlePreferences );
|
2022-11-02 03:51:15 +00:00
|
|
|
$wrapper = TestingAccessWrapper::newFromClass( NotificationController::class );
|
2022-09-29 13:41:35 +00:00
|
|
|
$wrapper->mutedPageLinkedTitlesCache = $this->createMock( MapCacheLRU::class );
|
2021-12-01 18:29:00 +00:00
|
|
|
$this->setService( 'UserOptionsLookup', $userOptionsLookup );
|
|
|
|
$this->assertSame(
|
|
|
|
$expected,
|
|
|
|
$wrapper->isPageLinkedTitleMutedByUser( $title, $user )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-20 18:35:53 +00:00
|
|
|
public static function PageLinkedTitleMutedByUserDataProvider(): array {
|
2021-12-01 18:29:00 +00:00
|
|
|
return [
|
|
|
|
[
|
2023-05-20 18:35:53 +00:00
|
|
|
123,
|
|
|
|
[],
|
2021-12-01 18:29:00 +00:00
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
2023-05-20 18:35:53 +00:00
|
|
|
123,
|
|
|
|
[ 123, 456, 789 ],
|
2021-12-01 18:29:00 +00:00
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
2023-05-20 18:35:53 +00:00
|
|
|
456,
|
|
|
|
[ 489 ],
|
2021-12-01 18:29:00 +00:00
|
|
|
false
|
|
|
|
]
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getMockTitle( int $articleID ) {
|
2022-09-29 13:41:35 +00:00
|
|
|
$title = $this->createMock( Title::class );
|
2021-12-01 18:29:00 +00:00
|
|
|
$title->method( 'getArticleID' )
|
|
|
|
->willReturn( $articleID );
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getMockUser() {
|
2022-09-29 13:41:35 +00:00
|
|
|
$user = $this->createMock( User::class );
|
2021-12-01 18:29:00 +00:00
|
|
|
$user->method( 'getId' )
|
|
|
|
->willReturn( 456 );
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getUserOptionsLookupMock( $mutedTitlePreferences = [] ) {
|
|
|
|
$userOptionsLookupMock = $this->createMock( UserOptionsLookup::class );
|
|
|
|
$userOptionsLookupMock->method( 'getOption' )
|
|
|
|
->willReturn( implode( "\n", $mutedTitlePreferences ) );
|
|
|
|
return $userOptionsLookupMock;
|
|
|
|
}
|
2014-07-29 23:54:00 +00:00
|
|
|
}
|