Cleanup acceptance tests (#6195)
This commit is contained in:
@@ -27,20 +27,15 @@ use Behat\Gherkin\Node\TableNode;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use TestHelpers\OcsApiHelper;
|
||||
use TestHelpers\OcisHelper;
|
||||
use TestHelpers\SharingHelper;
|
||||
use TestHelpers\HttpRequestHelper;
|
||||
use TestHelpers\SetupHelper;
|
||||
use TestHelpers\TranslationHelper;
|
||||
|
||||
/**
|
||||
* Sharing trait
|
||||
*/
|
||||
trait Sharing {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $sharingApiVersion = 1;
|
||||
private int $sharingApiVersion = 1;
|
||||
|
||||
/**
|
||||
* Contains the API response to the last share that was created by each user
|
||||
@@ -48,7 +43,7 @@ trait Sharing {
|
||||
*
|
||||
* @var SimpleXMLElement[]
|
||||
*/
|
||||
private $lastShareDataByUser = [];
|
||||
private array $lastShareDataByUser = [];
|
||||
|
||||
/**
|
||||
* Contains the share id of the last share that was created by each user,
|
||||
@@ -56,51 +51,33 @@ trait Sharing {
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $lastShareIdByUser = [];
|
||||
private array $lastShareIdByUser = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $userWhoCreatedLastShare = null;
|
||||
private ?string $userWhoCreatedLastShare = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $userWhoCreatedLastPublicShare = null;
|
||||
private ?string $userWhoCreatedLastPublicShare = null;
|
||||
|
||||
/**
|
||||
* Contains the API response to the last public link share that was created
|
||||
* by the test-runner using the Sharing API.
|
||||
* Shares created on the webUI do not have an entry.
|
||||
*
|
||||
* @var SimpleXMLElement
|
||||
*/
|
||||
private $lastPublicShareData = null;
|
||||
private ?SimpleXMLElement $lastPublicShareData = null;
|
||||
|
||||
/**
|
||||
* Contains the share id of the last public link share that was created by
|
||||
* the test-runner, either using the Sharing API or on the web UI.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $lastPublicShareId = null;
|
||||
private ?string $lastPublicShareId = null;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $savedShareId = null;
|
||||
private ?int $savedShareId = null;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $localLastShareTime = null;
|
||||
private ?float $localLastShareTime = null;
|
||||
|
||||
/**
|
||||
* Defines the fields that can be provided in a share request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $shareFields = [
|
||||
private array $shareFields = [
|
||||
'path', 'name', 'publicUpload', 'password', 'expireDate',
|
||||
'expireDateAsString', 'permissions', 'shareWith', 'shareType'
|
||||
];
|
||||
@@ -114,7 +91,7 @@ trait Sharing {
|
||||
*
|
||||
* @var array fields that are possible in a share response
|
||||
*/
|
||||
private $shareResponseFields = [
|
||||
private array $shareResponseFields = [
|
||||
'id', 'share_type', 'uid_owner', 'displayname_owner', 'stime', 'parent',
|
||||
'expiration', 'token', 'uid_file_owner', 'displayname_file_owner', 'path',
|
||||
'item_type', 'mimetype', 'storage_id', 'storage', 'item_source',
|
||||
@@ -126,7 +103,7 @@ trait Sharing {
|
||||
* Contains information about the public links that have been created with the webUI.
|
||||
* Each entry in the array has a "name", "url" and "path".
|
||||
*/
|
||||
private $createdPublicLinks = [];
|
||||
private array $createdPublicLinks = [];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@@ -244,9 +221,9 @@ trait Sharing {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @return float|null
|
||||
*/
|
||||
public function getLocalLastShareTime():int {
|
||||
public function getLocalLastShareTime():?float {
|
||||
return $this->localLastShareTime;
|
||||
}
|
||||
|
||||
@@ -263,7 +240,7 @@ trait Sharing {
|
||||
* @return string
|
||||
*/
|
||||
public function getSharesEndpointPath(?string $postfix = ''):string {
|
||||
return "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares$postfix";
|
||||
return "/apps/files_sharing/api/v$this->sharingApiVersion/shares$postfix";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,7 +285,7 @@ trait Sharing {
|
||||
*/
|
||||
public function getServerShareTimeFromLastResponse():int {
|
||||
$stime = $this->getResponseXml(null, __METHOD__)->xpath("//stime");
|
||||
if ((bool) $stime) {
|
||||
if ($stime) {
|
||||
return (int) $stime[0];
|
||||
}
|
||||
throw new Exception("Last share time (i.e. 'stime') could not be found in the response.");
|
||||
@@ -875,58 +852,6 @@ trait Sharing {
|
||||
return \json_decode(\json_encode($this->getLastShareData()->data->mimetype), true)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param string|null $user
|
||||
* @param string|null $password
|
||||
* @param string|null $mimeType
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function checkDownload(
|
||||
string $url,
|
||||
?string $user = null,
|
||||
?string $password = null,
|
||||
?string $mimeType = null
|
||||
) {
|
||||
$password = $this->getActualPassword($password);
|
||||
$headers = ['X-Requested-With' => 'XMLHttpRequest'];
|
||||
$this->response = HttpRequestHelper::get(
|
||||
$url,
|
||||
$this->getStepLineRef(),
|
||||
$user,
|
||||
$password,
|
||||
$headers
|
||||
);
|
||||
Assert::assertEquals(
|
||||
200,
|
||||
$this->response->getStatusCode(),
|
||||
__METHOD__
|
||||
. " Expected status code is '200' but got '"
|
||||
. $this->response->getStatusCode()
|
||||
. "'"
|
||||
);
|
||||
|
||||
$buf = '';
|
||||
$body = $this->response->getBody();
|
||||
while (!$body->eof()) {
|
||||
// read everything
|
||||
$buf .= $body->read(8192);
|
||||
}
|
||||
$body->close();
|
||||
|
||||
if ($mimeType !== null) {
|
||||
$finfo = new finfo;
|
||||
Assert::assertEquals(
|
||||
$mimeType,
|
||||
$finfo->buffer($buf, FILEINFO_MIME_TYPE),
|
||||
__METHOD__
|
||||
. " Expected mimeType '$mimeType' but got '"
|
||||
. $finfo->buffer($buf, FILEINFO_MIME_TYPE)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^user "([^"]*)" should not be able to create a public link share of (file|folder) "([^"]*)" using the sharing API$/
|
||||
*
|
||||
@@ -2065,8 +1990,7 @@ trait Sharing {
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
"DELETE",
|
||||
$url,
|
||||
null
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2192,7 +2116,7 @@ trait Sharing {
|
||||
/**
|
||||
* @Then /^as "([^"]*)" the info about the last share by user "([^"]*)" with user "([^"]*)" should include$/
|
||||
*
|
||||
* @param string $requestor
|
||||
* @param string $requester
|
||||
* @param string $sharer
|
||||
* @param string $sharee
|
||||
* @param TableNode $table
|
||||
@@ -2201,12 +2125,12 @@ trait Sharing {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function asLastShareInfoAboutUserSharingWithUserShouldInclude(
|
||||
string $requestor,
|
||||
string $sharer,
|
||||
string $sharee,
|
||||
string $requester,
|
||||
string $sharer,
|
||||
string $sharee,
|
||||
TableNode $table
|
||||
) {
|
||||
$this->userGetsInfoOfLastShareUsingTheSharingApi($requestor);
|
||||
$this->userGetsInfoOfLastShareUsingTheSharingApi($requester);
|
||||
$this->ocsContext->assertOCSResponseIndicatesSuccess();
|
||||
$this->checkFieldsOfLastResponseToUser($sharer, $sharee, $table);
|
||||
}
|
||||
@@ -2297,7 +2221,7 @@ trait Sharing {
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLastShareIdForUser(string $user):?string {
|
||||
if ($user === null) {
|
||||
if ($user === "") {
|
||||
throw new Exception(
|
||||
__METHOD__ . " user not specified. Probably no user or group shares have been created yet in the test scenario."
|
||||
);
|
||||
@@ -2370,8 +2294,7 @@ trait Sharing {
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
'GET',
|
||||
$url,
|
||||
null
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2383,7 +2306,7 @@ trait Sharing {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function userGetsTheLastShareSharedWithHimUsingTheSharingApi(string $user, $table):void {
|
||||
public function userGetsTheLastShareSharedWithHimUsingTheSharingApi(string $user, TableNode $table):void {
|
||||
$user = $this->getActualUsername($user);
|
||||
$shareId = $this->getLastPublicLinkShareId();
|
||||
$this->getShareData($user, $shareId);
|
||||
@@ -2419,8 +2342,7 @@ trait Sharing {
|
||||
'GET',
|
||||
$this->getSharesEndpointPath(
|
||||
"?shared_with_me=true" . $pendingClause . "&share_types=" . $rawShareTypes
|
||||
),
|
||||
null
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2435,12 +2357,11 @@ trait Sharing {
|
||||
public function userGetsAllSharesSharedWithHimFromFileOrFolderUsingTheProvisioningApi(string $user, string $path):void {
|
||||
$user = $this->getActualUsername($user);
|
||||
$url = "/apps/files_sharing/api/"
|
||||
. "v{$this->sharingApiVersion}/shares?shared_with_me=true&path=$path";
|
||||
. "v$this->sharingApiVersion/shares?shared_with_me=true&path=$path";
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
'GET',
|
||||
$url,
|
||||
null
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2918,7 +2839,7 @@ trait Sharing {
|
||||
$responseXml = $this->getResponseXml(null, __METHOD__)->data[0];
|
||||
$actualAttributesElement = $responseXml->xpath('//attributes');
|
||||
|
||||
if ((bool) $actualAttributesElement) {
|
||||
if ($actualAttributesElement) {
|
||||
$actualAttributes = (array) $actualAttributesElement[0];
|
||||
if (empty($actualAttributes)) {
|
||||
throw new Exception(
|
||||
@@ -3004,17 +2925,13 @@ trait Sharing {
|
||||
$user = $this->getActualUsername($user);
|
||||
$this->downloadFileAsUserUsingPassword($user, $fileName);
|
||||
$receivedErrorMessage = $this->getResponseXml(null, __METHOD__)->xpath('//s:message');
|
||||
if ((bool) $errorMessage) {
|
||||
Assert::assertEquals(
|
||||
$errorMessage,
|
||||
(string) $receivedErrorMessage[0],
|
||||
"Expected error message was '$errorMessage' but got '"
|
||||
. (string) $receivedErrorMessage[0]
|
||||
. "'"
|
||||
);
|
||||
return;
|
||||
}
|
||||
throw new Exception("No 's:message' element found on the response.");
|
||||
Assert::assertEquals(
|
||||
$errorMessage,
|
||||
(string) $receivedErrorMessage[0],
|
||||
"Expected error message was '$errorMessage' but got '"
|
||||
. (string) $receivedErrorMessage[0]
|
||||
. "'"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3072,7 +2989,7 @@ trait Sharing {
|
||||
$user,
|
||||
$this->getPasswordForUser($user),
|
||||
"DELETE",
|
||||
$this->getSharesEndpointPath("/{$id}"),
|
||||
$this->getSharesEndpointPath("/$id"),
|
||||
$this->getStepLineRef(),
|
||||
[],
|
||||
$this->ocsApiVersion
|
||||
@@ -3185,7 +3102,7 @@ trait Sharing {
|
||||
(string) $elementResponded->path[0],
|
||||
__METHOD__
|
||||
. " Expected '${expectedElementsArray['path']}' but got '"
|
||||
. (string) $elementResponded->path[0]
|
||||
. $elementResponded->path[0]
|
||||
. "'"
|
||||
);
|
||||
Assert::assertEquals(
|
||||
@@ -3193,7 +3110,7 @@ trait Sharing {
|
||||
(string) $elementResponded->permissions[0],
|
||||
__METHOD__
|
||||
. " Expected '${expectedElementsArray['permissions']}' but got '"
|
||||
. (string) $elementResponded->permissions[0]
|
||||
. $elementResponded->permissions[0]
|
||||
. "'"
|
||||
);
|
||||
$nameFound = true;
|
||||
@@ -3268,8 +3185,7 @@ trait Sharing {
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
"DELETE",
|
||||
$url,
|
||||
null
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3362,19 +3278,19 @@ trait Sharing {
|
||||
$shareId,
|
||||
__METHOD__ . " could not find share $share, offered by $offeredBy to $user"
|
||||
);
|
||||
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}" .
|
||||
$url = "/apps/files_sharing/api/v$this->sharingApiVersion" .
|
||||
"/shares/pending/$shareId";
|
||||
if (\substr($action, 0, 7) === "decline") {
|
||||
$httpRequestMethod = "DELETE";
|
||||
} elseif (\substr($action, 0, 6) === "accept") {
|
||||
} else {
|
||||
// do a POST to accept the share
|
||||
$httpRequestMethod = "POST";
|
||||
}
|
||||
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
$httpRequestMethod,
|
||||
$url,
|
||||
null
|
||||
$url
|
||||
);
|
||||
$this->pushToLastStatusCodesArrays();
|
||||
}
|
||||
@@ -3420,19 +3336,19 @@ trait Sharing {
|
||||
|
||||
$shareId = $this->substituteInLineCodes($share_id, $user);
|
||||
|
||||
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}" .
|
||||
$url = "/apps/files_sharing/api/v$this->sharingApiVersion" .
|
||||
"/shares/pending/$shareId";
|
||||
if (\substr($action, 0, 7) === "decline") {
|
||||
$httpRequestMethod = "DELETE";
|
||||
} elseif (\substr($action, 0, 6) === "accept") {
|
||||
} else {
|
||||
// do a POST to accept the share
|
||||
$httpRequestMethod = "POST";
|
||||
}
|
||||
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
$httpRequestMethod,
|
||||
$url,
|
||||
null
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3451,8 +3367,7 @@ trait Sharing {
|
||||
$this->userReactsToShareOfferedBy($user, $action, $share, $offeredBy);
|
||||
if ($action === 'declined') {
|
||||
$actionText = 'decline';
|
||||
}
|
||||
if ($action === 'accepted') {
|
||||
} else {
|
||||
$actionText = 'accept';
|
||||
}
|
||||
$this->theHTTPStatusCodeShouldBe(
|
||||
@@ -3641,15 +3556,13 @@ trait Sharing {
|
||||
throw new InvalidArgumentException(
|
||||
__METHOD__ . ' invalid "state" given'
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$url = $this->getSharesEndpointPath("?format=json&shared_with_me=true&state=$stateCode");
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
"GET",
|
||||
$url,
|
||||
null
|
||||
$url
|
||||
);
|
||||
if ($this->response->getStatusCode() !== 200) {
|
||||
throw new Exception(
|
||||
@@ -3973,7 +3886,7 @@ trait Sharing {
|
||||
$adminUser,
|
||||
$this->getAdminPassword(),
|
||||
'POST',
|
||||
"/apps/testing/api/v1/expire-share/{$shareId}",
|
||||
"/apps/testing/api/v1/expire-share/$shareId",
|
||||
$this->getStepLineRef(),
|
||||
[],
|
||||
$this->getOcsApiVersion()
|
||||
|
||||
Reference in New Issue
Block a user