From c55dbfea98e77a8dc24ff2361eb9ad856f20b7bb Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Fri, 26 May 2017 13:41:17 +1200 Subject: [PATCH] Add test for removing tag from attribute options when deleted --- tests/integration/bootstrap/RestContext.php | 33 +++++++++++++++++++++ tests/integration/tags.feature | 13 ++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/integration/bootstrap/RestContext.php b/tests/integration/bootstrap/RestContext.php index 100cf4df37..d1d3e6b6d0 100644 --- a/tests/integration/bootstrap/RestContext.php +++ b/tests/integration/bootstrap/RestContext.php @@ -471,6 +471,39 @@ public function thePropertyContains($propertyName, $propertyContainsValue) } } + /** + * @Given /^the "([^"]*)" property does not contain "([^"]*)"$/ + */ + public function thePropertyDoesNotContains($propertyName, $propertyContainsValue) + { + + $data = json_decode($this->response->getBody(true), true); + + $this->theResponseIsJson(); + + $actualPropertyValue = \Arr::path($data, $propertyName); + + if ($actualPropertyValue === null) { + throw new Exception("Property '".$propertyName."' is not set!\n"); + } + + if (is_array($actualPropertyValue) and in_array($propertyContainsValue, $actualPropertyValue)) { + throw new \Exception( + 'Property \''.$propertyName.'\' contains value!' . + '(given: '.$propertyContainsValue.', match: '.json_encode($actualPropertyValue).')' + ); + } elseif (is_string($actualPropertyValue) and strpos($actualPropertyValue, $propertyContainsValue) !== false) { + throw new \Exception( + 'Property \''.$propertyName.'\' does not contain value!' . + '(given: '.$propertyContainsValue.', match: '.$actualPropertyValue.')' + ); + } elseif (!is_array($actualPropertyValue) and !is_string($actualPropertyValue)) { + throw new \Exception( + "Property '".$propertyName."' could not be compared. Must be string or array.\n" + ); + } + } + /** * @Given /^the "([^"]*)" property count is "([^"]*)"$/ */ diff --git a/tests/integration/tags.feature b/tests/integration/tags.feature index 3926f56c60..090c149af6 100644 --- a/tests/integration/tags.feature +++ b/tests/integration/tags.feature @@ -267,6 +267,19 @@ Feature: Testing the Tags API When I request "/tags" Then the guzzle status code should be 200 + Scenario: Deleting a tag removes it from attribute options + Given that I want to delete a "Tag" + And that its "id" is "1" + When I request "/tags" + Then the guzzle status code should be 200 + Given that I want to find a "Attribute" + And that its "id" is "26" + When I request "/forms/1/attributes" + Then the response is JSON + And the response has an "options" property + And the "options" property does not contain "1" + Then the guzzle status code should be 200 + Scenario: Deleting a non-existent Tag Given that I want to delete a "Tag" And that its "id" is "35"