Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4057480
NotificationsTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
NotificationsTest.php
View Options
<?php
namespace
MediaWiki\Extension\Notifications\Test
;
use
MediaWiki\Context\DerivativeContext
;
use
MediaWiki\Context\RequestContext
;
use
MediaWiki\Extension\Notifications\Mapper\NotificationMapper
;
use
MediaWiki\Extension\Notifications\Model\Event
;
use
MediaWiki\User\User
;
use
MediaWiki\User\UserIdentity
;
use
MediaWikiIntegrationTestCase
;
/**
* 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'
]
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 16 2026, 04:06 (12 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bf/82/f9d45e9e3dc0b3886e95545222c9
Default Alt Text
NotificationsTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment