mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-11 15:38:37 +00:00
7e3d73c11b
Most notably: * Use the much more narrow UserIdentity interface where possible. * Make array type hints in PHPDocs as specific as possible. Change-Id: Id189da4028b7874909277881dcf6539169dd13b6
61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
|
use MediaWiki\User\User;
|
|
use MediaWiki\User\UserIdentity;
|
|
|
|
/**
|
|
* 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 UserIdentity $user
|
|
* @return Event
|
|
*/
|
|
public static function getLatestNotification( $user ) {
|
|
$notifMapper = new NotificationMapper();
|
|
$notifs = $notifMapper->fetchUnreadByUser( $user, 1, '', [ 'user-rights' ] );
|
|
$notif = array_pop( $notifs );
|
|
|
|
return $notif->getEvent();
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\Notifications\Hooks::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'] );
|
|
}
|
|
|
|
}
|