Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7421119
GlobalRenameDenylistTest.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
GlobalRenameDenylistTest.php
View Options
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
use
MediaWiki\Content\WikitextContent
;
use
MediaWiki\Extension\CentralAuth\GlobalRename\GlobalRenameDenylist
;
use
MediaWiki\Http\HttpRequestFactory
;
use
MediaWiki\Page\WikiPage
;
use
MediaWiki\Page\WikiPageFactory
;
use
MediaWiki\Title\Title
;
use
Psr\Log\NullLogger
;
/**
* @author DannyS712
* @covers MediaWiki\Extension\CentralAuth\GlobalRename\GlobalRenameDenylist
*/
class
GlobalRenameDenylistTest
extends
MediaWikiUnitTestCase
{
public
static
function
provideCheckUser
()
{
// $pageText, $userName, $expected
yield
'Good user does not match bad'
=>
[
'BadUser'
,
'GoodUser'
,
true
];
yield
'Bad user matches bad'
=>
[
'BadUser'
,
'BadUser'
,
false
];
yield
'Bad user does not match empty'
=>
[
''
,
'BadUser'
,
true
];
yield
'Bad user matches bad regex'
=>
[
'^Bad[A-Za-z]+$'
,
'BadUser'
,
false
];
yield
'Good user does not match bad regex'
=>
[
'^Bad[A-Za-z]+$'
,
'GoodUser'
,
true
];
}
/**
* @dataProvider provideCheckUser
*/
public
function
testCheckUser
(
$pageText
,
$userName
,
$expected
)
{
// Current tests are only for the case when a Title is provided, not when a url
// is used
$sourceTitle
=
$this
->
createNoOpMock
(
Title
::
class
);
$sourceWikiPage
=
$this
->
createMock
(
WikiPage
::
class
);
$sourceContent
=
$this
->
createMock
(
WikitextContent
::
class
);
$sourceContent
->
method
(
'getText'
)->
willReturn
(
$pageText
);
$sourceWikiPage
->
method
(
'getContent'
)->
willReturn
(
$sourceContent
);
$wikiPageFactory
=
$this
->
createMock
(
WikiPageFactory
::
class
);
$wikiPageFactory
->
expects
(
$this
->
once
()
)
->
method
(
'newFromTitle'
)
->
with
(
$sourceTitle
)
->
willReturn
(
$sourceWikiPage
);
$denylist
=
new
GlobalRenameDenylist
(
new
NullLogger
(),
$this
->
createNoOpMock
(
HttpRequestFactory
::
class
),
$wikiPageFactory
,
$sourceTitle
);
$this
->
assertSame
(
$expected
,
$denylist
->
checkUser
(
$userName
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 05:17 (1 d, 30 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
66/d9/864e5a9210b3d29a6c866b8753e8
Default Alt Text
GlobalRenameDenylistTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment