Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5980341
JsonContentTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
JsonContentTest.php
View Options
<?php
namespace
MediaWiki\Tests\Unit
;
use
MediaWiki\Content\JsonContent
;
use
MediaWikiUnitTestCase
;
/**
* Split from \JsonContentTest integration tests
*
* @author Addshore
* @covers \MediaWiki\Content\JsonContent
*/
class
JsonContentTest
extends
MediaWikiUnitTestCase
{
public
static
function
provideValidConstruction
()
{
return
[
[
'foo'
,
false
,
null
],
[
'[]'
,
true
,
[]
],
[
'{}'
,
true
,
(
object
)[]
],
[
'""'
,
true
,
''
],
[
'"0"'
,
true
,
'0'
],
[
'"bar"'
,
true
,
'bar'
],
[
'0'
,
true
,
'0'
],
[
'{ "0": "bar" }'
,
true
,
(
object
)[
'bar'
]
],
];
}
/**
* @dataProvider provideValidConstruction
*/
public
function
testIsValid
(
$text
,
$isValid
,
$expected
)
{
$obj
=
new
JsonContent
(
$text
,
CONTENT_MODEL_JSON
);
$this
->
assertEquals
(
$isValid
,
$obj
->
isValid
()
);
$this
->
assertEquals
(
$expected
,
$obj
->
getData
()->
getValue
()
);
}
public
static
function
provideDataToEncode
()
{
return
[
[
// Round-trip empty array
'[]'
,
'[]'
,
],
[
// Round-trip empty object
'{}'
,
'{}'
,
],
[
// Round-trip empty array/object (nested)
'{ "foo": {}, "bar": [] }'
,
"{
\n\t\"
foo
\"
: {},
\n\t\"
bar
\"
: []
\n
}"
,
],
[
'{ "foo": "bar" }'
,
"{
\n\t\"
foo
\"
:
\"
bar
\"\n
}"
,
],
[
'{ "foo": 1000 }'
,
"{
\n\t\"
foo
\"
: 1000
\n
}"
,
],
[
'{ "foo": 1000, "0": "bar" }'
,
"{
\n\t\"
foo
\"
: 1000,
\n\t\"
0
\"
:
\"
bar
\"\n
}"
,
],
];
}
/**
* @dataProvider provideDataToEncode
*/
public
function
testBeautifyJson
(
$input
,
$beautified
)
{
$obj
=
new
JsonContent
(
$input
);
$this
->
assertEquals
(
$beautified
,
$obj
->
beautifyJSON
()
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 21:20 (1 w, 17 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
6e/49/2648347a32298395f050d92421b8
Default Alt Text
JsonContentTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment