From 730b0c97eed7283699a65795535ad294e1af8e09 Mon Sep 17 00:00:00 2001 From: Anthony Sterling Date: Tue, 27 Feb 2018 09:40:50 +0000 Subject: [PATCH] Nest payload for forwarding_url page rule action in value block --- src/Configurations/PageRulesActions.php | 18 ++++++++++++++--- tests/Configurations/PageRulesActionTest.php | 21 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 tests/Configurations/PageRulesActionTest.php diff --git a/src/Configurations/PageRulesActions.php b/src/Configurations/PageRulesActions.php index c52ddc1..1c24661 100644 --- a/src/Configurations/PageRulesActions.php +++ b/src/Configurations/PageRulesActions.php @@ -133,8 +133,10 @@ class PageRulesActions implements Configurations } $this->addConfigurationOption("forwarding_url", [ - 'status_code' => $statusCode, - 'url' => $forwardingUrl, + 'value' => [ + 'status_code' => $statusCode, + 'url' => $forwardingUrl, + ], ]); } @@ -299,9 +301,19 @@ class PageRulesActions implements Configurations private function addConfigurationOption(string $setting, array $configuration) { + /** + * Transforms an, optionally nested, array in to a collection of + * stdClass objects. + * + * @var array $array + */ + $getArrayAsObject = function (array $array) { + return json_decode(json_encode($array)); + }; + $configuration['id'] = $setting; - array_push($this->configs, (object) $configuration); + array_push($this->configs, $getArrayAsObject($configuration)); } private function getBoolAsOnOrOff(bool $value): string diff --git a/tests/Configurations/PageRulesActionTest.php b/tests/Configurations/PageRulesActionTest.php new file mode 100644 index 0000000..88d4b91 --- /dev/null +++ b/tests/Configurations/PageRulesActionTest.php @@ -0,0 +1,21 @@ +setForwardingURL($statusCode, $forwardingURL); + $configuration = $actions->getArray(); + + $this->assertCount(1, $configuration); + $this->assertEquals($identifier, $configuration[0]->id); + $this->assertEquals($statusCode, $configuration[0]->value->status_code); + $this->assertEquals($forwardingURL, $configuration[0]->value->url); + } +}