Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/194251

Change subject: [wip] Fix php errors in paramOrder
......................................................................

[wip] Fix php errors in paramOrder

Make sure that paramOrder is initialized as an array even if the
params property of the TemplateData object is empty.

Bug: T91470
Change-Id: I2bc79421be33053e7e21170528fbbd1c01eaf4bb
---
M TemplateDataBlob.php
M tests/TemplateDataBlobTest.php
2 files changed, 27 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData 
refs/changes/51/194251/1

diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php
index b8220c3..e55cc60 100644
--- a/TemplateDataBlob.php
+++ b/TemplateDataBlob.php
@@ -46,6 +46,7 @@
                        $tdb->data = new stdClass();
                        $tdb->data->description = null;
                        $tdb->data->params = new stdClass();
+                       $tdb->data->paramOrder = array();
                        $tdb->data->sets = array();
                        $tdb->data->maps = new stdClass();
                }
@@ -344,9 +345,9 @@
                                return Status::newFatal( 
'templatedata-invalid-type', 'paramOrder', 'array' );
                        }
 
-                       if ( !count( $data->paramOrder ) ) {
-                               return Status::newFatal( 
'templatedata-invalid-empty-array', "paramOrder" );
-                       }
+                       // if ( !count( $data->paramOrder ) ) {
+                       //      return Status::newFatal( 
'templatedata-invalid-empty-array', "paramOrder" );
+                       // }
 
                        if ( count( $data->paramOrder ) < count( $paramNames ) 
) {
                                $i = count( $data->paramOrder );
@@ -373,6 +374,8 @@
 
                } elseif ( count( $paramNames ) ) {
                        $data->paramOrder = $paramNames;
+               } else {
+                       $data->paramOrder = array();
                }
 
                // Root.sets
diff --git a/tests/TemplateDataBlobTest.php b/tests/TemplateDataBlobTest.php
index d240ee5..65adf43 100644
--- a/tests/TemplateDataBlobTest.php
+++ b/tests/TemplateDataBlobTest.php
@@ -49,6 +49,7 @@
                                'output' => '{
                                        "description": null,
                                        "params": {},
+                                       "paramOrder": [],
                                        "sets": [],
                                        "maps" : {}
                                }
@@ -626,6 +627,7 @@
                                'output' => '{
                                        "description": "German",
                                        "params": {},
+                                       "paramOrder": [],
                                        "sets": [],
                                        "maps" : {}
                                }
@@ -641,6 +643,7 @@
                                ',
                                'output' => '{
                                        "description": "Hi",
+                                       "paramOrder": [],
                                        "params": {},
                                        "sets": [],
                                        "maps" : {}
@@ -662,6 +665,7 @@
                                'output' => '{
                                        "description": "Dutch",
                                        "params": {},
+                                       "paramOrder": [],
                                        "sets": [],
                                        "maps" : {}
                                }
@@ -681,6 +685,7 @@
                                'output' => '{
                                        "description": null,
                                        "params": {},
+                                       "paramOrder": [],
                                        "sets": [],
                                        "maps" : {}
                                }
@@ -701,6 +706,7 @@
                                'output' => '{
                                        "description": "German",
                                        "params": {},
+                                       "paramOrder": [],
                                        "sets": [],
                                        "maps" : {}
                                }
@@ -986,6 +992,21 @@
                        ),
                        array(
                                'input' => '{
+                                       "params": {}
+                               }
+                               ',
+                               'output' => '{
+                                       "description": null,
+                                       "params": {},
+                                       "paramOrder": [],
+                                       "sets": [],
+                                       "maps" : {}
+                               }
+                               ',
+                               'msg' => 'Empty parameter object produces empty 
array paramOrder'
+                       ),
+                       array(
+                               'input' => '{
                                        "params": {
                                                "foo": {},
                                                "bar": {},

-- 
To view, visit https://gerrit.wikimedia.org/r/194251
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2bc79421be33053e7e21170528fbbd1c01eaf4bb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to