Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5981853
ApiEchoCreateEventTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
ApiEchoCreateEventTest.php
View Options
<?php
use
MediaWiki\Api\ApiUsageException
;
use
MediaWiki\Extension\Notifications\Mapper\NotificationMapper
;
use
MediaWiki\Extension\Notifications\NotifUser
;
use
MediaWiki\Tests\Api\ApiTestCase
;
/**
* @group API
* @group Database
* @covers \MediaWiki\Extension\Notifications\Api\ApiEchoCreateEvent
*/
class
ApiEchoCreateEventTest
extends
ApiTestCase
{
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
overrideConfigValue
(
'EchoEnableApiEvents'
,
true
);
}
public
function
testNotifySelf
()
{
$result
=
$this
->
doApiRequestWithToken
(
[
'action'
=>
'echocreateevent'
,
'user'
=>
$this
->
getTestUser
()->
getUser
()->
getName
(),
'header'
=>
'notification header'
,
'content'
=>
'notification content'
,
],
null
,
$this
->
getTestUser
()->
getUser
()
);
$this
->
assertEquals
(
'success'
,
$result
[
0
][
'echocreateevent'
][
'result'
]
);
$user
=
NotifUser
::
newFromUser
(
$this
->
getTestUser
()->
getUser
()
);
$this
->
assertSame
(
1
,
$user
->
getNotificationCount
()
);
$mapper
=
new
NotificationMapper
();
$notifs
=
$mapper
->
fetchByUser
(
$this
->
getTestUser
()->
getUser
(),
5
,
null
,
[
'api-notice'
]
);
$this
->
assertCount
(
1
,
$notifs
);
$notif
=
array_values
(
$notifs
)[
0
];
$this
->
assertSame
(
'notification header'
,
$notif
->
getEvent
()->
getExtraParam
(
'header'
)
);
$this
->
assertSame
(
'notification content'
,
$notif
->
getEvent
()->
getExtraParam
(
'content'
)
);
$this
->
assertTrue
(
$notif
->
getEvent
()->
getExtraParam
(
'noemail'
)
);
}
public
function
testAlertWithEmail
()
{
$result
=
$this
->
doApiRequestWithToken
(
[
'action'
=>
'echocreateevent'
,
'user'
=>
$this
->
getTestUser
()->
getUser
()->
getName
(),
'header'
=>
'notification header'
,
'content'
=>
'notification content'
,
'email'
=>
true
,
'section'
=>
'alert'
],
null
,
$this
->
getTestUser
()->
getUser
()
);
$this
->
assertEquals
(
'success'
,
$result
[
0
][
'echocreateevent'
][
'result'
]
);
$mapper
=
new
NotificationMapper
();
$notifs
=
$mapper
->
fetchByUser
(
$this
->
getTestUser
()->
getUser
(),
5
,
null
,
[
'api-alert'
]
);
$this
->
assertFalse
(
array_values
(
$notifs
)[
0
]->
getEvent
()->
getExtraParam
(
'noemail'
)
);
}
public
function
testNotifyOthers
()
{
$this
->
setGroupPermissions
(
'sysop'
,
'echo-create'
,
true
);
$result
=
$this
->
doApiRequestWithToken
(
[
'action'
=>
'echocreateevent'
,
'user'
=>
$this
->
getTestUser
()->
getUser
()->
getName
(),
'header'
=>
'notification header'
,
'content'
=>
'notification content'
,
],
null
,
$this
->
getTestSysop
()->
getUser
()
);
$this
->
assertEquals
(
'success'
,
$result
[
0
][
'echocreateevent'
][
'result'
]
);
$user
=
NotifUser
::
newFromUser
(
$this
->
getTestUser
()->
getUser
()
);
$this
->
assertSame
(
1
,
$user
->
getNotificationCount
()
);
}
public
function
testNotifyOthersWithoutPermission
()
{
try
{
$this
->
doApiRequestWithToken
(
[
'action'
=>
'echocreateevent'
,
'user'
=>
$this
->
getTestUser
()->
getUser
()->
getName
(),
'header'
=>
'notification header'
,
'content'
=>
'notification content'
,
],
null
,
$this
->
getTestSysop
()->
getUser
()
);
}
catch
(
ApiUsageException
$ex
)
{
$this
->
assertApiErrorCode
(
'permissiondenied'
,
$ex
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 22:05 (1 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
12/92/28c962f3a794de36a48ad264a63f
Default Alt Text
ApiEchoCreateEventTest.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment