-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nextcloud/feature/1/integration-tests
provide integration tests
- Loading branch information
Showing
4 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
tests/integration/features/bootstrap/FeatureContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
/** | ||
* @license MIT <http://opensource.org/licenses/MIT> | ||
*/ | ||
|
||
use Behat\Behat\Context\SnippetAcceptingContext; | ||
|
||
class FeatureContext implements SnippetAcceptingContext { | ||
/** @var string */ | ||
protected $versionString; | ||
/** @var string */ | ||
protected $knownEtag = ''; | ||
|
||
/** @var string */ | ||
protected $responseBody = ''; | ||
/** @var int */ | ||
protected $responseCode; | ||
/** @var string */ | ||
protected $responseEtag; | ||
|
||
/** | ||
* @When /^the version of interest is "([^"]*)"$/ | ||
*/ | ||
public function theVersionOfInterestIs(string $versionString) | ||
{ | ||
$this->versionString = $versionString; | ||
} | ||
|
||
/** | ||
* @When /^the request is sent$/ | ||
*/ | ||
public function theRequestIsSent() | ||
{ | ||
$header = []; | ||
if($this->knownEtag !== '') { | ||
$header[] = 'If-None-Match: ' . $this->knownEtag; | ||
} | ||
|
||
$ch = curl_init(); | ||
$optArray = [ | ||
CURLOPT_URL => 'http://localhost:8888/?version=' . urlencode($this->versionString), | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_HTTPHEADER => $header, | ||
CURLOPT_HEADERFUNCTION => [$this, 'extractEtag'], | ||
]; | ||
curl_setopt_array($ch, $optArray); | ||
$this->responseBody = curl_exec($ch); | ||
$this->responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); | ||
curl_close($ch); | ||
} | ||
|
||
/** | ||
* @Then /^the response is empty$/ | ||
* @throws Exception | ||
*/ | ||
public function theResponseIsEmpty() | ||
{ | ||
if((string)$this->responseBody !== '') { | ||
throw new \Exception('Response is not empty'); | ||
} | ||
} | ||
|
||
/** | ||
* @Given /^the return code is "([^"]*)"$/ | ||
* @throws Exception | ||
*/ | ||
public function theReturnCodeIs($statusCode) | ||
{ | ||
if((int)$statusCode !== $this->responseCode) { | ||
throw new \Exception( | ||
'Response was expected to be ' . $statusCode | ||
. ', but actually is ' . $this->responseCode | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @Given /^the received Etag is "([^"]*)"$/ | ||
* @throws Exception | ||
*/ | ||
public function theReceivedEtagIs($expectedEtag) | ||
{ | ||
if($expectedEtag !== $this->responseEtag) { | ||
throw new \Exception( | ||
'Etag was expected to be ' . $expectedEtag | ||
. ', but actually is ' . $this->responseEtag | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @Given /^the response is$/ | ||
* @throws Exception | ||
*/ | ||
public function theResponseIs(\Behat\Gherkin\Node\PyStringNode $expectedResponse) | ||
{ | ||
if(trim($expectedResponse) !== trim($this->responseBody)) { | ||
throw new \Exception( | ||
'The response body was expected to be ' . $expectedResponse | ||
. ', but actually is ' . $this->responseBody | ||
); | ||
} | ||
} | ||
|
||
public function extractEtag($ch, $headerString) { | ||
$etagPrefix = 'Etag: '; | ||
if(strpos($headerString, $etagPrefix) === 0) { | ||
$this->responseEtag = trim(substr($headerString, strlen($etagPrefix))); | ||
} | ||
return strlen($headerString); | ||
} | ||
|
||
/** | ||
* @Given /^the known Etag is "([^"]*)"$/ | ||
*/ | ||
public function theKnownEtagIs($etag) | ||
{ | ||
$this->knownEtag = $etag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
Feature: testing the response of the Changelog Server | ||
Scenario: Request against a version which does not have any info available | ||
Given the version of interest is "11.0.0" | ||
When the request is sent | ||
Then the response is empty | ||
And the return code is "404" | ||
|
||
Scenario: Request against an invalid version (wrong format) | ||
Given the version of interest is "eleven oh oh" | ||
When the request is sent | ||
Then the response is empty | ||
And the return code is "400" | ||
|
||
Scenario: Request against an invalid version (too detailed) | ||
Given the version of interest is "11.0.0.7" | ||
When the request is sent | ||
Then the response is empty | ||
And the return code is "400" | ||
|
||
Scenario: Request against a valid version, expecting info | ||
Given the version of interest is "13.0.0" | ||
When the request is sent | ||
Then the return code is "200" | ||
And the received Etag is "eb7e047b4d0f16fc6de0859abc74a3f1" | ||
And the response is | ||
""" | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<release xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../schema.xsd" | ||
version="13.0.0"> | ||
<changelog href="https://nextcloud.com/changelog/#13-0-0"/> | ||
<whatsNew lang="en"> | ||
<regular> | ||
<item>Refined user interface</item> | ||
<item>End-to-end Encryption</item> | ||
<item>Video and Text Chat</item> | ||
</regular> | ||
<admin> | ||
<item>Changes to the Nginx configuration</item> | ||
<item>Theming: CSS files were consolidated</item> | ||
</admin> | ||
</whatsNew> | ||
</release> | ||
""" | ||
|
||
Scenario: Request against a valid version with matching an valid etag | ||
Given the version of interest is "13.0.0" | ||
And the known Etag is "eb7e047b4d0f16fc6de0859abc74a3f1" | ||
When the request is sent | ||
Then the return code is "304" | ||
And the response is empty | ||
|
||
Scenario: Request against a valid version with outdated etag | ||
Given the version of interest is "13.0.0" | ||
And the known Etag is "abcdefabcdef00011122233344455566" | ||
When the request is sent | ||
Then the return code is "200" | ||
And the received Etag is "eb7e047b4d0f16fc6de0859abc74a3f1" | ||
And the response is | ||
""" | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<release xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../schema.xsd" | ||
version="13.0.0"> | ||
<changelog href="https://nextcloud.com/changelog/#13-0-0"/> | ||
<whatsNew lang="en"> | ||
<regular> | ||
<item>Refined user interface</item> | ||
<item>End-to-end Encryption</item> | ||
<item>Video and Text Chat</item> | ||
</regular> | ||
<admin> | ||
<item>Changes to the Nginx configuration</item> | ||
<item>Theming: CSS files were consolidated</item> | ||
</admin> | ||
</whatsNew> | ||
</release> | ||
""" |