Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4103055
GlobalNameUtilsTest.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
GlobalNameUtilsTest.php
View Options
<?php
/**
* Generic tests for utility functions in AbuseFilter that do NOT require DB access
*
* 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
*
* @license GPL-2.0-or-later
*/
use
MediaWiki\Extension\AbuseFilter\GlobalNameUtils
;
/**
* @group Test
* @group AbuseFilter
* @group AbuseFilterGeneric
* @covers \MediaWiki\Extension\AbuseFilter\GlobalNameUtils
*/
class
GlobalNameUtilsTest
extends
MediaWikiUnitTestCase
{
/**
* @dataProvider provideBuildGlobalName
*/
public
function
testBuildGlobalName
(
int
$id
,
bool
$global
,
string
$expected
)
{
$name
=
GlobalNameUtils
::
buildGlobalName
(
$id
,
$global
);
$filterDef
=
GlobalNameUtils
::
splitGlobalName
(
$name
);
$this
->
assertSame
(
$expected
,
$name
);
$this
->
assertSame
(
[
$id
,
$global
],
$filterDef
);
}
public
static
function
provideBuildGlobalName
():
array
{
return
[
[
1
,
false
,
'1'
],
[
2
,
true
,
'global-2'
],
];
}
/**
* @param string $name The name of a filter
* @param array|null $expected If array, the expected result like [ id, isGlobal ].
* If null it means that we're expecting an exception.
* @dataProvider provideGlobalNames
*/
public
function
testSplitGlobalName
(
$name
,
$expected
)
{
if
(
$expected
!==
null
)
{
$actual
=
GlobalNameUtils
::
splitGlobalName
(
$name
);
$this
->
assertSame
(
$expected
,
$actual
);
}
else
{
$this
->
expectException
(
InvalidArgumentException
::
class
);
GlobalNameUtils
::
splitGlobalName
(
$name
);
}
}
public
static
function
provideGlobalNames
()
{
return
[
[
'15'
,
[
15
,
false
]
],
[
15
,
[
15
,
false
]
],
[
'global-1'
,
[
1
,
true
]
],
[
'new'
,
null
],
[
false
,
null
],
[
'global-15-global'
,
null
],
[
0
,
[
0
,
false
]
],
[
'global-'
,
null
],
[
'global-lol'
,
null
],
[
'global-17.2'
,
null
],
[
'17,2'
,
null
],
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 17:43 (3 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e0/aa/56a25b3c9e5390fbbd6cbdd8e3ee
Default Alt Text
GlobalNameUtilsTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment