summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-08-06 17:16:24 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-09-29 13:42:32 +0200
commit925aa6c0f51aac3f9a256aee431c708f33230f42 (patch)
treeb7f581ee57955ed3553e94e147dcc7a8b173cb7b /build
parentcb6e1b115d9b564910e7237fea1de855daec4647 (diff)
downloadnextcloud-server-925aa6c0f51aac3f9a256aee431c708f33230f42.tar.gz
nextcloud-server-925aa6c0f51aac3f9a256aee431c708f33230f42.zip
Test user creation
Diffstat (limited to 'build')
-rw-r--r--build/integration/features/bootstrap/FeatureContext.php140
-rw-r--r--build/integration/features/provisioning-v1.feature15
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
+