Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4106507
LazyVariableComputerDBTest.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
LazyVariableComputerDBTest.php
View Options
<?php
use
MediaWiki\Extension\AbuseFilter\AbuseFilterServices
;
use
MediaWiki\Extension\AbuseFilter\Variables\LazyLoadedVariable
;
use
MediaWiki\Extension\AbuseFilter\Variables\VariableHolder
;
use
MediaWiki\Permissions\UltimateAuthority
;
use
MediaWiki\Title\Title
;
use
MediaWiki\User\UserIdentityValue
;
/**
* @group Test
* @group AbuseFilter
* @group Database
* @covers \MediaWiki\Extension\AbuseFilter\Variables\LazyVariableComputer
* @todo Move to LazyVariableComputerTest
*/
class
LazyVariableComputerDBTest
extends
MediaWikiIntegrationTestCase
{
/**
* Make different users edit a page, so that we can check their names against
* the actual value of a _recent_contributors variable
* @param Title $title
* @return string[]
*/
private
function
computeRecentContributors
(
Title
$title
)
{
// This test uses a custom DB query and it's hard to use mocks
$user
=
$this
->
getMutableTestUser
()->
getUser
();
// Create the page and make a couple of edits from different users
$this
->
editPage
(
$title
,
'AbuseFilter test for title variables'
,
''
,
NS_MAIN
,
$user
);
$mockContributors
=
[
'X>Alice'
,
'X>Bob'
,
'X>Charlie'
];
foreach
(
$mockContributors
as
$contributor
)
{
$this
->
editPage
(
$title
,
"page revision by $contributor"
,
''
,
NS_MAIN
,
new
UltimateAuthority
(
UserIdentityValue
::
newAnonymous
(
$contributor
)
)
);
}
$contributors
=
array_reverse
(
$mockContributors
);
$contributors
[]
=
$user
->
getName
();
return
$contributors
;
}
public
function
testRecentContributors
()
{
$varName
=
"page_recent_contributors"
;
$title
=
Title
::
makeTitle
(
NS_MAIN
,
"Page to test $varName"
);
$expected
=
$this
->
computeRecentContributors
(
$title
);
$computer
=
AbuseFilterServices
::
getLazyVariableComputer
();
$var
=
new
LazyLoadedVariable
(
'load-recent-authors'
,
[
'title'
=>
$title
]
);
$forbidComputeCB
=
static
function
()
{
throw
new
LogicException
(
'Not expected to be called'
);
};
$actual
=
$computer
->
compute
(
$var
,
new
VariableHolder
(),
$forbidComputeCB
)->
toNative
();
$this
->
assertSame
(
$expected
,
$actual
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 19:35 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
69/96/ba763b768b59aec4874e20b7bc54
Default Alt Text
LazyVariableComputerDBTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment