2013-04-16 14:18:10 +00:00
|
|
|
<?php
|
2014-07-07 22:54:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group TemplateData
|
|
|
|
*/
|
2013-04-16 14:18:10 +00:00
|
|
|
class TemplateDataBlobTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
'wgLanguageCode' => 'en',
|
|
|
|
'wgContLang' => Language::factory( 'en' ),
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2013-07-23 13:33:45 +00:00
|
|
|
/**
|
|
|
|
* Helper method to generate a string that gzip can't compress.
|
|
|
|
*
|
|
|
|
* Output is consistent when given the same seed.
|
|
|
|
*/
|
|
|
|
private static function generatePseudorandomString( $length, $seed ) {
|
|
|
|
mt_srand( $seed );
|
|
|
|
|
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
$characters_max = strlen( $characters ) - 1;
|
|
|
|
|
|
|
|
$string = '';
|
|
|
|
|
|
|
|
for ( $i = 0; $i < $length; $i++ ) {
|
|
|
|
$string .= $characters[mt_rand( 0, $characters_max )];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
2013-10-06 16:31:20 +00:00
|
|
|
|
2013-04-16 14:18:10 +00:00
|
|
|
public static function provideParse() {
|
2013-05-15 23:05:06 +00:00
|
|
|
$cases = array(
|
2013-04-16 14:18:10 +00:00
|
|
|
array(
|
2013-05-15 23:05:06 +00:00
|
|
|
'input' => '[]
|
2013-04-16 14:18:10 +00:00
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'status' => 'Property "templatedata" is expected to be of type "object".'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
2013-05-15 22:15:52 +00:00
|
|
|
"params": {},
|
2015-03-04 01:40:40 +00:00
|
|
|
"paramOrder": [],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-05-15 23:05:06 +00:00
|
|
|
}
|
2013-04-16 14:18:10 +00:00
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'status' => true,
|
|
|
|
'msg' => 'Minimal valid blob'
|
2013-04-16 14:18:10 +00:00
|
|
|
),
|
|
|
|
array(
|
2013-05-15 23:05:06 +00:00
|
|
|
'input' => '{
|
|
|
|
"params": {},
|
2013-04-16 14:18:10 +00:00
|
|
|
"foo": "bar"
|
|
|
|
}
|
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'status' => 'Unexpected property "foo".',
|
|
|
|
'msg' => 'Unknown properties'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{}',
|
|
|
|
'status' => 'Required property "params" not found.',
|
|
|
|
'msg' => 'Empty object'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"foo": "bar"
|
|
|
|
}
|
2013-04-16 14:18:10 +00:00
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'status' => 'Unexpected property "foo".',
|
|
|
|
'msg' => 'Unknown properties invalidate the blob'
|
2013-04-16 14:18:10 +00:00
|
|
|
),
|
|
|
|
array(
|
2013-05-15 23:05:06 +00:00
|
|
|
'input' => '{
|
2013-04-16 14:18:10 +00:00
|
|
|
"params": {
|
|
|
|
"foo": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'output' => '{
|
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,
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-04-16 14:18:10 +00:00
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-04-16 14:18:10 +00:00
|
|
|
"deprecated": false,
|
2013-05-08 23:56:57 +00:00
|
|
|
"aliases": [],
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
2013-05-15 22:15:52 +00:00
|
|
|
},
|
2013-10-09 22:26:22 +00:00
|
|
|
"paramOrder": ["foo"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps": {}
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'msg' => 'Optional properties are added if missing'
|
2013-04-16 14:18:10 +00:00
|
|
|
),
|
2013-10-24 16:39:04 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"comment": {
|
|
|
|
"type": "string/line"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {
|
|
|
|
"comment": {
|
|
|
|
"label": null,
|
|
|
|
"description": null,
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"autovalue": null,
|
2013-10-24 16:39:04 +00:00
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-24 16:39:04 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
|
|
|
"type": "line"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"paramOrder": ["comment"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps": {}
|
2013-10-24 16:39:04 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'msg' => 'Old string/* types are mapped to the unprefixed versions'
|
|
|
|
),
|
2013-04-16 14:18:10 +00:00
|
|
|
array(
|
2013-05-15 23:05:06 +00:00
|
|
|
'input' => '{
|
2013-04-16 14:18:10 +00:00
|
|
|
"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",
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-04-16 14:18:10 +00:00
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": true,
|
2013-04-16 14:18:10 +00:00
|
|
|
"aliases": [
|
|
|
|
"1"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'output' => '{
|
2013-04-16 14:18:10 +00:00
|
|
|
"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"
|
|
|
|
},
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": {
|
|
|
|
"en": "Base page name of the host page"
|
|
|
|
},
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-04-16 14:18:10 +00:00
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": true,
|
2013-04-16 14:18:10 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [
|
|
|
|
"1"
|
2013-05-08 23:56:57 +00:00
|
|
|
],
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
2013-05-15 22:15:52 +00:00
|
|
|
},
|
2013-10-09 22:26:22 +00:00
|
|
|
"paramOrder": ["nickname"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps": {}
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'msg' => 'InterfaceText is expanded to langcode-keyed object, assuming content language'
|
2013-04-22 19:56:28 +00:00
|
|
|
),
|
2013-04-30 22:32:08 +00:00
|
|
|
array(
|
2013-05-15 23:05:06 +00:00
|
|
|
'input' => '{
|
2013-04-30 22:32:08 +00:00
|
|
|
"description": "Document the documenter.",
|
|
|
|
"params": {
|
|
|
|
"1d": {
|
|
|
|
"description": "Description of the template parameter",
|
|
|
|
"required": true,
|
|
|
|
"default": "example"
|
|
|
|
},
|
|
|
|
"2d": {
|
|
|
|
"inherits": "1d",
|
|
|
|
"default": "overridden"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
2013-05-15 23:05:06 +00:00
|
|
|
'output' => '{
|
2013-04-30 22:32:08 +00:00
|
|
|
"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"
|
|
|
|
},
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-04-30 22:32:08 +00:00
|
|
|
"required": true,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": {
|
|
|
|
"en": "example"
|
|
|
|
},
|
2013-04-30 22:32:08 +00:00
|
|
|
"deprecated": false,
|
2013-05-08 23:56:57 +00:00
|
|
|
"aliases": [],
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
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"
|
|
|
|
},
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-04-30 22:32:08 +00:00
|
|
|
"required": true,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": {
|
|
|
|
"en": "overridden"
|
|
|
|
},
|
2013-04-30 22:32:08 +00:00
|
|
|
"deprecated": false,
|
2013-05-08 23:56:57 +00:00
|
|
|
"aliases": [],
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-04-30 22:32:08 +00:00
|
|
|
}
|
2013-05-15 22:15:52 +00:00
|
|
|
},
|
2013-10-09 22:26:22 +00:00
|
|
|
"paramOrder": ["1d", "2d"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-04-30 22:32:08 +00:00
|
|
|
}
|
|
|
|
',
|
2013-05-16 15:01:00 +00:00
|
|
|
'msg' => 'The inherits property copies over properties from another parameter '
|
|
|
|
. '(preserving overides)'
|
2013-04-30 22:32:08 +00:00
|
|
|
),
|
2013-05-15 22:15:52 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {},
|
|
|
|
"sets": [
|
|
|
|
{
|
|
|
|
"label": "Example"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}',
|
|
|
|
'status' => 'Required property "sets.0.params" not found.'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sets": [
|
|
|
|
{
|
|
|
|
"params": ["foo"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}',
|
|
|
|
'status' => 'Required property "sets.0.label" not found.'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sets": [
|
|
|
|
{
|
|
|
|
"label": "Foo with Quux",
|
|
|
|
"params": ["foo", "quux"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}',
|
2014-11-08 19:44:56 +00:00
|
|
|
'status' => 'Invalid value for property "sets.0.params[1]".'
|
2013-05-15 22:15:52 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
},
|
|
|
|
"quux": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sets": [
|
|
|
|
{
|
|
|
|
"label": "Foo with Quux",
|
|
|
|
"params": ["foo", "quux"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"label": "Bar with Quux",
|
|
|
|
"params": ["bar", "quux"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-05-15 22:15:52 +00:00
|
|
|
"description": null,
|
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-05-15 22:15:52 +00:00
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-05-15 22:15:52 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-05-15 22:15:52 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-05-15 22:15:52 +00:00
|
|
|
},
|
|
|
|
"quux": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-05-15 22:15:52 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-05-15 22:15:52 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-05-15 22:15:52 +00:00
|
|
|
}
|
|
|
|
},
|
2013-10-09 22:26:22 +00:00
|
|
|
"paramOrder": ["foo", "bar", "quux"],
|
2013-05-15 22:15:52 +00:00
|
|
|
"sets": [
|
|
|
|
{
|
|
|
|
"label": {
|
|
|
|
"en": "Foo with Quux"
|
|
|
|
},
|
|
|
|
"params": ["foo", "quux"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"label": {
|
|
|
|
"en": "Bar with Quux"
|
|
|
|
},
|
|
|
|
"params": ["bar", "quux"]
|
|
|
|
}
|
2014-10-18 15:28:26 +00:00
|
|
|
],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps": {}
|
2013-05-15 22:15:52 +00:00
|
|
|
}',
|
|
|
|
'status' => true
|
|
|
|
),
|
2014-09-02 15:29:33 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"description": "Testing some template description.",
|
|
|
|
"params": {
|
|
|
|
"bar": {
|
|
|
|
"label": "Bar label",
|
|
|
|
"description": "Bar description",
|
|
|
|
"default": "Baz",
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": "Foo bar baz",
|
2014-09-02 15:29:33 +00:00
|
|
|
"autovalue": "{{SomeTemplate}}",
|
|
|
|
"required": true,
|
|
|
|
"suggested": false,
|
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [ "foo", "baz" ],
|
|
|
|
"type": "line"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": {
|
|
|
|
"en": "Testing some template description."
|
|
|
|
},
|
|
|
|
"params": {
|
|
|
|
"bar": {
|
|
|
|
"label": {
|
|
|
|
"en": "Bar label"
|
|
|
|
},
|
|
|
|
"description": {
|
|
|
|
"en": "Bar description"
|
|
|
|
},
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": {
|
|
|
|
"en": "Baz"
|
|
|
|
},
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": {
|
|
|
|
"en": "Foo bar baz"
|
|
|
|
},
|
2014-09-02 15:29:33 +00:00
|
|
|
"autovalue": "{{SomeTemplate}}",
|
|
|
|
"required": true,
|
|
|
|
"suggested": false,
|
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [ "foo", "baz" ],
|
|
|
|
"type": "line"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"paramOrder": ["bar"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2014-09-02 15:29:33 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'msg' => 'Parameter attributes preserve information.'
|
|
|
|
),
|
2014-10-18 15:28:26 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sets": [],
|
|
|
|
"maps": {
|
|
|
|
"application": {
|
|
|
|
"things": [
|
|
|
|
"foo",
|
|
|
|
["bar", "quux"]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'status' => 'Invalid parameter "quux" for property "maps.application.things".'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sets": [],
|
|
|
|
"maps": {
|
|
|
|
"application": {
|
|
|
|
"things": {
|
|
|
|
"appbar": "bar",
|
|
|
|
"appfoo": "foo"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'status' => 'Property "maps.application.things" is expected to be of type "string|array".'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sets": [],
|
|
|
|
"maps": {
|
|
|
|
"application": {
|
|
|
|
"things": [
|
|
|
|
[ true ]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'status' => 'Property "maps.application.things[0][0]" is expected to be of type "string".'
|
|
|
|
),
|
2015-10-02 10:34:57 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {}
|
|
|
|
},
|
|
|
|
"format": "meshuggah format"
|
|
|
|
}',
|
|
|
|
'status' => 'Property "format" is expected to be "inline" or "block".'
|
|
|
|
),
|
2013-07-23 12:29:43 +00:00
|
|
|
array(
|
2013-07-23 13:33:45 +00:00
|
|
|
// Should be long enough to trigger this condition after gzipping.
|
2013-07-23 12:29:43 +00:00
|
|
|
'input' => '{
|
2013-07-23 13:33:45 +00:00
|
|
|
"description": "' . self::generatePseudorandomString( 100000, 42 ) . '",
|
2013-07-23 12:29:43 +00:00
|
|
|
"params": {}
|
|
|
|
}',
|
2016-03-01 17:10:23 +00:00
|
|
|
'status' => 'Data too large to save (75,226 bytes, limit is 65,535)'
|
2013-07-23 12:29:43 +00:00
|
|
|
),
|
2013-04-16 14:18:10 +00:00
|
|
|
);
|
2013-05-15 23:05:06 +00:00
|
|
|
$calls = array();
|
|
|
|
foreach ( $cases as $case ) {
|
|
|
|
$calls[] = array( $case );
|
|
|
|
}
|
|
|
|
return $calls;
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 21:05:33 +00:00
|
|
|
protected static function getStatusText( Status $status ) {
|
|
|
|
$str = $status->getHtml();
|
2016-01-04 01:56:07 +00:00
|
|
|
// Based on wfMessage()->parse
|
2013-12-10 21:05:33 +00:00
|
|
|
$m = array();
|
|
|
|
if ( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $str, $m ) ) {
|
2014-11-08 19:44:56 +00:00
|
|
|
// Unescape char references for things like "[, "]" and "|" for
|
|
|
|
// cleaner test assertions and output
|
|
|
|
$str = Sanitizer::decodeCharReferences( $m[1] );
|
2013-12-10 21:05:33 +00:00
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2014-09-02 15:29:33 +00:00
|
|
|
private static function ksort( Array &$input ) {
|
|
|
|
ksort( $input );
|
|
|
|
foreach ( $input as $key => &$value ) {
|
|
|
|
if ( is_array( $value ) ) {
|
|
|
|
self::ksort( $value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHPUnit'a assertEquals does weak comparison, use strict instead.
|
|
|
|
*
|
|
|
|
* There is a built-in assertSame, but that only strictly compares
|
|
|
|
* the top level structure, not the invidual array values.
|
|
|
|
*
|
|
|
|
* so "array( 'a' => '' )" still equals "array( 'a' => null )"
|
|
|
|
* because empty string equals null in PHP's weak comparison.
|
|
|
|
*
|
|
|
|
* @param mixed $expected
|
|
|
|
* @param mixed $actual
|
|
|
|
*/
|
|
|
|
protected function assertStrictJsonEquals( $expected, $actual, $message = null ) {
|
|
|
|
// Lazy recursive strict comparison: Serialise to JSON and compare that
|
|
|
|
// Sort first to ensure key-order
|
|
|
|
$expected = json_decode( $expected, /* assoc = */ true );
|
|
|
|
$actual = json_decode( $actual, /* assoc = */ true );
|
|
|
|
self::ksort( $expected );
|
|
|
|
self::ksort( $actual );
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
FormatJson::encode( $expected, true ),
|
|
|
|
FormatJson::encode( $actual, true ),
|
|
|
|
$message
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-10-15 19:40:09 +00:00
|
|
|
protected function assertTemplateData( Array $case ) {
|
2013-05-15 23:05:06 +00:00
|
|
|
// Expand defaults
|
2013-10-15 19:40:09 +00:00
|
|
|
if ( !isset( $case['status'] ) ) {
|
|
|
|
$case['status'] = true;
|
2013-05-15 23:05:06 +00:00
|
|
|
}
|
2013-10-15 19:40:09 +00:00
|
|
|
if ( !isset( $case['msg'] ) ) {
|
|
|
|
$case['msg'] = is_string( $case['status'] ) ? $case['status'] : 'TemplateData assertion';
|
2013-05-15 23:05:06 +00:00
|
|
|
}
|
2013-10-15 19:40:09 +00:00
|
|
|
if ( !isset( $case['output'] ) ) {
|
|
|
|
if ( is_string( $case['status'] ) ) {
|
2015-03-04 01:40:40 +00:00
|
|
|
$case['output'] = '{
|
|
|
|
"description": null,
|
|
|
|
"params": {},
|
|
|
|
"sets": [],
|
|
|
|
"maps": {},
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2015-03-04 01:40:40 +00:00
|
|
|
"paramOrder": []
|
|
|
|
}';
|
2013-05-15 23:05:06 +00:00
|
|
|
} else {
|
2013-10-15 19:40:09 +00:00
|
|
|
$case['output'] = $case['input'];
|
2013-05-15 23:05:06 +00:00
|
|
|
}
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 19:40:09 +00:00
|
|
|
$t = TemplateDataBlob::newFromJSON( $case['input'] );
|
2013-05-15 23:05:06 +00:00
|
|
|
$actual = $t->getJSON();
|
2013-04-16 14:18:10 +00:00
|
|
|
$status = $t->getStatus();
|
2013-05-15 23:05:06 +00:00
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
$this->assertEquals(
|
2013-10-15 19:40:09 +00:00
|
|
|
$case['status'],
|
2013-12-10 21:05:33 +00:00
|
|
|
self::getStatusText( $status ),
|
2013-10-15 19:40:09 +00:00
|
|
|
'Status: ' . $case['msg']
|
2013-05-15 23:05:06 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->assertEquals(
|
2013-10-15 19:40:09 +00:00
|
|
|
$case['status'],
|
2013-05-15 23:05:06 +00:00
|
|
|
$status->isGood(),
|
2013-10-15 19:40:09 +00:00
|
|
|
'Status: ' . $case['msg']
|
2013-05-15 23:05:06 +00:00
|
|
|
);
|
|
|
|
}
|
2014-09-02 15:29:33 +00:00
|
|
|
|
|
|
|
$this->assertStrictJsonEquals(
|
2013-10-15 19:40:09 +00:00
|
|
|
$case['output'],
|
2013-05-15 23:05:06 +00:00
|
|
|
$actual,
|
2013-10-15 19:40:09 +00:00
|
|
|
$case['msg']
|
2013-04-16 14:18:10 +00:00
|
|
|
);
|
2013-10-24 16:34:04 +00:00
|
|
|
|
|
|
|
// Assert this case roundtrips properly by running through the output as input.
|
|
|
|
|
|
|
|
$t = TemplateDataBlob::newFromJSON( $case['output'] );
|
|
|
|
|
|
|
|
$status = $t->getStatus();
|
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
$this->assertEquals(
|
|
|
|
$case['status'],
|
2013-12-10 21:05:33 +00:00
|
|
|
self::getStatusText( $status ),
|
2013-10-24 16:34:04 +00:00
|
|
|
'Roundtrip status: ' . $case['msg']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-09-02 15:29:33 +00:00
|
|
|
$this->assertStrictJsonEquals(
|
2013-10-24 16:34:04 +00:00
|
|
|
$case['output'],
|
|
|
|
$t->getJSON(),
|
|
|
|
'Roundtrip: ' . $case['msg']
|
|
|
|
);
|
|
|
|
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|
2013-09-12 04:02:37 +00:00
|
|
|
|
2013-10-15 19:40:09 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider provideParse
|
|
|
|
*/
|
|
|
|
public function testParse( Array $case ) {
|
|
|
|
$this->assertTemplateData( $case );
|
|
|
|
}
|
|
|
|
|
2013-09-12 04:02:37 +00:00
|
|
|
/**
|
|
|
|
* Verify we can gzdecode() which came in PHP 5.4.0. Mediawiki needs a
|
|
|
|
* fallback function for it.
|
|
|
|
* If this test fail, we are most probably attempting to use gzdecode()
|
|
|
|
* with PHP before 5.4.
|
|
|
|
*
|
|
|
|
* @see bug 54058
|
|
|
|
*/
|
|
|
|
public function testGetJsonForDatabase() {
|
|
|
|
// Compress JSON to trigger the code pass in newFromDatabase that ends
|
|
|
|
// up calling gzdecode().
|
|
|
|
$gzJson = gzencode( '{}' );
|
2013-09-12 09:41:07 +00:00
|
|
|
$templateData = TemplateDataBlob::newFromDatabase( $gzJson );
|
|
|
|
$this->assertInstanceOf( 'TemplateDataBlob', $templateData );
|
2013-09-12 04:02:37 +00:00
|
|
|
}
|
2013-10-06 16:31:20 +00:00
|
|
|
|
|
|
|
public static function provideGetDataInLanguage() {
|
|
|
|
$cases = array(
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"description": {
|
|
|
|
"de": "German",
|
|
|
|
"nl": "Dutch",
|
|
|
|
"en": "English",
|
|
|
|
"de-formal": "German (formal address)"
|
|
|
|
},
|
|
|
|
"params": {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": "German",
|
|
|
|
"params": {},
|
2015-03-04 01:40:40 +00:00
|
|
|
"paramOrder": [],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'de',
|
|
|
|
'msg' => 'Simple description'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"description": "Hi",
|
|
|
|
"params": {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": "Hi",
|
2015-03-04 01:40:40 +00:00
|
|
|
"paramOrder": [],
|
2013-10-06 16:31:20 +00:00
|
|
|
"params": {},
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'fr',
|
|
|
|
'msg' => 'Non multi-language value returned as is (expands to { "en": value } for' .
|
|
|
|
' content-lang, "fr" falls back to "en")'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"description": {
|
|
|
|
"nl": "Dutch",
|
|
|
|
"de": "German"
|
|
|
|
},
|
|
|
|
"params": {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": "Dutch",
|
|
|
|
"params": {},
|
2015-03-04 01:40:40 +00:00
|
|
|
"paramOrder": [],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'fr',
|
|
|
|
'msg' => 'Try content language before giving up on user language and fallbacks'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"description": {
|
|
|
|
"es": "Spanish",
|
|
|
|
"de": "German"
|
|
|
|
},
|
|
|
|
"params": {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {},
|
2015-03-04 01:40:40 +00:00
|
|
|
"paramOrder": [],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'fr',
|
|
|
|
'msg' => 'Description is optional, use null if no suitable fallback'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"description": {
|
|
|
|
"de": "German",
|
|
|
|
"nl": "Dutch",
|
|
|
|
"en": "English"
|
|
|
|
},
|
|
|
|
"params": {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": "German",
|
|
|
|
"params": {},
|
2015-03-04 01:40:40 +00:00
|
|
|
"paramOrder": [],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'de-formal',
|
|
|
|
'msg' => '"de-formal" falls back to "de"'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"label": {
|
|
|
|
"fr": "French",
|
|
|
|
"en": "English"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"label": "French",
|
|
|
|
"required": false,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-06 16:31:20 +00:00
|
|
|
"description": null,
|
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
},
|
2013-10-09 22:26:22 +00:00
|
|
|
"paramOrder": ["foo"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'fr',
|
|
|
|
'msg' => 'Simple parameter label'
|
|
|
|
),
|
2015-03-09 21:45:04 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"default": {
|
|
|
|
"fr": "French",
|
|
|
|
"en": "English"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"default": "French",
|
|
|
|
"required": false,
|
|
|
|
"suggested": false,
|
|
|
|
"description": null,
|
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
|
|
|
"label": null,
|
|
|
|
"type": "unknown",
|
2015-03-04 20:32:38 +00:00
|
|
|
"autovalue": null,
|
|
|
|
"example": null
|
2015-03-09 21:45:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"paramOrder": ["foo"],
|
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2015-03-09 21:45:04 +00:00
|
|
|
"maps" : {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'fr',
|
|
|
|
'msg' => 'Simple parameter default value'
|
|
|
|
),
|
2013-10-06 16:31:20 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"label": {
|
|
|
|
"es": "Spanish",
|
|
|
|
"de": "German"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-06 16:31:20 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-10-06 16:31:20 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
},
|
2013-10-09 22:26:22 +00:00
|
|
|
"paramOrder": ["foo"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'fr',
|
|
|
|
'msg' => 'Parameter label is optional, use null if no matching fallback'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
2013-10-15 19:40:09 +00:00
|
|
|
"params": {
|
|
|
|
"foo": {}
|
|
|
|
},
|
2013-10-06 16:31:20 +00:00
|
|
|
"sets": [
|
|
|
|
{
|
|
|
|
"label": {
|
|
|
|
"es": "Spanish",
|
|
|
|
"de": "German"
|
|
|
|
},
|
2013-10-15 19:40:09 +00:00
|
|
|
"params": ["foo"]
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
2013-10-15 19:40:09 +00:00
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-15 19:40:09 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-10-15 19:40:09 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-15 19:40:09 +00:00
|
|
|
}
|
|
|
|
},
|
2013-10-09 22:26:22 +00:00
|
|
|
"paramOrder": ["foo"],
|
2013-10-06 16:31:20 +00:00
|
|
|
"sets": [
|
|
|
|
{
|
|
|
|
"label": "Spanish",
|
2013-10-15 19:40:09 +00:00
|
|
|
"params": ["foo"]
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
2014-10-18 15:28:26 +00:00
|
|
|
],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps": {}
|
2013-10-06 16:31:20 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'lang' => 'fr',
|
|
|
|
'msg' => 'Set label is not optional, choose first available key as final fallback'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$calls = array();
|
|
|
|
foreach ( $cases as $case ) {
|
|
|
|
$calls[] = array( $case );
|
|
|
|
}
|
|
|
|
return $calls;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideGetDataInLanguage
|
|
|
|
*/
|
|
|
|
public function testGetDataInLanguage( Array $case ) {
|
|
|
|
|
|
|
|
// Change content-language to be non-English so we can distinguish between the
|
|
|
|
// last 'en' fallback and the content language in our tests
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
'wgLanguageCode' => 'nl',
|
|
|
|
'wgContLang' => Language::factory( 'nl' ),
|
|
|
|
) );
|
|
|
|
|
|
|
|
if ( !isset( $case['msg'] ) ) {
|
|
|
|
$case['msg'] = is_string( $case['status'] ) ? $case['status'] : 'TemplateData assertion';
|
|
|
|
}
|
|
|
|
|
|
|
|
$t = TemplateDataBlob::newFromJSON( $case['input'] );
|
|
|
|
$status = $t->getStatus();
|
|
|
|
|
2013-12-10 21:05:33 +00:00
|
|
|
$this->assertTrue(
|
|
|
|
$status->isGood() ?: self::getStatusText( $status ),
|
|
|
|
'Status is good: ' . $case['msg']
|
|
|
|
);
|
2013-10-06 16:31:20 +00:00
|
|
|
|
|
|
|
$actual = $t->getDataInLanguage( $case['lang'] );
|
|
|
|
$this->assertJsonStringEqualsJsonString(
|
|
|
|
$case['output'],
|
|
|
|
json_encode( $actual ),
|
|
|
|
$case['msg']
|
|
|
|
);
|
|
|
|
}
|
2013-10-09 22:26:22 +00:00
|
|
|
|
|
|
|
public static function provideParamOrder() {
|
|
|
|
$cases = array(
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {},
|
|
|
|
"bar": {},
|
|
|
|
"baz": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-09 22:26:22 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-10-09 22:26:22 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-09 22:26:22 +00:00
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-09 22:26:22 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-10-09 22:26:22 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-09 22:26:22 +00:00
|
|
|
},
|
|
|
|
"baz": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-09 22:26:22 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-10-09 22:26:22 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-09 22:26:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"paramOrder": ["foo", "bar", "baz"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-09 22:26:22 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'msg' => 'Normalisation adds paramOrder'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {},
|
|
|
|
"bar": {},
|
|
|
|
"baz": {}
|
|
|
|
},
|
|
|
|
"paramOrder": ["baz", "foo", "bar"]
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {
|
|
|
|
"foo": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-09 22:26:22 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-10-09 22:26:22 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-09 22:26:22 +00:00
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-09 22:26:22 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-10-09 22:26:22 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-09 22:26:22 +00:00
|
|
|
},
|
|
|
|
"baz": {
|
|
|
|
"label": null,
|
|
|
|
"required": false,
|
2014-04-24 22:21:36 +00:00
|
|
|
"suggested": false,
|
2013-10-09 22:26:22 +00:00
|
|
|
"description": null,
|
2015-03-04 20:32:38 +00:00
|
|
|
"example": null,
|
2013-10-09 22:26:22 +00:00
|
|
|
"deprecated": false,
|
|
|
|
"aliases": [],
|
2015-03-09 21:45:04 +00:00
|
|
|
"default": null,
|
2014-09-02 15:29:33 +00:00
|
|
|
"type": "unknown",
|
|
|
|
"autovalue": null
|
2013-10-09 22:26:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"paramOrder": ["baz", "foo", "bar"],
|
2014-10-18 15:28:26 +00:00
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2014-10-18 15:28:26 +00:00
|
|
|
"maps" : {}
|
2013-10-09 22:26:22 +00:00
|
|
|
}
|
|
|
|
',
|
|
|
|
'msg' => 'Custom paramOrder'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {},
|
|
|
|
"bar": {},
|
|
|
|
"baz": {}
|
|
|
|
},
|
|
|
|
"paramOrder": ["foo", "bar"]
|
|
|
|
}
|
|
|
|
',
|
2014-11-08 19:44:56 +00:00
|
|
|
'status' => 'Required property "paramOrder[2]" not found.',
|
2013-10-09 22:26:22 +00:00
|
|
|
'msg' => 'Incomplete paramOrder'
|
|
|
|
),
|
2015-03-04 01:40:40 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'output' => '{
|
|
|
|
"description": null,
|
|
|
|
"params": {},
|
|
|
|
"paramOrder": [],
|
|
|
|
"sets": [],
|
2016-03-01 17:10:23 +00:00
|
|
|
"format": null,
|
2015-03-04 01:40:40 +00:00
|
|
|
"maps" : {}
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'msg' => 'Empty parameter object produces empty array paramOrder'
|
|
|
|
),
|
2013-10-09 22:26:22 +00:00
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {},
|
|
|
|
"bar": {},
|
|
|
|
"baz": {}
|
|
|
|
},
|
|
|
|
"paramOrder": ["foo", "bar", "baz", "quux"]
|
|
|
|
}
|
|
|
|
',
|
2014-11-08 19:44:56 +00:00
|
|
|
'status' => 'Invalid value for property "paramOrder[3]".',
|
2013-10-09 22:26:22 +00:00
|
|
|
'msg' => 'Unknown params in paramOrder'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'input' => '{
|
|
|
|
"params": {
|
|
|
|
"foo": {},
|
|
|
|
"bar": {},
|
|
|
|
"baz": {}
|
|
|
|
},
|
|
|
|
"paramOrder": ["foo", "bar", "baz", "bar"]
|
|
|
|
}
|
|
|
|
',
|
2014-11-08 19:44:56 +00:00
|
|
|
'status' => 'Property "paramOrder[3]" ("bar") is a duplicate of ' .
|
|
|
|
'"paramOrder[1]".',
|
2013-10-09 22:26:22 +00:00
|
|
|
'msg' => 'Duplicate params in paramOrder'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$calls = array();
|
|
|
|
foreach ( $cases as $case ) {
|
|
|
|
$calls[] = array( $case );
|
|
|
|
}
|
|
|
|
return $calls;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideParamOrder
|
|
|
|
*/
|
|
|
|
public function testParamOrder( Array $case ) {
|
|
|
|
$this->assertTemplateData( $case );
|
|
|
|
}
|
2013-04-16 14:18:10 +00:00
|
|
|
}
|