jenkins-bot has submitted this change and it was merged.
Change subject: Fix roundtrip issues (normalised output for API must be valid
input)
......................................................................
Fix roundtrip issues (normalised output for API must be valid input)
For example, in case of failure we were defaulting to an empty
object, even though that is invalid input.
Change-Id: I00b4ce26b04ec408b5e86b9a2242cf942300ad41
---
M TemplateDataBlob.php
M spec.templatedata.json
M tests/TemplateDataBlobTest.php
3 files changed, 31 insertions(+), 28 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php
index 681881b..19b9579 100644
--- a/TemplateDataBlob.php
+++ b/TemplateDataBlob.php
@@ -39,8 +39,13 @@
$status = $tdb->parse();
if ( !$status->isOK() ) {
- // Don't save invalid data, clear it.
+ // If data is invalid, replace with the minimal valid
blob.
+ // This is to make sure that, if something forgets to
check the status first,
+ // we don't end up with invalid data in the database.
$tdb->data = new stdClass();
+ $tdb->data->description = null;
+ $tdb->data->params = new stdClass();
+ $tdb->data->sets = array();
}
$tdb->status = $status;
return $tdb;
diff --git a/spec.templatedata.json b/spec.templatedata.json
index 83b1eda..7183401 100644
--- a/spec.templatedata.json
+++ b/spec.templatedata.json
@@ -5,6 +5,10 @@
Author: Timo Tijhof
Author: Trevor Parscal
+ Property names listed in brackets (e.g. [foo]) are optional. This means
+ they may be omitted from the object. If a null value is allowed, this
will
+ be explicitly specified.
+
@structure {Object} Root
@property {null|InterfaceText} [description]
@property {Object} params Contains all parameters.
diff --git a/tests/TemplateDataBlobTest.php b/tests/TemplateDataBlobTest.php
index 581afe2..9ae6bdf 100644
--- a/tests/TemplateDataBlobTest.php
+++ b/tests/TemplateDataBlobTest.php
@@ -142,32 +142,6 @@
),
array(
'input' => '{
- "description": {
- "en": "User badge MediaWiki
developers."
- },
- "params": {
- "nickname": {
- "label": null,
- "description": {
- "en": "User
name of user who owns the badge"
- },
- "default": "Base page
name of the host page",
- "required": false,
- "deprecated": false,
- "aliases": [
- "1"
- ],
- "type": "unknown"
- }
- },
- "paramOrder": ["nickname"],
- "sets": []
- }
- ',
- 'msg' => 'Fully normalised json should be valid
input and stay unchanged'
- ),
- array(
- 'input' => '{
"description": "Document the
documenter.",
"params": {
"1d": {
@@ -355,7 +329,7 @@
}
if ( !isset( $case['output'] ) ) {
if ( is_string( $case['status'] ) ) {
- $case['output'] = '{}';
+ $case['output'] = '{ "description": null,
"params": {}, "sets": [] }';
} else {
$case['output'] = $case['input'];
}
@@ -382,6 +356,26 @@
$actual,
$case['msg']
);
+
+ // 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'],
+ $status->getHtml(),
+ 'Roundtrip status: ' . $case['msg']
+ );
+ }
+
+ $this->assertJsonStringEqualsJsonString(
+ $case['output'],
+ $t->getJSON(),
+ 'Roundtrip: ' . $case['msg']
+ );
+
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/91622
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I00b4ce26b04ec408b5e86b9a2242cf942300ad41
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits