mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 17:50:39 +00:00
967a0b54e9
Not all tools require these to be absolute, full qualified class names. But some do. This does make the code more compatible with all kinds of tools. Change-Id: Ie7f9d9469b7a48b2fe908d3428fca9ec0120f855
61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* Tests for the built in notification types
|
|
*
|
|
* @group Database
|
|
*/
|
|
class NotificationsTest extends MediaWikiTestCase {
|
|
|
|
/** @var User $sysop */
|
|
// @codingStandardsIgnoreStart
|
|
var $sysop;
|
|
// @codingStandardsIgnoreEnd
|
|
|
|
protected function setUp() : void {
|
|
parent::setUp();
|
|
$this->sysop = User::newFromName( 'UTSysop' );
|
|
$this->setMwGlobals( 'wgUser', $this->sysop );
|
|
}
|
|
|
|
/**
|
|
* Helper function to get a user's latest notification
|
|
* @param User $user
|
|
* @return EchoEvent
|
|
*/
|
|
public static function getLatestNotification( $user ) {
|
|
$notifMapper = new EchoNotificationMapper();
|
|
$notifs = $notifMapper->fetchUnreadByUser( $user, 1, '', [ 'user-rights' ] );
|
|
$notif = array_pop( $notifs );
|
|
|
|
return $notif->getEvent();
|
|
}
|
|
|
|
/**
|
|
* @covers \EchoHooks::onUserGroupsChanged
|
|
*/
|
|
public function testUserRightsNotif() {
|
|
$user = new User();
|
|
$user->setName( 'Dummy' );
|
|
$user->addToDatabase();
|
|
|
|
$context = new DerivativeContext( RequestContext::getMain() );
|
|
$context->setUser( $this->sysop );
|
|
$ur = new UserrightsPage(
|
|
MediaWikiServices::getInstance()->getPermissionManager()
|
|
);
|
|
$ur->setContext( $context );
|
|
$ur->doSaveUserGroups( $user, [ 'sysop' ], [], 'reason' );
|
|
$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( [ 'sysop' ], $extra['add'] );
|
|
$this->assertArrayEquals( [], $extra['remove'] );
|
|
}
|
|
|
|
}
|