Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4137225
WikiFilePageTest.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
WikiFilePageTest.php
View Options
<?php
use
MediaWiki\Linker\LinkTarget
;
use
MediaWiki\Title\Title
;
use
MediaWiki\Title\TitleValue
;
/**
* @covers \WikiFilePage
* @group Database
*/
class
WikiFilePageTest
extends
MediaWikiLangTestCase
{
public
static
function
provideFollowRedirect
()
{
yield
'local nonexisting'
=>
[
null
,
[
'exists'
=>
false
],
false
];
yield
'local existing'
=>
[
'Bla bla'
,
[],
false
];
yield
'local redirect'
=>
[
'#REDIRECT [[Image:Target.png]]'
,
[],
new
TitleValue
(
NS_FILE
,
'Target.png'
),
];
yield
'remote nonexisting'
=>
[
null
,
[
'isLocal'
=>
false
,
'exists'
=>
false
,
],
false
,
];
yield
'remote existing'
=>
[
null
,
[
'isLocal'
=>
false
,
],
false
,
];
yield
'remote redirect'
=>
[
null
,
[
'isLocal'
=>
false
,
'redirectedFrom'
=>
'Test.png'
,
'name'
=>
'Target.png'
,
],
new
TitleValue
(
NS_FILE
,
'Target.png'
),
];
}
/**
* @dataProvider provideFollowRedirect
*/
public
function
testFollowRedirect
(
?
string
$content
,
array
$fileProps
,
$expected
)
{
$fileProps
+=
[
'name'
=>
'Test.png'
];
$this
->
installMockFileRepo
(
$fileProps
);
if
(
$content
===
null
)
{
$pageIdentity
=
$this
->
getNonexistingTestPage
(
'Image:Test.png'
);
}
else
{
$status
=
$this
->
editPage
(
'Image:Test.png'
,
$content
);
$pageIdentity
=
$status
->
getNewRevision
()->
getPage
();
}
$page
=
new
WikiFilePage
(
Title
::
newFromPageIdentity
(
$pageIdentity
)
);
$target
=
$page
->
followRedirect
();
if
(
$expected
instanceof
LinkTarget
)
{
$this
->
assertTrue
(
$expected
->
isSameLinkAs
(
$target
)
);
}
else
{
$this
->
assertSame
(
$expected
,
$target
);
}
}
private
function
installMockFileRepo
(
array
$props
=
[]
):
void
{
$repo
=
$this
->
createNoOpMock
(
FileRepo
::
class
,
[]
);
$file
=
$this
->
createNoOpMock
(
File
::
class
,
[
'isLocal'
,
'exists'
,
'getRepo'
,
'getRedirected'
,
'getName'
,
]
);
$file
->
method
(
'isLocal'
)->
willReturn
(
$props
[
'isLocal'
]
??
true
);
$file
->
method
(
'exists'
)->
willReturn
(
$props
[
'exists'
]
??
true
);
$file
->
method
(
'getRepo'
)->
willReturn
(
$repo
);
$file
->
method
(
'getRedirected'
)->
willReturn
(
$props
[
'redirectedFrom'
]
??
null
);
$file
->
method
(
'getName'
)->
willReturn
(
$props
[
'name'
]
??
'Test.png'
);
$localRepo
=
$this
->
createNoOpMock
(
FileRepo
::
class
,
[
'invalidateImageRedirect'
]
);
$repoGroup
=
$this
->
createNoOpMock
(
RepoGroup
::
class
,
[
'findFile'
,
'getLocalRepo'
]
);
$repoGroup
->
method
(
'getLocalRepo'
)->
willReturn
(
$localRepo
);
$repoGroup
->
method
(
'findFile'
)->
willReturn
(
$file
);
$this
->
setService
(
'RepoGroup'
,
$repoGroup
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 14:03 (3 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
7a/c5/51da752a2469f0f5cc1c2ecef52b
Default Alt Text
WikiFilePageTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment