mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
17a644263a
composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 The following sniffs are failing and were disabled: * PSR12.Functions.ReturnTypeDeclaration.SpaceBeforeReturnType npm: * svgo: 2.3.0 → 2.3.1 * https://npmjs.com/advisories/1754 (CVE-2021-33587) * postcss: 7.0.35 → 7.0.36 * https://npmjs.com/advisories/1693 (CVE-2021-23368) * trim-newlines: 3.0.0 → 3.0.1 * https://npmjs.com/advisories/1753 (CVE-2021-33623) Change-Id: Id866782d39ac02a329bd79539f2d52392fffd296
56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Tests for the built in notification types
|
|
*
|
|
* @group Database
|
|
*/
|
|
class NotificationsTest extends MediaWikiTestCase {
|
|
|
|
/** @var User */
|
|
private $sysop;
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
$this->sysop = $this->getTestSysop()->getUser();
|
|
}
|
|
|
|
/**
|
|
* 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 = $this->getServiceContainer()
|
|
->getSpecialPageFactory()
|
|
->getPage( 'Userrights' );
|
|
$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'] );
|
|
}
|
|
|
|
}
|