diff options
author | Joas Schilling <coding@schilljs.com> | 2016-09-06 11:34:53 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-09-06 11:34:53 +0300 |
commit | d61a1dfc396a09853f62633f7b96bce4b59e2b55 (patch) | |
tree | 0b0fd765973e3cfc922520d11fabc443f00d08e1 /tests/Integration | |
parent | 7829bf753041d58b2012f10beddb0d1e4be9e68b (diff) |
Check status code with ETag
Diffstat (limited to 'tests/Integration')
-rw-r--r-- | tests/Integration/features/bootstrap/FeatureContext.php | 25 | ||||
-rw-r--r-- | tests/Integration/features/statuscodes.feature | 28 |
2 files changed, 47 insertions, 6 deletions
diff --git a/tests/Integration/features/bootstrap/FeatureContext.php b/tests/Integration/features/bootstrap/FeatureContext.php index 30e7356..d151fc6 100644 --- a/tests/Integration/features/bootstrap/FeatureContext.php +++ b/tests/Integration/features/bootstrap/FeatureContext.php @@ -49,6 +49,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { /** @var string */ protected $baseUrl; + /** @var string */ + protected $lastEtag; + /** * FeatureContext constructor. */ @@ -83,6 +86,21 @@ class FeatureContext implements Context, SnippetAcceptingContext { } /** + * @When /^getting notifications(| with different etag| with matching etag)$/ + */ + public function gettingNotifications($etag) { + $headers = []; + if ($etag === ' with different etag') { + $headers['ETag'] = md5($this->lastEtag); + } else if ($etag === ' with matching etag') { + $headers['ETag'] = $this->lastEtag; + } + + $this->sendingToWith('GET', '/apps/notifications/api/v1/notifications?format=json', null, $headers); + $this->lastEtag = $this->response->getHeader('ETag'); + } + + /** * @Then /^list of notifications has (\d+) entries$/ * * @param int $numNotifications @@ -311,8 +329,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { * @param string $verb * @param string $url * @param \Behat\Gherkin\Node\TableNode $body + * @param array $headers */ - public function sendingToWith($verb, $url, $body) { + public function sendingToWith($verb, $url, $body, array $headers = []) { $fullUrl = $this->baseUrl . 'ocs/v2.php' . $url; $client = new Client(); $options = []; @@ -326,9 +345,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { $options['body'] = $fd; } - $options['headers'] = [ + $options['headers'] = array_merge($headers, [ 'OCS-APIREQUEST' => 'true', - ]; + ]); try { $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); diff --git a/tests/Integration/features/statuscodes.feature b/tests/Integration/features/statuscodes.feature index 5530e1c..b0a9cdd 100644 --- a/tests/Integration/features/statuscodes.feature +++ b/tests/Integration/features/statuscodes.feature @@ -4,13 +4,13 @@ Feature: statuscodes Given as user "test1" Scenario: Status code when reading notifications with notifiers and without notifications - When sending "GET" to "/apps/notifications/api/v1/notifications?format=json" + When getting notifications Then status code is 200 And list of notifications has 0 entries Scenario: Status code when reading notifications with notifiers and notification Given user "test1" has notifications - When sending "GET" to "/apps/notifications/api/v1/notifications?format=json" + When getting notifications Then status code is 200 And list of notifications has 1 entries @@ -18,6 +18,28 @@ Feature: statuscodes Given user "test1" has notifications Given user "test1" has notifications Given user "test1" has notifications - When sending "GET" to "/apps/notifications/api/v1/notifications?format=json" + When getting notifications Then status code is 200 And list of notifications has 3 entries + + Scenario: Status code when reading notifications with different etag + Given user "test1" has notifications + Given user "test1" has notifications + Given user "test1" has notifications + When getting notifications + Then status code is 200 + And list of notifications has 3 entries + When getting notifications with different etag + Then status code is 200 + And list of notifications has 3 entries + + Scenario: Status code when reading notifications with matching etag + Given user "test1" has notifications + Given user "test1" has notifications + Given user "test1" has notifications + When getting notifications + Then status code is 200 + And list of notifications has 3 entries + When getting notifications with matching etag + Then status code is 200 + # Then status code is 304 - Disabled because it's not listed in the API specs |