Return the actual ocs return codes and check it

This commit is contained in:
Sergio Bertolin 2015-09-30 15:50:18 +00:00 committed by Roeland Jago Douma
parent 186aff5dea
commit 0e3836ed48
2 changed files with 37 additions and 18 deletions

View File

@ -49,13 +49,28 @@ class FeatureContext extends BehatContext {
$this->sendingToWith($verb, $url, null); $this->sendingToWith($verb, $url, null);
} }
// /**
// * @Then /^the status code should be "([^"]*)"$/
// */
// public function theStatusCodeShouldBe($statusCode) {
// PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode());
// }
public function getOCSResponse($response){
return $response->xml()->meta[0]->statuscode;
}
/** /**
* @Then /^the status code should be "([^"]*)"$/ * @Then /^the status code should be "([^"]*)"$/
*/ */
public function theStatusCodeShouldBe($statusCode) { public function theStatusCodeShouldBe($statusCode) {
PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode()); PHPUnit_Framework_Assert::assertEquals($statusCode, $this->getOCSResponse($this->response));
} }
/** /**
* @Given /^As an "([^"]*)"$/ * @Given /^As an "([^"]*)"$/
*/ */
@ -74,7 +89,7 @@ class FeatureContext extends BehatContext {
* @Given /^user "([^"]*)" exists$/ * @Given /^user "([^"]*)" exists$/
*/ */
public function userExists($user) { public function userExists($user) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user"; $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
$client = new Client(); $client = new Client();
$options = []; $options = [];
if ($this->currentUser === 'admin') { if ($this->currentUser === 'admin') {
@ -82,7 +97,6 @@ class FeatureContext extends BehatContext {
} }
$this->response = $client->get($fullUrl, $options); $this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
} }
/** /**
@ -92,15 +106,16 @@ class FeatureContext extends BehatContext {
try { try {
$this->userExists($user); $this->userExists($user);
} catch (\GuzzleHttp\Exception\ClientException $ex) { } catch (\GuzzleHttp\Exception\ClientException $ex) {
PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); $this->response = $ex->getResponse();
} }
} }
/** /**
* @When /^creating the user "([^"]*)r"$/ * @When /^creating the user "([^"]*)r"$/
*/ */
public function creatingTheUser($user) { public function creatingTheUser($user) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user"; $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user" ;
$client = new Client(); $client = new Client();
$options = []; $options = [];
if ($this->currentUser === 'admin') { if ($this->currentUser === 'admin') {
@ -113,7 +128,7 @@ class FeatureContext extends BehatContext {
'password' => '123456' 'password' => '123456'
] ]
]); ]);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
} }
@ -133,7 +148,6 @@ class FeatureContext extends BehatContext {
'groupid' => $user 'groupid' => $user
] ]
]); ]);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
} }
@ -141,7 +155,7 @@ class FeatureContext extends BehatContext {
* @Given /^group "([^"]*)" exists$/ * @Given /^group "([^"]*)" exists$/
*/ */
public function groupExists($group) { public function groupExists($group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group"; $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/$group";
$client = new Client(); $client = new Client();
$options = []; $options = [];
if ($this->currentUser === 'admin') { if ($this->currentUser === 'admin') {
@ -149,7 +163,6 @@ class FeatureContext extends BehatContext {
} }
$this->response = $client->get($fullUrl, $options); $this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
} }
/** /**
@ -159,7 +172,7 @@ class FeatureContext extends BehatContext {
try { try {
$this->groupExists($group); $this->groupExists($group);
} catch (\GuzzleHttp\Exception\ClientException $ex) { } catch (\GuzzleHttp\Exception\ClientException $ex) {
PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); $this->response = $ex->getResponse();
} }
} }
@ -187,4 +200,9 @@ class FeatureContext extends BehatContext {
} }
} }
} }

View File

@ -5,12 +5,12 @@ Feature: provisioning
Scenario: Getting an not existing user Scenario: Getting an not existing user
Given As an "admin" Given As an "admin"
When sending "GET" to "/cloud/users/test" When sending "GET" to "/cloud/users/test"
Then the status code should be "200" Then the status code should be "998"
Scenario: Listing all users Scenario: Listing all users
Given As an "admin" Given As an "admin"
When sending "GET" to "/cloud/users" When sending "GET" to "/cloud/users"
Then the status code should be "200" Then the status code should be "100"
Scenario: Create a user Scenario: Create a user
Given As an "admin" Given As an "admin"
@ -18,8 +18,7 @@ Feature: provisioning
When sending "POST" to "/cloud/users" with When sending "POST" to "/cloud/users" with
| userid | brand-new-user | | userid | brand-new-user |
| password | 123456 | | password | 123456 |
Then the status code should be "100"
Then the status code should be "200"
And user "brand-new-user" exists And user "brand-new-user" exists
@ -27,7 +26,7 @@ Feature: provisioning
Given As an "admin" Given As an "admin"
And user "brand-new-user" exists And user "brand-new-user" exists
When sending "DELETE" to "/cloud/users/brand-new-user" When sending "DELETE" to "/cloud/users/brand-new-user"
Then the status code should be "200" Then the status code should be "100"
And user "brand-new-user" does not exist And user "brand-new-user" does not exist
@ -38,7 +37,7 @@ Feature: provisioning
| groupid | new-group | | groupid | new-group |
| password | 123456 | | password | 123456 |
Then the status code should be "200" Then the status code should be "100"
And group "new-group" exists And group "new-group" exists
@ -46,6 +45,8 @@ Feature: provisioning
Given As an "admin" Given As an "admin"
And group "new-group" exists And group "new-group" exists
When sending "DELETE" to "/cloud/groups/new-group" When sending "DELETE" to "/cloud/groups/new-group"
Then the status code should be "200" Then the status code should be "100"
And group "new-group" does not exist And group "new-group" does not exist