2015-08-06 13:47:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Behat\Behat\Context\BehatContext;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Message\ResponseInterface;
|
|
|
|
|
2015-08-06 14:46:06 +00:00
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
2015-08-06 13:47:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Features context.
|
|
|
|
*/
|
|
|
|
class FeatureContext extends BehatContext {
|
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
/** @var string */
|
|
|
|
private $baseUrl = '';
|
2015-08-06 13:47:21 +00:00
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
/** @var ResponseInterface */
|
|
|
|
private $response = null;
|
2015-08-06 13:47:21 +00:00
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $currentUser = '';
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
private $apiVersion = 1;
|
|
|
|
|
2015-10-09 13:00:34 +00:00
|
|
|
/** @var SimpleXMLElement */
|
|
|
|
private $lastShareData = null;
|
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
/**
|
|
|
|
* 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) {
|
2015-08-06 13:47:21 +00:00
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
// Initialize your context here
|
2015-08-06 13:47:21 +00:00
|
|
|
$this->baseUrl = $parameters['baseUrl'];
|
|
|
|
$this->adminUser = $parameters['admin'];
|
2015-10-14 16:30:18 +00:00
|
|
|
$this->regularUser = $parameters['regular_user_password'];
|
2015-09-29 11:56:56 +00:00
|
|
|
|
|
|
|
// in case of ci deployment we take the server url from the environment
|
|
|
|
$testServerUrl = getenv('TEST_SERVER_URL');
|
|
|
|
if ($testServerUrl !== false) {
|
|
|
|
$this->baseUrl = $testServerUrl;
|
|
|
|
}
|
2015-08-06 15:16:24 +00:00
|
|
|
}
|
2015-08-06 13:47:21 +00:00
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
/**
|
2015-10-08 14:21:31 +00:00
|
|
|
* @When /^sending "([^"]*)" to "([^"]*)"$/
|
|
|
|
*/
|
2015-08-06 15:16:24 +00:00
|
|
|
public function sendingTo($verb, $url) {
|
|
|
|
$this->sendingToWith($verb, $url, null);
|
|
|
|
}
|
|
|
|
|
2015-10-02 09:45:25 +00:00
|
|
|
/**
|
2015-10-08 14:21:31 +00:00
|
|
|
* Parses the xml answer to get ocs response which doesn't match with
|
|
|
|
* http one in v1 of the api.
|
|
|
|
*/
|
|
|
|
public function getOCSResponse($response) {
|
2015-10-02 09:45:25 +00:00
|
|
|
return $response->xml()->meta[0]->statuscode;
|
|
|
|
}
|
2015-09-30 15:50:18 +00:00
|
|
|
|
2015-10-06 16:37:55 +00:00
|
|
|
/**
|
2015-10-08 14:21:31 +00:00
|
|
|
* Parses the xml answer to get the array of users returned.
|
|
|
|
*/
|
2015-10-07 11:09:01 +00:00
|
|
|
public function getArrayOfUsersResponded($resp) {
|
|
|
|
$listCheckedElements = $resp->xml()->data[0]->users[0]->element;
|
2015-10-08 14:21:31 +00:00
|
|
|
$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
|
2015-10-07 11:09:01 +00:00
|
|
|
return $extractedElementsArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-08 14:21:31 +00:00
|
|
|
* Parses the xml answer to get the array of groups returned.
|
|
|
|
*/
|
2015-10-07 11:09:01 +00:00
|
|
|
public function getArrayOfGroupsResponded($resp) {
|
|
|
|
$listCheckedElements = $resp->xml()->data[0]->groups[0]->element;
|
2015-10-08 14:21:31 +00:00
|
|
|
$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
|
2015-10-07 11:09:01 +00:00
|
|
|
return $extractedElementsArray;
|
|
|
|
}
|
2015-10-06 16:37:55 +00:00
|
|
|
|
2015-10-14 16:30:18 +00:00
|
|
|
/**
|
|
|
|
* Parses the xml answer to get the array of subadmins returned.
|
|
|
|
*/
|
|
|
|
public function getArrayOfSubadminsResponded($resp) {
|
|
|
|
$listCheckedElements = $resp->xml()->data[0]->element;
|
|
|
|
$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
|
|
|
|
return $extractedElementsArray;
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:28:48 +00:00
|
|
|
/**
|
|
|
|
* Parses the xml answer to get the array of apps returned.
|
|
|
|
*/
|
|
|
|
public function getArrayOfAppsResponded($resp) {
|
|
|
|
$listCheckedElements = $resp->xml()->data[0]->apps[0]->element;
|
|
|
|
$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
|
|
|
|
return $extractedElementsArray;
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:30:18 +00:00
|
|
|
/**
|
|
|
|
* This function is needed to use a vertical fashion in the gherkin tables.
|
|
|
|
*/
|
|
|
|
public function simplifyArray($arrayOfArrays){
|
|
|
|
$a = array_map(function($subArray) { return $subArray[0]; }, $arrayOfArrays);
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
|
2015-10-06 16:37:55 +00:00
|
|
|
/**
|
|
|
|
* @Then /^users returned are$/
|
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $formData
|
|
|
|
*/
|
|
|
|
public function theUsersShouldBe($usersList) {
|
|
|
|
if ($usersList instanceof \Behat\Gherkin\Node\TableNode) {
|
2015-10-14 16:30:18 +00:00
|
|
|
$users = $usersList->getRows();
|
|
|
|
$usersSimplified = $this->simplifyArray($users);
|
2015-10-07 11:09:01 +00:00
|
|
|
$respondedArray = $this->getArrayOfUsersResponded($this->response);
|
2015-10-21 09:32:08 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals($usersSimplified, $respondedArray, "", 0.0, 10, true);
|
2015-10-06 16:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-07 09:03:00 +00:00
|
|
|
/**
|
|
|
|
* @Then /^groups returned are$/
|
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $formData
|
|
|
|
*/
|
|
|
|
public function theGroupsShouldBe($groupsList) {
|
|
|
|
if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) {
|
2015-10-14 16:30:18 +00:00
|
|
|
$groups = $groupsList->getRows();
|
|
|
|
$groupsSimplified = $this->simplifyArray($groups);
|
2015-10-07 11:09:01 +00:00
|
|
|
$respondedArray = $this->getArrayOfGroupsResponded($this->response);
|
2015-10-21 09:32:08 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true);
|
2015-10-07 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-10-08 14:21:31 +00:00
|
|
|
|
2015-10-14 16:30:18 +00:00
|
|
|
/**
|
|
|
|
* @Then /^subadmin groups returned are$/
|
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $formData
|
|
|
|
*/
|
|
|
|
public function theSubadminGroupsShouldBe($groupsList) {
|
|
|
|
if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) {
|
|
|
|
$groups = $groupsList->getRows();
|
|
|
|
$groupsSimplified = $this->simplifyArray($groups);
|
|
|
|
$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
|
2015-10-21 09:32:08 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true);
|
2015-10-14 16:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then /^subadmin users returned are$/
|
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $formData
|
|
|
|
*/
|
|
|
|
public function theSubadminUsersShouldBe($groupsList) {
|
|
|
|
$this->theSubadminGroupsShouldBe($groupsList);
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:28:48 +00:00
|
|
|
/**
|
|
|
|
* @Then /^apps returned are$/
|
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $formData
|
|
|
|
*/
|
|
|
|
public function theAppsShouldBe($appList) {
|
|
|
|
if ($appList instanceof \Behat\Gherkin\Node\TableNode) {
|
|
|
|
$apps = $appList->getRows();
|
|
|
|
$appsSimplified = $this->simplifyArray($apps);
|
|
|
|
$respondedArray = $this->getArrayOfAppsResponded($this->response);
|
|
|
|
PHPUnit_Framework_Assert::assertEquals($appsSimplified, $respondedArray, "", 0.0, 10, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-02 09:45:25 +00:00
|
|
|
/**
|
2015-10-02 07:40:25 +00:00
|
|
|
* @Then /^the OCS status code should be "([^"]*)"$/
|
2015-08-06 15:16:24 +00:00
|
|
|
*/
|
2015-10-02 07:40:25 +00:00
|
|
|
public function theOCSStatusCodeShouldBe($statusCode) {
|
2015-09-30 15:50:18 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals($statusCode, $this->getOCSResponse($this->response));
|
2015-08-06 15:16:24 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 09:45:25 +00:00
|
|
|
/**
|
2015-10-02 07:40:25 +00:00
|
|
|
* @Then /^the HTTP status code should be "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function theHTTPStatusCodeShouldBe($statusCode) {
|
|
|
|
PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
/**
|
|
|
|
* @Given /^As an "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function asAn($user) {
|
2015-08-06 13:47:21 +00:00
|
|
|
$this->currentUser = $user;
|
2015-08-06 15:16:24 +00:00
|
|
|
}
|
2015-08-06 13:47:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^using api version "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function usingApiVersion($version) {
|
|
|
|
$this->apiVersion = $version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^user "([^"]*)" exists$/
|
|
|
|
*/
|
2015-10-09 13:00:34 +00:00
|
|
|
public function assureUserExists($user) {
|
|
|
|
try {
|
|
|
|
$this->userExists($user);
|
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) {
|
|
|
|
$previous_user = $this->currentUser;
|
|
|
|
$this->currentUser = "admin";
|
|
|
|
$this->creatingTheUser($user);
|
|
|
|
$this->currentUser = $previous_user;
|
|
|
|
}
|
|
|
|
$this->userExists($user);
|
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userExists($user){
|
2015-10-02 07:40:25 +00:00
|
|
|
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user";
|
2015-08-06 15:16:24 +00:00
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
2015-10-09 13:00:34 +00:00
|
|
|
$options['auth'] = $this->adminUser;
|
2015-08-06 15:16:24 +00:00
|
|
|
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:30:18 +00:00
|
|
|
/**
|
|
|
|
* @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function userBelongsToGroup($user, $group) {
|
|
|
|
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
$groups = array($group);
|
|
|
|
$respondedArray = $this->getArrayOfGroupsResponded($this->response);
|
2015-10-21 09:32:08 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals($groups, $respondedArray, "", 0.0, 10, true);
|
2015-10-14 16:30:18 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^user "([^"]*)" does not belong to group "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function userDoesNotBelongToGroup($user, $group) {
|
|
|
|
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
$groups = array($group);
|
|
|
|
$respondedArray = $this->getArrayOfGroupsResponded($this->response);
|
2015-10-21 09:32:08 +00:00
|
|
|
PHPUnit_Framework_Assert::assertNotEquals($groups, $respondedArray, "", 0.0, 10, true);
|
2015-10-14 16:30:18 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^user "([^"]*)" is subadmin of group "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function userIsSubadminOfGroup($user, $group) {
|
|
|
|
$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
$subadmins = array($user);
|
|
|
|
$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
|
|
|
|
sort($respondedArray);
|
|
|
|
PHPUnit_Framework_Assert::assertContains($user, $respondedArray);
|
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^user "([^"]*)" is not a subadmin of group "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function userIsNotSubadminOfGroup($user, $group) {
|
|
|
|
$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
$subadmins = array($user);
|
|
|
|
$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
|
|
|
|
sort($respondedArray);
|
|
|
|
PHPUnit_Framework_Assert::assertNotContains($user, $respondedArray);
|
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
/**
|
|
|
|
* @Given /^user "([^"]*)" does not exist$/
|
|
|
|
*/
|
|
|
|
public function userDoesNotExist($user) {
|
|
|
|
try {
|
|
|
|
$this->userExists($user);
|
2015-10-09 13:00:34 +00:00
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) {
|
|
|
|
$this->response = $ex->getResponse();
|
|
|
|
PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$previous_user = $this->currentUser;
|
|
|
|
$this->currentUser = "admin";
|
|
|
|
$this->deletingTheUser($user);
|
|
|
|
$this->currentUser = $previous_user;
|
|
|
|
try {
|
|
|
|
$this->userExists($user);
|
2015-08-06 15:16:24 +00:00
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) {
|
2015-09-30 15:50:18 +00:00
|
|
|
$this->response = $ex->getResponse();
|
2015-10-02 09:45:25 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
|
2015-08-06 15:16:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:28:48 +00:00
|
|
|
/**
|
|
|
|
* @Given /^app "([^"]*)" is disabled$/
|
|
|
|
*/
|
|
|
|
public function appIsDisabled($app) {
|
|
|
|
$fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=disabled";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
$respondedArray = $this->getArrayOfAppsResponded($this->response);
|
|
|
|
PHPUnit_Framework_Assert::assertContains($app, $respondedArray);
|
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^app "([^"]*)" is enabled$/
|
|
|
|
*/
|
|
|
|
public function appIsEnabled($app) {
|
|
|
|
$fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=enabled";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
$respondedArray = $this->getArrayOfAppsResponded($this->response);
|
|
|
|
PHPUnit_Framework_Assert::assertContains($app, $respondedArray);
|
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
2015-10-09 13:00:34 +00:00
|
|
|
public function createUser($user) {
|
|
|
|
$this->creatingTheUser($user);
|
|
|
|
$this->userExists($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteUser($user) {
|
|
|
|
$this->deletingTheUser($user);
|
|
|
|
$this->userDoesNotExist($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createGroup($group) {
|
|
|
|
$this->creatingTheGroup($group);
|
|
|
|
$this->groupExists($group);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteGroup($group) {
|
|
|
|
$this->deletingTheGroup($group);
|
|
|
|
$this->groupDoesNotExist($group);
|
|
|
|
}
|
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
public function creatingTheUser($user) {
|
2015-10-09 13:00:34 +00:00
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users";
|
2015-08-06 15:16:24 +00:00
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
2015-10-09 13:00:34 +00:00
|
|
|
$options['body'] = [
|
|
|
|
'userid' => $user,
|
|
|
|
'password' => '123456'
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
|
2015-09-30 15:50:18 +00:00
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 09:45:25 +00:00
|
|
|
/**
|
2015-10-09 13:00:34 +00:00
|
|
|
* @When /^creating the group "([^"]*)"$/
|
2015-09-29 14:52:19 +00:00
|
|
|
*/
|
|
|
|
public function creatingTheGroup($group) {
|
2015-10-09 13:00:34 +00:00
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups";
|
2015-09-29 14:52:19 +00:00
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
2015-10-09 13:00:34 +00:00
|
|
|
$options['body'] = [
|
|
|
|
'groupid' => $group,
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
|
2015-09-29 14:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-09 13:00:34 +00:00
|
|
|
* @When /^Deleting the user "([^"]*)"$/
|
2015-09-29 14:52:19 +00:00
|
|
|
*/
|
2015-10-09 13:00:34 +00:00
|
|
|
public function deletingTheUser($user) {
|
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
|
2015-09-29 14:52:19 +00:00
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
2015-10-09 13:00:34 +00:00
|
|
|
$this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^Deleting the group "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function deletingTheGroup($group) {
|
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/$group";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^Add user "([^"]*)" to the group "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function addUserToGroup($user, $group) {
|
|
|
|
$this->userExists($user);
|
|
|
|
$this->groupExists($group);
|
|
|
|
$this->addingUserToGroup($user, $group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^User "([^"]*)" is added to the group "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function addingUserToGroup($user, $group) {
|
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/groups";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
$options['body'] = [
|
|
|
|
'groupid' => $group,
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function groupExists($group) {
|
|
|
|
$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
|
2015-09-29 14:52:19 +00:00
|
|
|
$this->response = $client->get($fullUrl, $options);
|
2015-10-09 13:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^group "([^"]*)" exists$/
|
|
|
|
*/
|
|
|
|
public function assureGroupExists($group) {
|
|
|
|
try {
|
|
|
|
$this->groupExists($group);
|
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) {
|
|
|
|
$previous_user = $this->currentUser;
|
|
|
|
$this->currentUser = "admin";
|
|
|
|
$this->creatingTheGroup($group);
|
|
|
|
$this->currentUser = $previous_user;
|
|
|
|
}
|
|
|
|
$this->groupExists($group);
|
2015-10-02 07:40:25 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
2015-09-29 14:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^group "([^"]*)" does not exist$/
|
|
|
|
*/
|
|
|
|
public function groupDoesNotExist($group) {
|
|
|
|
try {
|
|
|
|
$this->groupExists($group);
|
2015-10-09 13:00:34 +00:00
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) {
|
|
|
|
$this->response = $ex->getResponse();
|
|
|
|
PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$previous_user = $this->currentUser;
|
|
|
|
$this->currentUser = "admin";
|
|
|
|
$this->deletingTheGroup($group);
|
|
|
|
$this->currentUser = $previous_user;
|
|
|
|
try {
|
|
|
|
$this->groupExists($group);
|
2015-09-29 14:52:19 +00:00
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) {
|
2015-09-30 15:50:18 +00:00
|
|
|
$this->response = $ex->getResponse();
|
2015-10-02 09:45:25 +00:00
|
|
|
PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
|
2015-09-29 14:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-06 15:16:24 +00:00
|
|
|
/**
|
|
|
|
* @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;
|
2015-10-14 16:30:18 +00:00
|
|
|
} else {
|
2015-10-22 12:15:51 +00:00
|
|
|
$options['auth'] = [$this->currentUser, $this->regularUser];
|
2015-08-06 15:16:24 +00:00
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
2015-08-06 13:47:21 +00:00
|
|
|
}
|
2015-10-09 13:00:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^creating a public share with$/
|
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $formData
|
|
|
|
*/
|
|
|
|
public function createPublicShare($body) {
|
|
|
|
$this->sendingToWith("POST", "/apps/files_sharing/api/v1/shares", $body);
|
|
|
|
$this->lastShareData = $this->response->xml();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then /^Public shared file "([^"]*)" can be downloaded$/
|
|
|
|
*/
|
|
|
|
public function checkPublicSharedFile($filename) {
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
$url = $this->lastShareData->data[0]->url;
|
|
|
|
$fullUrl = $url . "/download";
|
|
|
|
$options['save_to'] = "./$filename";
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
$finfo = new finfo;
|
|
|
|
$fileinfo = $finfo->file("./$filename", FILEINFO_MIME_TYPE);
|
|
|
|
PHPUnit_Framework_Assert::assertEquals($fileinfo, "text/plain");
|
|
|
|
if (file_exists("./$filename")) {
|
|
|
|
unlink("./$filename");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then /^Public shared file "([^"]*)" with password "([^"]*)" can be downloaded$/
|
|
|
|
*/
|
|
|
|
public function checkPublicSharedFileWithPassword($filename, $password) {
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
$token = $this->lastShareData->data[0]->token;
|
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav";
|
|
|
|
$options['auth'] = [$token, $password];
|
|
|
|
$options['save_to'] = "./$filename";
|
|
|
|
$this->response = $client->get($fullUrl, $options);
|
|
|
|
$finfo = new finfo;
|
|
|
|
$fileinfo = $finfo->file("./$filename", FILEINFO_MIME_TYPE);
|
|
|
|
PHPUnit_Framework_Assert::assertEquals($fileinfo, "text/plain");
|
|
|
|
if (file_exists("./$filename")) {
|
|
|
|
unlink("./$filename");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^Adding expiration date to last share$/
|
|
|
|
*/
|
|
|
|
public function addingExpirationDate() {
|
|
|
|
$share_id = $this->lastShareData->data[0]->id;
|
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->apiVersion}/shares/$share_id";
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
} else {
|
|
|
|
$options['auth'] = [$this->currentUser, $this->regularUser];
|
|
|
|
}
|
|
|
|
$date = date('Y-m-d', strtotime("+3 days"));
|
|
|
|
$options['body'] = ['expireDate' => $date];
|
|
|
|
$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options));
|
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
|
|
|
|
}
|
2015-08-06 13:47:21 +00:00
|
|
|
}
|