Adjust integration tests to new guzzle

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-02-09 13:19:39 +01:00
parent 97b44605f4
commit 359ccbc023
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
17 changed files with 322 additions and 350 deletions

View File

@ -2,7 +2,7 @@
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.6", "phpunit/phpunit": "~4.6",
"behat/behat": "^3.0", "behat/behat": "^3.0",
"guzzlehttp/guzzle": "~5.0", "guzzlehttp/guzzle": "6.3.0",
"jarnaiz/behat-junit-formatter": "^1.3", "jarnaiz/behat-junit-formatter": "^1.3",
"sabre/dav": "3.2" "sabre/dav": "3.2"
} }

View File

@ -59,18 +59,20 @@ trait Auth {
$fullUrl = substr($this->baseUrl, 0, -5) . $url; $fullUrl = substr($this->baseUrl, 0, -5) . $url;
try { try {
if ($useCookies) { if ($useCookies) {
$request = $this->client->createRequest($method, $fullUrl, [ $options = [
'cookies' => $this->cookieJar, 'cookies' => $this->cookieJar,
]); ];
} else { } else {
$request = $this->client->createRequest($method, $fullUrl); $options = [];
} }
if ($authHeader) { if ($authHeader) {
$request->setHeader('Authorization', $authHeader); $options['headers'] = [
'Authorization' => $authHeader
];
} }
$request->setHeader('OCS_APIREQUEST', 'true'); $options['headers']['OCS_APIREQUEST'] = 'true';
$request->setHeader('requesttoken', $this->requestToken); $options['headers']['requesttoken'] = $this->requestToken;
$this->response = $this->client->send($request); $this->response = $this->client->request($method, $fullUrl, $options);
} catch (ClientException $ex) { } catch (ClientException $ex) {
$this->response = $ex->getResponse(); $this->response = $ex->getResponse();
} catch (ServerException $ex) { } catch (ServerException $ex) {
@ -90,7 +92,7 @@ trait Auth {
* @return object * @return object
*/ */
private function createClientToken($loginViaWeb = true) { private function createClientToken($loginViaWeb = true) {
if($loginViaWeb) { if ($loginViaWeb) {
$this->loggingInUsingWebAs('user0'); $this->loggingInUsingWebAs('user0');
} }
@ -101,7 +103,7 @@ trait Auth {
'user0', 'user0',
$loginViaWeb ? '123456' : $this->restrictedClientToken, $loginViaWeb ? '123456' : $this->restrictedClientToken,
], ],
'body' => [ 'form_params' => [
'requesttoken' => $this->requestToken, 'requesttoken' => $this->requestToken,
'name' => md5(microtime()), 'name' => md5(microtime()),
], ],
@ -109,7 +111,7 @@ trait Auth {
]; ];
try { try {
$this->response = $client->send($client->createRequest('POST', $fullUrl, $options)); $this->response = $client->request('POST', $fullUrl, $options);
} catch (\GuzzleHttp\Exception\ServerException $e) { } catch (\GuzzleHttp\Exception\ServerException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -119,7 +121,7 @@ trait Auth {
/** /**
* @Given a new restricted client token is added * @Given a new restricted client token is added
*/ */
public function aNewRestrictedClientTokenIsAdded() { public function aNewRestrictedClientTokenIsAdded() {
$tokenObj = $this->createClientToken(); $tokenObj = $this->createClientToken();
$newCreatedTokenId = $tokenObj->deviceToken->id; $newCreatedTokenId = $tokenObj->deviceToken->id;
$fullUrl = substr($this->baseUrl, 0, -5) . '/index.php/settings/personal/authtokens/' . $newCreatedTokenId; $fullUrl = substr($this->baseUrl, 0, -5) . '/index.php/settings/personal/authtokens/' . $newCreatedTokenId;
@ -136,7 +138,7 @@ trait Auth {
], ],
'cookies' => $this->cookieJar, 'cookies' => $this->cookieJar,
]; ];
$this->response = $client->send($client->createRequest('PUT', $fullUrl, $options)); $this->response = $client->request('PUT', $fullUrl, $options);
$this->restrictedClientToken = $tokenObj->token; $this->restrictedClientToken = $tokenObj->token;
} }
@ -232,13 +234,13 @@ trait Auth {
$client = new Client(); $client = new Client();
$response = $client->post( $response = $client->post(
$loginUrl, [ $loginUrl, [
'body' => [ 'form_params' => [
'user' => 'user0', 'user' => 'user0',
'password' => '123456', 'password' => '123456',
'remember_login' => $remember ? '1' : '0', 'remember_login' => $remember ? '1' : '0',
'requesttoken' => $this->requestToken, 'requesttoken' => $this->requestToken,
], ],
'cookies' => $this->cookieJar, 'cookies' => $this->cookieJar,
] ]
); );
$this->extracRequestTokenFromResponse($response); $this->extracRequestTokenFromResponse($response);

View File

@ -32,7 +32,7 @@
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar; use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
require __DIR__ . '/../../vendor/autoload.php'; require __DIR__ . '/../../vendor/autoload.php';
@ -97,7 +97,7 @@ trait BasicStructure {
* @param string $version * @param string $version
*/ */
public function usingApiVersion($version) { public function usingApiVersion($version) {
$this->apiVersion = (int) $version; $this->apiVersion = (int)$version;
} }
/** /**
@ -115,7 +115,7 @@ trait BasicStructure {
*/ */
public function usingServer($server) { public function usingServer($server) {
$previousServer = $this->currentServer; $previousServer = $this->currentServer;
if ($server === 'LOCAL'){ if ($server === 'LOCAL') {
$this->baseUrl = $this->localBaseUrl; $this->baseUrl = $this->localBaseUrl;
$this->currentServer = 'LOCAL'; $this->currentServer = 'LOCAL';
return $previousServer; return $previousServer;
@ -138,20 +138,24 @@ trait BasicStructure {
/** /**
* Parses the xml answer to get ocs response which doesn't match with * Parses the xml answer to get ocs response which doesn't match with
* http one in v1 of the api. * http one in v1 of the api.
*
* @param ResponseInterface $response * @param ResponseInterface $response
* @return string * @return string
*/ */
public function getOCSResponse($response) { public function getOCSResponse($response) {
return $response->xml()->meta[0]->statuscode; return simplexml_load_string($response->getBody())->meta[0]->statuscode;
} }
/** /**
* This function is needed to use a vertical fashion in the gherkin tables. * This function is needed to use a vertical fashion in the gherkin tables.
*
* @param array $arrayOfArrays * @param array $arrayOfArrays
* @return array * @return array
*/ */
public function simplifyArray($arrayOfArrays){ public function simplifyArray($arrayOfArrays) {
$a = array_map(function($subArray) { return $subArray[0]; }, $arrayOfArrays); $a = array_map(function ($subArray) {
return $subArray[0];
}, $arrayOfArrays);
return $a; return $a;
} }
@ -175,18 +179,18 @@ trait BasicStructure {
]; ];
if ($body instanceof \Behat\Gherkin\Node\TableNode) { if ($body instanceof \Behat\Gherkin\Node\TableNode) {
$fd = $body->getRowsHash(); $fd = $body->getRowsHash();
$options['body'] = $fd; $options['form_params'] = $fd;
} }
// TODO: Fix this hack! // TODO: Fix this hack!
if ($verb === 'PUT' && $body === null) { if ($verb === 'PUT' && $body === null) {
$options['body'] = [ $options['form_params'] = [
'foo' => 'bar', 'foo' => 'bar',
]; ];
} }
try { try {
$this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); $this->response = $client->request($verb, $fullUrl, $options);
} catch (ClientException $ex) { } catch (ClientException $ex) {
$this->response = $ex->getResponse(); $this->response = $ex->getResponse();
} }
@ -212,20 +216,20 @@ trait BasicStructure {
} }
if ($body instanceof \Behat\Gherkin\Node\TableNode) { if ($body instanceof \Behat\Gherkin\Node\TableNode) {
$fd = $body->getRowsHash(); $fd = $body->getRowsHash();
$options['body'] = $fd; $options['form_params'] = $fd;
} }
try { try {
$this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); $this->response = $client->request($verb, $fullUrl, $options);
} catch (ClientException $ex) { } catch (ClientException $ex) {
$this->response = $ex->getResponse(); $this->response = $ex->getResponse();
} }
} }
public function isExpectedUrl($possibleUrl, $finalPart){ public function isExpectedUrl($possibleUrl, $finalPart) {
$baseUrlChopped = substr($this->baseUrl, 0, -4); $baseUrlChopped = substr($this->baseUrl, 0, -4);
$endCharacter = strlen($baseUrlChopped) + strlen($finalPart); $endCharacter = strlen($baseUrlChopped) + strlen($finalPart);
return (substr($possibleUrl,0,$endCharacter) == "$baseUrlChopped" . "$finalPart"); return (substr($possibleUrl, 0, $endCharacter) == "$baseUrlChopped" . "$finalPart");
} }
/** /**
@ -249,13 +253,13 @@ trait BasicStructure {
* @param string $contentType * @param string $contentType
*/ */
public function theContentTypeShouldbe($contentType) { public function theContentTypeShouldbe($contentType) {
PHPUnit_Framework_Assert::assertEquals($contentType, $this->response->getHeader('Content-Type')); PHPUnit_Framework_Assert::assertEquals($contentType, $this->response->getHeader('Content-Type')[0]);
} }
/** /**
* @param ResponseInterface $response * @param ResponseInterface $response
*/ */
private function extracRequestTokenFromResponse(ResponseInterface $response) { private function extracRequestTokenFromResponse(\Psr\Http\Message\ResponseInterface $response) {
$this->requestToken = substr(preg_replace('/(.*)data-requesttoken="(.*)">(.*)/sm', '\2', $response->getBody()->getContents()), 0, 89); $this->requestToken = substr(preg_replace('/(.*)data-requesttoken="(.*)">(.*)/sm', '\2', $response->getBody()->getContents()), 0, 89);
} }
@ -281,7 +285,7 @@ trait BasicStructure {
$response = $client->post( $response = $client->post(
$loginUrl, $loginUrl,
[ [
'body' => [ 'form_params' => [
'user' => $user, 'user' => $user,
'password' => $password, 'password' => $password,
'requesttoken' => $this->requestToken, 'requesttoken' => $this->requestToken,
@ -301,16 +305,17 @@ trait BasicStructure {
$baseUrl = substr($this->baseUrl, 0, -5); $baseUrl = substr($this->baseUrl, 0, -5);
$client = new Client(); $client = new Client();
$request = $client->createRequest(
$method,
$baseUrl . $url,
[
'cookies' => $this->cookieJar,
]
);
$request->addHeader('requesttoken', $this->requestToken);
try { try {
$this->response = $client->send($request); $this->response = $client->request(
$method,
$baseUrl . $url,
[
'cookies' => $this->cookieJar,
'headers' => [
'requesttoken' => $this->requestToken
]
]
);
} catch (ClientException $e) { } catch (ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -325,21 +330,20 @@ trait BasicStructure {
$baseUrl = substr($this->baseUrl, 0, -5); $baseUrl = substr($this->baseUrl, 0, -5);
$client = new Client(); $client = new Client();
$request = $client->createRequest(
$method,
$baseUrl . $url,
[
'cookies' => $this->cookieJar,
]
);
try { try {
$this->response = $client->send($request); $this->response = $client->request(
$method,
$baseUrl . $url,
[
'cookies' => $this->cookieJar
]
);
} catch (ClientException $e) { } catch (ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
} }
public static function removeFile($path, $filename){ public static function removeFile($path, $filename) {
if (file_exists("$path" . "$filename")) { if (file_exists("$path" . "$filename")) {
unlink("$path" . "$filename"); unlink("$path" . "$filename");
} }
@ -358,12 +362,12 @@ trait BasicStructure {
public function createFileSpecificSize($name, $size) { public function createFileSpecificSize($name, $size) {
$file = fopen("work/" . "$name", 'w'); $file = fopen("work/" . "$name", 'w');
fseek($file, $size - 1 ,SEEK_CUR); fseek($file, $size - 1, SEEK_CUR);
fwrite($file,'a'); // write a dummy char at SIZE position fwrite($file, 'a'); // write a dummy char at SIZE position
fclose($file); fclose($file);
} }
public function createFileWithText($name, $text){ public function createFileWithText($name, $text) {
$file = fopen("work/" . "$name", 'w'); $file = fopen("work/" . "$name", 'w');
fwrite($file, $text); fwrite($file, $text);
fclose($file); fclose($file);
@ -398,8 +402,8 @@ trait BasicStructure {
/** /**
* @BeforeSuite * @BeforeSuite
*/ */
public static function addFilesToSkeleton(){ public static function addFilesToSkeleton() {
for ($i=0; $i<5; $i++){ for ($i = 0; $i < 5; $i++) {
file_put_contents("../../core/skeleton/" . "textfile" . "$i" . ".txt", "Nextcloud test text file\n"); file_put_contents("../../core/skeleton/" . "textfile" . "$i" . ".txt", "Nextcloud test text file\n");
} }
if (!file_exists("../../core/skeleton/FOLDER")) { if (!file_exists("../../core/skeleton/FOLDER")) {
@ -418,8 +422,8 @@ trait BasicStructure {
/** /**
* @AfterSuite * @AfterSuite
*/ */
public static function removeFilesFromSkeleton(){ public static function removeFilesFromSkeleton() {
for ($i=0; $i<5; $i++){ for ($i = 0; $i < 5; $i++) {
self::removeFile("../../core/skeleton/", "textfile" . "$i" . ".txt"); self::removeFile("../../core/skeleton/", "textfile" . "$i" . ".txt");
} }
if (is_dir("../../core/skeleton/FOLDER")) { if (is_dir("../../core/skeleton/FOLDER")) {
@ -438,24 +442,24 @@ trait BasicStructure {
/** /**
* @BeforeScenario @local_storage * @BeforeScenario @local_storage
*/ */
public static function removeFilesFromLocalStorageBefore(){ public static function removeFilesFromLocalStorageBefore() {
$dir = "./work/local_storage/"; $dir = "./work/local_storage/";
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS); $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST); $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) { foreach ($ri as $file) {
$file->isDir() ? rmdir($file) : unlink($file); $file->isDir() ? rmdir($file) : unlink($file);
} }
} }
/** /**
* @AfterScenario @local_storage * @AfterScenario @local_storage
*/ */
public static function removeFilesFromLocalStorageAfter(){ public static function removeFilesFromLocalStorageAfter() {
$dir = "./work/local_storage/"; $dir = "./work/local_storage/";
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS); $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST); $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) { foreach ($ri as $file) {
$file->isDir() ? rmdir($file) : unlink($file); $file->isDir() ? rmdir($file) : unlink($file);
} }
} }
} }

View File

@ -83,7 +83,7 @@ class CalDavContext implements \Behat\Behat\Context\Context {
$password = ($user === 'admin') ? 'admin' : '123456'; $password = ($user === 'admin') ? 'admin' : '123456';
try { try {
$request = $this->client->createRequest( $this->response = $this->client->request(
'PROPFIND', 'PROPFIND',
$davUrl, $davUrl,
[ [
@ -93,7 +93,6 @@ class CalDavContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -170,7 +169,7 @@ class CalDavContext implements \Behat\Behat\Context\Context {
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$user.'/'.$name; $davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$user.'/'.$name;
$password = ($user === 'admin') ? 'admin' : '123456'; $password = ($user === 'admin') ? 'admin' : '123456';
$request = $this->client->createRequest( $this->response = $this->client->request(
'MKCALENDAR', 'MKCALENDAR',
$davUrl, $davUrl,
[ [
@ -181,8 +180,6 @@ class CalDavContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} }
/** /**
@ -195,7 +192,7 @@ class CalDavContext implements \Behat\Behat\Context\Context {
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$user.'/'.$name; $davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$user.'/'.$name;
$password = ($user === 'admin') ? 'admin' : '123456'; $password = ($user === 'admin') ? 'admin' : '123456';
$request = $this->client->createRequest( $this->response = $this->client->request(
'POST', 'POST',
$davUrl, $davUrl,
[ [
@ -209,8 +206,6 @@ class CalDavContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} }
/** /**

View File

@ -44,7 +44,7 @@ class CapabilitiesContext implements Context, SnippetAcceptingContext {
* @param \Behat\Gherkin\Node\TableNode|null $formData * @param \Behat\Gherkin\Node\TableNode|null $formData
*/ */
public function checkCapabilitiesResponse(\Behat\Gherkin\Node\TableNode $formData){ public function checkCapabilitiesResponse(\Behat\Gherkin\Node\TableNode $formData){
$capabilitiesXML = $this->response->xml()->data->capabilities; $capabilitiesXML = simplexml_load_string($this->response->getBody())->data->capabilities;
foreach ($formData->getHash() as $row) { foreach ($formData->getHash() as $row) {
$path_to_element = explode('@@@', $row['path_to_element']); $path_to_element = explode('@@@', $row['path_to_element']);

View File

@ -86,7 +86,7 @@ class CardDavContext implements \Behat\Behat\Context\Context {
$password = ($user === 'admin') ? 'admin' : '123456'; $password = ($user === 'admin') ? 'admin' : '123456';
try { try {
$request = $this->client->createRequest( $this->response = $this->client->request(
'PROPFIND', 'PROPFIND',
$davUrl, $davUrl,
[ [
@ -96,7 +96,6 @@ class CardDavContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -130,7 +129,7 @@ class CardDavContext implements \Behat\Behat\Context\Context {
$davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook; $davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook;
$password = ($user === 'admin') ? 'admin' : '123456'; $password = ($user === 'admin') ? 'admin' : '123456';
$request = $this->client->createRequest( $this->response = $this->client->request(
'MKCOL', 'MKCOL',
$davUrl, $davUrl,
[ [
@ -154,8 +153,6 @@ class CardDavContext implements \Behat\Behat\Context\Context {
] ]
); );
$this->response = $this->client->send($request);
if($this->response->getStatusCode() !== (int)$statusCode) { if($this->response->getStatusCode() !== (int)$statusCode) {
throw new \Exception( throw new \Exception(
sprintf( sprintf(
@ -212,7 +209,7 @@ class CardDavContext implements \Behat\Behat\Context\Context {
$davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook . '/' . $fileName; $davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook . '/' . $fileName;
$password = ($user === 'admin') ? 'admin' : '123456'; $password = ($user === 'admin') ? 'admin' : '123456';
$request = $this->client->createRequest( $this->response = $this->client->request(
'PUT', 'PUT',
$davUrl, $davUrl,
[ [
@ -227,8 +224,6 @@ class CardDavContext implements \Behat\Behat\Context\Context {
] ]
); );
$this->response = $this->client->send($request);
if($this->response->getStatusCode() !== 201) { if($this->response->getStatusCode() !== 201) {
throw new \Exception( throw new \Exception(
sprintf( sprintf(
@ -248,7 +243,7 @@ class CardDavContext implements \Behat\Behat\Context\Context {
$password = ($user === 'admin') ? 'admin' : '123456'; $password = ($user === 'admin') ? 'admin' : '123456';
try { try {
$request = $this->client->createRequest( $this->response = $this->client->request(
'GET', 'GET',
$davUrl, $davUrl,
[ [
@ -261,7 +256,6 @@ class CardDavContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -275,7 +269,7 @@ class CardDavContext implements \Behat\Behat\Context\Context {
$password = ($user === 'admin') ? 'admin' : '123456'; $password = ($user === 'admin') ? 'admin' : '123456';
try { try {
$request = $this->client->createRequest( $this->response = $this->client->request(
'GET', 'GET',
$davUrl, $davUrl,
[ [
@ -288,7 +282,6 @@ class CardDavContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -303,7 +296,7 @@ class CardDavContext implements \Behat\Behat\Context\Context {
foreach($table->getTable() as $header) { foreach($table->getTable() as $header) {
$headerName = $header[0]; $headerName = $header[0];
$expectedHeaderValue = $header[1]; $expectedHeaderValue = $header[1];
$returnedHeader = $this->response->getHeader($headerName); $returnedHeader = $this->response->getHeader($headerName)[0];
if($returnedHeader !== $expectedHeaderValue) { if($returnedHeader !== $expectedHeaderValue) {
throw new \Exception( throw new \Exception(
sprintf( sprintf(

View File

@ -78,7 +78,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
*/ */
public function userUploadsFileToWithChecksum($user, $source, $destination, $checksum) public function userUploadsFileToWithChecksum($user, $source, $destination, $checksum)
{ {
$file = \GuzzleHttp\Stream\Stream::factory(fopen($source, 'r')); $file = \GuzzleHttp\Psr7\stream_for(fopen($source, 'r'));
try { try {
$this->response = $this->client->put( $this->response = $this->client->put(
$this->baseUrl . '/remote.php/webdav' . $destination, $this->baseUrl . '/remote.php/webdav' . $destination,
@ -117,7 +117,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
*/ */
public function userRequestTheChecksumOfViaPropfind($user, $path) public function userRequestTheChecksumOfViaPropfind($user, $path)
{ {
$request = $this->client->createRequest( $this->response = $this->client->request(
'PROPFIND', 'PROPFIND',
$this->baseUrl . '/remote.php/webdav' . $path, $this->baseUrl . '/remote.php/webdav' . $path,
[ [
@ -133,7 +133,6 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
] ]
] ]
); );
$this->response = $this->client->send($request);
} }
/** /**
@ -182,8 +181,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
*/ */
public function theHeaderChecksumShouldMatch($checksum) public function theHeaderChecksumShouldMatch($checksum)
{ {
if ($this->response->getHeader('OC-Checksum') !== $checksum) { if ($this->response->getHeader('OC-Checksum')[0] !== $checksum) {
throw new \Exception("Expected $checksum, got ".$this->response->getHeader('OC-Checksum')); throw new \Exception("Expected $checksum, got ".$this->response->getHeader('OC-Checksum')[0]);
} }
} }
@ -195,7 +194,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
*/ */
public function userCopiedFileTo($user, $source, $destination) public function userCopiedFileTo($user, $source, $destination)
{ {
$request = $this->client->createRequest( $this->response = $this->client->request(
'MOVE', 'MOVE',
$this->baseUrl . '/remote.php/webdav' . $source, $this->baseUrl . '/remote.php/webdav' . $source,
[ [
@ -208,7 +207,6 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} }
/** /**
@ -236,7 +234,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context {
public function theOcChecksumHeaderShouldNotBeThere() public function theOcChecksumHeaderShouldNotBeThere()
{ {
if ($this->response->hasHeader('OC-Checksum')) { if ($this->response->hasHeader('OC-Checksum')) {
throw new \Exception("Expected no checksum header but got ".$this->response->getHeader('OC-Checksum')); throw new \Exception("Expected no checksum header but got ".$this->response->getHeader('OC-Checksum')[0]);
} }
} }

View File

@ -59,8 +59,7 @@ trait CommandLine {
// Clean opcode cache // Clean opcode cache
$client = new GuzzleHttp\Client(); $client = new GuzzleHttp\Client();
$request = $client->createRequest('GET', 'http://localhost:8080/apps/testing/clean_opcode_cache.php'); $client->request('GET', 'http://localhost:8080/apps/testing/clean_opcode_cache.php');
$client->send($request);
return $this->lastCode; return $this->lastCode;
} }

View File

@ -52,7 +52,7 @@ class CommentsContext implements \Behat\Behat\Context\Context {
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
try { try {
$client->delete( $client->delete(
$this->baseUrl.'/remote.php/webdav/myFileToComment.txt', $this->baseUrl . '/remote.php/webdav/myFileToComment.txt',
[ [
'auth' => [ 'auth' => [
'user0', 'user0',
@ -73,7 +73,7 @@ class CommentsContext implements \Behat\Behat\Context\Context {
* @return int * @return int
*/ */
private function getFileIdForPath($path) { private function getFileIdForPath($path) {
$url = $this->baseUrl.'/remote.php/webdav/'.$path; $url = $this->baseUrl . '/remote.php/webdav/' . $path;
$context = stream_context_create(array( $context = stream_context_create(array(
'http' => array( 'http' => array(
'method' => 'PROPFIND', 'method' => 'PROPFIND',
@ -100,10 +100,10 @@ class CommentsContext implements \Behat\Behat\Context\Context {
* @param int $statusCode * @param int $statusCode
* @throws \Exception * @throws \Exception
*/ */
public function postsACommentWithContentOnTheFileNamedItShouldReturn($user, $content, $fileName, $statusCode) { public function postsACommentWithContentOnTheFileNamedItShouldReturn($user, $content, $fileName, $statusCode) {
$fileId = $this->getFileIdForPath($fileName); $fileId = $this->getFileIdForPath($fileName);
$this->fileId = (int)$fileId; $this->fileId = (int)$fileId;
$url = $this->baseUrl.'/remote.php/dav/comments/files/'.$fileId.'/'; $url = $this->baseUrl . '/remote.php/dav/comments/files/' . $fileId . '/';
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
try { try {
@ -124,8 +124,8 @@ class CommentsContext implements \Behat\Behat\Context\Context {
$res = $e->getResponse(); $res = $e->getResponse();
} }
if($res->getStatusCode() !== (int)$statusCode) { if ($res->getStatusCode() !== (int)$statusCode) {
throw new \Exception("Response status code was not $statusCode (".$res->getStatusCode().")"); throw new \Exception("Response status code was not $statusCode (" . $res->getStatusCode() . ")");
} }
} }
@ -139,11 +139,11 @@ class CommentsContext implements \Behat\Behat\Context\Context {
*/ */
public function asLoadloadAllTheCommentsOfTheFileNamedItShouldReturn($user, $fileName, $statusCode) { public function asLoadloadAllTheCommentsOfTheFileNamedItShouldReturn($user, $fileName, $statusCode) {
$fileId = $this->getFileIdForPath($fileName); $fileId = $this->getFileIdForPath($fileName);
$url = $this->baseUrl.'/remote.php/dav/comments/files/'.$fileId.'/'; $url = $this->baseUrl . '/remote.php/dav/comments/files/' . $fileId . '/';
try { try {
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
$res = $client->createRequest( $res = $client->request(
'REPORT', 'REPORT',
$url, $url,
[ [
@ -162,16 +162,15 @@ class CommentsContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$res = $client->send($res);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$res = $e->getResponse(); $res = $e->getResponse();
} }
if($res->getStatusCode() !== (int)$statusCode) { if ($res->getStatusCode() !== (int)$statusCode) {
throw new \Exception("Response status code was not $statusCode (".$res->getStatusCode().")"); throw new \Exception("Response status code was not $statusCode (" . $res->getStatusCode() . ")");
} }
if($res->getStatusCode() === 207) { if ($res->getStatusCode() === 207) {
$service = new Sabre\Xml\Service(); $service = new Sabre\Xml\Service();
$this->response = $service->parse($res->getBody()->getContents()); $this->response = $service->parse($res->getBody()->getContents());
$this->commentId = (int)$this->response[0]['value'][2]['value'][0]['value'][0]['value']; $this->commentId = (int)$this->response[0]['value'][2]['value'][0]['value'][0]['value'];
@ -191,11 +190,11 @@ class CommentsContext implements \Behat\Behat\Context\Context {
$options = []; $options = [];
$options['auth'] = [$user, '123456']; $options['auth'] = [$user, '123456'];
$fd = $body->getRowsHash(); $fd = $body->getRowsHash();
$options['body'] = $fd; $options['form_params'] = $fd;
$options['headers'] = [ $options['headers'] = [
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$client->send($client->createRequest($verb, $this->baseUrl.'/ocs/v1.php/'.$url, $options)); $client->request($verb, $this->baseUrl . '/ocs/v1.php/' . $url, $options);
} }
/** /**
@ -205,7 +204,7 @@ class CommentsContext implements \Behat\Behat\Context\Context {
* @throws \Exception * @throws \Exception
*/ */
public function asDeleteTheCreatedCommentItShouldReturn($user, $statusCode) { public function asDeleteTheCreatedCommentItShouldReturn($user, $statusCode) {
$url = $this->baseUrl.'/remote.php/dav/comments/files/'.$this->fileId.'/'.$this->commentId; $url = $this->baseUrl . '/remote.php/dav/comments/files/' . $this->fileId . '/' . $this->commentId;
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
try { try {
@ -225,8 +224,8 @@ class CommentsContext implements \Behat\Behat\Context\Context {
$res = $e->getResponse(); $res = $e->getResponse();
} }
if($res->getStatusCode() !== (int)$statusCode) { if ($res->getStatusCode() !== (int)$statusCode) {
throw new \Exception("Response status code was not $statusCode (".$res->getStatusCode().")"); throw new \Exception("Response status code was not $statusCode (" . $res->getStatusCode() . ")");
} }
} }
@ -239,14 +238,14 @@ class CommentsContext implements \Behat\Behat\Context\Context {
public function theResponseShouldContainAPropertyWithValue($key, $value) { public function theResponseShouldContainAPropertyWithValue($key, $value) {
$keys = $this->response[0]['value'][2]['value'][0]['value']; $keys = $this->response[0]['value'][2]['value'][0]['value'];
$found = false; $found = false;
foreach($keys as $singleKey) { foreach ($keys as $singleKey) {
if($singleKey['name'] === '{http://owncloud.org/ns}'.substr($key, 3)) { if ($singleKey['name'] === '{http://owncloud.org/ns}' . substr($key, 3)) {
if($singleKey['value'] === $value) { if ($singleKey['value'] === $value) {
$found = true; $found = true;
} }
} }
} }
if($found === false) { if ($found === false) {
throw new \Exception("Cannot find property $key with $value"); throw new \Exception("Cannot find property $key with $value");
} }
} }
@ -257,8 +256,8 @@ class CommentsContext implements \Behat\Behat\Context\Context {
* @throws \Exception * @throws \Exception
*/ */
public function theResponseShouldContainOnlyComments($number) { public function theResponseShouldContainOnlyComments($number) {
if(count($this->response) !== (int)$number) { if (count($this->response) !== (int)$number) {
throw new \Exception("Found more comments than $number (".count($this->response).")"); throw new \Exception("Found more comments than $number (" . count($this->response) . ")");
} }
} }
@ -277,18 +276,18 @@ class CommentsContext implements \Behat\Behat\Context\Context {
<d:propertyupdate xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"> <d:propertyupdate xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:set> <d:set>
<d:prop> <d:prop>
<oc:message>'.$text.'</oc:message> <oc:message>' . $text . '</oc:message>
</d:prop> </d:prop>
</d:set> </d:set>
</d:propertyupdate>'; </d:propertyupdate>';
try { try {
$res = $client->send($client->createRequest('PROPPATCH', $this->baseUrl.'/remote.php/dav/comments/files/' . $this->fileId . '/' . $this->commentId, $options)); $res = $client->request('PROPPATCH', $this->baseUrl . '/remote.php/dav/comments/files/' . $this->fileId . '/' . $this->commentId, $options);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$res = $e->getResponse(); $res = $e->getResponse();
} }
if($res->getStatusCode() !== (int)$statusCode) { if ($res->getStatusCode() !== (int)$statusCode) {
throw new \Exception("Response status code was not $statusCode (".$res->getStatusCode().")"); throw new \Exception("Response status code was not $statusCode (" . $res->getStatusCode() . ")");
} }
} }

View File

@ -67,7 +67,7 @@ class FederationContext implements Context, SnippetAcceptingContext {
$this->sendingToWith('GET', "/apps/files_sharing/api/v1/remote_shares/pending", null); $this->sendingToWith('GET', "/apps/files_sharing/api/v1/remote_shares/pending", null);
$this->theHTTPStatusCodeShouldBe('200'); $this->theHTTPStatusCodeShouldBe('200');
$this->theOCSStatusCodeShouldBe('100'); $this->theOCSStatusCodeShouldBe('100');
$share_id = $this->response->xml()->data[0]->element[0]->id; $share_id = simplexml_load_string($this->response->getBody())->data[0]->element[0]->id;
$this->sendingToWith('POST', "/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}", null); $this->sendingToWith('POST', "/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}", null);
$this->theHTTPStatusCodeShouldBe('200'); $this->theHTTPStatusCodeShouldBe('200');
$this->theOCSStatusCodeShouldBe('100'); $this->theOCSStatusCodeShouldBe('100');

View File

@ -50,13 +50,10 @@ class FilesDropContext implements Context, SnippetAcceptingContext {
$options['headers'] = [ $options['headers'] = [
'X-REQUESTED-WITH' => 'XMLHttpRequest' 'X-REQUESTED-WITH' => 'XMLHttpRequest'
]; ];
$options['body'] = \GuzzleHttp\Psr7\stream_for($content);
$request = $client->createRequest('PUT', $fullUrl, $options);
$file = \GuzzleHttp\Stream\Stream::factory($content);
$request->setBody($file);
try { try {
$this->response = $client->send($request); $this->response = $client->request('PUT', $fullUrl, $options);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -82,10 +79,8 @@ class FilesDropContext implements Context, SnippetAcceptingContext {
'X-REQUESTED-WITH' => 'XMLHttpRequest' 'X-REQUESTED-WITH' => 'XMLHttpRequest'
]; ];
$request = $client->createRequest('MKCOL', $fullUrl, $options);
try { try {
$this->response = $client->send($request); $this->response = $client->request('MKCOL', $fullUrl, $options);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }

View File

@ -35,7 +35,7 @@ class LDAPContext implements Context {
* @Given /^the response should contain a tag "([^"]*)"$/ * @Given /^the response should contain a tag "([^"]*)"$/
*/ */
public function theResponseShouldContainATag($arg1) { public function theResponseShouldContainATag($arg1) {
$configID = $this->response->xml()->data[0]->$arg1; $configID = simplexml_load_string($this->response->getBody())->data[0]->$arg1;
PHPUnit_Framework_Assert::assertInstanceOf(SimpleXMLElement::class, $configID[0]); PHPUnit_Framework_Assert::assertInstanceOf(SimpleXMLElement::class, $configID[0]);
} }
@ -45,7 +45,7 @@ class LDAPContext implements Context {
public function creatingAnLDAPConfigurationAt($apiUrl) { public function creatingAnLDAPConfigurationAt($apiUrl) {
$this->apiUrl = $apiUrl; $this->apiUrl = $apiUrl;
$this->sendingToWith('POST', $this->apiUrl, null); $this->sendingToWith('POST', $this->apiUrl, null);
$configElements = $this->response->xml()->data[0]->configID; $configElements = simplexml_load_string($this->response->getBody())->data[0]->configID;
$this->configID = $configElements[0]; $this->configID = $configElements[0];
} }
@ -60,7 +60,7 @@ class LDAPContext implements Context {
* @Given /^the response should contain a tag "([^"]*)" with value "([^"]*)"$/ * @Given /^the response should contain a tag "([^"]*)" with value "([^"]*)"$/
*/ */
public function theResponseShouldContainATagWithValue($tagName, $expectedValue) { public function theResponseShouldContainATagWithValue($tagName, $expectedValue) {
$data = $this->response->xml()->data[0]->$tagName; $data = simplexml_load_string($this->response->getBody())->data[0]->$tagName;
PHPUnit_Framework_Assert::assertEquals($expectedValue, $data[0]); PHPUnit_Framework_Assert::assertEquals($expectedValue, $data[0]);
} }

View File

@ -26,6 +26,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface; use GuzzleHttp\Message\ResponseInterface;
@ -95,7 +96,7 @@ trait Provisioning {
$options['auth'] = $this->adminUser; $options['auth'] = $this->adminUser;
} }
$options['body'] = [ $options['form_params'] = [
'userid' => $user, 'userid' => $user,
'password' => '123456' 'password' => '123456'
]; ];
@ -103,8 +104,8 @@ trait Provisioning {
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); $this->response = $client->post($fullUrl, $options);
if ($this->currentServer === 'LOCAL'){ if ($this->currentServer === 'LOCAL') {
$this->createdUsers[$user] = $user; $this->createdUsers[$user] = $user;
} elseif ($this->currentServer === 'REMOTE') { } elseif ($this->currentServer === 'REMOTE') {
$this->createdRemoteUsers[$user] = $user; $this->createdRemoteUsers[$user] = $user;
@ -117,8 +118,8 @@ trait Provisioning {
$options2['headers'] = [ $options2['headers'] = [
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$url = $fullUrl.'/'.$user; $url = $fullUrl . '/' . $user;
$client->send($client->createRequest('GET', $url, $options2)); $client->get($url, $options2);
} }
/** /**
@ -136,9 +137,9 @@ trait Provisioning {
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$response = $client->send($client->createRequest("GET", $fullUrl, $options)); $response = $client->get($fullUrl, $options);
foreach ($settings->getRows() as $setting) { foreach ($settings->getRows() as $setting) {
$value = json_decode(json_encode($response->xml()->data->{$setting[0]}), 1); $value = json_decode(json_encode(simplexml_load_string($response->getBody())->data->{$setting[0]}), 1);
if (isset($value[0])) { if (isset($value[0])) {
PHPUnit_Framework_Assert::assertEquals($setting[1], $value[0], "", 0.0, 10, true); PHPUnit_Framework_Assert::assertEquals($setting[1], $value[0], "", 0.0, 10, true);
} else { } else {
@ -179,7 +180,7 @@ trait Provisioning {
$this->currentUser = $previous_user; $this->currentUser = $previous_user;
} }
public function userExists($user){ public function userExists($user) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user"; $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user";
$client = new Client(); $client = new Client();
$options = []; $options = [];
@ -229,9 +230,9 @@ trait Provisioning {
$respondedArray = $this->getArrayOfGroupsResponded($this->response); $respondedArray = $this->getArrayOfGroupsResponded($this->response);
if (array_key_exists($group, $respondedArray)) { if (array_key_exists($group, $respondedArray)) {
return True; return true;
} else{ } else {
return False; return false;
} }
} }
@ -240,11 +241,11 @@ trait Provisioning {
* @param string $user * @param string $user
* @param string $group * @param string $group
*/ */
public function assureUserBelongsToGroup($user, $group){ public function assureUserBelongsToGroup($user, $group) {
$previous_user = $this->currentUser; $previous_user = $this->currentUser;
$this->currentUser = "admin"; $this->currentUser = "admin";
if (!$this->userBelongsToGroup($user, $group)){ if (!$this->userBelongsToGroup($user, $group)) {
$this->addingUserToGroup($user, $group); $this->addingUserToGroup($user, $group);
} }
@ -287,15 +288,15 @@ trait Provisioning {
$options['auth'] = $this->adminUser; $options['auth'] = $this->adminUser;
} }
$options['body'] = [ $options['form_params'] = [
'groupid' => $group, 'groupid' => $group,
]; ];
$options['headers'] = [ $options['headers'] = [
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); $this->response = $client->post($fullUrl, $options);
if ($this->currentServer === 'LOCAL'){ if ($this->currentServer === 'LOCAL') {
$this->createdGroups[$group] = $group; $this->createdGroups[$group] = $group;
} elseif ($this->currentServer === 'REMOTE') { } elseif ($this->currentServer === 'REMOTE') {
$this->createdRemoteGroups[$group] = $group; $this->createdRemoteGroups[$group] = $group;
@ -316,11 +317,11 @@ trait Provisioning {
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
// TODO: fix hack // TODO: fix hack
$options['body'] = [ $options['form_params'] = [
'foo' => 'bar' 'foo' => 'bar'
]; ];
$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options)); $this->response = $client->put($fullUrl, $options);
} }
/** /**
@ -338,7 +339,7 @@ trait Provisioning {
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options)); $this->response = $client->delete($fullUrl, $options);
} }
/** /**
@ -356,9 +357,9 @@ trait Provisioning {
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options)); $this->response = $client->delete($fullUrl, $options);
if ($this->currentServer === 'LOCAL'){ if ($this->currentServer === 'LOCAL') {
unset($this->createdGroups[$group]); unset($this->createdGroups[$group]);
} elseif ($this->currentServer === 'REMOTE') { } elseif ($this->currentServer === 'REMOTE') {
unset($this->createdRemoteGroups[$group]); unset($this->createdRemoteGroups[$group]);
@ -393,11 +394,11 @@ trait Provisioning {
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$options['body'] = [ $options['form_params'] = [
'groupid' => $group, 'groupid' => $group,
]; ];
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); $this->response =$client->post($fullUrl, $options);
} }
@ -489,13 +490,13 @@ trait Provisioning {
if ($this->currentUser === 'admin') { if ($this->currentUser === 'admin') {
$options['auth'] = $this->adminUser; $options['auth'] = $this->adminUser;
} }
$options['body'] = [ $options['form_params'] = [
'groupid' => $group 'groupid' => $group
]; ];
$options['headers'] = [ $options['headers'] = [
'OCS-APIREQUEST' => 'true', 'OCS-APIREQUEST' => 'true',
]; ];
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); $this->response = $client->post($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
} }
@ -588,44 +589,48 @@ trait Provisioning {
/** /**
* Parses the xml answer to get the array of users returned. * Parses the xml answer to get the array of users returned.
*
* @param ResponseInterface $resp * @param ResponseInterface $resp
* @return array * @return array
*/ */
public function getArrayOfUsersResponded($resp) { public function getArrayOfUsersResponded($resp) {
$listCheckedElements = $resp->xml()->data[0]->users[0]->element; $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->users[0]->element;
$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
return $extractedElementsArray; return $extractedElementsArray;
} }
/** /**
* Parses the xml answer to get the array of groups returned. * Parses the xml answer to get the array of groups returned.
*
* @param ResponseInterface $resp * @param ResponseInterface $resp
* @return array * @return array
*/ */
public function getArrayOfGroupsResponded($resp) { public function getArrayOfGroupsResponded($resp) {
$listCheckedElements = $resp->xml()->data[0]->groups[0]->element; $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->groups[0]->element;
$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
return $extractedElementsArray; return $extractedElementsArray;
} }
/** /**
* Parses the xml answer to get the array of apps returned. * Parses the xml answer to get the array of apps returned.
*
* @param ResponseInterface $resp * @param ResponseInterface $resp
* @return array * @return array
*/ */
public function getArrayOfAppsResponded($resp) { public function getArrayOfAppsResponded($resp) {
$listCheckedElements = $resp->xml()->data[0]->apps[0]->element; $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->apps[0]->element;
$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
return $extractedElementsArray; return $extractedElementsArray;
} }
/** /**
* Parses the xml answer to get the array of subadmins returned. * Parses the xml answer to get the array of subadmins returned.
*
* @param ResponseInterface $resp * @param ResponseInterface $resp
* @return array * @return array
*/ */
public function getArrayOfSubadminsResponded($resp) { public function getArrayOfSubadminsResponded($resp) {
$listCheckedElements = $resp->xml()->data[0]->element; $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->element;
$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1); $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
return $extractedElementsArray; return $extractedElementsArray;
} }
@ -689,7 +694,7 @@ trait Provisioning {
]; ];
$this->response = $client->get($fullUrl, $options); $this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals("false", $this->response->xml()->data[0]->enabled); PHPUnit_Framework_Assert::assertEquals("false", simplexml_load_string($this->response->getBody())->data[0]->enabled);
} }
/** /**
@ -708,7 +713,7 @@ trait Provisioning {
]; ];
$this->response = $client->get($fullUrl, $options); $this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals("true", $this->response->xml()->data[0]->enabled); PHPUnit_Framework_Assert::assertEquals("true", simplexml_load_string($this->response->getBody())->data[0]->enabled);
} }
/** /**
@ -716,8 +721,7 @@ trait Provisioning {
* @param string $user * @param string $user
* @param string $quota * @param string $quota
*/ */
public function userHasAQuotaOf($user, $quota) public function userHasAQuotaOf($user, $quota) {
{
$body = new \Behat\Gherkin\Node\TableNode([ $body = new \Behat\Gherkin\Node\TableNode([
0 => ['key', 'quota'], 0 => ['key', 'quota'],
1 => ['value', $quota], 1 => ['value', $quota],
@ -731,13 +735,13 @@ trait Provisioning {
* @Given user :user has unlimited quota * @Given user :user has unlimited quota
* @param string $user * @param string $user
*/ */
public function userHasUnlimitedQuota($user) public function userHasUnlimitedQuota($user) {
{
$this->userHasAQuotaOf($user, 'none'); $this->userHasAQuotaOf($user, 'none');
} }
/** /**
* Returns home path of the given user * Returns home path of the given user
*
* @param string $user * @param string $user
*/ */
public function getUserHome($user) { public function getUserHome($user) {
@ -746,22 +750,21 @@ trait Provisioning {
$options = []; $options = [];
$options['auth'] = $this->adminUser; $options['auth'] = $this->adminUser;
$this->response = $client->get($fullUrl, $options); $this->response = $client->get($fullUrl, $options);
return $this->response->xml()->data[0]->home; return simplexml_load_string($this->response->getBody())->data[0]->home;
} }
/** /**
* @BeforeScenario * @BeforeScenario
* @AfterScenario * @AfterScenario
*/ */
public function cleanupUsers() public function cleanupUsers() {
{
$previousServer = $this->currentServer; $previousServer = $this->currentServer;
$this->usingServer('LOCAL'); $this->usingServer('LOCAL');
foreach($this->createdUsers as $user) { foreach ($this->createdUsers as $user) {
$this->deleteUser($user); $this->deleteUser($user);
} }
$this->usingServer('REMOTE'); $this->usingServer('REMOTE');
foreach($this->createdRemoteUsers as $remoteUser) { foreach ($this->createdRemoteUsers as $remoteUser) {
$this->deleteUser($remoteUser); $this->deleteUser($remoteUser);
} }
$this->usingServer($previousServer); $this->usingServer($previousServer);
@ -771,15 +774,14 @@ trait Provisioning {
* @BeforeScenario * @BeforeScenario
* @AfterScenario * @AfterScenario
*/ */
public function cleanupGroups() public function cleanupGroups() {
{
$previousServer = $this->currentServer; $previousServer = $this->currentServer;
$this->usingServer('LOCAL'); $this->usingServer('LOCAL');
foreach($this->createdGroups as $group) { foreach ($this->createdGroups as $group) {
$this->deleteGroup($group); $this->deleteGroup($group);
} }
$this->usingServer('REMOTE'); $this->usingServer('REMOTE');
foreach($this->createdRemoteGroups as $remoteGroup) { foreach ($this->createdRemoteGroups as $remoteGroup) {
$this->deleteGroup($remoteGroup); $this->deleteGroup($remoteGroup);
} }
$this->usingServer($previousServer); $this->usingServer($previousServer);

View File

@ -23,7 +23,7 @@
*/ */
use Behat\Behat\Context\Context; use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext; use Behat\Behat\Context\SnippetAcceptingContext;
use GuzzleHttp\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
require __DIR__ . '/../../vendor/autoload.php'; require __DIR__ . '/../../vendor/autoload.php';
@ -72,7 +72,7 @@ class ShareesContext implements Context, SnippetAcceptingContext {
} }
public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) { public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) {
$elements = $response->xml()->data; $elements = simplexml_load_string($response->getBody())->data;
$elements = json_decode(json_encode($elements), 1); $elements = json_decode(json_encode($elements), 1);
if (strpos($shareeType, 'exact ') === 0) { if (strpos($shareeType, 'exact ') === 0) {
$elements = $elements['exact']; $elements = $elements['exact'];

View File

@ -44,6 +44,9 @@ trait Sharing {
/** @var int */ /** @var int */
private $savedShareId = null; private $savedShareId = null;
/** @var \Psr\Http\Message\ResponseInterface */
private $response;
/** /**
* @Given /^as "([^"]*)" creating a share with$/ * @Given /^as "([^"]*)" creating a share with$/
* @param string $user * @param string $user
@ -69,16 +72,16 @@ trait Sharing {
$dateModification = $fd['expireDate']; $dateModification = $fd['expireDate'];
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification)); $fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
} }
$options['body'] = $fd; $options['form_params'] = $fd;
} }
try { try {
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); $this->response = $client->request("POST", $fullUrl, $options);
} catch (\GuzzleHttp\Exception\ClientException $ex) { } catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse(); $this->response = $ex->getResponse();
} }
$this->lastShareData = $this->response->xml(); $this->lastShareData = simplexml_load_string($this->response->getBody());
} }
/** /**
@ -159,8 +162,8 @@ trait Sharing {
$options['auth'] = [$this->currentUser, $this->regularUser]; $options['auth'] = [$this->currentUser, $this->regularUser];
} }
$date = date('Y-m-d', strtotime("+3 days")); $date = date('Y-m-d', strtotime("+3 days"));
$options['body'] = ['expireDate' => $date]; $options['form_params'] = ['expireDate' => $date];
$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options)); $this->response = $this->response = $client->request("PUT", $fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
} }
@ -189,11 +192,11 @@ trait Sharing {
$dateModification = $fd['expireDate']; $dateModification = $fd['expireDate'];
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification)); $fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
} }
$options['body'] = $fd; $options['form_params'] = $fd;
} }
try { try {
$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options)); $this->response = $client->request("PUT", $fullUrl, $options);
} catch (\GuzzleHttp\Exception\ClientException $ex) { } catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse(); $this->response = $ex->getResponse();
} }
@ -221,38 +224,39 @@ trait Sharing {
} else { } else {
$options['auth'] = [$user, $this->regularUser]; $options['auth'] = [$user, $this->regularUser];
} }
$fd = []; $body = [];
if (!is_null($path)){ if (!is_null($path)){
$fd['path'] = $path; $body['path'] = $path;
} }
if (!is_null($shareType)){ if (!is_null($shareType)){
$fd['shareType'] = $shareType; $body['shareType'] = $shareType;
} }
if (!is_null($shareWith)){ if (!is_null($shareWith)){
$fd['shareWith'] = $shareWith; $body['shareWith'] = $shareWith;
} }
if (!is_null($publicUpload)){ if (!is_null($publicUpload)){
$fd['publicUpload'] = $publicUpload; $body['publicUpload'] = $publicUpload;
} }
if (!is_null($password)){ if (!is_null($password)){
$fd['password'] = $password; $body['password'] = $password;
} }
if (!is_null($permissions)){ if (!is_null($permissions)){
$fd['permissions'] = $permissions; $body['permissions'] = $permissions;
} }
$options['body'] = $fd; $options['form_params'] = $body;
try { try {
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); $this->response = $client->request("POST", $fullUrl, $options);
$this->lastShareData = $this->response->xml(); $this->lastShareData = simplexml_load_string($this->response->getBody());
} catch (\GuzzleHttp\Exception\ClientException $ex) { } catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse(); $this->response = $ex->getResponse();
throw new \Exception($this->response->getBody());
} }
} }
public function isFieldInResponse($field, $contentExpected){ public function isFieldInResponse($field, $contentExpected){
$data = $this->response->xml()->data[0]; $data = simplexml_load_string($this->response->getBody())->data[0];
if ((string)$field == 'expiration'){ if ((string)$field == 'expiration'){
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00"; $contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00";
} }
@ -330,7 +334,7 @@ trait Sharing {
} }
public function isUserOrGroupInSharedData($userOrGroup, $permissions = null){ public function isUserOrGroupInSharedData($userOrGroup, $permissions = null){
$data = $this->response->xml()->data[0]; $data = simplexml_load_string($this->response->getBody())->data[0];
foreach($data as $element) { foreach($data as $element) {
if ($element->share_with == $userOrGroup && ($permissions === null || $permissions == $element->permissions)){ if ($element->share_with == $userOrGroup && ($permissions === null || $permissions == $element->permissions)){
return True; return True;
@ -532,7 +536,7 @@ trait Sharing {
foreach($table->getTable() as $header) { foreach($table->getTable() as $header) {
$headerName = $header[0]; $headerName = $header[0];
$expectedHeaderValue = $header[1]; $expectedHeaderValue = $header[1];
$returnedHeader = $this->response->getHeader($headerName); $returnedHeader = $this->response->getHeader($headerName)[0];
if($returnedHeader !== $expectedHeaderValue) { if($returnedHeader !== $expectedHeaderValue) {
throw new \Exception( throw new \Exception(
sprintf( sprintf(

View File

@ -32,7 +32,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface; use GuzzleHttp\Message\ResponseInterface;
class TagsContext implements \Behat\Behat\Context\Context { class TagsContext implements \Behat\Behat\Context\Context {
/** @var string */ /** @var string */
private $baseUrl; private $baseUrl;
/** @var Client */ /** @var Client */
private $client; private $client;
@ -61,9 +61,9 @@ class TagsContext implements \Behat\Behat\Context\Context {
public function tearDownScenario() { public function tearDownScenario() {
$user = 'admin'; $user = 'admin';
$tags = $this->requestTagsForUser($user); $tags = $this->requestTagsForUser($user);
foreach($tags as $tagId => $tag) { foreach ($tags as $tagId => $tag) {
$this->response = $this->client->delete( $this->response = $this->client->delete(
$this->baseUrl . '/remote.php/dav/systemtags/'.$tagId, $this->baseUrl . '/remote.php/dav/systemtags/' . $tagId,
[ [
'auth' => [ 'auth' => [
$user, $user,
@ -88,7 +88,8 @@ class TagsContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
} catch (\GuzzleHttp\Exception\ClientException $e) {} } catch (\GuzzleHttp\Exception\ClientException $e) {
}
} }
/** /**
@ -96,7 +97,7 @@ class TagsContext implements \Behat\Behat\Context\Context {
* @return string * @return string
*/ */
private function getPasswordForUser($userName) { private function getPasswordForUser($userName) {
if($userName === 'admin') { if ($userName === 'admin') {
return 'admin'; return 'admin';
} }
return '123456'; return '123456';
@ -181,8 +182,8 @@ class TagsContext implements \Behat\Behat\Context\Context {
* @throws \Exception * @throws \Exception
*/ */
public function theResponseShouldHaveAStatusCode($statusCode) { public function theResponseShouldHaveAStatusCode($statusCode) {
if((int)$statusCode !== $this->response->getStatusCode()) { if ((int)$statusCode !== $this->response->getStatusCode()) {
throw new \Exception("Expected $statusCode, got ".$this->response->getStatusCode()); throw new \Exception("Expected $statusCode, got " . $this->response->getStatusCode());
} }
} }
@ -211,7 +212,7 @@ class TagsContext implements \Behat\Behat\Context\Context {
$body .= ' $body .= '
</d:prop> </d:prop>
</d:propfind>'; </d:propfind>';
$request = $this->client->createRequest( $this->response = $this->client->request(
'PROPFIND', 'PROPFIND',
$this->baseUrl . '/remote.php/dav/systemtags/', $this->baseUrl . '/remote.php/dav/systemtags/',
[ [
@ -225,7 +226,6 @@ class TagsContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -233,9 +233,9 @@ class TagsContext implements \Behat\Behat\Context\Context {
$tags = []; $tags = [];
$service = new Sabre\Xml\Service(); $service = new Sabre\Xml\Service();
$parsed = $service->parse($this->response->getBody()->getContents()); $parsed = $service->parse($this->response->getBody()->getContents());
foreach($parsed as $entry) { foreach ($parsed as $entry) {
$singleEntry = $entry['value'][1]['value'][0]['value']; $singleEntry = $entry['value'][1]['value'][0]['value'];
if(empty($singleEntry[0]['value'])) { if (empty($singleEntry[0]['value'])) {
continue; continue;
} }
@ -263,7 +263,7 @@ class TagsContext implements \Behat\Behat\Context\Context {
public function theFollowingTagsShouldExistFor($user, TableNode $table) { public function theFollowingTagsShouldExistFor($user, TableNode $table) {
$tags = $this->requestTagsForUser($user); $tags = $this->requestTagsForUser($user);
if(count($table->getRows()) !== count($tags)) { if (count($table->getRows()) !== count($tags)) {
throw new \Exception( throw new \Exception(
sprintf( sprintf(
"Expected %s tags, got %s.", "Expected %s tags, got %s.",
@ -273,9 +273,9 @@ class TagsContext implements \Behat\Behat\Context\Context {
); );
} }
foreach($table->getRowsHash() as $rowDisplayName => $row) { foreach ($table->getRowsHash() as $rowDisplayName => $row) {
foreach($tags as $key => $tag) { foreach ($tags as $key => $tag) {
if( if (
$tag['display-name'] === $rowDisplayName && $tag['display-name'] === $rowDisplayName &&
$tag['user-visible'] === $row[0] && $tag['user-visible'] === $row[0] &&
$tag['user-assignable'] === $row[1] $tag['user-assignable'] === $row[1]
@ -284,7 +284,7 @@ class TagsContext implements \Behat\Behat\Context\Context {
} }
} }
} }
if(count($tags) !== 0) { if (count($tags) !== 0) {
throw new \Exception('Not expected response'); throw new \Exception('Not expected response');
} }
} }
@ -331,9 +331,9 @@ class TagsContext implements \Behat\Behat\Context\Context {
* @param string $user * @param string $user
* @throws \Exception * @throws \Exception
*/ */
public function tagsShouldExistFor($count, $user) { public function tagsShouldExistFor($count, $user) {
if((int)$count !== count($this->requestTagsForUser($user))) { if ((int)$count !== count($this->requestTagsForUser($user))) {
throw new \Exception("Expected $count tags, got ".count($this->requestTagsForUser($user))); throw new \Exception("Expected $count tags, got " . count($this->requestTagsForUser($user)));
} }
} }
@ -369,8 +369,8 @@ class TagsContext implements \Behat\Behat\Context\Context {
if ($tag['display-name'] === $tagName if ($tag['display-name'] === $tagName
&& $tag['user-visible'] === $userVisible && $tag['user-visible'] === $userVisible
&& $tag['user-assignable'] === $userAssignable) { && $tag['user-assignable'] === $userAssignable) {
$foundTag = $tag; $foundTag = $tag;
break; break;
} }
} }
return $foundTag; return $foundTag;
@ -383,8 +383,8 @@ class TagsContext implements \Behat\Behat\Context\Context {
private function findTagIdByName($name) { private function findTagIdByName($name) {
$tags = $this->requestTagsForUser('admin'); $tags = $this->requestTagsForUser('admin');
$tagId = 0; $tagId = 0;
foreach($tags as $id => $tag) { foreach ($tags as $id => $tag) {
if($tag['display-name'] === $name) { if ($tag['display-name'] === $name) {
$tagId = $id; $tagId = $id;
break; break;
} }
@ -401,12 +401,12 @@ class TagsContext implements \Behat\Behat\Context\Context {
*/ */
public function editsTheTagWithNameAndSetsItsNameTo($user, $oldName, $newName) { public function editsTheTagWithNameAndSetsItsNameTo($user, $oldName, $newName) {
$tagId = $this->findTagIdByName($oldName); $tagId = $this->findTagIdByName($oldName);
if($tagId === 0) { if ($tagId === 0) {
throw new \Exception('Could not find tag to rename'); throw new \Exception('Could not find tag to rename');
} }
try { try {
$request = $this->client->createRequest( $this->response = $this->client->request(
'PROPPATCH', 'PROPPATCH',
$this->baseUrl . '/remote.php/dav/systemtags/' . $tagId, $this->baseUrl . '/remote.php/dav/systemtags/' . $tagId,
[ [
@ -424,7 +424,6 @@ class TagsContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -439,12 +438,12 @@ class TagsContext implements \Behat\Behat\Context\Context {
*/ */
public function editsTheTagWithNameAndSetsItsGroupsTo($user, $oldName, $groups) { public function editsTheTagWithNameAndSetsItsGroupsTo($user, $oldName, $groups) {
$tagId = $this->findTagIdByName($oldName); $tagId = $this->findTagIdByName($oldName);
if($tagId === 0) { if ($tagId === 0) {
throw new \Exception('Could not find tag to rename'); throw new \Exception('Could not find tag to rename');
} }
try { try {
$request = $this->client->createRequest( $this->response = $this->client->request(
'PROPPATCH', 'PROPPATCH',
$this->baseUrl . '/remote.php/dav/systemtags/' . $tagId, $this->baseUrl . '/remote.php/dav/systemtags/' . $tagId,
[ [
@ -462,7 +461,6 @@ class TagsContext implements \Behat\Behat\Context\Context {
], ],
] ]
); );
$this->response = $this->client->send($request);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
@ -473,7 +471,7 @@ class TagsContext implements \Behat\Behat\Context\Context {
* @param string $user * @param string $user
* @param string $name * @param string $name
*/ */
public function deletesTheTagWithName($user, $name) { public function deletesTheTagWithName($user, $name) {
$tagId = $this->findTagIdByName($name); $tagId = $this->findTagIdByName($name);
try { try {
$this->response = $this->client->delete( $this->response = $this->client->delete(
@ -499,8 +497,8 @@ class TagsContext implements \Behat\Behat\Context\Context {
* @return int * @return int
*/ */
private function getFileIdForPath($path, $user) { private function getFileIdForPath($path, $user) {
$url = $this->baseUrl.'/remote.php/webdav/'.$path; $url = $this->baseUrl . '/remote.php/webdav/' . $path;
$credentials = base64_encode($user .':'.$this->getPasswordForUser($user)); $credentials = base64_encode($user . ':' . $this->getPasswordForUser($user));
$context = stream_context_create(array( $context = stream_context_create(array(
'http' => array( 'http' => array(
'method' => 'PROPFIND', 'method' => 'PROPFIND',
@ -531,7 +529,7 @@ class TagsContext implements \Behat\Behat\Context\Context {
try { try {
$this->response = $this->client->put( $this->response = $this->client->put(
$this->baseUrl.'/remote.php/dav/systemtags-relations/files/'.$fileId.'/'.$tagId, $this->baseUrl . '/remote.php/dav/systemtags-relations/files/' . $fileId . '/' . $tagId,
[ [
'auth' => [ 'auth' => [
$taggingUser, $taggingUser,
@ -551,17 +549,17 @@ class TagsContext implements \Behat\Behat\Context\Context {
* @param TableNode $table * @param TableNode $table
* @throws \Exception * @throws \Exception
*/ */
public function sharedByHasTheFollowingTags($fileName, $sharedOrOwnedBy, $sharingUser, TableNode $table) { public function sharedByHasTheFollowingTags($fileName, $sharedOrOwnedBy, $sharingUser, TableNode $table) {
$loadedExpectedTags = $table->getTable(); $loadedExpectedTags = $table->getTable();
$expectedTags = []; $expectedTags = [];
foreach($loadedExpectedTags as $expected) { foreach ($loadedExpectedTags as $expected) {
$expectedTags[] = $expected[0]; $expectedTags[] = $expected[0];
} }
// Get the real tags // Get the real tags
$request = $this->client->createRequest( $response = $this->client->request(
'PROPFIND', 'PROPFIND',
$this->baseUrl.'/remote.php/dav/systemtags-relations/files/'.$this->getFileIdForPath($fileName, $sharingUser), $this->baseUrl . '/remote.php/dav/systemtags-relations/files/' . $this->getFileIdForPath($fileName, $sharingUser),
[ [
'auth' => [ 'auth' => [
$sharingUser, $sharingUser,
@ -577,19 +575,18 @@ class TagsContext implements \Behat\Behat\Context\Context {
</d:prop> </d:prop>
</d:propfind>', </d:propfind>',
] ]
); )->getBody()->getContents();
$response = $this->client->send($request)->getBody()->getContents();
preg_match_all('/\<oc:display-name\>(.*?)\<\/oc:display-name\>/', $response, $realTags); preg_match_all('/\<oc:display-name\>(.*?)\<\/oc:display-name\>/', $response, $realTags);
foreach($expectedTags as $key => $row) { foreach ($expectedTags as $key => $row) {
foreach($realTags as $tag) { foreach ($realTags as $tag) {
if($tag[0] === $row) { if ($tag[0] === $row) {
unset($expectedTags[$key]); unset($expectedTags[$key]);
} }
} }
} }
if(count($expectedTags) !== 0) { if (count($expectedTags) !== 0) {
throw new \Exception('Not all tags found.'); throw new \Exception('Not all tags found.');
} }
} }
@ -605,13 +602,13 @@ class TagsContext implements \Behat\Behat\Context\Context {
public function sharedByHasTheFollowingTagsFor($fileName, $sharingUser, $user, TableNode $table) { public function sharedByHasTheFollowingTagsFor($fileName, $sharingUser, $user, TableNode $table) {
$loadedExpectedTags = $table->getTable(); $loadedExpectedTags = $table->getTable();
$expectedTags = []; $expectedTags = [];
foreach($loadedExpectedTags as $expected) { foreach ($loadedExpectedTags as $expected) {
$expectedTags[] = $expected[0]; $expectedTags[] = $expected[0];
} }
// Get the real tags // Get the real tags
try { try {
$request = $this->client->createRequest( $this->response = $this->client->request(
'PROPFIND', 'PROPFIND',
$this->baseUrl . '/remote.php/dav/systemtags-relations/files/' . $this->getFileIdForPath($fileName, $sharingUser), $this->baseUrl . '/remote.php/dav/systemtags-relations/files/' . $this->getFileIdForPath($fileName, $sharingUser),
[ [
@ -630,25 +627,24 @@ class TagsContext implements \Behat\Behat\Context\Context {
</d:propfind>', </d:propfind>',
] ]
); );
$this->response = $this->client->send($request)->getBody()->getContents();
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse(); $this->response = $e->getResponse();
} }
preg_match_all('/\<oc:display-name\>(.*?)\<\/oc:display-name\>/', $this->response, $realTags); preg_match_all('/\<oc:display-name\>(.*?)\<\/oc:display-name\>/', $this->response->getBody()->getContents(), $realTags);
$realTags = array_filter($realTags); $realTags = array_filter($realTags);
$expectedTags = array_filter($expectedTags); $expectedTags = array_filter($expectedTags);
foreach($expectedTags as $key => $row) { foreach ($expectedTags as $key => $row) {
foreach($realTags as $tag) { foreach ($realTags as $tag) {
foreach($tag as $index => $foo) { foreach ($tag as $index => $foo) {
if($tag[$index] === $row) { if ($tag[$index] === $row) {
unset($expectedTags[$key]); unset($expectedTags[$key]);
} }
} }
} }
} }
if(count($expectedTags) !== 0) { if (count($expectedTags) !== 0) {
throw new \Exception('Not all tags found.'); throw new \Exception('Not all tags found.');
} }
} }
@ -666,7 +662,7 @@ class TagsContext implements \Behat\Behat\Context\Context {
try { try {
$this->response = $this->client->delete( $this->response = $this->client->delete(
$this->baseUrl.'/remote.php/dav/systemtags-relations/files/'.$fileId.'/'.$tagId, $this->baseUrl . '/remote.php/dav/systemtags-relations/files/' . $fileId . '/' . $tagId,
[ [
'auth' => [ 'auth' => [
$user, $user,

View File

@ -28,6 +28,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
use GuzzleHttp\Client as GClient; use GuzzleHttp\Client as GClient;
use GuzzleHttp\Message\ResponseInterface; use GuzzleHttp\Message\ResponseInterface;
use Sabre\DAV\Client as SClient; use Sabre\DAV\Client as SClient;
@ -39,9 +40,9 @@ require __DIR__ . '/../../vendor/autoload.php';
trait WebDav { trait WebDav {
use Sharing; use Sharing;
/** @var string*/ /** @var string */
private $davPath = "remote.php/webdav"; private $davPath = "remote.php/webdav";
/** @var boolean*/ /** @var boolean */
private $usingOldDavPath = true; private $usingOldDavPath = true;
/** @var ResponseInterface */ /** @var ResponseInterface */
private $response; private $response;
@ -73,40 +74,31 @@ trait WebDav {
$this->usingOldDavPath = false; $this->usingOldDavPath = false;
} }
public function getDavFilesPath($user){ public function getDavFilesPath($user) {
if ($this->usingOldDavPath === true){ if ($this->usingOldDavPath === true) {
return $this->davPath; return $this->davPath;
} else { } else {
return $this->davPath . '/files/' . $user; return $this->davPath . '/files/' . $user;
} }
} }
public function makeDavRequest($user, $method, $path, $headers, $body = null, $type = "files"){ public function makeDavRequest($user, $method, $path, $headers, $body = null, $type = "files") {
if ( $type === "files" ){ if ($type === "files") {
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . "$path"; $fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . "$path";
} else if ( $type === "uploads" ){ } else if ($type === "uploads") {
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path"; $fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
} }
$client = new GClient(); $client = new GClient();
$options = []; $options = [
'headers' => $headers,
'body' => $body
];
if ($user === 'admin') { if ($user === 'admin') {
$options['auth'] = $this->adminUser; $options['auth'] = $this->adminUser;
} else { } else {
$options['auth'] = [$user, $this->regularUser]; $options['auth'] = [$user, $this->regularUser];
} }
$request = $client->createRequest($method, $fullUrl, $options); return $client->request($method, $fullUrl, $options);
if (!is_null($headers)){
foreach ($headers as $key => $value) {
$request->addHeader($key, $value);
}
}
if (!is_null($body)) {
$request->setBody($body);
}
return $client->send($request);
} }
/** /**
@ -115,7 +107,7 @@ trait WebDav {
* @param string $fileSource * @param string $fileSource
* @param string $fileDestination * @param string $fileDestination
*/ */
public function userMovedFile($user, $entry, $fileSource, $fileDestination){ public function userMovedFile($user, $entry, $fileSource, $fileDestination) {
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user); $fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user);
$headers['Destination'] = $fullUrl . $fileDestination; $headers['Destination'] = $fullUrl . $fileDestination;
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers); $this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers);
@ -128,7 +120,7 @@ trait WebDav {
* @param string $fileSource * @param string $fileSource
* @param string $fileDestination * @param string $fileDestination
*/ */
public function userMovesFile($user, $entry, $fileSource, $fileDestination){ public function userMovesFile($user, $entry, $fileSource, $fileDestination) {
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user); $fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user);
$headers['Destination'] = $fullUrl . $fileDestination; $headers['Destination'] = $fullUrl . $fileDestination;
try { try {
@ -160,7 +152,7 @@ trait WebDav {
* @param string $fileSource * @param string $fileSource
* @param string $range * @param string $range
*/ */
public function downloadFileWithRange($fileSource, $range){ public function downloadFileWithRange($fileSource, $range) {
$headers['Range'] = $range; $headers['Range'] = $range;
$this->response = $this->makeDavRequest($this->currentUser, "GET", $fileSource, $headers); $this->response = $this->makeDavRequest($this->currentUser, "GET", $fileSource, $headers);
} }
@ -169,43 +161,44 @@ trait WebDav {
* @When /^Downloading last public shared file with range "([^"]*)"$/ * @When /^Downloading last public shared file with range "([^"]*)"$/
* @param string $range * @param string $range
*/ */
public function downloadPublicFileWithRange($range){ public function downloadPublicFileWithRange($range) {
$token = $this->lastShareData->data->token; $token = $this->lastShareData->data->token;
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav"; $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav";
$client = new GClient(); $client = new GClient();
$options = []; $options = [];
$options['auth'] = [$token, ""]; $options['auth'] = [$token, ""];
$options['headers'] = [
'Range' => $range
];
$request = $client->createRequest("GET", $fullUrl, $options); $this->response = $client->request("GET", $fullUrl, $options);
$request->addHeader('Range', $range);
$this->response = $client->send($request);
} }
/** /**
* @When /^Downloading last public shared file inside a folder "([^"]*)" with range "([^"]*)"$/ * @When /^Downloading last public shared file inside a folder "([^"]*)" with range "([^"]*)"$/
* @param string $range * @param string $range
*/ */
public function downloadPublicFileInsideAFolderWithRange($path, $range){ public function downloadPublicFileInsideAFolderWithRange($path, $range) {
$token = $this->lastShareData->data->token; $token = $this->lastShareData->data->token;
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav" . "$path"; $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav" . "$path";
$client = new GClient(); $client = new GClient();
$options = []; $options = [
'headers' => [
'Range' => $range
]
];
$options['auth'] = [$token, ""]; $options['auth'] = [$token, ""];
$request = $client->createRequest("GET", $fullUrl, $options); $this->response = $client->request("GET", $fullUrl, $options);
$request->addHeader('Range', $range);
$this->response = $client->send($request);
} }
/** /**
* @Then /^Downloaded content should be "([^"]*)"$/ * @Then /^Downloaded content should be "([^"]*)"$/
* @param string $content * @param string $content
*/ */
public function downloadedContentShouldBe($content){ public function downloadedContentShouldBe($content) {
PHPUnit_Framework_Assert::assertEquals($content, (string)$this->response->getBody()); PHPUnit_Framework_Assert::assertEquals($content, (string)$this->response->getBody());
} }
@ -215,7 +208,7 @@ trait WebDav {
* @param string $range * @param string $range
* @param string $content * @param string $content
*/ */
public function downloadedContentWhenDownloadindShouldBe($fileSource, $range, $content){ public function downloadedContentWhenDownloadindShouldBe($fileSource, $range, $content) {
$this->downloadFileWithRange($fileSource, $range); $this->downloadFileWithRange($fileSource, $range);
$this->downloadedContentShouldBe($content); $this->downloadedContentShouldBe($content);
} }
@ -238,11 +231,11 @@ trait WebDav {
* @throws \Exception * @throws \Exception
*/ */
public function theFollowingHeadersShouldBeSet(\Behat\Gherkin\Node\TableNode $table) { public function theFollowingHeadersShouldBeSet(\Behat\Gherkin\Node\TableNode $table) {
foreach($table->getTable() as $header) { foreach ($table->getTable() as $header) {
$headerName = $header[0]; $headerName = $header[0];
$expectedHeaderValue = $header[1]; $expectedHeaderValue = $header[1];
$returnedHeader = $this->response->getHeader($headerName); $returnedHeader = $this->response->getHeader($headerName)[0];
if($returnedHeader !== $expectedHeaderValue) { if ($returnedHeader !== $expectedHeaderValue) {
throw new \Exception( throw new \Exception(
sprintf( sprintf(
"Expected value '%s' for header '%s', got '%s'", "Expected value '%s' for header '%s', got '%s'",
@ -261,7 +254,7 @@ trait WebDav {
* @throws \Exception * @throws \Exception
*/ */
public function downloadedContentShouldStartWith($start) { public function downloadedContentShouldStartWith($start) {
if(strpos($this->response->getBody()->getContents(), $start) !== 0) { if (strpos($this->response->getBody()->getContents(), $start) !== 0) {
throw new \Exception( throw new \Exception(
sprintf( sprintf(
"Expected '%s', got '%s'", "Expected '%s', got '%s'",
@ -345,8 +338,7 @@ trait WebDav {
/** /**
* @Then the response should contain a share-types property with * @Then the response should contain a share-types property with
*/ */
public function theResponseShouldContainAShareTypesPropertyWith($table) public function theResponseShouldContainAShareTypesPropertyWith($table) {
{
$keys = $this->response; $keys = $this->response;
if (!array_key_exists('{http://owncloud.org/ns}share-types', $keys)) { if (!array_key_exists('{http://owncloud.org/ns}share-types', $keys)) {
throw new \Exception("Cannot find property \"{http://owncloud.org/ns}share-types\""); throw new \Exception("Cannot find property \"{http://owncloud.org/ns}share-types\"");
@ -393,7 +385,7 @@ trait WebDav {
} }
/*Returns the elements of a propfind, $folderDepth requires 1 to see elements without children*/ /*Returns the elements of a propfind, $folderDepth requires 1 to see elements without children*/
public function listFolder($user, $path, $folderDepth, $properties = null){ public function listFolder($user, $path, $folderDepth, $properties = null) {
$client = $this->getSabreClient($user); $client = $this->getSabreClient($user);
if (!$properties) { if (!$properties) {
$properties = [ $properties = [
@ -412,7 +404,7 @@ trait WebDav {
* @param string $properties properties which needs to be included in the report * @param string $properties properties which needs to be included in the report
* @param string $filterRules filter-rules to choose what needs to appear in the report * @param string $filterRules filter-rules to choose what needs to appear in the report
*/ */
public function reportFolder($user, $path, $properties, $filterRules){ public function reportFolder($user, $path, $properties, $filterRules) {
$client = $this->getSabreClient($user); $client = $this->getSabreClient($user);
$body = '<?xml version="1.0" encoding="utf-8" ?> $body = '<?xml version="1.0" encoding="utf-8" ?>
@ -457,14 +449,14 @@ trait WebDav {
* @param string $user * @param string $user
* @param \Behat\Gherkin\Node\TableNode|null $expectedElements * @param \Behat\Gherkin\Node\TableNode|null $expectedElements
*/ */
public function checkElementList($user, $expectedElements){ public function checkElementList($user, $expectedElements) {
$elementList = $this->listFolder($user, '/', 3); $elementList = $this->listFolder($user, '/', 3);
if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) { if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) {
$elementRows = $expectedElements->getRows(); $elementRows = $expectedElements->getRows();
$elementsSimplified = $this->simplifyArray($elementRows); $elementsSimplified = $this->simplifyArray($elementRows);
foreach($elementsSimplified as $expectedElement) { foreach ($elementsSimplified as $expectedElement) {
$webdavPath = "/" . $this->getDavFilesPath($user) . $expectedElement; $webdavPath = "/" . $this->getDavFilesPath($user) . $expectedElement;
if (!array_key_exists($webdavPath,$elementList)){ if (!array_key_exists($webdavPath, $elementList)) {
PHPUnit_Framework_Assert::fail("$webdavPath" . " is not in propfind answer"); PHPUnit_Framework_Assert::fail("$webdavPath" . " is not in propfind answer");
} }
} }
@ -477,9 +469,8 @@ trait WebDav {
* @param string $source * @param string $source
* @param string $destination * @param string $destination
*/ */
public function userUploadsAFileTo($user, $source, $destination) public function userUploadsAFileTo($user, $source, $destination) {
{ $file = \GuzzleHttp\Psr7\stream_for(fopen($source, 'r'));
$file = \GuzzleHttp\Stream\Stream::factory(fopen($source, 'r'));
try { try {
$this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file); $this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file);
} catch (\GuzzleHttp\Exception\ServerException $e) { } catch (\GuzzleHttp\Exception\ServerException $e) {
@ -494,7 +485,7 @@ trait WebDav {
* @param string $bytes * @param string $bytes
* @param string $destination * @param string $destination
*/ */
public function userAddsAFileTo($user, $bytes, $destination){ public function userAddsAFileTo($user, $bytes, $destination) {
$filename = "filespecificSize.txt"; $filename = "filespecificSize.txt";
$this->createFileSpecificSize($filename, $bytes); $this->createFileSpecificSize($filename, $bytes);
PHPUnit_Framework_Assert::assertEquals(1, file_exists("work/$filename")); PHPUnit_Framework_Assert::assertEquals(1, file_exists("work/$filename"));
@ -507,9 +498,8 @@ trait WebDav {
/** /**
* @When User :user uploads file with content :content to :destination * @When User :user uploads file with content :content to :destination
*/ */
public function userUploadsAFileWithContentTo($user, $content, $destination) public function userUploadsAFileWithContentTo($user, $content, $destination) {
{ $file = \GuzzleHttp\Psr7\stream_for($content);
$file = \GuzzleHttp\Stream\Stream::factory($content);
try { try {
$this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file); $this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file);
} catch (\GuzzleHttp\Exception\ServerException $e) { } catch (\GuzzleHttp\Exception\ServerException $e) {
@ -524,7 +514,7 @@ trait WebDav {
* @param string $type * @param string $type
* @param string $file * @param string $file
*/ */
public function userDeletesFile($user, $type, $file) { public function userDeletesFile($user, $type, $file) {
try { try {
$this->response = $this->makeDavRequest($user, 'DELETE', $file, []); $this->response = $this->makeDavRequest($user, 'DELETE', $file, []);
} catch (\GuzzleHttp\Exception\ServerException $e) { } catch (\GuzzleHttp\Exception\ServerException $e) {
@ -556,38 +546,34 @@ trait WebDav {
* @param string $data * @param string $data
* @param string $destination * @param string $destination
*/ */
public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination) public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination) {
{
$num -= 1; $num -= 1;
$data = \GuzzleHttp\Stream\Stream::factory($data); $data = \GuzzleHttp\Psr7\stream_for($data);
$file = $destination . '-chunking-42-' . $total . '-' . $num; $file = $destination . '-chunking-42-' . $total . '-' . $num;
$this->makeDavRequest($user, 'PUT', $file, ['OC-Chunked' => '1'], $data, "uploads"); $this->makeDavRequest($user, 'PUT', $file, ['OC-Chunked' => '1'], $data, "uploads");
} }
/** /**
* @Given user :user creates a new chunking upload with id :id * @Given user :user creates a new chunking upload with id :id
*/ */
public function userCreatesANewChunkingUploadWithId($user, $id) public function userCreatesANewChunkingUploadWithId($user, $id) {
{ $destination = '/uploads/' . $user . '/' . $id;
$destination = '/uploads/'.$user.'/'.$id;
$this->makeDavRequest($user, 'MKCOL', $destination, [], null, "uploads"); $this->makeDavRequest($user, 'MKCOL', $destination, [], null, "uploads");
} }
/** /**
* @Given user :user uploads new chunk file :num with :data to id :id * @Given user :user uploads new chunk file :num with :data to id :id
*/ */
public function userUploadsNewChunkFileOfWithToId($user, $num, $data, $id) public function userUploadsNewChunkFileOfWithToId($user, $num, $data, $id) {
{ $data = \GuzzleHttp\Psr7\stream_for($data);
$data = \GuzzleHttp\Stream\Stream::factory($data); $destination = '/uploads/' . $user . '/' . $id . '/' . $num;
$destination = '/uploads/'. $user .'/'. $id .'/' . $num;
$this->makeDavRequest($user, 'PUT', $destination, [], $data, "uploads"); $this->makeDavRequest($user, 'PUT', $destination, [], $data, "uploads");
} }
/** /**
* @Given user :user moves new chunk file with id :id to :dest * @Given user :user moves new chunk file with id :id to :dest
*/ */
public function userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $dest) public function userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $dest) {
{
$source = '/uploads/' . $user . '/' . $id . '/.file'; $source = '/uploads/' . $user . '/' . $id . '/.file';
$destination = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $dest; $destination = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $dest;
$this->makeDavRequest($user, 'MOVE', $source, [ $this->makeDavRequest($user, 'MOVE', $source, [
@ -598,8 +584,7 @@ trait WebDav {
/** /**
* @Then user :user moves new chunk file with id :id to :dest with size :size * @Then user :user moves new chunk file with id :id to :dest with size :size
*/ */
public function userMovesNewChunkFileWithIdToMychunkedfileWithSize($user, $id, $dest, $size) public function userMovesNewChunkFileWithIdToMychunkedfileWithSize($user, $id, $dest, $size) {
{
$source = '/uploads/' . $user . '/' . $id . '/.file'; $source = '/uploads/' . $user . '/' . $id . '/.file';
$destination = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $dest; $destination = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $dest;
@ -608,7 +593,7 @@ trait WebDav {
'Destination' => $destination, 'Destination' => $destination,
'OC-Total-Length' => $size 'OC-Total-Length' => $size
], null, "uploads"); ], null, "uploads");
} catch(\GuzzleHttp\Exception\BadResponseException $ex) { } catch (\GuzzleHttp\Exception\BadResponseException $ex) {
$this->response = $ex->getResponse(); $this->response = $ex->getResponse();
} }
} }
@ -638,19 +623,19 @@ trait WebDav {
/** /**
* @When user :user favorites element :path * @When user :user favorites element :path
*/ */
public function userFavoritesElement($user, $path){ public function userFavoritesElement($user, $path) {
$this->response = $this->changeFavStateOfAnElement($user, $path, 1, 0, null); $this->response = $this->changeFavStateOfAnElement($user, $path, 1, 0, null);
} }
/** /**
* @When user :user unfavorites element :path * @When user :user unfavorites element :path
*/ */
public function userUnfavoritesElement($user, $path){ public function userUnfavoritesElement($user, $path) {
$this->response = $this->changeFavStateOfAnElement($user, $path, 0, 0, null); $this->response = $this->changeFavStateOfAnElement($user, $path, 0, 0, null);
} }
/*Set the elements of a proppatch, $folderDepth requires 1 to see elements without children*/ /*Set the elements of a proppatch, $folderDepth requires 1 to see elements without children*/
public function changeFavStateOfAnElement($user, $path, $favOrUnfav, $folderDepth, $properties = null){ public function changeFavStateOfAnElement($user, $path, $favOrUnfav, $folderDepth, $properties = null) {
$fullUrl = substr($this->baseUrl, 0, -4); $fullUrl = substr($this->baseUrl, 0, -4);
$settings = [ $settings = [
'baseUri' => $fullUrl, 'baseUri' => $fullUrl,
@ -677,17 +662,17 @@ trait WebDav {
/** /**
* @Given user :user stores etag of element :path * @Given user :user stores etag of element :path
*/ */
public function userStoresEtagOfElement($user, $path){ public function userStoresEtagOfElement($user, $path) {
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]); $propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
$this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable); $this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable);
$pathETAG[$path] = $this->response['{DAV:}getetag']; $pathETAG[$path] = $this->response['{DAV:}getetag'];
$this->storedETAG[$user]= $pathETAG; $this->storedETAG[$user] = $pathETAG;
} }
/** /**
* @Then etag of element :path of user :user has not changed * @Then etag of element :path of user :user has not changed
*/ */
public function checkIfETAGHasNotChanged($path, $user){ public function checkIfETAGHasNotChanged($path, $user) {
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]); $propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
$this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable); $this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable);
PHPUnit_Framework_Assert::assertEquals($this->response['{DAV:}getetag'], $this->storedETAG[$user][$path]); PHPUnit_Framework_Assert::assertEquals($this->response['{DAV:}getetag'], $this->storedETAG[$user][$path]);
@ -696,7 +681,7 @@ trait WebDav {
/** /**
* @Then etag of element :path of user :user has changed * @Then etag of element :path of user :user has changed
*/ */
public function checkIfETAGHasChanged($path, $user){ public function checkIfETAGHasChanged($path, $user) {
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]); $propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
$this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable); $this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable);
PHPUnit_Framework_Assert::assertNotEquals($this->response['{DAV:}getetag'], $this->storedETAG[$user][$path]); PHPUnit_Framework_Assert::assertNotEquals($this->response['{DAV:}getetag'], $this->storedETAG[$user][$path]);
@ -724,25 +709,25 @@ trait WebDav {
throw new \Exception('Duplicate header found: ' . $headerName); throw new \Exception('Duplicate header found: ' . $headerName);
} }
} }
} }
/** /**
* @Then /^user "([^"]*)" in folder "([^"]*)" should have favorited the following elements$/ * @Then /^user "([^"]*)" in folder "([^"]*)" should have favorited the following elements$/
* @param string $user * @param string $user
* @param string $folder * @param string $folder
* @param \Behat\Gherkin\Node\TableNode|null $expectedElements * @param \Behat\Gherkin\Node\TableNode|null $expectedElements
*/ */
public function checkFavoritedElements($user, $folder, $expectedElements){ public function checkFavoritedElements($user, $folder, $expectedElements) {
$elementList = $this->reportFolder($user, $elementList = $this->reportFolder($user,
$folder, $folder,
'<oc:favorite/>', '<oc:favorite/>',
'<oc:favorite>1</oc:favorite>'); '<oc:favorite>1</oc:favorite>');
if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) { if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) {
$elementRows = $expectedElements->getRows(); $elementRows = $expectedElements->getRows();
$elementsSimplified = $this->simplifyArray($elementRows); $elementsSimplified = $this->simplifyArray($elementRows);
foreach($elementsSimplified as $expectedElement) { foreach ($elementsSimplified as $expectedElement) {
$webdavPath = "/" . $this->getDavFilesPath($user) . $expectedElement; $webdavPath = "/" . $this->getDavFilesPath($user) . $expectedElement;
if (!array_key_exists($webdavPath,$elementList)){ if (!array_key_exists($webdavPath, $elementList)) {
PHPUnit_Framework_Assert::fail("$webdavPath" . " is not in report answer"); PHPUnit_Framework_Assert::fail("$webdavPath" . " is not in report answer");
} }
} }
@ -754,12 +739,12 @@ trait WebDav {
* @param string $user * @param string $user
* @param string $folder * @param string $folder
*/ */
public function userDeletesEverythingInFolder($user, $folder) { public function userDeletesEverythingInFolder($user, $folder) {
$elementList = $this->listFolder($user, $folder, 1); $elementList = $this->listFolder($user, $folder, 1);
$elementListKeys = array_keys($elementList); $elementListKeys = array_keys($elementList);
array_shift($elementListKeys); array_shift($elementListKeys);
$davPrefix = "/" . $this->getDavFilesPath($user); $davPrefix = "/" . $this->getDavFilesPath($user);
foreach($elementListKeys as $element) { foreach ($elementListKeys as $element) {
if (substr($element, 0, strlen($davPrefix)) == $davPrefix) { if (substr($element, 0, strlen($davPrefix)) == $davPrefix) {
$element = substr($element, strlen($davPrefix)); $element = substr($element, strlen($davPrefix));
} }
@ -776,7 +761,7 @@ trait WebDav {
private function getFileIdForPath($user, $path) { private function getFileIdForPath($user, $path) {
$propertiesTable = new \Behat\Gherkin\Node\TableNode([["{http://owncloud.org/ns}fileid"]]); $propertiesTable = new \Behat\Gherkin\Node\TableNode([["{http://owncloud.org/ns}fileid"]]);
$this->asGetsPropertiesOfFolderWith($user, 'file', $path, $propertiesTable); $this->asGetsPropertiesOfFolderWith($user, 'file', $path, $propertiesTable);
return (int) $this->response['{http://owncloud.org/ns}fileid']; return (int)$this->response['{http://owncloud.org/ns}fileid'];
} }
/** /**