mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-18 02:40:50 +00:00
2c3d370846
Change-Id: I10e9f9f6ddd9539ff95636902219c0e9fa35fc0f
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 MediaWikiIntegrationTestCase {
|
|
|
|
/** @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( 'user-rights', $event->getType() );
|
|
$this->assertEquals( $this->sysop->getName(), $event->getAgent()->getName() );
|
|
$extra = $event->getExtra();
|
|
$this->assertArrayHasKey( 'add', $extra );
|
|
$this->assertArrayEquals( [ 'sysop' ], $extra['add'] );
|
|
$this->assertArrayEquals( [], $extra['remove'] );
|
|
}
|
|
|
|
}
|