Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5942033
EventIntegrationTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
EventIntegrationTest.php
View Options
<?php
use
MediaWiki\Extension\Notifications\Mapper\EventMapper
;
use
MediaWiki\Extension\Notifications\Model\Event
;
use
MediaWiki\User\UserIdentityValue
;
/**
* @covers \MediaWiki\Extension\Notifications\Model\Event
* @covers \MediaWiki\Extension\Notifications\Controller\NotificationController
* @covers \MediaWiki\Extension\Notifications\Jobs\NotificationJob
* @group Database
*/
class
EventIntegrationTest
extends
MediaWikiIntegrationTestCase
{
public
function
testEventInsertionImmediate
()
{
$this
->
clearHook
(
'BeforeEchoEventInsert'
);
$this
->
overrideConfigValue
(
'EchoUseJobQueue'
,
false
);
$user
=
$this
->
getTestUser
()->
getUser
();
$event
=
Event
::
create
(
[
'type'
=>
'welcome'
,
'agent'
=>
$user
,
'extra'
=>
[
'key'
=>
'value'
],
]
);
$eventId
=
$event
->
getId
();
$this
->
assertNotFalse
(
$eventId
);
$this
->
assertSame
(
$eventId
,
$event
->
acquireId
()
);
$this
->
assertSelect
(
'echo_event'
,
[
'count'
=>
'COUNT(*)'
],
[
'event_type'
=>
'welcome'
],
[
[
'1'
]
]
);
}
public
function
testEventNotInserted
()
{
$this
->
clearHook
(
'BeforeEchoEventInsert'
);
$this
->
overrideConfigValue
(
'EchoUseJobQueue'
,
false
);
$event
=
Event
::
create
(
[
'type'
=>
'welcome'
,
// anons cannot be notified
'agent'
=>
UserIdentityValue
::
newAnonymous
(
'1.2.3.4'
),
'extra'
=>
[
'key'
=>
'value'
],
]
);
$this
->
assertFalse
(
$event
->
getId
()
);
$this
->
assertSelect
(
'echo_event'
,
[
'count'
=>
'COUNT(*)'
],
[
'event_type'
=>
'welcome'
],
[
[
'0'
]
]
);
}
public
function
testEventNotCreatedForUnknownUser
()
{
$this
->
clearHook
(
'BeforeEchoEventInsert'
);
$this
->
expectException
(
\Wikimedia\NormalizedException\NormalizedException
::
class
);
$event
=
Event
::
create
(
[
'type'
=>
'welcome'
,
'agent'
=>
UserIdentityValue
::
newAnonymous
(
'Anonymous user'
),
]
);
}
public
function
testEventInsertionDeferred
()
{
$this
->
markTestSkipped
(
'T386364'
);
$this
->
clearHook
(
'BeforeEchoEventInsert'
);
$this
->
clearHook
(
'PageSaveComplete'
);
$this
->
overrideConfigValue
(
'EchoUseJobQueue'
,
true
);
$user
=
$this
->
getTestUser
()->
getUser
();
$title
=
$this
->
getExistingTestPage
()->
getTitle
();
$this
->
runJobs
();
$event
=
Event
::
create
(
[
'type'
=>
'welcome'
,
'agent'
=>
$user
,
'title'
=>
$title
,
'extra'
=>
[
'key'
=>
'value'
],
]
);
$this
->
assertFalse
(
$event
->
getId
()
);
unset
(
$event
);
$jobQueueGroup
=
$this
->
getServiceContainer
()->
getJobQueueGroup
();
$queues
=
$jobQueueGroup
->
getQueuesWithJobs
();
$this
->
assertSame
(
[
'EchoNotificationJob'
],
$queues
);
$job
=
$jobQueueGroup
->
pop
(
'EchoNotificationJob'
);
$job
->
run
();
$eventMapper
=
new
EventMapper
();
$events
=
$eventMapper
->
fetchByPage
(
$title
->
getArticleID
()
);
$this
->
assertCount
(
1
,
$events
);
[
$event
]
=
$events
;
$this
->
assertSame
(
'welcome'
,
$event
->
getType
()
);
$this
->
assertTrue
(
$user
->
equals
(
$event
->
getAgent
()
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 2 2026, 17:35 (6 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f8/91/92d0b3d7d493e0d6cb14288c4e85
Default Alt Text
EventIntegrationTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment