Merge pull request #23141 from owncloud/behat-code-style

Fix all the yellow, orange and red errors in integration tests
This commit is contained in:
Thomas Müller 2016-03-11 14:56:44 +01:00
commit c874ebf425
13 changed files with 233 additions and 51 deletions

View File

@ -4,6 +4,6 @@
"behat/behat": "^3.0",
"guzzlehttp/guzzle": "~5.0",
"jarnaiz/behat-junit-formatter": "^1.3",
"sabre/dav": "3.0.x-dev"
"sabre/dav": "3.0.x-dev"
}
}

View File

@ -1,7 +1,5 @@
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;
@ -17,6 +15,9 @@ trait BasicStructure {
/** @var string */
private $baseUrl = '';
/** @var int */
private $apiVersion = 1;
/** @var ResponseInterface */
private $response = null;
@ -51,8 +52,17 @@ trait BasicStructure {
}
}
/**
* @Given /^using api version "([^"]*)"$/
* @param string $version
*/
public function usingApiVersion($version) {
$this->apiVersion = $version;
}
/**
* @Given /^As an "([^"]*)"$/
* @param string $user
*/
public function asAn($user) {
$this->currentUser = $user;
@ -60,6 +70,7 @@ trait BasicStructure {
/**
* @Given /^Using server "([^"]*)"$/
* @param string $server
*/
public function usingServer($server) {
if ($server === 'LOCAL'){
@ -75,6 +86,8 @@ trait BasicStructure {
/**
* @When /^sending "([^"]*)" to "([^"]*)"$/
* @param string $verb
* @param string $url
*/
public function sendingTo($verb, $url) {
$this->sendingToWith($verb, $url, null);
@ -92,6 +105,8 @@ trait BasicStructure {
/**
* This function is needed to use a vertical fashion in the gherkin tables.
* @param array $arrayOfArrays
* @return array
*/
public function simplifyArray($arrayOfArrays){
$a = array_map(function($subArray) { return $subArray[0]; }, $arrayOfArrays);
@ -100,6 +115,9 @@ trait BasicStructure {
/**
* @When /^sending "([^"]*)" to "([^"]*)" with$/
* @param string $verb
* @param string $url
* @param \Behat\Gherkin\Node\TableNode $body
*/
public function sendingToWith($verb, $url, $body) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url;
@ -130,6 +148,7 @@ trait BasicStructure {
/**
* @Then /^the OCS status code should be "([^"]*)"$/
* @param int $statusCode
*/
public function theOCSStatusCodeShouldBe($statusCode) {
PHPUnit_Framework_Assert::assertEquals($statusCode, $this->getOCSResponse($this->response));
@ -137,6 +156,7 @@ trait BasicStructure {
/**
* @Then /^the HTTP status code should be "([^"]*)"$/
* @param int $statusCode
*/
public function theHTTPStatusCodeShouldBe($statusCode) {
PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode());
@ -151,6 +171,7 @@ trait BasicStructure {
/**
* @Given Logging in using web as :user
* @param string $user
*/
public function loggingInUsingWebAs($user) {
$loginUrl = substr($this->baseUrl, 0, -5);
@ -183,6 +204,8 @@ trait BasicStructure {
/**
* @When Sending a :method to :url with requesttoken
* @param string $method
* @param string $url
*/
public function sendingAToWithRequesttoken($method, $url) {
$baseUrl = substr($this->baseUrl, 0, -5);
@ -205,6 +228,8 @@ trait BasicStructure {
/**
* @When Sending a :method to :url without requesttoken
* @param string $method
* @param string $url
*/
public function sendingAToWithoutRequesttoken($method, $url) {
$baseUrl = substr($this->baseUrl, 0, -5);
@ -248,7 +273,6 @@ trait BasicStructure {
mkdir("../../core/skeleton/PARENT/CHILD", 0777, true);
}
file_put_contents("../../core/skeleton/PARENT/CHILD/" . "child.txt", "ownCloud test text file\n");
}
/**
@ -269,8 +293,6 @@ trait BasicStructure {
if (is_dir("../../core/skeleton/PARENT")) {
rmdir("../../core/skeleton/PARENT");
}
}
}

View File

@ -71,6 +71,8 @@ class CalDavContext implements \Behat\Behat\Context\Context {
/**
* @When :user requests calendar :calendar
* @param string $user
* @param string $calendar
*/
public function requestsCalendar($user, $calendar) {
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$calendar;
@ -93,6 +95,8 @@ class CalDavContext implements \Behat\Behat\Context\Context {
/**
* @Then The CalDAV HTTP status code should be :code
* @param int $code
* @throws \Exception
*/
public function theCaldavHttpStatusCodeShouldBe($code) {
if((int)$code !== $this->response->getStatusCode()) {
@ -115,6 +119,8 @@ class CalDavContext implements \Behat\Behat\Context\Context {
/**
* @Then The exception is :message
* @param string $message
* @throws \Exception
*/
public function theExceptionIs($message) {
$result = $this->responseXml['value'][0]['value'];
@ -132,6 +138,8 @@ class CalDavContext implements \Behat\Behat\Context\Context {
/**
* @Then The error message is :message
* @param string $message
* @throws \Exception
*/
public function theErrorMessageIs($message) {
$result = $this->responseXml['value'][1]['value'];
@ -149,6 +157,8 @@ class CalDavContext implements \Behat\Behat\Context\Context {
/**
* @Given :user creates a calendar named :name
* @param string $user
* @param string $name
*/
public function createsACalendarNamed($user, $name) {
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$user.'/'.$name;

View File

@ -15,8 +15,6 @@ require __DIR__ . '/../../vendor/autoload.php';
class CapabilitiesContext implements Context, SnippetAcceptingContext {
use BasicStructure;
use Provisioning;
use Sharing;
/**
* @Given /^parameter "([^"]*)" of app "([^"]*)" is set to "([^"]*)"$/

View File

@ -73,6 +73,10 @@ class CardDavContext implements \Behat\Behat\Context\Context {
/**
* @When :user requests addressbook :addressBook with statuscode :statusCode
* @param string $user
* @param string $addressBook
* @param int $statusCode
* @throws \Exception
*/
public function requestsAddressbookWithStatuscode($user, $addressBook, $statusCode) {
$davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$addressBook;
@ -112,6 +116,10 @@ class CardDavContext implements \Behat\Behat\Context\Context {
/**
* @Given :user creates an addressbook named :addressBook with statuscode :statusCode
* @param string $user
* @param string $addressBook
* @param int $statusCode
* @throws \Exception
*/
public function createsAnAddressbookNamedWithStatuscode($user, $addressBook, $statusCode) {
$davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook;
@ -121,9 +129,7 @@ class CardDavContext implements \Behat\Behat\Context\Context {
'MKCOL',
$davUrl,
[
'body' => '<d:mkcol xmlns:c="urn:ietf:params:xml:ns:caldav"
xmlns:card="urn:ietf:params:xml:ns:carddav"
xmlns:cs="http://calendarserver.org/ns/"
'body' => '<d:mkcol xmlns:card="urn:ietf:params:xml:ns:carddav"
xmlns:d="DAV:">
<d:set>
<d:prop>
@ -158,6 +164,8 @@ class CardDavContext implements \Behat\Behat\Context\Context {
/**
* @When The CardDAV exception is :message
* @param string $message
* @throws \Exception
*/
public function theCarddavExceptionIs($message) {
$result = $this->responseXml['value'][0]['value'];
@ -175,6 +183,8 @@ class CardDavContext implements \Behat\Behat\Context\Context {
/**
* @When The CardDAV error message is :arg1
* @param string $message
* @throws \Exception
*/
public function theCarddavErrorMessageIs($message) {
$result = $this->responseXml['value'][1]['value'];

View File

@ -2,7 +2,6 @@
require __DIR__ . '/../../vendor/autoload.php';
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;
@ -50,6 +49,10 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
/**
* @When user :user uploads file :source to :destination with checksum :checksum
* @param string $user
* @param string $source
* @param string $destination
* @param string $checksum
*/
public function userUploadsFileToWithChecksum($user, $source, $destination, $checksum)
{
@ -76,6 +79,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
/**
* @Then The webdav response should have a status code :statusCode
* @param int $statusCode
* @throws \Exception
*/
public function theWebdavResponseShouldHaveAStatusCode($statusCode) {
if((int)$statusCode !== $this->response->getStatusCode()) {
@ -85,6 +90,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
/**
* @When user :user request the checksum of :path via propfind
* @param string $user
* @param string $path
*/
public function userRequestTheChecksumOfViaPropfind($user, $path)
{
@ -109,6 +116,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
/**
* @Then The webdav checksum should match :checksum
* @param string $checksum
* @throws \Exception
*/
public function theWebdavChecksumShouldMatch($checksum)
{
@ -128,6 +137,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
/**
* @When user :user downloads the file :path
* @param string $user
* @param string $path
*/
public function userDownloadsTheFile($user, $path)
{
@ -144,6 +155,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
/**
* @Then The header checksum should match :checksum
* @param string $checksum
* @throws \Exception
*/
public function theHeaderChecksumShouldMatch($checksum)
{
@ -154,6 +167,9 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
/**
* @Given User :user copied file :source to :destination
* @param string $user
* @param string $source
* @param string $destination
*/
public function userCopiedFileTo($user, $source, $destination)
{
@ -204,6 +220,12 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
/**
* @Given user :user uploads chunk file :num of :total with :data to :destination with checksum :checksum
* @param string $user
* @param int $num
* @param int $total
* @param string $data
* @param string $destination
* @param string $checksum
*/
public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination, $checksum)
{

View File

@ -45,7 +45,7 @@ class CommentsContext implements \Behat\Behat\Context\Context {
}
/** @AfterScenario */
public function teardownScenario(\Behat\Behat\Hook\Scope\AfterScenarioScope $scope) {
public function teardownScenario() {
$client = new \GuzzleHttp\Client();
try {
$client->delete(
@ -66,6 +66,7 @@ class CommentsContext implements \Behat\Behat\Context\Context {
}
/**
* @param string $path
* @return int
*/
private function getFileIdForPath($path) {
@ -90,6 +91,11 @@ class CommentsContext implements \Behat\Behat\Context\Context {
/**
* @When :user posts a comment with content :content on the file named :fileName it should return :statusCode
* @param string $user
* @param string $content
* @param string $fileName
* @param int $statusCode
* @throws \Exception
*/
public function postsACommentWithContentOnTheFileNamedItShouldReturn($user, $content, $fileName, $statusCode) {
$fileId = $this->getFileIdForPath($fileName);
@ -123,6 +129,10 @@ class CommentsContext implements \Behat\Behat\Context\Context {
/**
* @Then As :user load all the comments of the file named :fileName it should return :statusCode
* @param string $user
* @param string $fileName
* @param int $statusCode
* @throws \Exception
*/
public function asLoadloadAllTheCommentsOfTheFileNamedItShouldReturn($user, $fileName, $statusCode) {
$fileId = $this->getFileIdForPath($fileName);
@ -135,7 +145,7 @@ class CommentsContext implements \Behat\Behat\Context\Context {
$url,
[
'body' => '<?xml version="1.0" encoding="utf-8" ?>
<oc:filter-comments xmlns:D="DAV:" xmlns:oc="http://owncloud.org/ns">
<oc:filter-comments xmlns:oc="http://owncloud.org/ns">
<oc:limit>200</oc:limit>
<oc:offset>0</oc:offset>
</oc:filter-comments>
@ -167,6 +177,11 @@ class CommentsContext implements \Behat\Behat\Context\Context {
/**
* @Given As :user sending :verb to :url with
* @param string $user
* @param string $verb
* @param string $url
* @param \Behat\Gherkin\Node\TableNode $body
* @throws \Exception
*/
public function asUserSendingToWith($user, $verb, $url, \Behat\Gherkin\Node\TableNode $body) {
$client = new \GuzzleHttp\Client();
@ -179,6 +194,9 @@ class CommentsContext implements \Behat\Behat\Context\Context {
/**
* @Then As :user delete the created comment it should return :statusCode
* @param string $user
* @param int $statusCode
* @throws \Exception
*/
public function asDeleteTheCreatedCommentItShouldReturn($user, $statusCode) {
$url = $this->baseUrl.'/remote.php/dav/comments/files/'.$this->fileId.'/'.$this->commentId;
@ -208,6 +226,9 @@ class CommentsContext implements \Behat\Behat\Context\Context {
/**
* @Then the response should contain a property :key with value :value
* @param string $key
* @param string $value
* @throws \Exception
*/
public function theResponseShouldContainAPropertyWithValue($key, $value) {
$keys = $this->response[0]['value'][2]['value'][0]['value'];
@ -226,6 +247,8 @@ class CommentsContext implements \Behat\Behat\Context\Context {
/**
* @Then the response should contain only :number comments
* @param int $number
* @throws \Exception
*/
public function theResponseShouldContainOnlyComments($number) {
if(count($this->response) !== (int)$number) {
@ -235,6 +258,10 @@ class CommentsContext implements \Behat\Behat\Context\Context {
/**
* @Then As :user edit the last created comment and set text to :text it should return :statusCode
* @param string $user
* @param string $text
* @param int $statusCode
* @throws \Exception
*/
public function asEditTheLastCreatedCommentAndSetTextToItShouldReturn($user, $text, $statusCode) {
$client = new \GuzzleHttp\Client();

View File

@ -2,8 +2,6 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;
require __DIR__ . '/../../vendor/autoload.php';
@ -12,8 +10,5 @@ require __DIR__ . '/../../vendor/autoload.php';
* Features context.
*/
class FeatureContext implements Context, SnippetAcceptingContext {
use BasicStructure;
use Provisioning;
use Sharing;
use WebDav;
}

View File

@ -12,8 +12,6 @@ require __DIR__ . '/../../vendor/autoload.php';
*/
class FederationContext implements Context, SnippetAcceptingContext {
use BasicStructure;
use Provisioning;
use Sharing;
/**

View File

@ -1,16 +1,12 @@
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;
require __DIR__ . '/../../vendor/autoload.php';
trait Provisioning {
/** @var int */
private $apiVersion = 1;
use BasicStructure;
/** @var array */
private $createdUsers = [];
@ -24,15 +20,9 @@ trait Provisioning {
/** @var array */
private $createdGroups = [];
/**
* @Given /^using api version "([^"]*)"$/
*/
public function usingApiVersion($version) {
$this->apiVersion = $version;
}
/**
* @Given /^user "([^"]*)" exists$/
* @param string $user
*/
public function assureUserExists($user) {
try {
@ -50,6 +40,7 @@ trait Provisioning {
/**
* @Given /^user "([^"]*)" does not exist$/
* @param string $user
*/
public function userDoesNotExist($user) {
try {
@ -142,6 +133,8 @@ trait Provisioning {
/**
* @Then /^check that user "([^"]*)" belongs to group "([^"]*)"$/
* @param string $user
* @param string $group
*/
public function checkThatUserBelongsToGroup($user, $group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
@ -167,7 +160,6 @@ trait Provisioning {
}
$this->response = $client->get($fullUrl, $options);
$groups = array($group);
$respondedArray = $this->getArrayOfGroupsResponded($this->response);
if (array_key_exists($group, $respondedArray)) {
@ -179,6 +171,8 @@ trait Provisioning {
/**
* @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
* @param string $user
* @param string $group
*/
public function assureUserBelongsToGroup($user, $group){
if (!$this->userBelongsToGroup($user, $group)){
@ -193,6 +187,8 @@ trait Provisioning {
/**
* @Given /^user "([^"]*)" does not belong to group "([^"]*)"$/
* @param string $user
* @param string $group
*/
public function userDoesNotBelongToGroup($user, $group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
@ -209,8 +205,9 @@ trait Provisioning {
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
}
/**
/**
* @When /^creating the group "([^"]*)"$/
* @param string $group
*/
public function creatingTheGroup($group) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups";
@ -234,6 +231,7 @@ trait Provisioning {
/**
* @When /^Deleting the user "([^"]*)"$/
* @param string $user
*/
public function deletingTheUser($user) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
@ -248,6 +246,7 @@ trait Provisioning {
/**
* @When /^Deleting the group "([^"]*)"$/
* @param string $group
*/
public function deletingTheGroup($group) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/$group";
@ -262,6 +261,8 @@ trait Provisioning {
/**
* @Given /^Add user "([^"]*)" to the group "([^"]*)"$/
* @param string $user
* @param string $group
*/
public function addUserToGroup($user, $group) {
$this->userExists($user);
@ -272,6 +273,8 @@ trait Provisioning {
/**
* @When /^User "([^"]*)" is added to the group "([^"]*)"$/
* @param string $user
* @param string $group
*/
public function addingUserToGroup($user, $group) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/groups";
@ -300,6 +303,7 @@ trait Provisioning {
/**
* @Given /^group "([^"]*)" exists$/
* @param string $group
*/
public function assureGroupExists($group) {
try {
@ -316,6 +320,7 @@ trait Provisioning {
/**
* @Given /^group "([^"]*)" does not exist$/
* @param string $group
*/
public function groupDoesNotExist($group) {
try {
@ -339,6 +344,8 @@ trait Provisioning {
/**
* @Given /^user "([^"]*)" is subadmin of group "([^"]*)"$/
* @param string $user
* @param string $group
*/
public function userIsSubadminOfGroup($user, $group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
@ -357,6 +364,8 @@ trait Provisioning {
/**
* @Given /^user "([^"]*)" is not a subadmin of group "([^"]*)"$/
* @param string $user
* @param string $group
*/
public function userIsNotSubadminOfGroup($user, $group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
@ -484,6 +493,7 @@ trait Provisioning {
/**
* @Given /^app "([^"]*)" is disabled$/
* @param string $app
*/
public function appIsDisabled($app) {
$fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=disabled";
@ -501,6 +511,7 @@ trait Provisioning {
/**
* @Given /^app "([^"]*)" is enabled$/
* @param string $app
*/
public function appIsEnabled($app) {
$fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=enabled";
@ -518,6 +529,8 @@ trait Provisioning {
/**
* @Given user :user has a quota of :quota
* @param string $user
* @param string $quota
*/
public function userHasAQuotaOf($user, $quota)
{
@ -532,6 +545,7 @@ trait Provisioning {
/**
* @Given user :user has unlimited quota
* @param string $user
*/
public function userHasUnlimitedQuota($user)
{

View File

@ -1,7 +1,5 @@
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;
@ -10,6 +8,7 @@ require __DIR__ . '/../../vendor/autoload.php';
trait Sharing{
use Provisioning;
/** @var int */
private $sharingApiVersion = 1;
@ -22,10 +21,11 @@ trait Sharing{
/**
* @Given /^as "([^"]*)" creating a share with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData
* @param string $user
* @param \Behat\Gherkin\Node\TableNode|null $body
*/
public function asCreatingAShareWith($user, $body) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v1/shares";
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
$client = new Client();
$options = [];
if ($user === 'admin') {
@ -54,10 +54,10 @@ trait Sharing{
/**
* @When /^creating a share with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData
* @param \Behat\Gherkin\Node\TableNode|null $body
*/
public function creatingShare($body) {
return $this->asCreatingAShareWith($this->currentUser, $body);
$this->asCreatingAShareWith($this->currentUser, $body);
}
/**
@ -112,7 +112,7 @@ trait Sharing{
* @When /^Adding expiration date to last share$/
*/
public function addingExpirationDate() {
$share_id = $this->lastShareData->data[0]->id;
$share_id = (string) $this->lastShareData->data[0]->id;
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
$client = new Client();
$options = [];
@ -132,7 +132,7 @@ trait Sharing{
* @param \Behat\Gherkin\Node\TableNode|null $body
*/
public function updatingLastShare($body) {
$share_id = $this->lastShareData->data[0]->id;
$share_id = (string) $this->lastShareData->data[0]->id;
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
$client = new Client();
$options = [];
@ -250,6 +250,8 @@ trait Sharing{
/**
* @Then /^File "([^"]*)" should be included in the response$/
*
* @param string $filename
*/
public function checkSharedFileInResponse($filename){
PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse('file_target', "/$filename"));
@ -257,6 +259,8 @@ trait Sharing{
/**
* @Then /^File "([^"]*)" should not be included in the response$/
*
* @param string $filename
*/
public function checkSharedFileNotInResponse($filename){
PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('file_target', "/$filename"));
@ -264,6 +268,8 @@ trait Sharing{
/**
* @Then /^User "([^"]*)" should be included in the response$/
*
* @param string $user
*/
public function checkSharedUserInResponse($user){
PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse('share_with', "$user"));
@ -271,6 +277,8 @@ trait Sharing{
/**
* @Then /^User "([^"]*)" should not be included in the response$/
*
* @param string $user
*/
public function checkSharedUserNotInResponse($user){
PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('share_with', "$user"));
@ -288,6 +296,10 @@ trait Sharing{
/**
* @Given /^file "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"$/
*
* @param string $filepath
* @param string $user1
* @param string $user2
*/
public function assureFileIsShared($filepath, $user1, $user2){
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
@ -310,6 +322,10 @@ trait Sharing{
/**
* @Given /^file "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"$/
*
* @param string $filepath
* @param string $user
* @param string $group
*/
public function assureFileIsSharedWithGroup($filepath, $user, $group){
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
@ -370,7 +386,7 @@ trait Sharing{
/**
* @Then /^Share fields of last share match with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData
* @param \Behat\Gherkin\Node\TableNode|null $body
*/
public function checkShareFields($body){
if ($body instanceof \Behat\Gherkin\Node\TableNode) {
@ -396,7 +412,7 @@ trait Sharing{
* @Then As :user remove all shares from the file named :fileName
*/
public function asRemoveAllSharesFromTheFileNamed($user, $fileName) {
$url = $this->baseUrl.'v2.php/apps/files_sharing/api/v1/shares?format=json';
$url = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares?format=json";
$client = new \GuzzleHttp\Client();
$res = $client->get(
$url,
@ -416,7 +432,7 @@ trait Sharing{
if (stripslashes($data['path']) === $fileName) {
$id = $data['id'];
$client->delete(
$this->baseUrl.'v2.php/apps/files_sharing/api/v1/shares/'.$id,
$this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/{$id}",
[
'auth' => [
$user,
@ -450,7 +466,7 @@ trait Sharing{
public function shareIdsShouldMatch()
{
if ($this->savedShareId !== $this->lastShareData['data']['id']) {
throw new \Excetion('Expected the same link share to be returned');
throw new \Exception('Expected the same link share to be returned');
}
}
}

View File

@ -98,6 +98,10 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @When :user creates a :type tag with name :name
* @param string $user
* @param string $type
* @param string $name
* @throws \Exception
*/
public function createsATagWithName($user, $type, $name) {
$userVisible = 'true';
@ -136,6 +140,8 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @Then The response should have a status code :statusCode
* @param int $statusCode
* @throws \Exception
*/
public function theResponseShouldHaveAStatusCode($statusCode) {
if((int)$statusCode !== $this->response->getStatusCode()) {
@ -199,6 +205,9 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @Then The following tags should exist for :user
* @param string $user
* @param TableNode $table
* @throws \Exception
*/
public function theFollowingTagsShouldExistFor($user, TableNode $table) {
$tags = $this->requestTagsForUser($user);
@ -231,6 +240,9 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @Then :count tags should exist for :user
* @param int $count
* @param string $user
* @throws \Exception
*/
public function tagsShouldExistFor($count, $user) {
if((int)$count !== count($this->requestTagsForUser($user))) {
@ -256,6 +268,10 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @When :user edits the tag with name :oldNmae and sets its name to :newName
* @param string $user
* @param string $oldName
* @param string $newName
* @throws \Exception
*/
public function editsTheTagWithNameAndSetsItsNameTo($user, $oldName, $newName) {
$tagId = $this->findTagIdByName($oldName);
@ -290,6 +306,8 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @When :user deletes the tag with name :name
* @param string $user
* @param string $name
*/
public function deletesTheTagWithName($user, $name) {
$tagId = $this->findTagIdByName($name);
@ -338,6 +356,10 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @When :taggingUser adds the tag :tagName to :fileName shared by :sharingUser
* @param string $taggingUser
* @param string $tagName
* @param string $fileName
* @param string $sharingUser
*/
public function addsTheTagToSharedBy($taggingUser, $tagName, $fileName, $sharingUser) {
$fileId = $this->getFileIdForPath($fileName, $sharingUser);
@ -360,6 +382,10 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @Then :fileName shared by :sharingUser has the following tags
* @param string $fileName
* @param string $sharingUser
* @param TableNode $table
* @throws \Exception
*/
public function sharedByHasTheFollowingTags($fileName, $sharingUser, TableNode $table) {
$loadedExpectedTags = $table->getTable();
@ -406,6 +432,11 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @Then :fileName shared by :sharingUser has the following tags for :user
* @param string $fileName
* @param string $sharingUser
* @param string $user
* @param TableNode $table
* @throws \Exception
*/
public function sharedByHasTheFollowingTagsFor($fileName, $sharingUser, $user, TableNode $table) {
$loadedExpectedTags = $table->getTable();
@ -460,6 +491,10 @@ class TagsContext implements \Behat\Behat\Context\Context {
/**
* @When :user removes the tag :tagName from :fileName shared by :shareUser
* @param string $user
* @param string $tagName
* @param string $fileName
* @param string $shareUser
*/
public function removesTheTagFromSharedBy($user, $tagName, $fileName, $shareUser) {
$tagId = $this->findTagIdByName($tagName);

View File

@ -1,7 +1,5 @@
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use GuzzleHttp\Client as GClient;
use GuzzleHttp\Message\ResponseInterface;
use Sabre\DAV\Client as SClient;
@ -10,6 +8,8 @@ require __DIR__ . '/../../vendor/autoload.php';
trait WebDav {
use Sharing;
/** @var string*/
private $davPath = "remote.php/webdav";
/** @var ResponseInterface */
@ -47,6 +47,9 @@ trait WebDav {
/**
* @Given /^User "([^"]*)" moved file "([^"]*)" to "([^"]*)"$/
* @param string $user
* @param string $fileSource
* @param string $fileDestination
*/
public function userMovedFile($user, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
@ -57,6 +60,9 @@ trait WebDav {
/**
* @When /^User "([^"]*)" moves file "([^"]*)" to "([^"]*)"$/
* @param string $user
* @param string $fileSource
* @param string $fileDestination
*/
public function userMovesFile($user, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
@ -66,15 +72,17 @@ trait WebDav {
/**
* @When /^Downloading file "([^"]*)" with range "([^"]*)"$/
* @param string $fileSource
* @param string $range
*/
public function downloadFileWithRange($fileSource, $range){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
$headers['Range'] = $range;
$this->response = $this->makeDavRequest($this->currentUser, "GET", $fileSource, $headers);
}
/**
* @When /^Downloading last public shared file with range "([^"]*)"$/
* @param string $range
*/
public function downloadPublicFileWithRange($range){
$token = $this->lastShareData->data->token;
@ -93,6 +101,7 @@ trait WebDav {
/**
* @Then /^Downloaded content should be "([^"]*)"$/
* @param string $content
*/
public function downloadedContentShouldBe($content){
PHPUnit_Framework_Assert::assertEquals($content, (string)$this->response->getBody());
@ -100,6 +109,9 @@ trait WebDav {
/**
* @Then /^Downloaded content when downloading file "([^"]*)" with range "([^"]*)" should be "([^"]*)"$/
* @param string $fileSource
* @param string $range
* @param string $content
*/
public function downloadedContentWhenDownloadindShouldBe($fileSource, $range, $content){
$this->downloadFileWithRange($fileSource, $range);
@ -108,6 +120,7 @@ trait WebDav {
/**
* @When Downloading file :fileName
* @param string $fileName
*/
public function downloadingFile($fileName) {
$this->response = $this->makeDavRequest($this->currentUser, 'GET', $fileName, []);
@ -115,6 +128,8 @@ trait WebDav {
/**
* @Then The following headers should be set
* @param \Behat\Gherkin\Node\TableNode $table
* @throws \Exception
*/
public function theFollowingHeadersShouldBeSet(\Behat\Gherkin\Node\TableNode $table) {
foreach($table->getTable() as $header) {
@ -136,6 +151,8 @@ trait WebDav {
/**
* @Then Downloaded content should start with :start
* @param int $start
* @throws \Exception
*/
public function downloadedContentShouldStartWith($start) {
if(strpos($this->response->getBody()->getContents(), $start) !== 0) {
@ -151,6 +168,8 @@ trait WebDav {
/**
* @Then /^as "([^"]*)" gets properties of folder "([^"]*)" with$/
* @param string $user
* @param string $path
* @param \Behat\Gherkin\Node\TableNode|null $propertiesTable
*/
public function asGetsPropertiesOfFolderWith($user, $path, $propertiesTable) {
@ -165,11 +184,14 @@ trait WebDav {
/**
* @Then the single response should contain a property :key with value :value
* @param string $key
* @param string $expectedValue
* @throws \Exception
*/
public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) {
$keys = $this->response;
if (!isset($keys[$key])) {
throw new \Exception("Cannot find property \"$key\" with \"$expectedalue\"");
throw new \Exception("Cannot find property \"$key\" with \"$expectedValue\"");
}
$value = $keys[$key];
@ -208,6 +230,7 @@ trait WebDav {
/**
* @Then /^user "([^"]*)" should see following elements$/
* @param string $user
* @param \Behat\Gherkin\Node\TableNode|null $expectedElements
*/
public function checkElementList($user, $expectedElements){
@ -226,6 +249,9 @@ trait WebDav {
/**
* @When User :user uploads file :source to :destination
* @param string $user
* @param string $source
* @param string $destination
*/
public function userUploadsAFileTo($user, $source, $destination)
{
@ -240,6 +266,8 @@ trait WebDav {
/**
* @When User :user deletes file :file
* @param string $user
* @param string $file
*/
public function userDeletesFile($user, $file) {
try {
@ -252,6 +280,8 @@ trait WebDav {
/**
* @Given User :user created a folder :destination
* @param string $user
* @param string $destination
*/
public function userCreatedAFolder($user, $destination){
try {
@ -264,6 +294,11 @@ trait WebDav {
/**
* @Given user :user uploads chunk file :num of :total with :data to :destination
* @param string $user
* @param int $num
* @param int $total
* @param string $data
* @param string $destination
*/
public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination)
{