Commit a990e0ac authored by Sergio Bertolin's avatar Sergio Bertolin
Browse files

Added some requirements for first test case

parent 58eaeb26
......@@ -238,8 +238,23 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
* @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
* @Then /^check that user "([^"]*)" belongs to group "([^"]*)"$/
*/
public function checkThatUserBelongsToGroup($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);
$respondedArray = $this->getArrayOfGroupsResponded($this->response);
sort($respondedArray);
PHPUnit_Framework_Assert::assertContains($group, $respondedArray);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
}
public function userBelongsToGroup($user, $group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
$client = new Client();
......@@ -251,8 +266,26 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$this->response = $client->get($fullUrl, $options);
$groups = array($group);
$respondedArray = $this->getArrayOfGroupsResponded($this->response);
PHPUnit_Framework_Assert::assertEquals($groups, $respondedArray, "", 0.0, 10, true);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
if (array_key_exists($group, $respondedArray)) {
return True;
} else{
return False;
}
}
/**
* @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
*/
public function assureUserBelongsToGroup($user, $group){
if (!$this->userBelongsToGroup($user, $group)){
$previous_user = $this->currentUser;
$this->currentUser = "admin";
$this->addingUserToGroup($user, $group);
$this->currentUser = $previous_user;
}
$this->checkThatUserBelongsToGroup($user, $group);
}
/**
......@@ -818,10 +851,10 @@ class FeatureContext implements Context, SnippetAcceptingContext {
PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('share_with', "$user"));
}
public function isUserInSharedData($user){
public function isUserOrGroupInSharedData($userOrGroup){
$data = $this->response->xml()->data[0];
foreach($data as $element) {
if ($element->share_with == $user){
if ($element->share_with == $userOrGroup){
return True;
}
}
......@@ -841,13 +874,70 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$options['auth'] = [$user1, $this->regularUser];
}
$this->response = $client->get($fullUrl, $options);
if ($this->isUserInSharedData($user2)){
if ($this->isUserOrGroupInSharedData($user2)){
return;
} else {
$this->createShare($user1, $filepath, 0, $user2, null, null, null);
}
$this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(True, $this->isUserInSharedData($user2));
PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($user2));
}
/**
* @Given /^file "([^"]*)" from user "([^"]*)" is shared with group "([^"]*)"$/
*/
public function assureFileIsSharedWithGroup($filepath, $user, $group){
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
$client = new Client();
$options = [];
if ($user === 'admin') {
$options['auth'] = $this->adminUser;
} else {
$options['auth'] = [$user, $this->regularUser];
}
$this->response = $client->get($fullUrl, $options);
if ($this->isUserOrGroupInSharedData($group)){
return;
} else {
$this->createShare($user, $filepath, 1, $group, null, null, null);
}
$this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($group));
}
public function makeDavRequest($user, $method, $path, $headers){
$fullUrl = substr($this->baseUrl, 0, -4) . "remote.php/webdav" . "$path";
$client = new Client();
$options = [];
if ($user === 'admin') {
$options['auth'] = $this->adminUser;
} else {
$options['auth'] = [$user, $this->regularUser];
}
$request = $client->createRequest($method, $fullUrl, $options);
foreach ($headers as $key => $value) {
$request->addHeader($key, $value);
}
$this->response = $client->send($request);
}
/**
* @Given /^User "([^"]*)" moved file "([^"]*)" to "([^"]*)"$/
*/
public function userMovedFile($user, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . "remote.php/webdav";
$headers['Destination'] = $fullUrl . $fileDestination;
$this->makeDavRequest($user, "MOVE", $fileSource, $headers);
PHPUnit_Framework_Assert::assertEquals(201, $this->response->getStatusCode());
}
/**
* @When /^User "([^"]*)" moves file "([^"]*)" to "([^"]*)"$/
*/
public function userMovesFile($user, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . "remote.php/webdav";
$headers['Destination'] = $fullUrl . $fileDestination;
$this->makeDavRequest($user, "MOVE", $fileSource, $headers);
}
/**
......@@ -877,7 +967,9 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$fd = $body->getRowsHash();
foreach($fd as $field => $value) {
PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse($field, $value));
if (!$this->isFieldInResponse($field, $value)){
PHPUnit_Framework_Assert::fail("$field" . " doesn't have value " . "$value");
}
}
}
}
......
......@@ -272,6 +272,36 @@ Feature: sharing
| share_with_displayname | user1 |
| displayname_owner | user0 |
Scenario: keep group permissions in sync
Given As an "admin"
Given user "user0" exists
And user "user1" exists
And group "group1" exists
And user "user1" belongs to group "group1"
And file "textfile0.txt" from user "user0" is shared with group "group1"
And User "user1" moved file "/textfile0.txt" to "/FOLDER/textfile0.txt"
And As an "user0"
When Updating last share with
| permissions | 1 |
And Getting info of last share
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And Share fields of last share match with
| id | A_NUMBER |
| item_type | file |
| item_source | A_NUMBER |
| share_type | 1 |
| file_source | A_NUMBER |
| file_target | /textfile0.txt |
| permissions | 1 |
| stime | A_NUMBER |
| storage | A_NUMBER |
| mail_send | 0 |
| uid_owner | user0 |
| storage_id | home::user0 |
| file_parent | A_NUMBER |
| displayname_owner | user0 |
Scenario: delete a share
Given user "user0" exists
And user "user1" exists
......
Feature: sharing
Background:
Given using api version "1"
Scenario: moving a file
Given As an "admin"
And user "user0" exists
When User "user0" moves file "/textfile0.txt" to "/FOLDER/textfile0.txt"
Then the HTTP status code should be "201"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment