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 */
|
|
|
|
var $sysop;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
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 ) {
|
|
|
|
$notifs = ApiEchoNotifications::getNotifications( $user );
|
2015-10-01 13:48:52 +00:00
|
|
|
$index = array_keys( $notifs );
|
|
|
|
|
2013-10-28 02:43:55 +00:00
|
|
|
return EchoEvent::newFromID( $notifs[$index[0]]['id'] );
|
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2013-10-28 02:43:55 +00:00
|
|
|
/**
|
|
|
|
* @covers EchoHooks::onUserRights
|
|
|
|
*/
|
|
|
|
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 );
|
2015-10-01 13:48:52 +00:00
|
|
|
$ur->doSaveUserGroups( $user, array( 'sysop' ), array(), '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 );
|
|
|
|
$this->assertArrayEquals( array( 'sysop' ), $extra['add'] );
|
|
|
|
$this->assertArrayEquals( array(), $extra['remove'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|