Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7486459
ImageRedirectConstraintTest.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
ImageRedirectConstraintTest.php
View Options
<?php
/**
* @license GPL-2.0-or-later
* @file
*/
use
MediaWiki\Content\Content
;
use
MediaWiki\EditPage\Constraint\IEditConstraint
;
use
MediaWiki\EditPage\Constraint\ImageRedirectConstraint
;
use
MediaWiki\Permissions\Authority
;
use
MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait
;
use
MediaWiki\Title\Title
;
/**
* Tests the ImageRedirectConstraint
*
* @author DannyS712
*
* @covers \MediaWiki\EditPage\Constraint\ImageRedirectConstraint
*/
class
ImageRedirectConstraintTest
extends
MediaWikiUnitTestCase
{
use
EditConstraintTestTrait
;
use
MockAuthorityTrait
;
/**
* @param Authority $performer
* @return ImageRedirectConstraint
*/
private
function
getConstraint
(
Authority
$performer
)
{
$content
=
$this
->
createMock
(
Content
::
class
);
$content
->
method
(
'isRedirect'
)->
willReturn
(
true
);
$title
=
$this
->
createMock
(
Title
::
class
);
$title
->
method
(
'getNamespace'
)->
willReturn
(
NS_FILE
);
return
new
ImageRedirectConstraint
(
$content
,
$title
,
$performer
);
}
public
function
testPass
()
{
$constraint
=
$this
->
getConstraint
(
$this
->
mockRegisteredUltimateAuthority
()
);
$this
->
assertConstraintPassed
(
$constraint
);
}
/**
* @dataProvider provideTestFailure
*/
public
function
testFailure
(
string
$performerSpec
,
int
$expectedValue
)
{
$performer
=
$performerSpec
===
'anon'
?
$this
->
mockAnonAuthorityWithoutPermissions
(
[
'upload'
]
)
:
$this
->
mockRegisteredAuthorityWithoutPermissions
(
[
'upload'
]
);
$constraint
=
$this
->
getConstraint
(
$performer
);
$this
->
assertConstraintFailed
(
$constraint
,
$expectedValue
);
}
public
static
function
provideTestFailure
()
{
yield
'Anonymous user'
=>
[
'performerSpec'
=>
'anon'
,
'expectedValue'
=>
IEditConstraint
::
AS_IMAGE_REDIRECT_ANON
];
yield
'Registered user'
=>
[
'performerSpec'
=>
'registered'
,
'expectedValue'
=>
IEditConstraint
::
AS_IMAGE_REDIRECT_LOGGED
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 15:27 (5 d, 22 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
ba/dc/cfd192afe8554da6dc196ef99dcd
Default Alt Text
ImageRedirectConstraintTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment