Merge "Show much more actionable context when paramOrder is incomplete"

This commit is contained in:
jenkins-bot 2023-09-04 13:45:24 +00:00 committed by Gerrit Code Review
commit bde2188280
2 changed files with 6 additions and 5 deletions

View file

@ -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',

View file

@ -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'
],
[