2013-10-28 02:43:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for the built in notification types
|
|
|
|
*
|
|
|
|
* @group Database
|
|
|
|
*/
|
|
|
|
class NotificationsTest extends MediaWikiTestCase {
|
|
|
|
|
2020-10-29 11:07:16 +00:00
|
|
|
/** @var User */
|
2021-01-29 12:55:41 +00:00
|
|
|
private $sysop;
|
2013-10-28 02:43:55 +00:00
|
|
|
|
2021-07-23 21:23:16 +00:00
|
|
|
protected function setUp(): void {
|
2013-10-28 02:43:55 +00:00
|
|
|
parent::setUp();
|
2021-01-29 12:54:21 +00:00
|
|
|
$this->sysop = $this->getTestSysop()->getUser();
|
2013-10-28 02:43:55 +00:00
|
|
|
}
|
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
|
|
|
/**
|
2019-10-23 10:23:09 +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 );
|
2021-03-04 21:49:16 +00:00
|
|
|
$ur = $this->getServiceContainer()
|
|
|
|
->getSpecialPageFactory()
|
|
|
|
->getPage( 'Userrights' );
|
2013-10-28 02:43:55 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
}
|