2015-11-24 15:48:06 +03:00
|
|
|
<?php
|
2016-07-21 19:13:36 +03:00
|
|
|
/**
|
2017-11-06 17:56:42 +03:00
|
|
|
*
|
2016-07-21 19:13:36 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Sergio Bertolin <sbertolin@solidgear.es>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Sergio Bertolín <sbertolin@solidgear.es>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2016-07-21 19:13:36 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-07-21 19:13:36 +03:00
|
|
|
*
|
|
|
|
*/
|
2017-01-02 13:20:22 +03:00
|
|
|
|
2019-06-03 16:24:26 +03:00
|
|
|
use Behat\Gherkin\Node\TableNode;
|
2015-11-24 15:48:06 +03:00
|
|
|
use GuzzleHttp\Client;
|
2017-01-02 13:20:22 +03:00
|
|
|
use GuzzleHttp\Cookie\CookieJar;
|
|
|
|
use GuzzleHttp\Exception\ClientException;
|
2018-06-13 08:15:42 +03:00
|
|
|
use PHPUnit\Framework\Assert;
|
2018-02-09 15:19:39 +03:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2015-11-24 15:48:06 +03:00
|
|
|
|
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
|
2016-02-25 19:19:24 +03:00
|
|
|
trait BasicStructure {
|
2016-05-03 17:21:49 +03:00
|
|
|
|
|
|
|
use Auth;
|
2018-02-06 16:50:15 +03:00
|
|
|
use Download;
|
2017-02-01 12:54:10 +03:00
|
|
|
use Trashbin;
|
2016-05-03 17:21:49 +03:00
|
|
|
|
2015-11-24 15:48:06 +03:00
|
|
|
/** @var string */
|
|
|
|
private $currentUser = '';
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $currentServer = '';
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $baseUrl = '';
|
|
|
|
|
2016-03-11 12:23:38 +03:00
|
|
|
/** @var int */
|
|
|
|
private $apiVersion = 1;
|
|
|
|
|
2015-11-24 15:48:06 +03:00
|
|
|
/** @var ResponseInterface */
|
|
|
|
private $response = null;
|
|
|
|
|
2017-01-02 13:20:22 +03:00
|
|
|
/** @var CookieJar */
|
2016-02-25 19:19:24 +03:00
|
|
|
private $cookieJar;
|
|
|
|
|
|
|
|
/** @var string */
|
2016-04-12 15:42:29 +03:00
|
|
|
private $requestToken;
|
2016-02-25 19:19:24 +03:00
|
|
|
|
2017-09-27 18:46:24 +03:00
|
|
|
protected $adminUser;
|
|
|
|
protected $regularUser;
|
|
|
|
protected $localBaseUrl;
|
|
|
|
protected $remoteBaseUrl;
|
|
|
|
|
2015-11-24 15:48:06 +03:00
|
|
|
public function __construct($baseUrl, $admin, $regular_user_password) {
|
|
|
|
|
|
|
|
// Initialize your context here
|
|
|
|
$this->baseUrl = $baseUrl;
|
|
|
|
$this->adminUser = $admin;
|
|
|
|
$this->regularUser = $regular_user_password;
|
2016-04-12 15:42:29 +03:00
|
|
|
$this->localBaseUrl = $this->baseUrl;
|
|
|
|
$this->remoteBaseUrl = $this->baseUrl;
|
2015-11-24 15:48:06 +03:00
|
|
|
$this->currentServer = 'LOCAL';
|
2017-01-02 13:20:22 +03:00
|
|
|
$this->cookieJar = new CookieJar();
|
2015-11-24 15:48:06 +03:00
|
|
|
|
|
|
|
// in case of ci deployment we take the server url from the environment
|
|
|
|
$testServerUrl = getenv('TEST_SERVER_URL');
|
|
|
|
if ($testServerUrl !== false) {
|
|
|
|
$this->baseUrl = $testServerUrl;
|
|
|
|
$this->localBaseUrl = $testServerUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// federated server url from the environment
|
|
|
|
$testRemoteServerUrl = getenv('TEST_SERVER_FED_URL');
|
|
|
|
if ($testRemoteServerUrl !== false) {
|
|
|
|
$this->remoteBaseUrl = $testRemoteServerUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 12:23:38 +03:00
|
|
|
/**
|
2017-03-17 13:07:51 +03:00
|
|
|
* @Given /^using api version "(\d+)"$/
|
2016-03-11 12:23:38 +03:00
|
|
|
* @param string $version
|
|
|
|
*/
|
|
|
|
public function usingApiVersion($version) {
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->apiVersion = (int)$version;
|
2016-03-11 12:23:38 +03:00
|
|
|
}
|
|
|
|
|
2015-11-24 15:48:06 +03:00
|
|
|
/**
|
|
|
|
* @Given /^As an "([^"]*)"$/
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param string $user
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
|
|
|
public function asAn($user) {
|
|
|
|
$this->currentUser = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-14 12:51:52 +03:00
|
|
|
* @Given /^Using server "(LOCAL|REMOTE)"$/
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param string $server
|
2016-03-14 12:51:52 +03:00
|
|
|
* @return string Previous used server
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
|
|
|
public function usingServer($server) {
|
2016-03-14 12:51:52 +03:00
|
|
|
$previousServer = $this->currentServer;
|
2018-02-09 15:19:39 +03:00
|
|
|
if ($server === 'LOCAL') {
|
2015-11-24 15:48:06 +03:00
|
|
|
$this->baseUrl = $this->localBaseUrl;
|
|
|
|
$this->currentServer = 'LOCAL';
|
2016-03-14 12:51:52 +03:00
|
|
|
return $previousServer;
|
|
|
|
} else {
|
2015-11-24 15:48:06 +03:00
|
|
|
$this->baseUrl = $this->remoteBaseUrl;
|
|
|
|
$this->currentServer = 'REMOTE';
|
2016-03-14 12:51:52 +03:00
|
|
|
return $previousServer;
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^sending "([^"]*)" to "([^"]*)"$/
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param string $verb
|
|
|
|
* @param string $url
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
|
|
|
public function sendingTo($verb, $url) {
|
|
|
|
$this->sendingToWith($verb, $url, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the xml answer to get ocs response which doesn't match with
|
|
|
|
* http one in v1 of the api.
|
2018-02-09 15:19:39 +03:00
|
|
|
*
|
2015-11-24 15:48:06 +03:00
|
|
|
* @param ResponseInterface $response
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getOCSResponse($response) {
|
2018-02-09 15:19:39 +03:00
|
|
|
return simplexml_load_string($response->getBody())->meta[0]->statuscode;
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is needed to use a vertical fashion in the gherkin tables.
|
2018-02-09 15:19:39 +03:00
|
|
|
*
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param array $arrayOfArrays
|
|
|
|
* @return array
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function simplifyArray($arrayOfArrays) {
|
|
|
|
$a = array_map(function ($subArray) {
|
|
|
|
return $subArray[0];
|
|
|
|
}, $arrayOfArrays);
|
2015-11-24 15:48:06 +03:00
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^sending "([^"]*)" to "([^"]*)" with$/
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param string $verb
|
|
|
|
* @param string $url
|
2019-06-03 16:24:26 +03:00
|
|
|
* @param TableNode $body
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
|
|
|
public function sendingToWith($verb, $url, $body) {
|
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url;
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
} else {
|
|
|
|
$options['auth'] = [$this->currentUser, $this->regularUser];
|
|
|
|
}
|
2016-08-01 09:33:49 +03:00
|
|
|
$options['headers'] = [
|
|
|
|
'OCS_APIREQUEST' => 'true'
|
|
|
|
];
|
2019-06-03 16:24:26 +03:00
|
|
|
if ($body instanceof TableNode) {
|
2015-11-24 15:48:06 +03:00
|
|
|
$fd = $body->getRowsHash();
|
2018-02-09 15:19:39 +03:00
|
|
|
$options['form_params'] = $fd;
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:46:33 +03:00
|
|
|
// TODO: Fix this hack!
|
|
|
|
if ($verb === 'PUT' && $body === null) {
|
2018-02-09 15:19:39 +03:00
|
|
|
$options['form_params'] = [
|
2016-08-12 11:46:33 +03:00
|
|
|
'foo' => 'bar',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-11-24 15:48:06 +03:00
|
|
|
try {
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->response = $client->request($verb, $fullUrl, $options);
|
2017-01-02 13:20:22 +03:00
|
|
|
} catch (ClientException $ex) {
|
2015-11-24 15:48:06 +03:00
|
|
|
$this->response = $ex->getResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:51:54 +03:00
|
|
|
/**
|
|
|
|
* @When /^sending "([^"]*)" with exact url to "([^"]*)"$/
|
|
|
|
* @param string $verb
|
|
|
|
* @param string $url
|
|
|
|
*/
|
|
|
|
public function sendingToDirectUrl($verb, $url) {
|
|
|
|
$this->sendingToWithDirectUrl($verb, $url, null);
|
|
|
|
}
|
|
|
|
|
2016-08-30 09:47:39 +03:00
|
|
|
public function sendingToWithDirectUrl($verb, $url, $body) {
|
|
|
|
$fullUrl = substr($this->baseUrl, 0, -5) . $url;
|
|
|
|
$client = new Client();
|
|
|
|
$options = [];
|
|
|
|
if ($this->currentUser === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
} else {
|
|
|
|
$options['auth'] = [$this->currentUser, $this->regularUser];
|
|
|
|
}
|
2019-06-03 16:24:26 +03:00
|
|
|
if ($body instanceof TableNode) {
|
2016-08-30 09:47:39 +03:00
|
|
|
$fd = $body->getRowsHash();
|
2018-02-09 15:19:39 +03:00
|
|
|
$options['form_params'] = $fd;
|
2016-08-30 09:47:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->response = $client->request($verb, $fullUrl, $options);
|
2017-01-02 13:20:22 +03:00
|
|
|
} catch (ClientException $ex) {
|
2016-08-30 09:47:39 +03:00
|
|
|
$this->response = $ex->getResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
public function isExpectedUrl($possibleUrl, $finalPart) {
|
2015-11-24 15:48:06 +03:00
|
|
|
$baseUrlChopped = substr($this->baseUrl, 0, -4);
|
|
|
|
$endCharacter = strlen($baseUrlChopped) + strlen($finalPart);
|
2018-02-09 15:19:39 +03:00
|
|
|
return (substr($possibleUrl, 0, $endCharacter) == "$baseUrlChopped" . "$finalPart");
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then /^the OCS status code should be "([^"]*)"$/
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param int $statusCode
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
|
|
|
public function theOCSStatusCodeShouldBe($statusCode) {
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertEquals($statusCode, $this->getOCSResponse($this->response));
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then /^the HTTP status code should be "([^"]*)"$/
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param int $statusCode
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
|
|
|
public function theHTTPStatusCodeShouldBe($statusCode) {
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertEquals($statusCode, $this->response->getStatusCode());
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
2016-09-07 14:01:42 +03:00
|
|
|
/**
|
|
|
|
* @Then /^the Content-Type should be "([^"]*)"$/
|
|
|
|
* @param string $contentType
|
|
|
|
*/
|
|
|
|
public function theContentTypeShouldbe($contentType) {
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertEquals($contentType, $this->response->getHeader('Content-Type')[0]);
|
2016-09-07 14:01:42 +03:00
|
|
|
}
|
|
|
|
|
2016-02-25 19:19:24 +03:00
|
|
|
/**
|
|
|
|
* @param ResponseInterface $response
|
|
|
|
*/
|
2018-02-12 17:41:23 +03:00
|
|
|
private function extracRequestTokenFromResponse(ResponseInterface $response) {
|
2016-04-12 15:42:29 +03:00
|
|
|
$this->requestToken = substr(preg_replace('/(.*)data-requesttoken="(.*)">(.*)/sm', '\2', $response->getBody()->getContents()), 0, 89);
|
2016-02-25 19:19:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given Logging in using web as :user
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param string $user
|
2016-02-25 19:19:24 +03:00
|
|
|
*/
|
|
|
|
public function loggingInUsingWebAs($user) {
|
2016-04-28 12:59:26 +03:00
|
|
|
$loginUrl = substr($this->baseUrl, 0, -5) . '/login';
|
2016-02-25 19:19:24 +03:00
|
|
|
// Request a new session and extract CSRF token
|
|
|
|
$client = new Client();
|
|
|
|
$response = $client->get(
|
|
|
|
$loginUrl,
|
|
|
|
[
|
|
|
|
'cookies' => $this->cookieJar,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->extracRequestTokenFromResponse($response);
|
|
|
|
|
|
|
|
// Login and extract new token
|
|
|
|
$password = ($user === 'admin') ? 'admin' : '123456';
|
|
|
|
$client = new Client();
|
|
|
|
$response = $client->post(
|
|
|
|
$loginUrl,
|
|
|
|
[
|
2018-02-09 15:19:39 +03:00
|
|
|
'form_params' => [
|
2016-02-25 19:19:24 +03:00
|
|
|
'user' => $user,
|
|
|
|
'password' => $password,
|
2016-04-12 15:42:29 +03:00
|
|
|
'requesttoken' => $this->requestToken,
|
2016-02-25 19:19:24 +03:00
|
|
|
],
|
|
|
|
'cookies' => $this->cookieJar,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->extracRequestTokenFromResponse($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When Sending a :method to :url with requesttoken
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param string $method
|
|
|
|
* @param string $url
|
2016-02-25 19:19:24 +03:00
|
|
|
*/
|
|
|
|
public function sendingAToWithRequesttoken($method, $url) {
|
|
|
|
$baseUrl = substr($this->baseUrl, 0, -5);
|
|
|
|
|
|
|
|
$client = new Client();
|
|
|
|
try {
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->response = $client->request(
|
|
|
|
$method,
|
|
|
|
$baseUrl . $url,
|
|
|
|
[
|
|
|
|
'cookies' => $this->cookieJar,
|
|
|
|
'headers' => [
|
|
|
|
'requesttoken' => $this->requestToken
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
2017-01-02 13:20:22 +03:00
|
|
|
} catch (ClientException $e) {
|
2016-02-25 19:19:24 +03:00
|
|
|
$this->response = $e->getResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When Sending a :method to :url without requesttoken
|
2016-03-11 12:37:21 +03:00
|
|
|
* @param string $method
|
|
|
|
* @param string $url
|
2016-02-25 19:19:24 +03:00
|
|
|
*/
|
|
|
|
public function sendingAToWithoutRequesttoken($method, $url) {
|
|
|
|
$baseUrl = substr($this->baseUrl, 0, -5);
|
|
|
|
|
|
|
|
$client = new Client();
|
|
|
|
try {
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->response = $client->request(
|
|
|
|
$method,
|
|
|
|
$baseUrl . $url,
|
|
|
|
[
|
|
|
|
'cookies' => $this->cookieJar
|
|
|
|
]
|
|
|
|
);
|
2017-01-02 13:20:22 +03:00
|
|
|
} catch (ClientException $e) {
|
2016-02-25 19:19:24 +03:00
|
|
|
$this->response = $e->getResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
public static function removeFile($path, $filename) {
|
2015-11-24 15:48:06 +03:00
|
|
|
if (file_exists("$path" . "$filename")) {
|
|
|
|
unlink("$path" . "$filename");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-14 15:27:17 +03:00
|
|
|
/**
|
|
|
|
* @Given User :user modifies text of :filename with text :text
|
|
|
|
* @param string $user
|
|
|
|
* @param string $filename
|
|
|
|
* @param string $text
|
|
|
|
*/
|
|
|
|
public function modifyTextOfFile($user, $filename, $text) {
|
2018-02-06 19:55:15 +03:00
|
|
|
self::removeFile($this->getDataDirectory() . "/$user/files", "$filename");
|
|
|
|
file_put_contents($this->getDataDirectory() . "/$user/files" . "$filename", "$text");
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getDataDirectory() {
|
|
|
|
// Based on "runOcc" from CommandLine trait
|
|
|
|
$args = ['config:system:get', 'datadirectory'];
|
|
|
|
$args = array_map(function($arg) {
|
|
|
|
return escapeshellarg($arg);
|
|
|
|
}, $args);
|
|
|
|
$args[] = '--no-ansi --no-warnings';
|
|
|
|
$args = implode(' ', $args);
|
|
|
|
|
|
|
|
$descriptor = [
|
|
|
|
0 => ['pipe', 'r'],
|
|
|
|
1 => ['pipe', 'w'],
|
|
|
|
2 => ['pipe', 'w'],
|
|
|
|
];
|
|
|
|
$process = proc_open('php console.php ' . $args, $descriptor, $pipes, $ocPath = '../..');
|
|
|
|
$lastStdOut = stream_get_contents($pipes[1]);
|
|
|
|
proc_close($process);
|
|
|
|
|
|
|
|
return trim($lastStdOut);
|
2016-04-14 15:27:17 +03:00
|
|
|
}
|
|
|
|
|
2018-02-06 16:50:15 +03:00
|
|
|
/**
|
|
|
|
* @Given file :filename is created :times times in :user user data
|
|
|
|
* @param string $filename
|
|
|
|
* @param string $times
|
|
|
|
* @param string $user
|
|
|
|
*/
|
|
|
|
public function fileIsCreatedTimesInUserData($filename, $times, $user) {
|
|
|
|
for ($i = 0; $i < $times; $i++) {
|
|
|
|
file_put_contents($this->getDataDirectory() . "/$user/files" . "$filename-$i", "content-$i");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:17:01 +03:00
|
|
|
public function createFileSpecificSize($name, $size) {
|
|
|
|
$file = fopen("work/" . "$name", 'w');
|
2018-02-09 15:19:39 +03:00
|
|
|
fseek($file, $size - 1, SEEK_CUR);
|
|
|
|
fwrite($file, 'a'); // write a dummy char at SIZE position
|
2016-09-26 13:44:14 +03:00
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
public function createFileWithText($name, $text) {
|
2017-03-01 13:10:30 +03:00
|
|
|
$file = fopen("work/" . "$name", 'w');
|
|
|
|
fwrite($file, $text);
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given file :filename of size :size is created in local storage
|
|
|
|
* @param string $filename
|
|
|
|
* @param string $size
|
|
|
|
*/
|
|
|
|
public function fileIsCreatedInLocalStorageWithSize($filename, $size) {
|
|
|
|
$this->createFileSpecificSize("local_storage/$filename", $size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given file :filename with text :text is created in local storage
|
|
|
|
* @param string $filename
|
|
|
|
* @param string $text
|
|
|
|
*/
|
|
|
|
public function fileIsCreatedInLocalStorageWithText($filename, $text) {
|
|
|
|
$this->createFileWithText("local_storage/$filename", $text);
|
|
|
|
}
|
|
|
|
|
2016-11-04 13:16:12 +03:00
|
|
|
/**
|
|
|
|
* @When Sleep for :seconds seconds
|
|
|
|
* @param int $seconds
|
|
|
|
*/
|
|
|
|
public function sleepForSeconds($seconds) {
|
|
|
|
sleep((int)$seconds);
|
|
|
|
}
|
|
|
|
|
2015-11-24 15:48:06 +03:00
|
|
|
/**
|
|
|
|
* @BeforeSuite
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public static function addFilesToSkeleton() {
|
|
|
|
for ($i = 0; $i < 5; $i++) {
|
2016-07-29 00:46:36 +03:00
|
|
|
file_put_contents("../../core/skeleton/" . "textfile" . "$i" . ".txt", "Nextcloud test text file\n");
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
if (!file_exists("../../core/skeleton/FOLDER")) {
|
|
|
|
mkdir("../../core/skeleton/FOLDER", 0777, true);
|
|
|
|
}
|
2015-11-27 15:55:48 +03:00
|
|
|
if (!file_exists("../../core/skeleton/PARENT")) {
|
|
|
|
mkdir("../../core/skeleton/PARENT", 0777, true);
|
|
|
|
}
|
2016-07-29 00:46:36 +03:00
|
|
|
file_put_contents("../../core/skeleton/PARENT/" . "parent.txt", "Nextcloud test text file\n");
|
2015-11-27 15:55:48 +03:00
|
|
|
if (!file_exists("../../core/skeleton/PARENT/CHILD")) {
|
|
|
|
mkdir("../../core/skeleton/PARENT/CHILD", 0777, true);
|
|
|
|
}
|
2016-07-29 00:46:36 +03:00
|
|
|
file_put_contents("../../core/skeleton/PARENT/CHILD/" . "child.txt", "Nextcloud test text file\n");
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @AfterSuite
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public static function removeFilesFromSkeleton() {
|
|
|
|
for ($i = 0; $i < 5; $i++) {
|
2015-11-24 15:48:06 +03:00
|
|
|
self::removeFile("../../core/skeleton/", "textfile" . "$i" . ".txt");
|
|
|
|
}
|
|
|
|
if (is_dir("../../core/skeleton/FOLDER")) {
|
|
|
|
rmdir("../../core/skeleton/FOLDER");
|
|
|
|
}
|
2015-11-27 15:55:48 +03:00
|
|
|
self::removeFile("../../core/skeleton/PARENT/CHILD/", "child.txt");
|
|
|
|
if (is_dir("../../core/skeleton/PARENT/CHILD")) {
|
|
|
|
rmdir("../../core/skeleton/PARENT/CHILD");
|
|
|
|
}
|
|
|
|
self::removeFile("../../core/skeleton/PARENT/", "parent.txt");
|
|
|
|
if (is_dir("../../core/skeleton/PARENT")) {
|
|
|
|
rmdir("../../core/skeleton/PARENT");
|
|
|
|
}
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
2016-08-09 11:24:03 +03:00
|
|
|
|
2016-08-26 10:57:48 +03:00
|
|
|
/**
|
|
|
|
* @BeforeScenario @local_storage
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public static function removeFilesFromLocalStorageBefore() {
|
2016-08-30 13:53:19 +03:00
|
|
|
$dir = "./work/local_storage/";
|
2016-08-26 10:57:48 +03:00
|
|
|
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
|
|
|
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
|
2018-02-09 15:19:39 +03:00
|
|
|
foreach ($ri as $file) {
|
|
|
|
$file->isDir() ? rmdir($file) : unlink($file);
|
2016-08-26 10:57:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-09 11:24:03 +03:00
|
|
|
/**
|
|
|
|
* @AfterScenario @local_storage
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public static function removeFilesFromLocalStorageAfter() {
|
2016-08-30 13:53:19 +03:00
|
|
|
$dir = "./work/local_storage/";
|
2016-08-09 11:24:03 +03:00
|
|
|
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
|
|
|
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
|
2018-02-09 15:19:39 +03:00
|
|
|
foreach ($ri as $file) {
|
|
|
|
$file->isDir() ? rmdir($file) : unlink($file);
|
2016-08-09 11:24:03 +03:00
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:43:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^cookies are reset$/
|
|
|
|
*/
|
|
|
|
public function cookiesAreReset() {
|
|
|
|
$this->cookieJar = new CookieJar();
|
|
|
|
}
|
2019-06-03 16:24:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then The following headers should be set
|
|
|
|
* @param TableNode $table
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function theFollowingHeadersShouldBeSet(TableNode $table) {
|
|
|
|
foreach($table->getTable() as $header) {
|
|
|
|
$headerName = $header[0];
|
|
|
|
$expectedHeaderValue = $header[1];
|
|
|
|
$returnedHeader = $this->response->getHeader($headerName)[0];
|
|
|
|
if($returnedHeader !== $expectedHeaderValue) {
|
|
|
|
throw new \Exception(
|
|
|
|
sprintf(
|
|
|
|
"Expected value '%s' for header '%s', got '%s'",
|
|
|
|
$expectedHeaderValue,
|
|
|
|
$headerName,
|
|
|
|
$returnedHeader
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|