Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7445732
YamlFormatTest.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
YamlFormatTest.php
View Options
<?php
namespace
MediaWiki\Tests\Unit\Settings\Source\Format
;
use
MediaWiki\Settings\Source\Format\YamlFormat
;
use
MediaWikiCoversValidator
;
use
PHPUnit\Framework\TestCase
;
use
UnexpectedValueException
;
/** @covers \MediaWiki\Settings\Source\Format\YamlFormat */
class
YamlFormatTest
extends
TestCase
{
use
MediaWikiCoversValidator
;
private
const
VALID_YAML
=
<<<'VALID_YAML'
config-schema:
MySetting:
type: boolean
VALID_YAML;
private
const
INVALID_YAML
=
<<<'INVALID_YAML'
config-schema: []
MySetting: []
INVALID_YAML;
public
static
function
provideParser
()
{
yield
'php-yaml'
=>
[
'parser'
=>
YamlFormat
::
PARSER_PHP_YAML
];
yield
'symfony'
=>
[
'parser'
=>
YamlFormat
::
PARSER_SYMFONY
];
}
/**
* @dataProvider provideParser
*/
public
function
testDecode
(
string
$parser
)
{
if
(
!
YamlFormat
::
isParserAvailable
(
$parser
)
)
{
$this
->
markTestSkipped
(
"Parser '$parser' is not available"
);
}
$format
=
new
YamlFormat
(
[
$parser
]
);
$this
->
assertEquals
(
[
'config-schema'
=>
[
'MySetting'
=>
[
'type'
=>
'boolean'
]
]
],
$format
->
decode
(
self
::
VALID_YAML
)
);
}
/**
* @dataProvider provideParser
*/
public
function
testDecodeInvalid
(
string
$parser
)
{
if
(
!
YamlFormat
::
isParserAvailable
(
$parser
)
)
{
$this
->
markTestSkipped
(
"Parser '$parser' is not available"
);
}
$format
=
new
YamlFormat
(
[
$parser
]
);
$this
->
expectException
(
UnexpectedValueException
::
class
);
$format
->
decode
(
self
::
INVALID_YAML
);
}
/**
* @dataProvider provideParser
*/
public
function
testDecodeDoesNotUnserializeObjects
(
string
$parser
)
{
if
(
!
YamlFormat
::
isParserAvailable
(
$parser
)
)
{
$this
->
markTestSkipped
(
"Parser '$parser' is not available"
);
}
$format
=
new
YamlFormat
(
[
$parser
]
);
$this
->
expectException
(
UnexpectedValueException
::
class
);
$format
->
decode
(
'object: !php/object "'
.
serialize
(
$format
)
.
'"'
);
}
/**
* @dataProvider provideParser
*/
public
function
testDecodeDoesNotRespectPHPConst
(
string
$parser
)
{
if
(
!
YamlFormat
::
isParserAvailable
(
$parser
)
)
{
$this
->
markTestSkipped
(
"Parser '$parser' is not available"
);
}
$format
=
new
YamlFormat
(
[
$parser
]
);
$this
->
expectException
(
UnexpectedValueException
::
class
);
$format
->
decode
(
'{ bar: !php/const PHP_INT_SIZE }'
);
}
public
static
function
provideSupportsFileExtension
()
{
yield
'Supported'
=>
[
'yaml'
,
true
];
yield
'Supported, uppercase'
=>
[
'YAML'
,
true
];
yield
'Supported, short'
=>
[
'yml'
,
true
];
yield
'Unsupported'
=>
[
'txt'
,
false
];
}
/**
* @dataProvider provideSupportsFileExtension
*/
public
function
testSupportsFileExtension
(
$extension
,
$expected
)
{
$this
->
assertSame
(
$expected
,
YamlFormat
::
supportsFileExtension
(
$extension
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 18:16 (1 d, 6 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
02/e6/980d52cf6b9f7969234f196e615d
Default Alt Text
YamlFormatTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment