mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-30 10:34:19 +00:00
Merge "Show much more actionable context when paramOrder is incomplete"
This commit is contained in:
commit
bde2188280
|
@ -280,8 +280,9 @@ class TemplateDataValidator {
|
|||
} elseif ( !is_array( $paramOrder ) ) {
|
||||
return Status::newFatal( 'templatedata-invalid-type', 'paramOrder', 'array' );
|
||||
} elseif ( count( $paramOrder ) < count( (array)$params ) ) {
|
||||
$firstMissing = count( $paramOrder );
|
||||
return Status::newFatal( 'templatedata-invalid-missing', "paramOrder[$firstMissing]" );
|
||||
$missing = array_diff( array_keys( (array)$params ), $paramOrder );
|
||||
return Status::newFatal( 'templatedata-invalid-missing',
|
||||
"paramOrder[ \"" . implode( '", "', $missing ) . '" ]' );
|
||||
}
|
||||
|
||||
// Validate each of the values corresponds to a parameter and that there are no
|
||||
|
@ -289,7 +290,7 @@ class TemplateDataValidator {
|
|||
$seen = [];
|
||||
foreach ( $paramOrder as $i => $param ) {
|
||||
if ( !isset( $params->$param ) ) {
|
||||
return Status::newFatal( 'templatedata-invalid-value', "paramOrder[$i]" );
|
||||
return Status::newFatal( 'templatedata-invalid-value', "paramOrder[ \"$param\" ]" );
|
||||
}
|
||||
if ( isset( $seen[$param] ) ) {
|
||||
return Status::newFatal( 'templatedata-invalid-duplicate-value',
|
||||
|
|
|
@ -1292,7 +1292,7 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
|
|||
"paramOrder": ["foo", "bar"]
|
||||
}
|
||||
',
|
||||
'status' => '(templatedata-invalid-missing: paramOrder[2])',
|
||||
'status' => '(templatedata-invalid-missing: paramOrder[ "baz" ])',
|
||||
'msg' => 'Incomplete paramOrder'
|
||||
],
|
||||
[
|
||||
|
@ -1320,7 +1320,7 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
|
|||
"paramOrder": ["foo", "bar", "baz", "quux"]
|
||||
}
|
||||
',
|
||||
'status' => '(templatedata-invalid-value: paramOrder[3])',
|
||||
'status' => '(templatedata-invalid-value: paramOrder[ "quux" ])',
|
||||
'msg' => 'Unknown params in paramOrder'
|
||||
],
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue