2013-10-28 02:43:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for the built in notification types
|
|
|
|
*
|
|
|
|
* @group Database
|
|
|
|
*/
|
|
|
|
class NotificationsTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
/** @var User $sysop */
|
2015-10-29 11:35:14 +00:00
|
|
|
// @codingStandardsIgnoreStart
|
2013-10-28 02:43:55 +00:00
|
|
|
var $sysop;
|
2015-10-29 11:35:14 +00:00
|
|
|
// @codingStandardsIgnoreEnd
|
2013-10-28 02:43:55 +00:00
|
|
|
|
2015-12-14 10:02:34 +00:00
|
|
|
protected function setUp() {
|
2013-10-28 02:43:55 +00:00
|
|
|
parent::setUp();
|
|
|
|
$this->sysop = User::newFromName( 'UTSysop' );
|
|
|
|
$this->setMwGlobals( 'wgUser', $this->sysop );
|
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2013-10-28 02:43:55 +00:00
|
|
|
/**
|
|
|
|
* Helper function to get a user's latest notification
|
|
|
|
* @param User $user
|
|
|
|
* @return EchoEvent
|
|
|
|
*/
|
|
|
|
public static function getLatestNotification( $user ) {
|
2018-04-24 19:46:31 +00:00
|
|
|
$notifMapper = new EchoNotificationMapper();
|
|
|
|
$notifs = $notifMapper->fetchUnreadByUser( $user, 1, '', [ 'user-rights' ] );
|
|
|
|
$notif = array_pop( $notifs );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2018-04-24 19:46:31 +00:00
|
|
|
return $notif->getEvent();
|
2013-10-28 02:43:55 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2013-10-28 02:43:55 +00:00
|
|
|
/**
|
2018-04-24 19:46:31 +00:00
|
|
|
* @covers EchoHooks::onUserGroupsChanged
|
2013-10-28 02:43:55 +00:00
|
|
|
*/
|
|
|
|
public function testUserRightsNotif() {
|
|
|
|
$user = new User();
|
|
|
|
$user->setName( 'Dummy' );
|
|
|
|
$user->addToDatabase();
|
|
|
|
|
|
|
|
$context = new DerivativeContext( RequestContext::getMain() );
|
|
|
|
$context->setUser( $this->sysop );
|
|
|
|
$ur = new UserrightsPage();
|
|
|
|
$ur->setContext( $context );
|
2016-12-05 18:51:07 +00:00
|
|
|
$ur->doSaveUserGroups( $user, [ 'sysop' ], [], 'reason' );
|
2013-10-28 02:43:55 +00:00
|
|
|
$event = self::getLatestNotification( $user );
|
|
|
|
$this->assertEquals( $event->getType(), 'user-rights' );
|
|
|
|
$this->assertEquals( $this->sysop->getName(), $event->getAgent()->getName() );
|
|
|
|
$extra = $event->getExtra();
|
|
|
|
$this->assertArrayHasKey( 'add', $extra );
|
2016-12-05 18:51:07 +00:00
|
|
|
$this->assertArrayEquals( [ 'sysop' ], $extra['add'] );
|
|
|
|
$this->assertArrayEquals( [], $extra['remove'] );
|
2013-10-28 02:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|