mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 01:30:15 +00:00
f995de90c8
There are a variety of generic strategies you could define to choose which users should be notified about an event, such as 'users watching the title' or 'talk page owner' (User_talk only). This adds a new way to generically implement these in Echo and expose them to other extensions rather than having each extension implement these generic strategies themselves. This patch only converts one notification, edit-user-talk. The remaining notifications will be converted in future patches. The first user of this will be Flow for notifying all users watching a particular talk page in I4e46a9c003fbdde274b20ac7aef8455eab4a5222 The users watching title implementation provided here is minimalist, a larger refactor to accomidate pages with thousands of watchers is being handled in I3d3fa9328f348bb48682d3658622952ce82d3925 Change-Id: I19bb6a794d22565f3bb5421de92426d390197796
68 lines
1.5 KiB
PHP
68 lines
1.5 KiB
PHP
<?php
|
|
|
|
class NotificationControllerTest extends MediaWikiTestCase {
|
|
|
|
public function getUsersToNotifyForEventProvider() {
|
|
return array(
|
|
array(
|
|
'With no options no users are notified',
|
|
// expected result
|
|
array(),
|
|
// event user locator config
|
|
array(),
|
|
),
|
|
|
|
array(
|
|
'Does not error when given non-existant user-locator',
|
|
// expected result
|
|
array(),
|
|
// event user locator config
|
|
array( 'not-callable' ),
|
|
),
|
|
|
|
array(
|
|
'Calls selected locator and returns result',
|
|
// expected result
|
|
array( 123 ),
|
|
// event user locator config
|
|
function() { return array( 123 => 123 ); }
|
|
),
|
|
|
|
array(
|
|
'merges results of multiple locators',
|
|
// expected result
|
|
array( 123, 456 ),
|
|
// event user locator config
|
|
array(
|
|
function() { return array( 123 => 123 ); },
|
|
function() { return array( 456 => 456 ); },
|
|
),
|
|
),
|
|
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getUsersToNotifyForEventProvider
|
|
*/
|
|
public function testGetUsersToNotifyForEvent( $message, $expect, $locatorConfigForEventType ) {
|
|
$this->setMwGlobals( array(
|
|
'wgEchoNotifications' => array(
|
|
'unit-test' => array(
|
|
'user-locators' => $locatorConfigForEventType
|
|
),
|
|
),
|
|
) );
|
|
|
|
$event = $this->getMockBuilder( 'EchoEvent' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$event->expects( $this->any() )
|
|
->method( 'getType' )
|
|
->will( $this->returnValue( 'unit-test' ) );
|
|
|
|
$users = EchoNotificationController::getUsersToNotifyForEvent( $event );
|
|
$this->assertEquals( $expect, array_keys( $users ), $message );
|
|
}
|
|
}
|