Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5979114
LCStoreStaticArrayTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
LCStoreStaticArrayTest.php
View Options
<?php
/**
* @covers \LCStoreStaticArray
* @group Language
*/
class
LCStoreStaticArrayTest
extends
MediaWikiUnitTestCase
{
/** @var string */
private
$dir
;
/** @var string */
private
$file
;
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
dir
=
sys_get_temp_dir
()
.
'/lcstore-array'
;
$this
->
file
=
$this
->
dir
.
'/en.l10n.php'
;
}
protected
function
tearDown
():
void
{
@
unlink
(
$this
->
file
);
@
rmdir
(
$this
->
dir
);
parent
::
tearDown
();
}
private
function
prepareDir
()
{
@
mkdir
(
$this
->
dir
);
return
$this
->
dir
;
}
private
function
prepareFile
(
$dir
,
$lang
,
array
$data
)
{
file_put_contents
(
$this
->
file
,
'<?php return '
.
var_export
(
$data
,
true
)
.
';'
);
}
public
function
testEncodeDecode
()
{
$dir
=
$this
->
prepareDir
();
$cache
=
new
LCStoreStaticArray
(
[
'directory'
=>
$dir
]
);
$data
=
[
'mr-boole'
=>
false
,
'the-zero'
=>
0
,
'a-number'
=>
42
,
'some-string'
=>
'0'
,
'common-data'
=>
[
3
=>
[
'three'
,
'threa'
,
'phree'
],
6
=>
[
'six'
,
'seaks'
,
'phrix'
],
],
'some-obj'
=>
new
DateTimeZone
(
'-0630'
),
'unlikely'
=>
[
3
=>
'three'
,
6
=>
new
DateTimeZone
(
'-0315'
),
],
];
$this
->
file
=
$dir
.
'/en.l10n.php'
;
$cache
->
startWrite
(
'en'
);
foreach
(
$data
as
$key
=>
$value
)
{
$cache
->
set
(
$key
,
$value
);
}
$cache
->
finishWrite
();
$this
->
assertEquals
(
[
'mr-boole'
=>
false
,
'the-zero'
=>
0
,
'a-number'
=>
42
,
'some-string'
=>
'0'
,
'common-data'
=>
[
'v'
,
[
3
=>
[
'three'
,
'threa'
,
'phree'
],
6
=>
[
'six'
,
'seaks'
,
'phrix'
],
]
],
'some-obj'
=>
[
's'
,
'O:12:"DateTimeZone":2:{s:13:"timezone_type";i:1;s:8:"timezone";s:6:"-06:30";}'
],
'unlikely'
=>
[
's'
,
'a:2:{i:3;s:5:"three";i:6;O:12:"DateTimeZone":2:{s:13:"timezone_type";i:1;s:8:"timezone";s:6:"-03:15";}}'
],
],
require
$dir
.
'/en.l10n.php'
,
'Encoded data'
);
$this
->
assertSame
(
false
,
$cache
->
get
(
'en'
,
'mr-boole'
),
'decode boolean'
);
$this
->
assertSame
(
0
,
$cache
->
get
(
'en'
,
'the-zero'
),
'decode number'
);
$this
->
assertSame
(
'0'
,
$cache
->
get
(
'en'
,
'some-string'
),
'decode string'
);
$this
->
assertSame
(
[
'six'
,
'seaks'
,
'phrix'
],
$cache
->
get
(
'en'
,
'common-data'
)[
6
],
'decode array'
);
$this
->
assertInstanceOf
(
DateTimeZone
::
class
,
$cache
->
get
(
'en'
,
'some-obj'
),
'decode object'
);
$this
->
assertInstanceOf
(
DateTimeZone
::
class
,
$cache
->
get
(
'en'
,
'unlikely'
)[
6
],
'decode nested object'
);
}
public
function
testDecodeMw132Value
()
{
$dir
=
$this
->
prepareDir
();
$this
->
prepareFile
(
$dir
,
'en'
,
[
'mr-boole'
=>
[
'v'
,
false
],
'the-zero'
=>
[
'v'
,
0
],
'a-number'
=>
[
'v'
,
42
],
'some-string'
=>
[
'v'
,
'0'
],
]
);
$cache
=
new
LCStoreStaticArray
(
[
'directory'
=>
$dir
]
);
$this
->
assertSame
(
false
,
$cache
->
get
(
'en'
,
'mr-boole'
)
);
$this
->
assertSame
(
0
,
$cache
->
get
(
'en'
,
'the-zero'
)
);
$this
->
assertSame
(
'0'
,
$cache
->
get
(
'en'
,
'some-string'
)
);
$this
->
assertSame
(
42
,
$cache
->
get
(
'en'
,
'a-number'
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 20:45 (4 d, 10 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
71/38/4ed6c0508238fbf822140565bf40
Default Alt Text
LCStoreStaticArrayTest.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment