From 631303c1e74cb10a63fa46f99e3111067ec2f010 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 6 Aug 2015 15:44:24 +0200 Subject: First integration tests for provisioning api --- build/integration/composer.json | 6 ++++++ build/integration/config/behat.yml | 17 +++++++++++++++++ build/integration/features/provisioning-v1.feature | 9 +++++++++ build/integration/features/provisioning-v2.feature | 9 +++++++++ build/integration/run.sh | 18 ++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 build/integration/composer.json create mode 100644 build/integration/config/behat.yml create mode 100644 build/integration/features/provisioning-v1.feature create mode 100644 build/integration/features/provisioning-v2.feature create mode 100755 build/integration/run.sh diff --git a/build/integration/composer.json b/build/integration/composer.json new file mode 100644 index 00000000000..f77ddba9bcd --- /dev/null +++ b/build/integration/composer.json @@ -0,0 +1,6 @@ +{ + "require-dev": { + "guzzlehttp/guzzle": "~5.0", + "behat/behat": "2.4.*@stable" + } +} diff --git a/build/integration/config/behat.yml b/build/integration/config/behat.yml new file mode 100644 index 00000000000..78a228a5c1e --- /dev/null +++ b/build/integration/config/behat.yml @@ -0,0 +1,17 @@ +default: + paths: + features: ../features + bootstrap: %behat.paths.features%/bootstrap + + context: + parameters: + baseUrl: http://localhost:8080/ocs/ + admin: + - admin + - admin + +ci: + formatter: + name: junit + parameters: + output_path: ./output diff --git a/build/integration/features/provisioning-v1.feature b/build/integration/features/provisioning-v1.feature new file mode 100644 index 00000000000..dd574186b56 --- /dev/null +++ b/build/integration/features/provisioning-v1.feature @@ -0,0 +1,9 @@ +Feature: provisioning + Background: + Given using api version "1" + + Scenario: Getting an not existing user + Given As an "admin" + When sending "GET" to "/cloud/users/test" + Then the status code should be "200" + diff --git a/build/integration/features/provisioning-v2.feature b/build/integration/features/provisioning-v2.feature new file mode 100644 index 00000000000..72ceed5d6a5 --- /dev/null +++ b/build/integration/features/provisioning-v2.feature @@ -0,0 +1,9 @@ +Feature: provisioning + Background: + Given using api version "2" + + Scenario: Getting an not existing user + Given As an "admin" + When sending "GET" to "/cloud/users/test" + Then the status code should be "404" + diff --git a/build/integration/run.sh b/build/integration/run.sh new file mode 100755 index 00000000000..40afbe85b9b --- /dev/null +++ b/build/integration/run.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +composer install + +# TODO: avoid port collision on jenkins - use $EXECUTOR_NUMBER +if [ -z "$EXECUTOR_NUMBER" ]; then + EXECUTOR_NUMBER=0 +fi +PORT=$((8080 + $EXECUTOR_NUMBER)) +echo $PORT +php -S localhost:$PORT -t ../.. & +PHPPID=$! +echo $PHPPID + +export BEHAT_PARAMS="context[parameters][base_url]=http://localhost:$PORT/ocs" +vendor/bin/behat + +kill $PHPPID -- cgit v1.2.3 From d26aab7e05cde33265fe857b92a1d0faa80ea6d9 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 6 Aug 2015 15:47:21 +0200 Subject: Adding missing files --- build/integration/.gitignore | 3 + .../features/bootstrap/FeatureContext.php | 91 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 build/integration/.gitignore create mode 100644 build/integration/features/bootstrap/FeatureContext.php diff --git a/build/integration/.gitignore b/build/integration/.gitignore new file mode 100644 index 00000000000..18b981bf7ed --- /dev/null +++ b/build/integration/.gitignore @@ -0,0 +1,3 @@ +vendor +output +composer.lock diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php new file mode 100644 index 00000000000..e1185debbc5 --- /dev/null +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -0,0 +1,91 @@ +baseUrl = $parameters['baseUrl']; + $this->adminUser = $parameters['admin']; + } + + /** + * @When /^sending "([^"]*)" to "([^"]*)"$/ + */ + public function sendingTo($verb, $url) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url; + $client = new Client(); + // TODO: get admin user from config + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + + try { + $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + $this->response = $ex->getResponse(); + } + } + + /** + * @Then /^the status code should be "([^"]*)"$/ + */ + public function theStatusCodeShouldBe($statusCode) { + PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode()); + } + + /** + * @Given /^As an "([^"]*)"$/ + */ + public function asAn($user) { + $this->currentUser = $user; + } + + /** + * @Given /^using api version "([^"]*)"$/ + */ + public function usingApiVersion($version) { + $this->apiVersion = $version; + } + + /** + * @Given /^user "([^"]*)" exists$/ + */ + public function userExists($user) { + throw new \Behat\Behat\Exception\PendingException(); + } + +} -- cgit v1.2.3 From 6749071667491ce51af585e9e39667d3ee40cefd Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 6 Aug 2015 16:41:46 +0200 Subject: Adding phpunit for the assertions --- build/integration/composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/build/integration/composer.json b/build/integration/composer.json index f77ddba9bcd..98b2f294c7a 100644 --- a/build/integration/composer.json +++ b/build/integration/composer.json @@ -1,5 +1,6 @@ { "require-dev": { + "phpunit/phpunit": "~4.6", "guzzlehttp/guzzle": "~5.0", "behat/behat": "2.4.*@stable" } -- cgit v1.2.3 From cb6e1b115d9b564910e7237fea1de855daec4647 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 6 Aug 2015 16:46:06 +0200 Subject: require autoload.php --- build/integration/features/bootstrap/FeatureContext.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index e1185debbc5..6dab7100f22 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -4,12 +4,7 @@ use Behat\Behat\Context\BehatContext; use GuzzleHttp\Client; use GuzzleHttp\Message\ResponseInterface; -// -// Require 3rd-party libraries here: -// -// require_once 'PHPUnit/Autoload.php'; -// require_once 'PHPUnit/Framework/Assert/Functions.php'; -// +require __DIR__ . '/../../vendor/autoload.php'; /** * Features context. -- cgit v1.2.3 From 925aa6c0f51aac3f9a256aee431c708f33230f42 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 6 Aug 2015 17:16:24 +0200 Subject: Test user creation --- .../features/bootstrap/FeatureContext.php | 140 ++++++++++++++------- build/integration/features/provisioning-v1.feature | 15 +++ 2 files changed, 110 insertions(+), 45 deletions(-) diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index 6dab7100f22..527e0c9ba08 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -11,11 +11,11 @@ require __DIR__ . '/../../vendor/autoload.php'; */ class FeatureContext extends BehatContext { - /** @var string */ - private $baseUrl = ''; + /** @var string */ + private $baseUrl = ''; - /** @var ResponseInterface */ - private $response = null; + /** @var ResponseInterface */ + private $response = null; /** @var string */ private $currentUser = ''; @@ -23,51 +23,39 @@ class FeatureContext extends BehatContext { /** @var int */ private $apiVersion = 1; - /** - * Initializes context. - * Every scenario gets it's own context object. - * - * @param array $parameters context parameters (set them up through behat.yml) - */ - public function __construct(array $parameters) { + /** + * Initializes context. + * Every scenario gets it's own context object. + * + * @param array $parameters context parameters (set them up through behat.yml) + */ + public function __construct(array $parameters) { - // Initialize your context here + // Initialize your context here $this->baseUrl = $parameters['baseUrl']; $this->adminUser = $parameters['admin']; - } - - /** - * @When /^sending "([^"]*)" to "([^"]*)"$/ - */ - public function sendingTo($verb, $url) { - $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url; - $client = new Client(); - // TODO: get admin user from config - $options = []; - if ($this->currentUser === 'admin') { - $options['auth'] = $this->adminUser; - } + } - try { - $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); - } catch (\GuzzleHttp\Exception\ClientException $ex) { - $this->response = $ex->getResponse(); - } - } - - /** - * @Then /^the status code should be "([^"]*)"$/ - */ - public function theStatusCodeShouldBe($statusCode) { - PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode()); - } - - /** - * @Given /^As an "([^"]*)"$/ - */ - public function asAn($user) { + /** + * @When /^sending "([^"]*)" to "([^"]*)"$/ + */ + public function sendingTo($verb, $url) { + $this->sendingToWith($verb, $url, null); + } + + /** + * @Then /^the status code should be "([^"]*)"$/ + */ + public function theStatusCodeShouldBe($statusCode) { + PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode()); + } + + /** + * @Given /^As an "([^"]*)"$/ + */ + public function asAn($user) { $this->currentUser = $user; - } + } /** * @Given /^using api version "([^"]*)"$/ @@ -80,7 +68,69 @@ class FeatureContext extends BehatContext { * @Given /^user "([^"]*)" exists$/ */ public function userExists($user) { - throw new \Behat\Behat\Exception\PendingException(); + $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + + $this->response = $client->get($fullUrl, $options); + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + } + + /** + * @Given /^user "([^"]*)" does not exist$/ + */ + public function userDoesNotExist($user) { + try { + $this->userExists($user); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode()); + } + } + + /** + * @When /^creating the user "([^"]*)r"$/ + */ + public function creatingTheUser($user) { + $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + + $this->response = $client->post($fullUrl, [ + 'form_params' => [ + 'userid' => $user, + 'password' => '123456' + ] + ]); + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + } + + /** + * @When /^sending "([^"]*)" to "([^"]*)" with$/ + * @param \Behat\Gherkin\Node\TableNode|null $formData + */ + public function sendingToWith($verb, $url, $body) { + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } + if ($body instanceof \Behat\Gherkin\Node\TableNode) { + $fd = $body->getRowsHash(); + $options['body'] = $fd; + } + + try { + $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + $this->response = $ex->getResponse(); + } } } diff --git a/build/integration/features/provisioning-v1.feature b/build/integration/features/provisioning-v1.feature index dd574186b56..aa3b31260e7 100644 --- a/build/integration/features/provisioning-v1.feature +++ b/build/integration/features/provisioning-v1.feature @@ -7,3 +7,18 @@ Feature: provisioning When sending "GET" to "/cloud/users/test" Then the status code should be "200" + Scenario: Listing all users + Given As an "admin" + When sending "GET" to "/cloud/users" + Then the status code should be "200" + + Scenario: Create a user + Given As an "admin" + And user "brand-new-user" does not exist + When sending "POST" to "/cloud/users" with + | userid | brand-new-user | + | password | 123456 | + + Then the status code should be "200" + And user "brand-new-user" exists + -- cgit v1.2.3 From db0a8aa795710d94f88f3c036983992792dd4191 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 6 Aug 2015 17:29:39 +0200 Subject: Use fixed port for now --- build/integration/run.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/build/integration/run.sh b/build/integration/run.sh index 40afbe85b9b..baf31b411c4 100755 --- a/build/integration/run.sh +++ b/build/integration/run.sh @@ -3,16 +3,17 @@ composer install # TODO: avoid port collision on jenkins - use $EXECUTOR_NUMBER -if [ -z "$EXECUTOR_NUMBER" ]; then - EXECUTOR_NUMBER=0 -fi -PORT=$((8080 + $EXECUTOR_NUMBER)) +#if [ -z "$EXECUTOR_NUMBER" ]; then +# EXECUTOR_NUMBER=0 +#fi +#PORT=$((8080 + $EXECUTOR_NUMBER)) +PORT=8080 echo $PORT php -S localhost:$PORT -t ../.. & PHPPID=$! echo $PHPPID -export BEHAT_PARAMS="context[parameters][base_url]=http://localhost:$PORT/ocs" +#export BEHAT_PARAMS="context[parameters][base_url]=http://localhost:$PORT/ocs" vendor/bin/behat kill $PHPPID -- cgit v1.2.3 From 933121c66f65ee4a3ac8b0741741b1445b50afa5 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 6 Aug 2015 17:35:59 +0200 Subject: Use ci profile --- build/integration/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/integration/run.sh b/build/integration/run.sh index baf31b411c4..df33d85fc74 100755 --- a/build/integration/run.sh +++ b/build/integration/run.sh @@ -14,6 +14,6 @@ PHPPID=$! echo $PHPPID #export BEHAT_PARAMS="context[parameters][base_url]=http://localhost:$PORT/ocs" -vendor/bin/behat +vendor/bin/behat --profile ci kill $PHPPID -- cgit v1.2.3 From 2d1f509acf6bab68d4b1f092a0f4b8fc8da5e125 Mon Sep 17 00:00:00 2001 From: Sergio Bertolin Date: Tue, 29 Sep 2015 10:54:43 +0000 Subject: added delete user test --- build/integration/features/provisioning-v1.feature | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build/integration/features/provisioning-v1.feature b/build/integration/features/provisioning-v1.feature index aa3b31260e7..9e3d2df50bb 100644 --- a/build/integration/features/provisioning-v1.feature +++ b/build/integration/features/provisioning-v1.feature @@ -22,3 +22,11 @@ Feature: provisioning Then the status code should be "200" And user "brand-new-user" exists + + Scenario: Delete a user + Given As an "admin" + And user "brand-new-user" exists + When sending "POST" to "/cloud/users" with + | userid | brand-new-user | + Then the status code should be "200" + And user "brand-new-user" does not exist -- cgit v1.2.3 From e3a98e4959c36432b1e8250afc03708e10a32cca Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 29 Sep 2015 13:56:56 +0200 Subject: Support different server ports - defined by EXECUTOR_NUMBER --- build/integration/config/behat.yml | 4 ++-- build/integration/features/bootstrap/FeatureContext.php | 6 ++++++ build/integration/run.sh | 12 ++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/build/integration/config/behat.yml b/build/integration/config/behat.yml index 78a228a5c1e..01ca0d18790 100644 --- a/build/integration/config/behat.yml +++ b/build/integration/config/behat.yml @@ -12,6 +12,6 @@ default: ci: formatter: - name: junit + name: pretty,junit parameters: - output_path: ./output + output_path: null,./output diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index 527e0c9ba08..b7a04e1ca76 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -34,6 +34,12 @@ class FeatureContext extends BehatContext { // Initialize your context here $this->baseUrl = $parameters['baseUrl']; $this->adminUser = $parameters['admin']; + + // in case of ci deployment we take the server url from the environment + $testServerUrl = getenv('TEST_SERVER_URL'); + if ($testServerUrl !== false) { + $this->baseUrl = $testServerUrl; + } } /** diff --git a/build/integration/run.sh b/build/integration/run.sh index df33d85fc74..08f10b86c5f 100755 --- a/build/integration/run.sh +++ b/build/integration/run.sh @@ -3,17 +3,17 @@ composer install # TODO: avoid port collision on jenkins - use $EXECUTOR_NUMBER -#if [ -z "$EXECUTOR_NUMBER" ]; then -# EXECUTOR_NUMBER=0 -#fi -#PORT=$((8080 + $EXECUTOR_NUMBER)) -PORT=8080 +if [ -z "$EXECUTOR_NUMBER" ]; then + EXECUTOR_NUMBER=0 +fi +PORT=$((8080 + $EXECUTOR_NUMBER)) +#PORT=8080 echo $PORT php -S localhost:$PORT -t ../.. & PHPPID=$! echo $PHPPID -#export BEHAT_PARAMS="context[parameters][base_url]=http://localhost:$PORT/ocs" +export TEST_SERVER_URL="http://localhost:$PORT/ocs/" vendor/bin/behat --profile ci kill $PHPPID -- cgit v1.2.3