Skip to content

Commit

Permalink
Add test for removing tag from attribute options when deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed May 26, 2017
1 parent 344fc16 commit c55dbfe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/integration/bootstrap/RestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "([^"]*)"$/
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/tags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c55dbfe

Please sign in to comment.