Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4099888
EmergencyCacheTest.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
EmergencyCacheTest.php
View Options
<?php
namespace
MediaWiki\Extension\AbuseFilter\Tests\Unit
;
use
MediaWiki\Extension\AbuseFilter\EmergencyCache
;
use
MediaWikiUnitTestCase
;
use
Wikimedia\ObjectCache\HashBagOStuff
;
/**
* @covers \MediaWiki\Extension\AbuseFilter\EmergencyCache
*/
class
EmergencyCacheTest
extends
MediaWikiUnitTestCase
{
public
function
testEmptyCache
()
{
$cache
=
new
EmergencyCache
(
new
HashBagOStuff
(),
[
'default'
=>
86400
]
);
$this
->
assertSame
(
[],
$cache
->
getFiltersToCheckInGroup
(
'default'
)
);
$this
->
assertFalse
(
$cache
->
getForFilter
(
1
)
);
}
public
function
testSetNewForFilter
()
{
$time
=
microtime
(
true
);
$stash
=
new
HashBagOStuff
();
$stash
->
setMockTime
(
$time
);
$cache
=
new
EmergencyCache
(
$stash
,
[
'default'
=>
86400
,
'other'
=>
3600
]
);
$cache
->
setNewForFilter
(
2
,
'other'
);
$this
->
assertSame
(
[
'total'
=>
0
,
'matches'
=>
0
],
$cache
->
getForFilter
(
2
)
);
$this
->
assertSame
(
[
2
],
$cache
->
getFiltersToCheckInGroup
(
'other'
)
);
$this
->
assertSame
(
[],
$cache
->
getFiltersToCheckInGroup
(
'default'
)
);
$time
+=
3599
;
$this
->
assertNotFalse
(
$cache
->
getForFilter
(
2
)
);
$time
+=
2
;
$this
->
assertFalse
(
$cache
->
getForFilter
(
2
)
);
$this
->
assertSame
(
[],
$cache
->
getFiltersToCheckInGroup
(
'other'
)
);
}
public
function
testIncrementForFilter
()
{
$time
=
microtime
(
true
);
$stash
=
new
HashBagOStuff
();
$stash
->
setMockTime
(
$time
);
$cache
=
new
EmergencyCache
(
$stash
,
[
'default'
=>
86400
]
);
$cache
->
setNewForFilter
(
1
,
'default'
);
$cache
->
incrementForFilter
(
1
,
false
);
$this
->
assertSame
(
[
'total'
=>
1
,
'matches'
=>
0
],
$cache
->
getForFilter
(
1
)
);
$cache
->
incrementForFilter
(
1
,
true
);
$this
->
assertSame
(
[
'total'
=>
2
,
'matches'
=>
1
],
$cache
->
getForFilter
(
1
)
);
$time
+=
86401
;
$cache
->
incrementForFilter
(
1
,
true
);
$this
->
assertFalse
(
$cache
->
getForFilter
(
1
)
);
}
public
function
testGetFiltersToCheckInGroup
()
{
$time
=
microtime
(
true
);
$stash
=
new
HashBagOStuff
();
$stash
->
setMockTime
(
$time
);
$cache
=
new
EmergencyCache
(
$stash
,
[
'default'
=>
3600
]
);
$cache
->
setNewForFilter
(
1
,
'default'
);
$time
+=
1000
;
$cache
->
setNewForFilter
(
2
,
'default'
);
$this
->
assertArrayEquals
(
[
1
,
2
],
$cache
->
getFiltersToCheckInGroup
(
'default'
)
);
$time
+=
2601
;
$this
->
assertArrayEquals
(
[
2
],
$cache
->
getFiltersToCheckInGroup
(
'default'
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 16:08 (3 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4b/eb/857438c47f695f093ef31dbec7d5
Default Alt Text
EmergencyCacheTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment