diff --git a/features/3_api_topics.feature b/features/3_api_topics.feature index 06367878a0..6ff0b12c9a 100644 --- a/features/3_api_topics.feature +++ b/features/3_api_topics.feature @@ -7,7 +7,7 @@ Feature: Testing Topics API When I request "/topics" Then the response is JSON - Scenario: Creating a new root topic and checking if it has been created successfully + Scenario: Creating a new root topic and subtopic, checking if topics have been created successfully Given that I want to make a new topic And that i have fake "topic" data: | title | roottopic | 4 | @@ -31,12 +31,12 @@ Feature: Testing Topics API And the response should contain field "translations" And field "level" in the response should be "0" And field "title" in the response should be "roottopic" + And save "id" field under location "topic_id" - Scenario: Creating a new subtopic and checking if it has been created successfully Given that I want to make a new subtopic And that i have fake "topic" data: | title | <> | 4 | - | parent | 1 || + | parent | (topic_id) || And I'm logged in as "testuser" with "testpassword" with client "1_svdg45ew371vtsdgd29fgvwe5v" and secret "h48fgsmv0due4nexjsy40jdf3sswwr" When I submit "topic" data to "/topics" @@ -56,7 +56,7 @@ Feature: Testing Topics API And the response should contain field "root" And the response should contain field "level" And the response should contain field "translations" - And field "parent" in the response should be "1" + And field "parent" in the response should be "(topic_id)" And field "level" in the response should be "1" Scenario: Getting all the topics diff --git a/features/4_api_link_unlink_topic_to_from_article.feature b/features/4_api_link_unlink_topic_to_from_article.feature index 9a1b9dca2d..c6f6e71824 100644 --- a/features/4_api_link_unlink_topic_to_from_article.feature +++ b/features/4_api_link_unlink_topic_to_from_article.feature @@ -1,5 +1,5 @@ Feature: Testing linking/unlinking topics to/from the articles - In order to link/ublink topics through the API + In order to link/unlink topics through the API As a service user I want to see if the topics can be linked or unlinked to/from the articles diff --git a/features/bootstrap/RestContext.php b/features/bootstrap/RestContext.php index 1430b24a59..d4f4377c35 100644 --- a/features/bootstrap/RestContext.php +++ b/features/bootstrap/RestContext.php @@ -248,7 +248,6 @@ public function collectFakeData($dataKey, \Behat\Gherkin\Node\TableNode $data) if (strpos($value[1], '<<') !== false) { $functionName = str_replace('>>', '', str_replace('<<', '', $value[1])); $fakeValue = call_user_func_array(array($faker, $functionName), explode(',', $value[2])); - if ($functionName == 'file' || $functionName == 'image') { $fakeValue = new FormUpload($fakeValue); } @@ -269,6 +268,15 @@ public function collectFakeData($dataKey, \Behat\Gherkin\Node\TableNode $data) continue; } + if (strpos($value[1], '(') !== false) { + $locationIndex = str_replace(')', '', str_replace('(', '', $value[1])); + $locationValue = $this->locations[$locationIndex]; + parse_str($value[0].'='.$locationValue, $temp); + $temp = array($dataKey => $temp); + $this->collectedData = array_merge_recursive($this->collectedData, $temp); + continue; + } + $this->collectedData[$dataKey][$value[0]] = $value[1]; } } @@ -288,6 +296,38 @@ public function collectLocations($locationIndex) $this->locations[$locationIndex] = $this->response->getHeader('X-Location'); } + /** + * @Then /^save "([^"]+)" field under location "([^"]*)"$/ + * @param string $fieldName + * @param string $locationIndex + * @return Step|void + * @throws Exception + */ + public function saveFieldValueUnderLocation($fieldName, $locationIndex) + { + $this->response = $this->client->getLastResponse(); + $fieldValue = null; + if ($this->responseIsJson) { + if ($this->associative) { + if (!(is_array($this->responseData)) || !array_key_exists($fieldName, $this->responseData)) { + throw new \Exception('Field "' . $fieldName . '" is not set!'); + } + + $fieldValue = $this->responseData[$fieldName]; + } else { + if (!($this->responseData instanceof stdClass) || !property_exists($this->responseData, $name)) { + throw new \Exception('Field "' . $fieldName . '" is not set!'); + } + + $fieldValue = $this->responseData->$fieldName; + } + + $this->locations[$locationIndex] = $fieldValue; + } else { + return new Step\Then('the response is JSON'); + } + } + /** * @When /^I request "([^"]*)"$/ * @param string $pageUrl @@ -474,6 +514,7 @@ public function valueOfTheFieldEquals($fieldName, $fieldValue) { if ($this->responseIsJson) { if (new Step\Given("the response should contain field \"{$fieldName}\"")) { + $fieldValue = $this->extractValueByGivenLocation($fieldValue) ?: $fieldValue; if ($this->associative) { if ($this->responseData[$fieldName] != $fieldValue) { throw new \Exception( @@ -501,6 +542,15 @@ public function valueOfTheFieldEquals($fieldName, $fieldValue) } } + private function extractValueByGivenLocation($fieldValue) + { + if (strpos($fieldValue, '(') !== false) { + $locationIndex = str_replace(')', '', str_replace('(', '', $fieldValue)); + + return $this->locations[$locationIndex]; + } + } + /** * @Then /^the response should contain "([^"]*)"$/ * @param string $str