MaxSem has uploaded a new change for review. https://gerrit.wikimedia.org/r/315831
Change subject: Add parser tests, fix warning they discovered ...................................................................... Add parser tests, fix warning they discovered PHP Warning: First parameter must either be an object or the name of an existing class in includes/Graph.body.php on line 138 Change-Id: I62d8ae49143ebab70fb636fe87a4c0ed21ad79d1 --- M extension.json M includes/Graph.body.php A tests/parserTests.txt 3 files changed, 44 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Graph refs/changes/31/315831/1 diff --git a/extension.json b/extension.json index 336b229..34866da 100644 --- a/extension.json +++ b/extension.json @@ -194,5 +194,8 @@ "ExtensionMessagesFiles": { "GraphAliases": "Graph.alias.php" }, + "ParserTestFiles": [ + "tests/parserTests.txt" + ], "manifest_version": 1 } diff --git a/includes/Graph.body.php b/includes/Graph.body.php index bcb2872..c3f8260 100644 --- a/includes/Graph.body.php +++ b/includes/Graph.body.php @@ -132,6 +132,10 @@ $isInteractive = isset( $args['mode'] ) && $args['mode'] === 'interactive'; $graphTitle = isset( $args['title'] ) ? $args['title'] : ''; $data = $status->getValue(); + if ( !is_object( $data ) ) { + // @todo: Output an error message instead? + $data = (object)[ 'width' => 200, 'height' => 200 ]; + } // Figure out which vega version to use global $wgGraphDefaultVegaVer; diff --git a/tests/parserTests.txt b/tests/parserTests.txt new file mode 100644 index 0000000..428311b --- /dev/null +++ b/tests/parserTests.txt @@ -0,0 +1,37 @@ +!! test +<graph> +!! input +<graph> +{} +</graph> +<graph> +{ + "width": 100, + "height": 200 +} +</graph> +!! result +<div class="mw-graph mw-graph-always" data-graph-id="cb66159a7f0070f4faaef2f353cb67c0d178d678"></div> +<div class="mw-graph mw-graph-always" style="min-width:100px;min-height:200px" data-graph-id="35d4ad35da17b39e7e4464fd7af741dadda01a91"></div> + +!! end + +!! test +<graph> - error handling +!! input +<graph/> +<graph></graph> +<graph> +{fail +</graph> +<graph> +[ "foo", "bar" ] +</graph> +!! result +<div class="mw-graph mw-graph-always" style="min-width:200px;min-height:200px" data-graph-id="4406ae21fb62ba4a67e041d0f9e026a2819e48a8"></div> +<div class="mw-graph mw-graph-always" style="min-width:200px;min-height:200px" data-graph-id="4406ae21fb62ba4a67e041d0f9e026a2819e48a8"></div> +<p>Syntax error +</p> +<div class="mw-graph mw-graph-always" style="min-width:200px;min-height:200px" data-graph-id="4406ae21fb62ba4a67e041d0f9e026a2819e48a8"></div> + +!! end -- To view, visit https://gerrit.wikimedia.org/r/315831 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I62d8ae49143ebab70fb636fe87a4c0ed21ad79d1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Graph Gerrit-Branch: master Gerrit-Owner: MaxSem <maxsem.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits