2013-04-16 14:18:10 +00:00
|
|
|
<?php
|
|
|
|
class TemplateDataBlobTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
'wgLanguageCode' => 'en',
|
|
|
|
'wgContLang' => Language::factory( 'en' ),
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function provideParse() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
{}
|
|
|
|
',
|
|
|
|
'
|
|
|
|
{}
|
|
|
|
',
|
|
|
|
'Empty object'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"foo": "bar"
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'
|
|
|
|
{}
|
|
|
|
',
|
|
|
|
'Unknown properties are stripped'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"params": {
|
|
|
|
"foo": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'
|
|
|
|
{
|
2013-05-08 23:56:57 +00:00
|
|
|
"description": null,
|
2013-04-16 14:18:10 +00:00
|
|
|
"params": {
|
|
|
|
"foo": {
|
2013-05-08 23:56:57 +00:00
|
|
|
"label": null,
|
|
|
|
"description": null,
|
2013-04-16 14:18:10 +00:00
|
|
|
"default": "",
|
|
|
|
"required": false,
|
|
|
|
"deprecated": false,
|
2013-05-08 23:56:57 +00:00
|
|
|
"aliases": [],
|
|
|
|
"type": "unknown"
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'Optional properties are added if missing'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"description": "User badge MediaWiki developers.",
|
|
|
|
"params": {
|
|
|
|
"nickname": {
|
2013-05-08 23:56:57 +00:00
|
|
|
"label": null,
|
2013-04-16 14:18:10 +00:00
|
|
|
"description": "User name of user who owns the badge",
|
|
|
|
"default": "Base page name of the host page",
|
|
|
|
"required": false,
|
|
|
|
"aliases": [
|
|
|
|
"1"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"description": {
|
|
|
|
"en": "User badge MediaWiki developers."
|
|
|
|
},
|
|
|
|
"params": {
|
|
|
|
"nickname": {
|
2013-05-08 23:56:57 +00:00
|
|
|
"label": null,
|
2013-04-16 14:18:10 +00:00
|
|
|
"description": {
|
|
|
|
"en": "User name of user who owns the badge"
|
|
|
|
},
|
|
|
|
"default": "Base page name of the host page",
|
|
|
|
"required": false,
|
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [
|
|
|
|
"1"
|
2013-05-08 23:56:57 +00:00
|
|
|
],
|
|
|
|
"type": "unknown"
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'InterfaceText is expanded to langcode-keyed object, assuming content language'
|
2013-04-22 19:56:28 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"description": {
|
|
|
|
"en": "User badge MediaWiki developers."
|
|
|
|
},
|
|
|
|
"params": {
|
|
|
|
"nickname": {
|
2013-05-08 23:56:57 +00:00
|
|
|
"label": null,
|
2013-04-22 19:56:28 +00:00
|
|
|
"description": {
|
|
|
|
"en": "User name of user who owns the badge"
|
|
|
|
},
|
|
|
|
"default": "Base page name of the host page",
|
|
|
|
"required": false,
|
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [
|
|
|
|
"1"
|
2013-05-08 23:56:57 +00:00
|
|
|
],
|
|
|
|
"type": "unknown"
|
2013-04-22 19:56:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'Fully normalised json should be valid input and stay unchanged'
|
2013-04-30 22:32:08 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"description": "Document the documenter.",
|
|
|
|
"params": {
|
|
|
|
"1d": {
|
|
|
|
"description": "Description of the template parameter",
|
|
|
|
"required": true,
|
|
|
|
"default": "example"
|
|
|
|
},
|
|
|
|
"2d": {
|
|
|
|
"inherits": "1d",
|
|
|
|
"default": "overridden"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"description": {
|
|
|
|
"en": "Document the documenter."
|
|
|
|
},
|
|
|
|
"params": {
|
|
|
|
"1d": {
|
2013-05-08 23:56:57 +00:00
|
|
|
"label": null,
|
2013-04-30 22:32:08 +00:00
|
|
|
"description": {
|
|
|
|
"en": "Description of the template parameter"
|
|
|
|
},
|
|
|
|
"required": true,
|
|
|
|
"default": "example",
|
|
|
|
"deprecated": false,
|
2013-05-08 23:56:57 +00:00
|
|
|
"aliases": [],
|
|
|
|
"type": "unknown"
|
2013-04-30 22:32:08 +00:00
|
|
|
},
|
|
|
|
"2d": {
|
2013-05-08 23:56:57 +00:00
|
|
|
"label": null,
|
2013-04-30 22:32:08 +00:00
|
|
|
"description": {
|
|
|
|
"en": "Description of the template parameter"
|
|
|
|
},
|
|
|
|
"required": true,
|
|
|
|
"default": "overridden",
|
|
|
|
"deprecated": false,
|
2013-05-08 23:56:57 +00:00
|
|
|
"aliases": [],
|
|
|
|
"type": "unknown"
|
2013-04-30 22:32:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'The inherits property copies over properties from another parameter (preserving overides)'
|
|
|
|
),
|
2013-04-16 14:18:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideParse
|
|
|
|
*/
|
2013-04-22 19:56:28 +00:00
|
|
|
public function testParse( $input, $expected, $msg = null ) {
|
|
|
|
if ( !$msg ) {
|
|
|
|
$msg = $expected;
|
|
|
|
$expected = $input;
|
|
|
|
}
|
2013-04-16 14:18:10 +00:00
|
|
|
$t = TemplateDataBlob::newFromJSON( $input );
|
|
|
|
$actual = $t->getJSON();
|
|
|
|
$this->assertJsonStringEqualsJsonString(
|
|
|
|
$expected,
|
|
|
|
$actual,
|
|
|
|
$msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function provideStatus() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
[]
|
|
|
|
',
|
|
|
|
false,
|
|
|
|
'Not an object'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"params": {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
true,
|
|
|
|
'Minimal valid blob'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"params": {},
|
|
|
|
"foo": "bar"
|
|
|
|
}
|
|
|
|
',
|
|
|
|
false,
|
|
|
|
'Unknown properties'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideStatus
|
|
|
|
*/
|
|
|
|
public function testStatus( $inputJSON, $isGood, $msg ) {
|
|
|
|
// Make sure we don't have two errors cancelling each other out
|
|
|
|
if ( json_decode( $inputJSON ) === null ) {
|
|
|
|
throw new Exception( 'Test case provided invalid JSON.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$t = TemplateDataBlob::newFromJSON( $inputJSON );
|
|
|
|
$status = $t->getStatus();
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$status->isGood(),
|
|
|
|
$isGood,
|
|
|
|
$msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|