2022-03-30 21:34:41 +02:00
<? php
declare ( strict_types = 1 );
2021-11-03 09:32:21 +01:00
/**
* ownCloud
*
* @author Michael Barz <mbarz@owncloud.com>
* @copyright Copyright (c) 2021 Michael Barz mbarz@owncloud.com
*
* This code 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 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
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
2022-03-30 21:34:41 +02:00
2021-10-20 17:25:09 +02:00
use Behat\Behat\Context\Context ;
use Behat\Behat\Hook\Scope\BeforeScenarioScope ;
2023-03-15 10:06:58 +05:45
use Behat\Gherkin\Node\PyStringNode ;
2021-10-28 13:27:41 +05:45
use Behat\Gherkin\Node\TableNode ;
2021-10-28 11:13:17 +02:00
use GuzzleHttp\Exception\GuzzleException ;
2024-10-08 12:26:40 +05:45
use PHPUnit\Framework\Assert ;
2021-10-20 17:25:09 +02:00
use Psr\Http\Message\ResponseInterface ;
use TestHelpers\HttpRequestHelper ;
2022-08-09 14:00:02 +05:45
use TestHelpers\WebDavHelper ;
2022-04-25 11:35:50 +02:00
use TestHelpers\GraphHelper ;
2024-10-08 12:26:40 +05:45
use TestHelpers\OcisHelper ;
use TestHelpers\BehatHelper ;
2026-07-14 10:53:02 +05:45
use TestHelpers\KeycloakHelper ;
2021-10-20 17:25:09 +02:00
require_once 'bootstrap.php' ;
/**
* Context for ocis spaces specific steps
*/
class SpacesContext implements Context {
2021-11-11 12:15:15 +05:45
private FeatureContext $featureContext ;
2021-12-21 13:47:15 +05:45
private OCSContext $ocsContext ;
2022-04-12 08:51:35 +02:00
private TrashbinContext $trashbinContext ;
2022-08-09 14:00:02 +05:45
private WebDavPropertiesContext $webDavPropertiesContext ;
2022-09-01 14:19:11 +05:45
private FavoritesContext $favoritesContext ;
2022-09-08 13:00:48 +05:45
private ChecksumContext $checksumContext ;
2022-09-14 13:38:15 +05:45
private FilesVersionsContext $filesVersionsContext ;
2024-09-17 17:11:20 +05:45
private ArchiverContext $archiverContext ;
2021-12-22 09:49:44 +05:45
2021-11-11 12:19:54 +05:45
/**
2023-05-02 17:25:56 +05:45
* key is space name and value is the username that created the space
2021-11-11 12:19:54 +05:45
*/
2025-02-17 17:44:48 +05:45
private array $createdSpaces = [];
2026-08-07 09:11:49 +05:45
private array $createdVaultSpaces = [];
2022-05-11 15:04:12 +05:45
private string $ocsApiUrl = '/ocs/v2.php/apps/files_sharing/api/v1/shares' ;
2022-05-11 09:13:59 +02:00
2022-07-14 16:59:36 +05:45
/**
* @var array map with user as key, spaces and file etags as value
* @example
* [
* "user1" => [
* "Personal" => [
* "file1.txt": "etag1",
* ],
2022-10-20 20:49:57 +02:00
* "Shares" => []
2022-07-14 16:59:36 +05:45
* ],
* "user2" => [
* ...
* ]
* ]
*/
2023-05-02 17:25:56 +05:45
private array $storedEtags = [];
2022-07-14 16:59:36 +05:45
2021-11-11 12:19:54 +05:45
/**
2025-02-17 17:44:48 +05:45
* @param string $spaceCreator
* @param object $space
2021-11-11 12:19:54 +05:45
*
2025-02-17 17:44:48 +05:45
* @return void
2021-11-11 12:19:54 +05:45
*/
2025-02-17 17:44:48 +05:45
public function addToCreatedSpace ( string $spaceCreator , object $space ) : void {
$spaceName = $space -> name ;
$this -> createdSpaces [ $spaceName ] = $space ;
$this -> createdSpaces [ $spaceName ] -> spaceCreator = $spaceCreator ;
$this -> createdSpaces [ $spaceName ] -> fileId = $space -> id . '!' . $space -> owner -> user -> id ;
2025-02-17 18:44:30 +05:45
$this -> createdSpaces [ $spaceName ] -> serverType = $this -> featureContext -> getCurrentServer ();
2021-11-11 12:19:54 +05:45
}
2026-08-07 09:11:49 +05:45
/**
* @param string $spaceCreator
* @param object $space
*
* @return void
*/
public function addToCreatedVaultSpace ( string $spaceCreator , object $space ) : void {
$spaceName = $space -> name ;
$this -> createdVaultSpaces [ $spaceName ] = $space ;
$this -> createdVaultSpaces [ $spaceName ] -> spaceCreator = $spaceCreator ;
$this -> createdVaultSpaces [ $spaceName ] -> fileId = $space -> id . '!' . $space -> owner -> user -> id ;
$this -> createdVaultSpaces [ $spaceName ] -> serverType = $this -> featureContext -> getCurrentServer ();
}
2021-11-11 12:19:54 +05:45
/**
2025-02-17 17:44:48 +05:45
* @return array
2021-11-11 12:19:54 +05:45
*/
2025-02-17 17:44:48 +05:45
public function getCreatedSpaces () : array {
return $this -> createdSpaces ;
2024-01-31 16:26:29 +05:45
}
2026-08-07 09:11:49 +05:45
/**
* @return array
*/
public function getCreatedVaultSpaces () : array {
return $this -> createdVaultSpaces ;
}
2024-01-31 16:26:29 +05:45
/**
* @param string $spaceName
*
2025-02-17 17:44:48 +05:45
* @return string name of the user that created the space
* @throws Exception
2024-01-31 16:26:29 +05:45
*/
2025-02-17 17:44:48 +05:45
public function getSpaceCreator ( string $spaceName ) : string {
if ( ! \array_key_exists ( $spaceName , $this -> createdSpaces )) {
throw new Exception ( __METHOD__ . " space ' $spaceName ' has not been created in this scenario" );
}
return $this -> createdSpaces [ $spaceName ][ 'spaceCreator' ];
2021-11-11 12:19:54 +05:45
}
2025-02-17 17:44:48 +05:45
private array $personalSpaces = [];
2021-11-11 12:15:15 +05:45
2025-02-17 18:44:30 +05:45
/**
* @return array
*/
public function getPersonalSpaces () : array {
return $this -> personalSpaces ;
}
2021-11-11 12:15:15 +05:45
/**
2025-02-17 17:44:48 +05:45
* @param string $user
*
* @return object|null
2021-11-11 12:15:15 +05:45
*/
2025-02-17 17:44:48 +05:45
public function getPersonalSpaceForUser ( string $user ) : ? object {
$spaceName = $this -> featureContext -> getUserDisplayName ( $user );
if ( ! isset ( $this -> personalSpaces [ $spaceName ])) {
return null ;
}
return $this -> personalSpaces [ $spaceName ];
2021-11-11 12:15:15 +05:45
}
/**
2025-02-17 17:44:48 +05:45
* @param string $user
* @param object $space
2026-07-14 10:53:02 +05:45
* @param boolean $isVault
2021-11-11 12:15:15 +05:45
*
* @return void
*/
2026-07-14 10:53:02 +05:45
public function addPersonalSpaceForUser ( string $user , object $space , bool $isVault = false ) : void {
2025-02-17 17:44:48 +05:45
$spaceName = $this -> featureContext -> getUserDisplayName ( $user );
$this -> personalSpaces [ $spaceName ] = $space ;
2025-02-17 18:44:30 +05:45
$this -> personalSpaces [ $spaceName ] -> serverType = $this -> featureContext -> getCurrentServer ();
2026-07-14 10:53:02 +05:45
$this -> personalSpaces [ $spaceName ] -> isVault = $isVault ;
2021-11-11 12:15:15 +05:45
}
/**
* Get SpaceId by Name
*
* @param $name string
*
* @return string
*
* @throws Exception
*/
public function getSpaceIdByNameFromResponse ( string $name ) : string {
$space = $this -> getSpaceByNameFromResponse ( $name );
Assert :: assertIsArray ( $space , "Space with name $name not found" );
if ( ! isset ( $space [ "id" ])) {
throw new Exception ( __METHOD__ . " space with name $name not found" );
}
return $space [ "id" ];
}
/**
* Get Space Array by name
*
* @param string $name
2023-10-17 11:41:47 +05:45
* @param ResponseInterface|null $response
2021-11-11 12:15:15 +05:45
*
* @return array
*
* @throws Exception
*/
2023-10-17 11:41:47 +05:45
public function getSpaceByNameFromResponse ( string $name , ? ResponseInterface $response = null ) : array {
$response = $response ?? $this -> featureContext -> getResponse ();
$decodedResponse = $this -> featureContext -> getJsonDecodedResponse ( $response );
$spaceAsArray = $decodedResponse ;
if ( isset ( $decodedResponse [ 'name' ]) && $decodedResponse [ 'name' ] === $name ) {
return $decodedResponse ;
2021-11-11 12:15:15 +05:45
}
2023-02-22 10:09:19 +01:00
if ( isset ( $spaceAsArray [ "value" ])) {
foreach ( $spaceAsArray [ "value" ] as $spaceCandidate ) {
if ( $spaceCandidate [ 'name' ] === $name ) {
return $spaceCandidate ;
}
2021-11-11 12:15:15 +05:45
}
}
return [];
}
/**
2021-12-02 00:01:52 +01:00
* @param string $user
* @param string $spaceName
2026-07-14 10:53:02 +05:45
* @param boolean $isVault
2021-11-11 12:15:15 +05:45
*
* @return array
2022-05-11 15:04:12 +05:45
* @throws GuzzleException
2021-11-11 12:15:15 +05:45
*/
2026-07-14 10:53:02 +05:45
public function getSpaceByName ( string $user , string $spaceName , bool $isVault = false ) : array {
2025-02-17 18:44:30 +05:45
$password = $this -> featureContext -> getPasswordForUser ( $user );
2026-08-07 09:11:49 +05:45
if ( $isVault ) {
$createdSpaces = $this -> getCreatedVaultSpaces ();
} else {
$createdSpaces = $this -> getCreatedSpaces ();
}
2025-02-17 18:44:30 +05:45
$personalSpaces = $this -> getPersonalSpaces ();
$allSpaces = \array_merge ( $createdSpaces , $personalSpaces );
2025-02-17 17:44:48 +05:45
2022-07-14 16:59:36 +05:45
if ( $spaceName === "Personal" ) {
$spaceName = $this -> featureContext -> getUserDisplayName ( $user );
}
2025-02-17 17:44:48 +05:45
2025-02-17 18:44:30 +05:45
if ( isset ( $allSpaces [ $spaceName ])
&& $allSpaces [ $spaceName ] -> serverType === $this -> featureContext -> getCurrentServer ()
2026-07-14 10:53:02 +05:45
&& ( ! isset ( $allSpaces [ $spaceName ] -> isVault ) || $allSpaces [ $spaceName ] -> isVault === $isVault )
2025-02-17 18:44:30 +05:45
) {
return json_decode ( json_encode ( $allSpaces [ $spaceName ]), true );
2022-08-04 13:11:51 +02:00
}
2023-10-19 13:32:47 +05:45
2026-07-14 10:53:02 +05:45
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$access_token = $this -> featureContext -> getOcisUserToken ( $user )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $access_token ;
}
2024-04-26 15:27:00 +05:45
// Sometimes listing available spaces might not return newly created/shared spaces.
// So we try again until we find the space or we reach the max number of retries (i.e. 10)
2023-10-19 13:32:47 +05:45
$retried = 0 ;
do {
2025-02-17 18:44:30 +05:45
// list 'me/drives' as given user
$response = GraphHelper :: getMySpaces (
2025-02-17 17:44:48 +05:45
$this -> featureContext -> getBaseUrl (),
2026-07-14 10:53:02 +05:45
KeycloakHelper :: isTestingWithKeycloak () ? null : $user ,
KeycloakHelper :: isTestingWithKeycloak () ? null : $password ,
2025-02-17 17:44:48 +05:45
"" ,
2026-07-14 10:53:02 +05:45
[],
$headers ,
$isVault ,
2025-02-17 17:44:48 +05:45
);
2025-02-17 18:44:30 +05:45
// NOTE: user can be created with empty password
2025-02-19 11:51:59 +05:45
// so if that's the case, the user won't be able to request using empty password
2025-02-17 18:44:30 +05:45
// and user won't have personal space.
if ( $response -> getStatusCode () === 401 && ! $password ) {
return [];
}
$this -> featureContext -> theHttpStatusCodeShouldBe (
200 ,
"Failed to fetch me/drives for user ' $user '" ,
2025-06-19 15:34:02 +05:45
$response ,
2025-02-17 18:44:30 +05:45
);
2025-02-17 17:44:48 +05:45
$spaces = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response ) -> value ;
2023-10-19 13:32:47 +05:45
2025-02-17 17:44:48 +05:45
$found = false ;
$foundSpace = [];
2025-02-19 11:51:59 +05:45
// update the Shares space with other properties
// NOTE: the order of drives list can be different
// so this extra loop is needed to find and update the Shares space properties
if ( $allSpaces [ "Shares" ] -> name !== "Shares" ) {
foreach ( $spaces as $space ) {
if ( $space -> name === "Shares" ) {
$this -> addPersonalSpaceForUser ( "Shares" , $space );
break ;
}
2025-02-17 17:44:48 +05:45
}
2025-02-19 11:51:59 +05:45
}
foreach ( $spaces as $space ) {
2025-02-24 12:16:45 +05:45
if ( $space -> name === $spaceName && ! isset ( $space -> root -> deleted )) {
2025-02-17 17:44:48 +05:45
$found = true ;
$foundSpace = $space ;
2025-02-17 18:44:30 +05:45
if ( $space -> driveType === "project" ) {
$this -> addToCreatedSpace ( $user , $space );
2025-02-19 11:51:59 +05:45
} elseif ( ! ( $space -> name === "Shares" && $space -> driveType === "virtual" )) {
2026-07-14 10:53:02 +05:45
$this -> addPersonalSpaceForUser ( $user , $space , $isVault );
2025-02-17 18:44:30 +05:45
}
2025-02-17 17:44:48 +05:45
break ;
}
}
2023-10-19 13:32:47 +05:45
2025-02-17 17:44:48 +05:45
$tryAgain = ! $found && $retried < HttpRequestHelper :: maxHTTPRequestRetries ();
2023-10-19 13:32:47 +05:45
if ( $tryAgain ) {
$retried += 1 ;
echo "Space ' $spaceName ' not found for user ' $user ', retrying ( $retried )... \n " ;
// wait 500ms and try again
\usleep ( 500 * 1000 );
}
} while ( $tryAgain );
2025-02-17 18:44:30 +05:45
Assert :: assertTrue ( $found , "Space ' $spaceName ' not found for user ' $user '" );
return json_decode ( json_encode ( $foundSpace ), true );
2021-11-11 12:15:15 +05:45
}
2023-06-27 12:50:10 +02:00
/**
* The method finds available spaces to the user and returns the spaceId by spaceName
*
* @param string $user
* @param string $spaceName
2026-07-14 10:53:02 +05:45
* @param boolean $isVault
2023-06-27 12:50:10 +02:00
*
* @return string
* @throws GuzzleException
*/
2026-07-14 10:53:02 +05:45
public function getSpaceIdByName ( string $user , string $spaceName , bool $isVault = false ) : string {
$space = $this -> getSpaceByName ( $user , $spaceName , $isVault );
2023-06-27 12:50:10 +02:00
return $space [ "id" ];
}
2025-05-22 12:07:02 +05:45
/**
* finds available spaces to the user and returns the owner userId by spaceName
*
* @param string $user
* @param string $spaceName
*
* @return string
* @throws GuzzleException
*/
public function getSpaceOwnerUserIdByName ( string $user , string $spaceName ) : string {
$space = $this -> getSpaceByName ( $user , $spaceName );
return $space [ "owner" ][ "user" ][ "id" ];
}
2024-10-24 12:30:50 +05:45
/**
* @param string $user
* @param string $share
*
2025-04-03 18:32:11 +05:45
* @return object
2024-10-24 12:30:50 +05:45
*
* @throws Exception|GuzzleException
*/
2025-04-03 18:32:11 +05:45
public function getSharesRemoteItem ( string $user , string $share ) : object {
2025-02-18 17:03:41 +05:45
$share = ltrim ( $share , '/' );
2024-10-24 12:30:50 +05:45
$credentials = $this -> featureContext -> graphContext -> getAdminOrUserCredentials ( $user );
$response = GraphHelper :: getSharesSharedWithMe (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
2025-06-19 15:34:02 +05:45
$credentials [ 'password' ],
2024-10-24 12:30:50 +05:45
);
$jsonBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response );
// Search remoteItem ID of a given share
foreach ( $jsonBody -> value as $item ) {
if ( isset ( $item -> name ) && $item -> name === $share ) {
2025-04-03 18:32:11 +05:45
return $item -> remoteItem ;
2024-10-24 12:30:50 +05:45
}
}
throw new Exception ( "Cannot find share: $share " );
}
2025-04-03 18:32:11 +05:45
/**
* @param string $user
* @param string $share
*
* @return string
*
* @throws Exception|GuzzleException
*/
public function getSharesRemoteItemId ( string $user , string $share ) : string {
$remoteItem = $this -> getSharesRemoteItem ( $user , $share );
if ( isset ( $remoteItem -> id )) {
return $remoteItem -> id ;
}
throw new Exception ( "Failed to find remoteItem ID for share: $share " );
}
/**
* @param string $user
* @param string $share
*
* @return string
*
* @throws Exception|GuzzleException
*/
public function getSharesRemoteItemParentDriveId ( string $user , string $share ) : string {
$remoteItem = $this -> getSharesRemoteItem ( $user , $share );
if ( isset ( $remoteItem -> parentReference -> driveId )) {
return $remoteItem -> parentReference -> driveId ;
}
throw new Exception ( "Failed to find remoteItem ID for share: $share " );
}
2022-03-10 09:29:26 +01:00
/**
2022-05-03 09:48:12 +05:45
* The method finds file by fileName and spaceName and returns data of file which contains in responseHeader
2022-03-10 09:29:26 +01:00
* fileName contains the path, if the file is in the folder
*
* @param string $user
* @param string $spaceName
* @param string $fileName
2024-10-24 12:30:50 +05:45
* @param bool $federatedShare
2026-07-28 14:23:42 +05:45
* @param bool $isVault
2022-03-10 09:29:26 +01:00
*
2022-03-30 21:34:41 +02:00
* @return ResponseInterface
2022-05-11 15:04:12 +05:45
* @throws GuzzleException
2022-03-10 09:29:26 +01:00
*/
2024-12-24 09:30:42 +05:45
public function getFileData (
string $user ,
string $spaceName ,
string $fileName ,
2025-06-19 15:34:02 +05:45
bool $federatedShare = false ,
2026-07-28 14:23:42 +05:45
bool $isVault = false ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
2024-10-24 12:30:50 +05:45
if ( $federatedShare ) {
$remoteItemId = $this -> getSharesRemoteItemId ( $user , $spaceName );
$spaceId = \rawurlencode ( $remoteItemId );
} else {
2026-07-28 14:23:42 +05:45
$space = $this -> getSpaceByName ( $user , $spaceName , $isVault );
2024-10-24 12:30:50 +05:45
$spaceId = $space [ "id" ];
}
$davPath = WebdavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $spaceId );
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $fileName " ;
2022-03-30 21:34:41 +02:00
2026-07-28 14:23:42 +05:45
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( $user )[ 'token' ][ 'accessToken' ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2022-12-05 22:27:51 +05:45
return HttpRequestHelper :: get (
$fullUrl ,
$user ,
2026-07-28 14:23:42 +05:45
$password ,
$headers ,
2025-06-19 15:34:02 +05:45
"{}" ,
2022-03-10 09:29:26 +01:00
);
}
/**
* The method returns fileId
*
* @param string $user
* @param string $spaceName
* @param string $fileName
2026-08-07 09:11:49 +05:45
* @param bool $isVault
2022-03-10 09:29:26 +01:00
*
* @return string
2022-05-11 15:04:12 +05:45
* @throws GuzzleException
2022-03-10 09:29:26 +01:00
*/
2026-08-07 09:11:49 +05:45
public function getFileId ( string $user , string $spaceName , string $fileName , bool $isVault = false ) : string {
$fileData = $this -> getFileData ( $user , $spaceName , $fileName , false , $isVault ) -> getHeaders ();
2022-03-10 09:29:26 +01:00
return $fileData [ "Oc-Fileid" ][ 0 ];
}
2022-10-17 13:46:07 +02:00
/**
2023-02-01 09:55:51 +01:00
* The method returns "fileid" from the PROPFIND response
2022-10-17 13:46:07 +02:00
*
* @param string $user
* @param string $spaceName
* @param string $folderName
2026-07-30 12:07:41 +05:45
* @param boolean $isVault
2022-10-17 13:46:07 +02:00
*
* @return string
* @throws GuzzleException
*/
2026-07-30 12:07:41 +05:45
public function getResourceId ( string $user , string $spaceName , string $folderName , bool $isVault = false ) : string {
$space = $this -> getSpaceByName ( $user , $spaceName , $isVault );
2022-10-17 13:46:07 +02:00
// For a level 1 folder, the parent is space so $folderName = ''
if ( $folderName === $space [ "name" ]) {
$folderName = '' ;
}
2024-09-17 17:11:20 +05:45
$encodedName = \rawurlencode ( $folderName );
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebDavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $encodedName " ;
2024-09-17 17:11:20 +05:45
2026-07-30 12:07:41 +05:45
$headers = [ 'Depth' => '0' ];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( $user )[ 'token' ][ 'accessToken' ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2022-12-05 22:27:51 +05:45
$response = HttpRequestHelper :: sendRequest (
$fullUrl ,
'PROPFIND' ,
$user ,
2026-07-30 12:07:41 +05:45
$password ,
$headers ,
2022-10-17 13:46:07 +02:00
);
2024-10-01 12:58:30 +05:45
$this -> featureContext -> theHttpStatusCodeShouldBe ( 207 , '' , $response );
2024-11-29 13:19:54 +05:45
$responseXmlObject = HttpRequestHelper :: getResponseXml ( $response , __METHOD__ );
$fileId = $responseXmlObject -> xpath ( "//d:response/d:propstat/d:prop/oc:fileid" )[ 0 ];
2024-10-01 12:58:30 +05:45
return $fileId -> __toString ();
2022-10-17 13:46:07 +02:00
}
2022-11-28 14:27:41 +05:45
/**
* @param string $user
* @param string $spaceName
*
* @return string
* @throws GuzzleException
* @throws JsonException
*/
public function getPrivateLink ( string $user , string $spaceName ) : string {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2022-11-28 14:27:41 +05:45
$response = WebDavHelper :: propfind (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
"" ,
[ 'oc:privatelink' ],
"0" ,
2024-09-18 11:26:20 +05:45
$spaceId ,
2022-11-28 14:27:41 +05:45
"files" ,
2025-06-19 15:34:02 +05:45
WebDavHelper :: DAV_VERSION_SPACES ,
2022-11-28 14:27:41 +05:45
);
2024-12-24 09:30:42 +05:45
$responseArray = json_decode (
json_encode (
HttpRequestHelper :: getResponseXml ( $response , __METHOD__ )
2025-06-19 15:34:02 +05:45
-> xpath ( "//d:response/d:propstat/d:prop/oc:privatelink" ),
2024-12-24 09:30:42 +05:45
),
true ,
512 ,
2025-06-19 15:34:02 +05:45
JSON_THROW_ON_ERROR ,
2024-12-24 09:30:42 +05:45
);
2022-11-28 14:27:41 +05:45
Assert :: assertNotEmpty ( $responseArray , "the PROPFIND response for $spaceName is empty" );
return $responseArray [ 0 ][ 0 ];
}
2022-03-10 09:29:26 +01:00
/**
* The method returns eTag
*
* @param string $user
* @param string $spaceName
* @param string $fileName
*
* @return string
2022-05-11 15:04:12 +05:45
* @throws GuzzleException
2022-03-10 09:29:26 +01:00
*/
public function getETag ( string $user , string $spaceName , string $fileName ) : string {
2022-03-30 21:34:41 +02:00
$fileData = $this -> getFileData ( $user , $spaceName , $fileName ) -> getHeaders ();
2023-03-15 10:06:58 +05:45
return \str_replace ( '"' , '\"' , $fileData [ "Etag" ][ 0 ]);
2022-03-10 09:29:26 +01:00
}
2023-10-20 15:04:07 +05:45
/**
* @param string $user
* @param string $spaceName
*
* @return string
*
* @throws GuzzleException
*/
public function getEtagOfASpace ( string $user , string $spaceName ) : string {
2024-05-21 15:04:48 +05:45
return $this -> getSpaceByName ( $user , $spaceName )[ "root" ][ "eTag" ];
2023-10-20 15:04:07 +05:45
}
2021-11-11 12:15:15 +05:45
/**
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
*
* @throws Exception
*/
2024-10-08 12:26:40 +05:45
public function before ( BeforeScenarioScope $scope ) : void {
2021-11-11 12:15:15 +05:45
// Get the environment
$environment = $scope -> getEnvironment ();
// Get all the contexts you need in this context
2024-10-08 12:26:40 +05:45
$this -> featureContext = BehatHelper :: getContext ( $scope , $environment , 'FeatureContext' );
$this -> ocsContext = BehatHelper :: getContext ( $scope , $environment , 'OCSContext' );
$this -> trashbinContext = BehatHelper :: getContext ( $scope , $environment , 'TrashbinContext' );
$this -> webDavPropertiesContext = BehatHelper :: getContext ( $scope , $environment , 'WebDavPropertiesContext' );
$this -> favoritesContext = BehatHelper :: getContext ( $scope , $environment , 'FavoritesContext' );
$this -> checksumContext = BehatHelper :: getContext ( $scope , $environment , 'ChecksumContext' );
$this -> filesVersionsContext = BehatHelper :: getContext ( $scope , $environment , 'FilesVersionsContext' );
2024-09-17 17:11:20 +05:45
$this -> archiverContext = BehatHelper :: getContext ( $scope , $environment , 'ArchiverContext' );
2025-02-19 11:51:59 +05:45
// add Shares space as its drive-id is known
// NOTE: this cannot be moved into a constructor method
// because it uses the $this->featureContext object
$this -> personalSpaces = [
"Shares" => ( object )[
"id" => GraphHelper :: SHARES_SPACE_ID ,
// let 'name' be empty, it is used to update the shares space later on
"name" => "" ,
2025-06-19 10:46:56 +05:45
"serverType" => $this -> featureContext -> getCurrentServer (),
],
2025-02-19 11:51:59 +05:45
];
2021-11-11 12:15:15 +05:45
}
2022-08-04 13:11:51 +02:00
/**
* @AfterScenario
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function cleanDataAfterTests () : void {
2024-10-08 12:26:40 +05:45
if ( OcisHelper :: isTestingOnReva ()) {
return ;
}
2022-08-23 13:48:30 +02:00
$this -> deleteAllProjectSpaces ();
2022-08-04 13:11:51 +02:00
}
/**
2022-09-07 16:52:26 +02:00
* the admin user first disables and then deletes spaces
2022-08-04 13:11:51 +02:00
*
* @return void
*
* @throws Exception|GuzzleException
*/
2022-08-23 13:48:30 +02:00
public function deleteAllProjectSpaces () : void {
2022-08-04 13:11:51 +02:00
$userAdmin = $this -> featureContext -> getAdminUsername ();
2025-02-17 17:44:48 +05:45
$drives = $this -> getCreatedSpaces ();
2022-08-04 13:11:51 +02:00
2025-02-17 17:44:48 +05:45
foreach ( $drives as $drive ) {
if ( ! isset ( $drive -> root -> deleted )) {
2022-12-05 22:27:51 +05:45
GraphHelper :: disableSpace (
2022-09-07 17:11:34 +02:00
$this -> featureContext -> getBaseUrl (),
$userAdmin ,
$this -> featureContext -> getPasswordForUser ( $userAdmin ),
2025-02-17 17:44:48 +05:45
$drive -> id ,
2022-12-05 22:27:51 +05:45
);
}
GraphHelper :: deleteSpace (
$this -> featureContext -> getBaseUrl (),
$userAdmin ,
$this -> featureContext -> getPasswordForUser ( $userAdmin ),
2025-02-17 17:44:48 +05:45
$drive -> id ,
2022-09-07 17:11:34 +02:00
);
2022-08-04 13:11:51 +02:00
}
}
2022-07-21 17:42:39 +02:00
/**
* Send POST Request to url
*
* @param string $fullUrl
* @param string $user
* @param string $password
* @param mixed $body
* @param array $headers
2022-07-26 11:27:28 +02:00
*
2022-07-21 17:42:39 +02:00
* @return ResponseInterface
*
* @throws GuzzleException
*/
public function sendPostRequestToUrl (
string $fullUrl ,
string $user ,
string $password ,
$body ,
2025-06-19 15:34:02 +05:45
array $headers = [],
2022-07-21 17:42:39 +02:00
) : ResponseInterface {
2025-04-07 16:55:33 +05:45
return HttpRequestHelper :: post ( $fullUrl , $user , $password , $headers , $body );
2022-07-21 17:42:39 +02:00
}
/**
* Send Graph Create Folder Request
*
* @param string $fullUrl
* @param string $method
* @param string $user
* @param string $password
* @param array $headers
*
* @return ResponseInterface
*
* @throws GuzzleException
*/
public function sendCreateFolderRequest (
string $fullUrl ,
string $method ,
string $user ,
string $password ,
2025-06-19 15:34:02 +05:45
array $headers = [],
2022-07-21 17:42:39 +02:00
) : ResponseInterface {
2025-04-07 16:55:33 +05:45
return HttpRequestHelper :: sendRequest ( $fullUrl , $method , $user , $password , $headers );
2022-07-21 17:42:39 +02:00
}
2023-10-17 11:41:47 +05:45
/**
* @param string $user
* @param string $query
2024-01-24 19:25:20 +01:00
* @param array $headers
2023-10-17 11:41:47 +05:45
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
2025-02-17 17:44:48 +05:45
public function listAllMySpaces (
2024-12-24 09:30:42 +05:45
string $user ,
string $query = '' ,
2025-06-19 15:34:02 +05:45
array $headers = [],
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2025-02-17 17:44:48 +05:45
return GraphHelper :: getMySpaces (
2023-10-17 11:41:47 +05:45
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-02-17 17:44:48 +05:45
$query ,
2024-01-24 19:25:20 +01:00
[],
2025-06-19 15:34:02 +05:45
$headers ,
2023-10-17 11:41:47 +05:45
);
}
2021-11-11 12:15:15 +05:45
/**
2023-10-30 17:57:42 +05:45
* @When /^user "([^"]*)" lists all available spaces via the Graph API$/
* @When /^user "([^"]*)" lists all available spaces via the Graph API with query "([^"]*)"$/
2021-11-11 12:15:15 +05:45
*
* @param string $user
2022-07-08 05:18:40 +02:00
* @param string $query
2021-11-11 12:15:15 +05:45
*
* @return void
*
* @throws GuzzleException
2022-05-11 15:04:12 +05:45
* @throws Exception
2021-11-11 12:15:15 +05:45
*/
2022-07-08 05:18:40 +02:00
public function theUserListsAllHisAvailableSpacesUsingTheGraphApi ( string $user , string $query = '' ) : void {
2025-02-17 17:44:48 +05:45
$this -> featureContext -> setResponse ( $this -> listAllMySpaces ( $user , $query ));
2021-11-11 12:15:15 +05:45
}
2024-01-24 19:25:20 +01:00
/**
* @When /^user "([^"]*)" lists all available spaces with headers using the Graph API$/
*
* @param string $user
* @param TableNode $headersTable
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserListsAllHisAvailableSpacesWithHeadersUsingTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $headersTable ,
2024-12-24 09:30:42 +05:45
) : void {
2024-01-24 19:25:20 +01:00
$this -> featureContext -> verifyTableNodeColumns (
$headersTable ,
2025-06-19 15:34:02 +05:45
[ 'header' , 'value' ],
2024-01-24 19:25:20 +01:00
);
2024-04-26 15:27:00 +05:45
$headers = [];
2024-01-24 19:25:20 +01:00
foreach ( $headersTable as $row ) {
$headers [ $row [ 'header' ]] = $row [ 'value' ];
}
2025-02-17 17:44:48 +05:45
$this -> featureContext -> setResponse ( $this -> listAllMySpaces ( $user , '' , $headers ));
2023-10-17 11:41:47 +05:45
}
/**
2023-10-30 17:57:42 +05:45
* @When /^user "([^"]*)" lists all spaces via the Graph API$/
* @When /^user "([^"]*)" lists all spaces via the Graph API with query "([^"]*)"$/
* @When /^user "([^"]*)" tries to list all spaces via the Graph API$/
2022-04-29 22:22:41 +02:00
*
* @param string $user
2022-07-07 13:05:00 +02:00
* @param string $query
2022-04-29 22:22:41 +02:00
*
* @return void
*
* @throws GuzzleException
2022-05-11 15:04:12 +05:45
* @throws Exception
2022-04-29 22:22:41 +02:00
*/
2022-07-07 13:05:00 +02:00
public function theUserListsAllAvailableSpacesUsingTheGraphApi ( string $user , string $query = '' ) : void {
2025-02-17 17:44:48 +05:45
$response = GraphHelper :: getAllSpaces (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$query ,
2022-04-29 22:22:41 +02:00
);
2025-02-17 17:44:48 +05:45
$this -> featureContext -> setResponse ( $response );
2022-04-29 22:22:41 +02:00
}
2022-01-18 16:42:30 +01:00
/**
2023-10-30 17:57:42 +05:45
* @When /^user "([^"]*)" looks up the single space "([^"]*)" via the Graph API by using its id$/
2023-02-22 10:09:19 +01:00
* @When /^user "([^"]*)" tries to look up the single space "([^"]*)" owned by the user "([^"]*)" by using its id$/
2022-01-18 16:42:30 +01:00
*
* @param string $user
2022-05-11 15:04:12 +05:45
* @param string $spaceName
2023-02-22 10:09:19 +01:00
* @param string $ownerUser
2022-01-18 16:42:30 +01:00
*
2022-09-06 12:32:56 +05:45
* @return void
2022-01-18 16:42:30 +01:00
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function theUserLooksUpTheSingleSpaceUsingTheGraphApiByUsingItsId (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $ownerUser = '' ,
2024-12-24 09:30:42 +05:45
) : void {
2023-02-22 10:09:19 +01:00
$space = $this -> getSpaceByName (( $ownerUser !== "" ) ? $ownerUser : $user , $spaceName );
2023-05-02 17:25:56 +05:45
Assert :: assertNotEmpty ( $space [ "id" ]);
2022-05-11 15:04:12 +05:45
Assert :: assertNotEmpty ( $space [ "root" ][ "webDavUrl" ]);
2022-01-18 16:42:30 +01:00
$this -> featureContext -> setResponse (
2022-08-31 15:11:31 +02:00
GraphHelper :: getSingleSpace (
$this -> featureContext -> getBaseUrl (),
2022-01-18 16:42:30 +01:00
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2023-09-06 16:07:53 +05:45
$space [ "id" ],
'' ,
2025-06-19 15:34:02 +05:45
),
2022-01-18 16:42:30 +01:00
);
}
2021-11-11 12:15:15 +05:45
/**
2023-06-28 10:56:08 +05:45
* @When /^user "([^"]*)" (?:creates|tries to create) a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)" using the Graph API$/
2023-03-28 09:10:21 +05:45
* @When /^user "([^"]*)" (?:creates|tries to create) a space "([^"]*)" of type "([^"]*)" with the default quota using the Graph API$/
2021-11-11 12:15:15 +05:45
*
* @param string $user
* @param string $spaceName
* @param string $spaceType
2023-06-28 10:56:08 +05:45
* @param int|null $quota
2021-11-11 12:15:15 +05:45
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserCreatesASpaceWithQuotaUsingTheGraphApi (
string $user ,
string $spaceName ,
string $spaceType ,
2025-06-19 15:34:02 +05:45
? int $quota = null ,
2021-11-11 12:15:15 +05:45
) : void {
2024-05-28 11:36:02 +02:00
$space = [ "name" => $spaceName , "driveType" => $spaceType , "quota" => [ "total" => $quota ]];
2021-11-11 12:15:15 +05:45
$body = json_encode ( $space );
2024-01-31 16:26:29 +05:45
$response = GraphHelper :: createSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
2022-08-31 15:11:31 +02:00
);
2024-01-31 16:26:29 +05:45
$this -> featureContext -> setResponse ( $response );
2024-06-21 12:31:53 +05:45
if ( $response -> getStatusCode () === 201 ) {
2025-02-17 17:44:48 +05:45
$space = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response );
$this -> addToCreatedSpace ( $user , $space );
2024-01-31 16:26:29 +05:45
}
2021-11-11 12:15:15 +05:45
}
2024-05-21 15:04:48 +05:45
/**
* @param string $user
* @param string $spaceName
* @param string $foldersPath
2026-07-14 10:53:02 +05:45
* @param boolean $isVault
2024-05-21 15:04:48 +05:45
*
* @return ResponseInterface
* @throws GuzzleException
*/
2026-07-14 10:53:02 +05:45
public function propfindSpace (
string $user ,
string $spaceName ,
string $foldersPath = '' ,
bool $isVault = false ,
) : ResponseInterface {
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName , $isVault );
$password = $this -> featureContext -> getPasswordForUser ( $user );
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$access_token = $this -> featureContext -> getOcisUserToken ( $user )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $access_token ;
$user = null ;
$password = null ;
}
2024-05-21 15:04:48 +05:45
return WebDavHelper :: propfind (
$this -> featureContext -> getBaseUrl (),
$user ,
2026-07-14 10:53:02 +05:45
$password ,
2024-05-21 15:04:48 +05:45
$foldersPath ,
[],
null ,
2024-09-18 11:26:20 +05:45
$spaceId ,
2024-05-21 15:04:48 +05:45
'files' ,
2025-06-19 15:34:02 +05:45
WebDavHelper :: DAV_VERSION_SPACES ,
2026-07-14 10:53:02 +05:45
null ,
$headers ,
2024-05-21 15:04:48 +05:45
);
}
2021-11-11 12:15:15 +05:45
/**
* @When /^user "([^"]*)" lists the content of the space with the name "([^"]*)" using the WebDav Api$/
*
* @param string $user
2021-11-11 12:19:54 +05:45
* @param string $spaceName
2022-05-11 15:04:12 +05:45
* @param string $foldersPath
2021-11-11 12:15:15 +05:45
*
2022-09-06 12:32:56 +05:45
* @return void
2021-11-11 12:15:15 +05:45
* @throws GuzzleException
*/
public function theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi (
string $user ,
2022-01-25 14:59:15 +01:00
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $foldersPath = '' ,
2021-11-11 12:15:15 +05:45
) : void {
2024-05-21 15:04:48 +05:45
$this -> featureContext -> setResponse ( $this -> propfindSpace ( $user , $spaceName , $foldersPath ));
2021-11-11 12:15:15 +05:45
}
2023-01-04 12:11:09 +05:45
/**
* @When /^user "([^"]*)" sends PATCH request to the space "([^"]*)" of user "([^"]*)" with data "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $owner
* @param string $data
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSendsPatchRequestToTheSpaceOfUserWithData (
string $user ,
string $spaceName ,
string $owner ,
2025-06-19 15:34:02 +05:45
string $data ,
2024-12-24 09:30:42 +05:45
) : void {
2023-01-04 12:11:09 +05:45
$space = $this -> getSpaceByName ( $owner , $spaceName );
Assert :: assertIsArray ( $space );
Assert :: assertNotEmpty ( $spaceId = $space [ "id" ]);
$url = GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'drives/' . $spaceId );
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
$url ,
"PATCH" ,
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
null ,
2025-06-19 15:34:02 +05:45
$data ,
),
2023-01-04 12:11:09 +05:45
);
}
2021-11-11 12:15:15 +05:45
/**
* @Then /^the (?:propfind|search) result of the space should (not|)\s?contain these (?:files|entries):$/
*
* @param string $shouldOrNot (not|)
* @param TableNode $expectedFiles
*
* @return void
*
* @throws Exception
*/
public function thePropfindResultShouldContainEntries (
string $shouldOrNot ,
2025-06-19 15:34:02 +05:45
TableNode $expectedFiles ,
2021-12-21 13:47:15 +05:45
) : void {
2022-09-14 13:38:15 +05:45
$this -> featureContext -> propfindResultShouldContainEntries (
2021-11-11 12:15:15 +05:45
$shouldOrNot ,
$expectedFiles ,
);
}
2021-11-12 10:41:31 +05:45
/**
2026-07-14 10:53:02 +05:45
* @Then /^for user "([^"]*)" the space "([^"]*)"(| in vault)? should (not|)\s?contain these (?:files|entries):$/
2021-11-12 10:41:31 +05:45
*
* @param string $user
* @param string $spaceName
2026-07-14 10:53:02 +05:45
* @param string $isVault
2021-11-12 10:41:31 +05:45
* @param string $shouldOrNot (not|)
* @param TableNode $expectedFiles
*
* @return void
*
* @throws Exception|GuzzleException
*/
2021-12-14 10:10:13 +05:45
public function userTheSpaceShouldContainEntries (
2021-11-12 10:41:31 +05:45
string $user ,
string $spaceName ,
2026-07-14 10:53:02 +05:45
string $isVault ,
2021-11-12 10:41:31 +05:45
string $shouldOrNot ,
2025-06-19 15:34:02 +05:45
TableNode $expectedFiles ,
2021-12-21 13:47:15 +05:45
) : void {
2026-07-14 10:53:02 +05:45
$isVault = trim ( $isVault ) === "in vault" ;
$space = $this -> getSpaceByName ( $user , $spaceName , $isVault );
$this -> featureContext -> setResponse ( $this -> propfindSpace ( $user , $spaceName , '' , $isVault ));
2024-12-24 09:30:42 +05:45
$this -> featureContext -> propfindResultShouldContainEntries (
$shouldOrNot ,
$expectedFiles ,
$user ,
'PROPFIND' ,
'' ,
2025-06-19 15:34:02 +05:45
$space [ 'id' ],
2024-12-24 09:30:42 +05:45
);
2022-01-25 14:59:15 +01:00
}
/**
2026-07-28 14:23:42 +05:45
* @Then /^for user "([^"]*)" folder "([^"]*)" of the space "([^"]*)"(| in vault)? should (not|)\s?contain these (?:files|entries):$/
2022-01-25 14:59:15 +01:00
*
* @param string $user
* @param string $folderPath
* @param string $spaceName
2026-07-28 14:23:42 +05:45
* @param string $isVault
2022-01-25 14:59:15 +01:00
* @param string $shouldOrNot (not|)
* @param TableNode $expectedFiles
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function folderOfTheSpaceShouldContainEntries (
string $user ,
string $folderPath ,
string $spaceName ,
2026-07-28 14:23:42 +05:45
string $isVault ,
2022-01-25 14:59:15 +01:00
string $shouldOrNot ,
2025-06-19 15:34:02 +05:45
TableNode $expectedFiles ,
2022-01-25 14:59:15 +01:00
) : void {
2026-07-28 14:23:42 +05:45
$isVault = trim ( $isVault ) === 'in vault' ;
$space = $this -> getSpaceByName ( $user , $spaceName , $isVault );
$this -> featureContext -> setResponse ( $this -> propfindSpace ( $user , $spaceName , $folderPath , $isVault ));
2022-09-14 13:38:15 +05:45
$this -> featureContext -> propfindResultShouldContainEntries (
2021-11-12 10:41:31 +05:45
$shouldOrNot ,
$expectedFiles ,
2022-09-14 13:38:15 +05:45
$this -> featureContext -> getActualUsername ( $user ),
'PROPFIND' ,
2024-09-18 11:26:20 +05:45
$folderPath ,
2025-06-19 15:34:02 +05:45
$space [ 'id' ],
2021-11-12 10:41:31 +05:45
);
}
2022-03-30 21:34:41 +02:00
/**
2026-07-28 14:23:42 +05:45
* @Then /^for user "([^"]*)" the content of the file "([^"]*)" of the space "([^"]*)"(| in vault) should be "([^"]*)"$/
2022-03-30 21:34:41 +02:00
*
* @param string $user
* @param string $file
* @param string $spaceName
2026-07-28 14:23:42 +05:45
* @param string $isVault
2022-03-30 21:34:41 +02:00
* @param string $fileContent
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function checkFileContent (
string $user ,
string $file ,
string $spaceName ,
2026-07-28 14:23:42 +05:45
string $isVault ,
2025-06-19 15:34:02 +05:45
string $fileContent ,
2022-03-30 21:34:41 +02:00
) : void {
2026-07-28 14:23:42 +05:45
$isVault = trim ( $isVault ) === 'in vault' ;
$actualFileContent = $this -> getFileData ( $user , $spaceName , $file , false , $isVault ) -> getBody () -> getContents ();
2022-03-30 21:34:41 +02:00
Assert :: assertEquals ( $fileContent , $actualFileContent , " $file does not contain $fileContent " );
}
2024-10-24 12:30:50 +05:45
/**
* @Then /^for user "([^"]*)" the content of file "([^"]*)" of federated share "([^"]*)" should be "([^"]*)"$/
*
* @param string $user
* @param string $file
* @param string $share
* @param string $fileContent
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function forUserTheContentOfFileOfFederatedShareShouldBe (
string $user ,
string $file ,
string $share ,
2025-06-19 15:34:02 +05:45
string $fileContent ,
2024-10-24 12:30:50 +05:45
) : void {
2024-12-24 09:30:42 +05:45
$actualFileContent = $this -> getFileData (
$user ,
$share ,
$file ,
2025-06-19 15:34:02 +05:45
true ,
2024-12-24 09:30:42 +05:45
) -> getBody () -> getContents ();
2024-10-24 12:30:50 +05:45
Assert :: assertEquals ( $fileContent , $actualFileContent , "File content did not match" );
}
2023-03-15 10:06:58 +05:45
/**
* @Then /^the JSON response should contain space called "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )(?:|(?:with description file|with space image) "([^"]*)" )and match$/
*
* @param string $spaceName
* @param string|null $userName
* @param string|null $fileName
2023-03-31 21:23:01 +05:45
* @param PyStringNode|null $schemaString
2023-03-15 10:06:58 +05:45
*
* @return void
*/
public function theJsonDataFromLastResponseShouldMatch (
string $spaceName ,
? string $userName = null ,
? string $fileName = null ,
2025-06-19 15:34:02 +05:45
? PyStringNode $schemaString = null ,
2023-03-15 10:06:58 +05:45
) : void {
2023-03-31 21:23:01 +05:45
Assert :: assertNotNull ( $schemaString , 'schema is not valid JSON' );
2023-05-04 18:40:11 +05:45
2023-03-15 10:06:58 +05:45
if ( isset ( $this -> featureContext -> getJsonDecodedResponseBodyContent () -> value )) {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> value ;
foreach ( $responseBody as $value ) {
if ( isset ( $value -> name ) && $value -> name === $spaceName ) {
$responseBody = $value ;
break ;
}
}
} else {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
}
// substitute the value here
2023-03-31 21:23:01 +05:45
if ( \gettype ( $schemaString ) !== 'string' ) {
$schemaString = $schemaString -> getRaw ();
}
2023-03-15 10:06:58 +05:45
$schemaString = $this -> featureContext -> substituteInLineCodes (
$schemaString ,
$this -> featureContext -> getCurrentUser (),
[],
[
[
"code" => "%space_id%" ,
"function" =>
[ $this , "getSpaceIdByNameFromResponse" ],
2025-06-19 10:46:56 +05:45
"parameter" => [ $spaceName ],
2023-03-15 10:06:58 +05:45
],
[
"code" => "%file_id%" ,
"function" =>
[ $this , "getFileId" ],
2025-06-19 10:46:56 +05:45
"parameter" => [ $userName , $spaceName , $fileName ],
2023-03-15 10:06:58 +05:45
],
[
"code" => "%eTag%" ,
"function" =>
[ $this , "getETag" ],
2025-06-19 10:46:56 +05:45
"parameter" => [ $userName , $spaceName , $fileName ],
2023-03-15 10:06:58 +05:45
],
2023-10-20 15:04:07 +05:45
[
"code" => "%space_etag%" ,
"function" =>
[ $this , "getEtagOfASpace" ],
2025-06-19 10:46:56 +05:45
"parameter" => [ $userName , $spaceName ],
],
2023-03-15 10:06:58 +05:45
],
null ,
$userName ,
);
2023-06-02 14:36:05 +05:45
$this -> featureContext -> assertJsonDocumentMatchesSchema (
2023-03-15 10:06:58 +05:45
$responseBody ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getJSONSchema ( $schemaString ),
2023-03-15 10:06:58 +05:45
);
}
2022-07-08 05:18:40 +02:00
/**
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" granted to "([^"]*)" with role "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $grantedUser
2022-02-17 11:21:07 +01:00
* @param string $role
*
* @return void
2022-05-11 15:04:12 +05:45
* @throws Exception|GuzzleException
2022-02-17 11:21:07 +01:00
*/
public function checkPermissionsInResponse (
2022-07-08 05:18:40 +02:00
string $user ,
2022-02-17 11:21:07 +01:00
string $spaceName ,
2022-07-08 05:18:40 +02:00
string $grantedUser ,
2025-06-19 15:34:02 +05:45
string $role ,
2022-02-17 11:21:07 +01:00
) : void {
2025-02-17 17:44:48 +05:45
$response = $this -> listAllMySpaces ( $user );
2022-07-08 05:18:40 +02:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-07-08 05:18:40 +02:00
);
2024-12-24 09:30:42 +05:45
Assert :: assertIsArray (
$spaceAsArray = $this -> getSpaceByNameFromResponse ( $spaceName , $response ),
2025-06-19 15:34:02 +05:45
"No space with name $spaceName found" ,
2024-12-24 09:30:42 +05:45
);
2022-02-17 11:21:07 +01:00
$permissions = $spaceAsArray [ "root" ][ "permissions" ];
2023-02-16 16:34:13 +01:00
$userId = $this -> featureContext -> getUserIdByUserName ( $grantedUser );
2022-03-30 21:34:41 +02:00
2022-02-17 11:21:07 +01:00
$userRole = "" ;
foreach ( $permissions as $permission ) {
2022-12-30 17:23:56 +01:00
foreach ( $permission [ "grantedToIdentities" ] as $grantedToIdentities ) {
if ( $grantedToIdentities [ "user" ][ "id" ] === $userId ) {
2022-03-10 09:29:26 +01:00
$userRole = $permission [ "roles" ][ 0 ];
}
}
2022-02-17 11:21:07 +01:00
}
2022-07-08 05:18:40 +02:00
Assert :: assertEquals ( $userRole , $role , "the user $grantedUser with the role $role could not be found" );
2022-02-17 11:21:07 +01:00
}
2021-12-19 22:21:24 +01:00
/**
2024-12-17 12:24:11 +05:45
* @Then /^the json response should not contain a space with name "([^"]*)"$/
2021-12-19 22:21:24 +01:00
*
* @param string $spaceName
*
* @return void
* @throws Exception
*/
public function jsonRespondedShouldNotContain (
2025-06-19 15:34:02 +05:45
string $spaceName ,
2021-12-19 22:21:24 +01:00
) : void {
2024-12-24 09:30:42 +05:45
Assert :: assertEmpty (
$this -> getSpaceByNameFromResponse ( $spaceName ),
2025-06-19 15:34:02 +05:45
"space $spaceName should not be available for a user" ,
2024-12-24 09:30:42 +05:45
);
2021-12-19 22:21:24 +01:00
}
2022-07-08 05:18:40 +02:00
/**
2023-05-04 18:40:11 +05:45
* @Then /^the user "([^"]*)" should (not |)have a space called "([^"]*)"$/
2022-07-08 05:18:40 +02:00
*
* @param string $user
2023-05-04 18:40:11 +05:45
* @param string $shouldOrNot
2022-07-08 05:18:40 +02:00
* @param string $spaceName
*
* @return void
* @throws Exception
*/
2023-04-21 14:59:50 +05:45
public function userShouldNotHaveSpace (
2023-05-04 18:40:11 +05:45
string $user ,
string $shouldOrNot ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-05-04 18:40:11 +05:45
) : void {
2025-02-17 17:44:48 +05:45
$response = $this -> listAllMySpaces ( $user );
2023-05-04 18:40:11 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2023-05-04 18:40:11 +05:45
);
if ( \trim ( $shouldOrNot ) === "not" ) {
2024-12-24 09:30:42 +05:45
Assert :: assertEmpty (
$this -> getSpaceByNameFromResponse ( $spaceName , $response ),
2025-06-19 15:34:02 +05:45
"space $spaceName should not be available for a user" ,
2024-12-24 09:30:42 +05:45
);
2023-05-04 18:40:11 +05:45
} else {
2024-12-24 09:30:42 +05:45
Assert :: assertNotEmpty (
$this -> getSpaceByNameFromResponse ( $spaceName , $response ),
2025-06-19 15:34:02 +05:45
"space ' $spaceName ' should be available for a user ' $user ' but not found" ,
2024-12-24 09:30:42 +05:45
);
2023-05-04 18:40:11 +05:45
}
}
/**
* @Then /^the user "([^"]*)" should have a space "([^"]*)" in the disable state$/
*
* @param string $user
* @param string $spaceName
*
* @return mixed
* @throws Exception
*/
public function theUserShouldHaveASpaceInTheDisableState (
2022-07-08 05:18:40 +02:00
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-07-08 05:18:40 +02:00
) : void {
2025-02-17 17:44:48 +05:45
$response = $this -> listAllMySpaces ( $user );
2022-07-08 05:18:40 +02:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-07-08 05:18:40 +02:00
);
2023-10-17 11:41:47 +05:45
$decodedResponse = $this -> featureContext -> getJsonDecodedResponse ( $response );
if ( isset ( $decodedResponse [ "value" ])) {
foreach ( $decodedResponse [ "value" ] as $spaceCandidate ) {
2023-05-04 18:40:11 +05:45
if ( $spaceCandidate [ 'name' ] === $spaceName ) {
if ( $spaceCandidate [ 'root' ][ 'deleted' ][ 'state' ] !== 'trashed' ) {
throw new \Exception (
2025-06-19 15:34:02 +05:45
"space $spaceName should be in disable state but it's not " ,
2023-05-04 18:40:11 +05:45
);
}
return ;
}
}
}
throw new \Exception ( "space ' $spaceName ' should be available for a user ' $user ' but not found" );
2022-07-08 05:18:40 +02:00
}
2022-01-13 15:28:33 +01:00
/**
2024-12-17 12:24:11 +05:45
* @Then /^the json response should (not|only|)\s?contain spaces of type "([^"]*)"$/
2022-01-13 15:28:33 +01:00
*
2022-05-11 15:04:12 +05:45
* @param string $onlyOrNot (not|only|)
2022-01-13 15:28:33 +01:00
* @param string $type
*
* @return void
* @throws Exception
*/
public function jsonRespondedShouldNotContainSpaceType (
string $onlyOrNot ,
2025-06-19 15:34:02 +05:45
string $type ,
2022-01-13 15:28:33 +01:00
) : void {
Assert :: assertNotEmpty (
$spaces = json_decode (
( string ) $this -> featureContext
-> getResponse () -> getBody (),
true ,
512 ,
2025-06-19 15:34:02 +05:45
JSON_THROW_ON_ERROR ,
),
2022-01-13 15:28:33 +01:00
);
$matches = [];
2022-03-10 09:29:26 +01:00
foreach ( $spaces [ "value" ] as $space ) {
if ( $onlyOrNot === "not" ) {
2022-01-13 15:28:33 +01:00
Assert :: assertNotEquals ( $space [ "driveType" ], $type );
}
2022-03-10 09:29:26 +01:00
if ( $onlyOrNot === "only" ) {
2022-01-13 15:28:33 +01:00
Assert :: assertEquals ( $space [ "driveType" ], $type );
}
2022-03-10 09:29:26 +01:00
if ( $onlyOrNot === "" && $space [ "driveType" ] === $type ) {
2022-01-13 15:28:33 +01:00
$matches [] = $space ;
}
}
2022-03-10 09:29:26 +01:00
if ( $onlyOrNot === "" ) {
2022-01-13 15:28:33 +01:00
Assert :: assertNotEmpty ( $matches );
}
}
2021-11-11 12:15:15 +05:45
/**
* Verify that the tableNode contains expected number of columns
*
* @param TableNode $table
2022-11-28 14:27:41 +05:45
* @param int $count
2021-11-11 12:15:15 +05:45
*
* @return void
*
* @throws Exception
*/
public function verifyTableNodeColumnsCount (
TableNode $table ,
2025-06-19 15:34:02 +05:45
int $count ,
2021-11-11 12:15:15 +05:45
) : void {
if ( \count ( $table -> getRows ()) < 1 ) {
throw new Exception ( "Table should have at least one row." );
}
$rowCount = \count ( $table -> getRows ()[ 0 ]);
if ( $count !== $rowCount ) {
throw new Exception ( "Table expected to have $count rows but found $rowCount " );
}
}
2022-08-18 17:20:57 +05:45
/**
* Escapes the given string for
* 1. Space --> %20
* 2. Opening Small Bracket --> %28
* 3. Closing Small Bracket --> %29
*
* @param string $path - File path to parse
*
* @return string
*/
public function escapePath ( string $path ) : string {
return \str_replace ([ " " , "(" , ")" ], [ "%20" , "%28" , "%29" ], $path );
}
2021-11-11 12:15:15 +05:45
/**
2026-07-14 10:53:02 +05:45
* @When /^user "([^"]*)" creates a (?:folder|subfolder) "([^"]*)" in space "([^"]*)"(| in vault)? using the WebDav Api$/
2021-11-11 12:15:15 +05:45
*
* @param string $user
* @param string $folder
* @param string $spaceName
2026-07-14 10:53:02 +05:45
* @param string $isVault
2021-11-11 12:15:15 +05:45
*
* @return void
*
* @throws GuzzleException
*/
public function theUserCreatesAFolderUsingTheGraphApi (
string $user ,
string $folder ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2026-07-14 10:53:02 +05:45
string $isVault ,
2021-11-11 12:15:15 +05:45
) : void {
2023-10-11 16:15:31 +05:45
$folder = \trim ( $folder , '/' );
2022-01-25 14:59:15 +01:00
$exploded = explode ( '/' , $folder );
$path = '' ;
2026-07-14 10:53:02 +05:45
$isVault = trim ( $isVault ) === "in vault" ;
2022-03-10 09:29:26 +01:00
for ( $i = 0 ; $i < \count ( $exploded ); $i ++ ) {
2022-01-25 14:59:15 +01:00
$path = $path . $exploded [ $i ] . '/' ;
2026-07-14 10:53:02 +05:45
$response = $this -> createFolderInSpace ( $user , $path , $spaceName , '' , $isVault );
2024-05-21 15:04:48 +05:45
$this -> featureContext -> setResponse ( $response );
2022-05-11 15:04:12 +05:45
}
2021-12-02 00:01:52 +01:00
}
2025-02-13 12:06:17 +05:45
/**
* @When /^user "([^"]*)" creates a folder "([^"]*)" inside federated share "([^"]*)" using the WebDav API$/
*
* @param string $user
* @param string $folder
* @param string $federatedShare
*
* @return void
*
* @throws GuzzleException
*/
public function userCreatesAFolderInsideFederatedShareUsingTheWebDavApi (
string $user ,
string $folder ,
2025-06-19 15:34:02 +05:45
string $federatedShare ,
2025-02-13 12:06:17 +05:45
) : void {
$folder = \trim ( $folder , '/' );
$remoteItemId = $this -> featureContext -> spacesContext -> getSharesRemoteItemId ( $user , $federatedShare );
$remoteItemId = \rawurlencode ( $remoteItemId );
$response = $this -> featureContext -> createFolder ( $user , $folder , false , null , $remoteItemId );
$this -> featureContext -> setResponse ( $response );
}
2023-05-25 14:47:32 +02:00
/**
* @When /^user "([^"]*)" tries to create subfolder "([^"]*)" in a nonexistent folder of the space "([^"]*)" using the WebDav Api$/
*
* @param string $user
* @param string $subfolder
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
*/
public function theUserTriesToCreateASubFolderUsingTheGraphApi (
string $user ,
string $subfolder ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-05-25 14:47:32 +02:00
) : void {
2024-05-21 15:04:48 +05:45
$response = $this -> createFolderInSpace ( $user , $subfolder , $spaceName );
$this -> featureContext -> setResponse ( $response );
2023-05-25 14:47:32 +02:00
}
2021-12-19 22:21:24 +01:00
/**
2026-07-14 10:53:02 +05:45
* @Given /^user "([^"]*)" has created a (?:folder|subfolder) "([^"]*)" in space "([^"]*)"(| in vault)?$/
2021-12-19 22:21:24 +01:00
*
* @param string $user
* @param string $folder
* @param string $spaceName
2026-07-14 10:53:02 +05:45
* @param string $isVault
2021-12-19 22:21:24 +01:00
*
* @return void
*
* @throws GuzzleException
*/
2023-10-11 16:15:31 +05:45
public function userHasCreatedAFolderInSpace (
2021-12-19 22:21:24 +01:00
string $user ,
string $folder ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2026-07-14 10:53:02 +05:45
string $isVault ,
2021-12-19 22:21:24 +01:00
) : void {
2023-10-11 16:15:31 +05:45
$folder = \trim ( $folder , '/' );
$paths = explode ( '/' , $folder );
$folderPath = '' ;
2026-07-14 10:53:02 +05:45
$isVault = trim ( $isVault ) === "in vault" ;
2023-10-11 16:15:31 +05:45
foreach ( $paths as $path ) {
$folderPath .= " $path /" ;
2026-07-14 10:53:02 +05:45
$response = $this -> createFolderInSpace ( $user , $folderPath , $spaceName , '' , $isVault );
2023-10-11 16:15:31 +05:45
}
2021-12-19 22:21:24 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
201 ,
2023-10-11 16:15:31 +05:45
"Expected response status code should be 201" ,
2025-06-19 15:34:02 +05:45
$response ,
2021-12-19 22:21:24 +01:00
);
}
2023-10-11 16:15:31 +05:45
/**
* @param string $user
* @param string $folder
* @param string $spaceName
* @param string $ownerUser
2026-07-14 10:53:02 +05:45
* @param boolean $isVault
2023-10-11 16:15:31 +05:45
*
* @return ResponseInterface
*
* @throws GuzzleException
*/
public function createFolderInSpace (
string $user ,
string $folder ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $ownerUser = '' ,
2026-07-14 10:53:02 +05:45
bool $isVault = false ,
2023-10-11 16:15:31 +05:45
) : ResponseInterface {
if ( $ownerUser === '' ) {
$ownerUser = $user ;
}
2026-07-14 10:53:02 +05:45
$spaceId = $this -> getSpaceIdByName ( $ownerUser , $spaceName , $isVault );
2024-09-18 11:26:20 +05:45
return $this -> featureContext -> createFolder ( $user , $folder , false , null , $spaceId );
2023-10-11 16:15:31 +05:45
}
2021-12-02 00:01:52 +01:00
/**
* @When /^user "([^"]*)" creates a folder "([^"]*)" in space "([^"]*)" owned by the user "([^"]*)" using the WebDav Api$/
*
* @param string $user
* @param string $folder
* @param string $spaceName
* @param string $ownerUser
*
* @return void
*
* @throws GuzzleException
*/
public function theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi (
string $user ,
string $folder ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $ownerUser = '' ,
2021-12-02 00:01:52 +01:00
) : void {
2023-10-11 16:15:31 +05:45
$response = $this -> createFolderInSpace ( $user , $folder , $spaceName , $ownerUser );
2023-10-03 18:31:24 +05:45
$this -> featureContext -> setResponse ( $response );
2021-11-11 12:15:15 +05:45
}
/**
2026-07-14 10:53:02 +05:45
* @When /^user "([^"]*)" uploads a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)"(| in vault)? using the WebDAV API$/
2021-11-11 12:15:15 +05:45
*
* @param string $user
* @param string $spaceName
* @param string $content
* @param string $destination
2026-07-14 10:53:02 +05:45
* @param string $isVault
2021-11-11 12:15:15 +05:45
*
2023-10-11 16:15:31 +05:45
* @return void
2021-11-11 12:15:15 +05:45
* @throws GuzzleException
* @throws Exception
*/
public function theUserUploadsAFileToSpace (
string $user ,
string $spaceName ,
string $content ,
2025-06-19 15:34:02 +05:45
string $destination ,
2026-07-14 10:53:02 +05:45
string $isVault ,
2023-10-11 16:15:31 +05:45
) : void {
2026-07-14 10:53:02 +05:45
$isVault = trim ( $isVault ) === "in vault" ;
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName , $isVault );
2024-07-09 14:42:15 +05:45
if ( $spaceName === "Shares" && ! \str_starts_with ( $destination , "Shares/" )) {
$destination = "Shares/" . \ltrim ( $destination , "/" );
}
2024-09-18 11:26:20 +05:45
$response = $this -> featureContext -> uploadFileWithContent ( $user , $content , $destination , $spaceId );
2023-10-11 16:15:31 +05:45
$this -> featureContext -> setResponse ( $response );
2021-12-02 00:01:52 +01:00
}
2024-11-08 16:11:23 +05:45
/**
* @When user :user updates the content of federated share :share with :content using the WebDAV API
*
* @param string $user
* @param string $share
* @param string $content
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userUpdatesTheContentOfFederatedShareWithUsingTheWebdavApi (
string $user ,
string $share ,
string $content ,
) : void {
$spaceId = $this -> getSharesRemoteItemId ( $user , $share );
$this -> featureContext -> setResponse (
$this -> featureContext -> uploadFileWithContent (
$user ,
$content ,
'' ,
2025-06-19 15:34:02 +05:45
$spaceId ,
),
2024-11-08 16:11:23 +05:45
);
}
2023-06-12 17:12:01 +05:45
/**
* @When /^user "([^"]*)" uploads a file "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $source
* @param string $destination
* @param string $spaceName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserUploadsALocalFileToSpace (
string $user ,
string $source ,
string $destination ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-06-12 17:12:01 +05:45
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-09-18 11:26:20 +05:45
$response = $this -> featureContext -> uploadFile ( $user , $source , $destination , $spaceId );
2023-10-11 16:15:31 +05:45
$this -> featureContext -> setResponse ( $response );
2023-06-12 17:12:01 +05:45
}
2023-11-30 12:42:32 +05:45
/**
* @Given user :user has uploaded a file :source to :destination in space :spaceName
*
* @param string $user
* @param string $source
* @param string $destination
* @param string $spaceName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userHasUploadedAFileToInSpaceUsingTheWebdavApi (
string $user ,
string $source ,
string $destination ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-09-18 11:26:20 +05:45
$response = $this -> featureContext -> uploadFile ( $user , $source , $destination , $spaceId );
2023-11-30 12:42:32 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
201 ,
"Expected response status code should be 201" ,
2025-06-19 15:34:02 +05:45
$response ,
2023-11-30 12:42:32 +05:45
);
}
2021-12-02 00:01:52 +01:00
/**
2021-12-02 10:05:28 +01:00
* @When /^user "([^"]*)" uploads a file inside space "([^"]*)" owned by the user "([^"]*)" with content "([^"]*)" to "([^"]*)" using the WebDAV API$/
2021-12-02 00:01:52 +01:00
*
* @param string $user
* @param string $spaceName
* @param string $ownerUser
* @param string $content
* @param string $destination
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserUploadsAFileToAnotherOwnerSpace (
string $user ,
string $spaceName ,
string $ownerUser ,
string $content ,
2025-06-19 15:34:02 +05:45
string $destination ,
2021-12-02 00:01:52 +01:00
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $ownerUser , $spaceName );
2024-12-24 09:30:42 +05:45
$response = $this -> featureContext -> uploadFileWithContent (
$user ,
$content ,
$destination ,
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-12-24 09:30:42 +05:45
);
2023-10-11 16:15:31 +05:45
$this -> featureContext -> setResponse ( $response );
2021-11-11 12:15:15 +05:45
}
2021-11-19 18:24:43 +01:00
/**
* @param string $user
* @param string $spaceName
2023-06-28 10:56:08 +05:45
* @param array $bodyData
2023-02-06 23:48:30 +01:00
* @param string $owner
2021-11-19 18:24:43 +01:00
*
2023-06-28 10:56:08 +05:45
* @return ResponseInterface
2021-11-19 18:24:43 +01:00
* @throws GuzzleException
2023-06-28 10:56:08 +05:45
* @throws JsonException
2021-11-19 18:24:43 +01:00
*/
2023-06-28 10:56:08 +05:45
public function updateSpace (
2021-11-19 18:24:43 +01:00
string $user ,
string $spaceName ,
2023-06-28 10:56:08 +05:45
array $bodyData ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2023-06-28 10:56:08 +05:45
) : ResponseInterface {
2023-01-04 17:00:59 +05:45
if ( $spaceName === "non-existing" ) {
// check sending invalid data
$spaceId = "39c49dd3-1f24-4687-97d1-42df43f71713" ;
} else {
2023-02-06 23:48:30 +01:00
$space = $this -> getSpaceByName (( $owner !== "" ) ? $owner : $user , $spaceName );
2023-01-04 17:00:59 +05:45
$spaceId = $space [ "id" ];
}
2021-11-19 18:24:43 +01:00
$body = json_encode ( $bodyData , JSON_THROW_ON_ERROR );
2023-06-28 10:56:08 +05:45
return GraphHelper :: updateSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
2023-09-06 16:07:53 +05:45
$spaceId ,
2022-08-31 15:11:31 +02:00
);
2021-11-19 18:24:43 +01:00
}
2023-06-28 10:56:08 +05:45
/**
* @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)"$/
* @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $newName
* @param string $owner
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function updateSpaceName (
string $user ,
string $spaceName ,
string $newName ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2023-06-28 10:56:08 +05:45
) : void {
$bodyData = [ "Name" => $newName ];
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> updateSpace ( $user , $spaceName , $bodyData , $owner ),
2024-12-24 09:30:42 +05:45
);
2023-06-28 10:56:08 +05:45
}
2022-02-15 14:18:27 +01:00
/**
2023-01-04 17:00:59 +05:45
* @When /^user "([^"]*)" (?:changes|tries to change) the description of the "([^"]*)" space to "([^"]*)"$/
2023-02-06 23:48:30 +01:00
* @When /^user "([^"]*)" (?:changes|tries to change) the description of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/
2022-03-10 09:29:26 +01:00
*
* @param string $user
* @param string $spaceName
2022-05-11 15:04:12 +05:45
* @param string $newDescription
2023-02-06 23:48:30 +01:00
* @param string $owner
2022-09-06 12:32:56 +05:45
*
2022-03-10 09:29:26 +01:00
* @return void
* @throws GuzzleException
2022-05-11 15:04:12 +05:45
* @throws JsonException
2022-03-10 09:29:26 +01:00
*/
public function updateSpaceDescription (
string $user ,
string $spaceName ,
2023-02-06 23:48:30 +01:00
string $newDescription ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2022-03-10 09:29:26 +01:00
) : void {
$bodyData = [ "description" => $newDescription ];
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> updateSpace ( $user , $spaceName , $bodyData , $owner ),
2024-12-24 09:30:42 +05:45
);
2022-03-10 09:29:26 +01:00
}
2022-02-15 14:18:27 +01:00
2023-02-06 23:48:30 +01:00
/**
* @Given /^user "([^"]*)" has changed the description of the "([^"]*)" space to "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $newDescription
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function userHasChangedDescription (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $newDescription ,
2023-02-06 23:48:30 +01:00
) : void {
2023-10-17 11:41:47 +05:45
$bodyData = [ "description" => $newDescription ];
2024-04-26 15:27:00 +05:45
$response = $this -> updateSpace ( $user , $spaceName , $bodyData );
2023-02-06 23:48:30 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2023-02-06 23:48:30 +01:00
);
}
2021-11-19 18:24:43 +01:00
/**
2023-01-04 17:00:59 +05:45
* @When /^user "([^"]*)" (?:changes|tries to change) the quota of the "([^"]*)" space to "([^"]*)"$/
2023-02-06 23:48:30 +01:00
* @When /^user "([^"]*)" (?:changes|tries to change) the quota of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/
2021-11-19 18:24:43 +01:00
*
* @param string $user
* @param string $spaceName
* @param int $newQuota
2023-02-06 23:48:30 +01:00
* @param string $owner
2021-11-19 18:24:43 +01:00
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function updateSpaceQuota (
string $user ,
string $spaceName ,
2023-02-06 23:48:30 +01:00
int $newQuota ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2021-11-19 18:24:43 +01:00
) : void {
$bodyData = [ "quota" => [ "total" => $newQuota ]];
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> updateSpace ( $user , $spaceName , $bodyData , $owner ),
2024-12-24 09:30:42 +05:45
);
2021-11-19 18:24:43 +01:00
}
2022-08-10 09:40:26 +05:45
/**
2025-02-12 16:17:23 +05:45
* @Given /^user "([^"]*)" has changed the quota of space "([^"]*)" to "([^"]*)"$/
2022-08-10 09:40:26 +05:45
*
* @param string $user
* @param string $spaceName
* @param int $newQuota
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userHasChangedTheQuotaOfTheSpaceTo (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
int $newQuota ,
2022-08-10 09:40:26 +05:45
) : void {
2023-10-17 11:41:47 +05:45
$bodyData = [ "quota" => [ "total" => $newQuota ]];
2024-04-26 15:27:00 +05:45
$response = $this -> updateSpace ( $user , $spaceName , $bodyData );
2022-08-10 09:40:26 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-08-10 09:40:26 +05:45
);
}
2022-12-14 14:13:55 +05:45
2022-03-10 09:29:26 +01:00
/**
* @param string $user
* @param string $file
* @param string $type
* @param string $spaceName
*
2023-10-17 11:41:47 +05:45
* @return ResponseInterface
2022-03-10 09:29:26 +01:00
* @throws GuzzleException
* @throws Exception
*/
public function updateSpaceSpecialSection (
string $user ,
string $file ,
string $type ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
2022-03-10 09:29:26 +01:00
$space = $this -> getSpaceByName ( $user , $spaceName );
$spaceId = $space [ "id" ];
$fileId = $this -> getFileId ( $user , $spaceName , $file );
if ( $type === "description" ) {
$type = "readme" ;
} else {
$type = "image" ;
}
$bodyData = [ "special" => [[ "specialFolder" => [ "name" => " $type " ], "id" => " $fileId " ]]];
$body = json_encode ( $bodyData , JSON_THROW_ON_ERROR );
2023-10-17 11:41:47 +05:45
return GraphHelper :: updateSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
$spaceId ,
);
}
2022-03-10 09:29:26 +01:00
2023-10-17 11:41:47 +05:45
/**
* @When /^user "([^"]*)" sets the file "([^"]*)" as a (description|space image)\s? in a special section of the "([^"]*)" space$/
*
* @param string $user
* @param string $file
* @param string $type
* @param string $spaceName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userSetsFileAsDescriptionOrImageInSpecialSectionOfSpace (
string $user ,
string $file ,
string $type ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-10-17 11:41:47 +05:45
) : void {
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
2023-10-17 11:41:47 +05:45
$this -> updateSpaceSpecialSection (
2022-08-31 15:11:31 +02:00
$user ,
2023-10-17 11:41:47 +05:45
$file ,
$type ,
2025-06-19 15:34:02 +05:45
$spaceName ,
),
2022-08-31 15:11:31 +02:00
);
2022-03-10 09:29:26 +01:00
}
2022-03-30 21:34:41 +02:00
/**
2022-04-12 08:51:35 +02:00
* @Given /^user "([^"]*)" has set the file "([^"]*)" as a (description|space image)\s? in a special section of the "([^"]*)" space$/
2022-03-30 21:34:41 +02:00
*
* @param string $user
* @param string $file
* @param string $type
* @param string $spaceName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userHasUpdatedSpaceSpecialSection (
string $user ,
string $file ,
string $type ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-03-30 21:34:41 +02:00
) : void {
2023-10-17 11:41:47 +05:45
$response = $this -> updateSpaceSpecialSection ( $user , $file , $type , $spaceName );
2022-03-30 21:34:41 +02:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-03-30 21:34:41 +02:00
);
}
2021-12-02 00:01:52 +01:00
/**
* @Given /^user "([^"]*)" has created a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
2023-06-28 10:56:08 +05:45
* @param string|null $spaceType
* @param int|null $quota
2021-12-02 00:01:52 +01:00
*
* @return void
2022-05-11 15:04:12 +05:45
* @throws GuzzleException
2021-12-02 00:01:52 +01:00
*/
2021-12-21 13:47:15 +05:45
public function userHasCreatedSpace (
string $user ,
string $spaceName ,
string $spaceType ,
2025-06-19 15:34:02 +05:45
int $quota ,
2021-12-21 13:47:15 +05:45
) : void {
2024-05-28 11:36:02 +02:00
$space = [ "name" => $spaceName , "driveType" => $spaceType , "quota" => [ "total" => $quota ]];
2023-10-17 11:41:47 +05:45
$response = $this -> createSpace ( $user , $space );
2021-12-02 00:01:52 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
2021-12-02 10:05:28 +01:00
201 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 201 (Created)" ,
2025-06-19 15:34:02 +05:45
$response ,
2021-12-02 00:01:52 +01:00
);
2025-02-17 17:44:48 +05:45
$space = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response );
$this -> addToCreatedSpace ( $user , $space );
2021-12-02 00:01:52 +01:00
}
2022-03-10 09:29:26 +01:00
/**
2026-08-14 12:11:34 +05:45
* @Given /^user "([^"]*)" has created a space "([^"]*)"(| in vault)?(| with retry) with the default quota using the Graph API$/
2022-03-10 09:29:26 +01:00
*
* @param string $user
* @param string $spaceName
2026-07-14 10:53:02 +05:45
* @param string $isVault
2026-08-14 12:11:34 +05:45
* @param string $withRetry
2022-03-10 09:29:26 +01:00
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserHasCreatedASpaceByDefaultUsingTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2026-07-14 10:53:02 +05:45
string $isVault ,
2026-08-14 12:11:34 +05:45
string $withRetry ,
2022-03-10 09:29:26 +01:00
) : void {
2024-05-28 11:36:02 +02:00
$space = [ "name" => $spaceName ];
2026-07-14 10:53:02 +05:45
$isVault = trim ( $isVault ) === "in vault" ;
2026-08-14 12:11:34 +05:45
$withRetry = trim ( $withRetry ) === "with retry" ;
// The user role may take some time to update
// This can cause an unauthorized error
// Retry once after 1 second
2026-07-14 10:53:02 +05:45
$response = $this -> createSpace ( $user , $space , $isVault );
2026-08-14 12:11:34 +05:45
if ( $withRetry && $response -> getStatusCode () === 401 ) {
sleep ( 1 ); // Wait 1 second before retrying.
$response = $this -> createSpace ( $user , $space , $isVault );
}
2022-03-10 09:29:26 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
201 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 201 (Created)" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-03-10 09:29:26 +01:00
);
2025-02-17 17:44:48 +05:45
$space = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response );
2026-08-07 09:11:49 +05:45
if ( $isVault ) {
$this -> addToCreatedVaultSpace ( $user , $space );
} else {
$this -> addToCreatedSpace ( $user , $space );
}
2022-03-10 09:29:26 +01:00
}
2023-06-28 10:56:08 +05:45
/**
* @param string $user
* @param string $space
2026-07-14 10:53:02 +05:45
* @param boolean $isVault
2023-06-28 10:56:08 +05:45
*
* @return ResponseInterface
* @throws GuzzleException
* @throws JsonException
*/
public function createSpace (
string $user ,
2025-06-19 15:34:02 +05:45
array $space ,
2026-07-14 10:53:02 +05:45
bool $isVault = false ,
2023-06-28 10:56:08 +05:45
) : ResponseInterface {
$body = json_encode ( $space , JSON_THROW_ON_ERROR );
2026-07-14 10:53:02 +05:45
$password = $this -> featureContext -> getPasswordForUser ( $user );
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$access_token = $this -> featureContext -> getOcisUserToken ( $user )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $access_token ;
$user = null ;
$password = null ;
}
2023-06-28 10:56:08 +05:45
return GraphHelper :: createSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
2026-07-14 10:53:02 +05:45
$password ,
2023-09-06 16:07:53 +05:45
$body ,
2026-07-14 10:53:02 +05:45
$headers ,
$isVault ,
2023-06-28 10:56:08 +05:45
);
}
2022-07-14 16:59:36 +05:45
/**
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fileDestination
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userCopiesFileWithinSpaceUsingTheWebDAVAPI (
string $user ,
string $fileSource ,
string $fileDestination ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2022-07-14 16:59:36 +05:45
$space = $this -> getSpaceByName ( $user , $spaceName );
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
2025-06-19 15:34:02 +05:45
$spaceName ,
2022-07-14 16:59:36 +05:45
);
2024-09-17 17:11:20 +05:45
$encodedName = \rawurlencode ( ltrim ( $fileSource , "/" ));
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $encodedName " ;
2024-09-17 17:11:20 +05:45
2022-12-05 22:27:51 +05:45
$this -> featureContext -> setResponse ( $this -> copyFilesAndFoldersRequest ( $user , $fullUrl , $headers ));
2022-07-14 16:59:36 +05:45
}
2022-08-04 13:11:51 +02:00
/**
* @param string $user
* @param string $fileSource
* @param string $fileDestination
* @param string $spaceName
*
2023-10-17 11:41:47 +05:45
* @return ResponseInterface
2022-08-18 17:20:57 +05:45
* @throws GuzzleException
2022-08-04 13:11:51 +02:00
*/
2023-10-17 11:41:47 +05:45
public function moveFileWithinSpace (
2022-08-04 13:11:51 +02:00
string $user ,
string $fileSource ,
string $fileDestination ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-08-04 13:11:51 +02:00
$space = $this -> getSpaceByName ( $user , $spaceName );
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
2025-06-19 15:34:02 +05:45
$spaceName ,
2022-08-04 13:11:51 +02:00
);
2023-05-24 17:12:19 +02:00
$headers [ 'Overwrite' ] = 'F' ;
2022-08-04 13:11:51 +02:00
2024-09-17 17:11:20 +05:45
$encodedName = \rawurlencode ( ltrim ( $fileSource , "/" ));
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $encodedName " ;
2024-09-17 17:11:20 +05:45
2023-10-17 11:41:47 +05:45
return $this -> moveFilesAndFoldersRequest ( $user , $fullUrl , $headers );
}
/**
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fileDestination
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userMovesFileWithinSpaceUsingTheWebDAVAPI (
string $user ,
string $fileSource ,
string $fileDestination ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : void {
$this -> featureContext -> setResponse (
$this -> moveFileWithinSpace (
$user ,
$fileSource ,
$fileDestination ,
2025-06-19 15:34:02 +05:45
$spaceName ,
),
2024-12-24 09:30:42 +05:45
);
2022-12-05 22:27:51 +05:45
$this -> featureContext -> pushToLastHttpStatusCodesArray ();
2022-08-04 13:11:51 +02:00
}
2022-08-18 17:20:57 +05:45
/**
* @Given /^user "([^"]*)" has moved (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)"$/
*
* @param string $user
* @param string $fileSource
* @param string $fileDestination
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userHasMovedFileWithinSpaceUsingTheWebDAVAPI (
string $user ,
string $fileSource ,
string $fileDestination ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-17 11:41:47 +05:45
$response = $this -> moveFileWithinSpace (
2022-08-18 17:20:57 +05:45
$user ,
$fileSource ,
$fileDestination ,
2025-06-19 15:34:02 +05:45
$spaceName ,
2022-08-18 17:20:57 +05:45
);
$this -> featureContext -> theHTTPStatusCodeShouldBe (
201 ,
__METHOD__ . "Expected response status code should be 201 (Created) \n " .
2023-10-17 11:41:47 +05:45
"Actual response status code was: " . $response -> getStatusCode () . " \n " .
"Actual response body was: " . $response -> getBody (),
2025-06-19 15:34:02 +05:45
$response ,
2022-08-18 17:20:57 +05:45
);
}
2022-08-04 13:11:51 +02:00
/**
* MOVE request for files|folders
*
* @param string $user
* @param string $fullUrl
2023-01-17 12:41:56 +01:00
* @param array $headers
2022-08-04 13:11:51 +02:00
*
2022-12-05 22:27:51 +05:45
* @return ResponseInterface
2022-08-04 13:11:51 +02:00
* @throws GuzzleException
*/
2022-12-05 22:27:51 +05:45
public function moveFilesAndFoldersRequest ( string $user , string $fullUrl , array $headers ) : ResponseInterface {
return HttpRequestHelper :: sendRequest (
$fullUrl ,
'MOVE' ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$headers ,
2022-08-18 17:20:57 +05:45
);
2022-08-04 13:11:51 +02:00
}
2022-07-22 10:14:06 +05:45
2022-07-14 16:59:36 +05:45
/**
2026-07-28 14:23:42 +05:45
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)"(| in vault)? to "([^"]*)" inside space "([^"]*)"(| in vault)? using the WebDAV API$/
2022-07-14 16:59:36 +05:45
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
2026-07-28 14:23:42 +05:45
* @param string $isSourceVault
2022-07-14 16:59:36 +05:45
* @param string $fileDestination
* @param string $toSpaceName
2026-07-28 14:23:42 +05:45
* @param string $isDestinationVault
2022-07-14 16:59:36 +05:45
*
* @return void
* @throws GuzzleException
*/
public function userCopiesFileFromAndToSpaceBetweenSpaces (
2026-07-28 14:23:42 +05:45
string $user ,
string $fileSource ,
string $fromSpaceName ,
string $isSourceVault ,
string $fileDestination ,
string $toSpaceName ,
string $isDestinationVault ,
) : void {
$isSourceVault = trim ( $isSourceVault ) === "in vault" ;
$isDestinationVault = trim ( $isDestinationVault ) === "in vault" ;
$this -> copyFileBetweenSpaces (
$user ,
$fileSource ,
$fromSpaceName ,
$fileDestination ,
$toSpaceName ,
$isSourceVault ,
$isDestinationVault ,
);
}
/**
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" with following headers using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
public function userCopiesFileFromAndToSpaceBetweenSpacesWithHeaders (
2022-07-14 16:59:36 +05:45
string $user ,
string $fileSource ,
string $fromSpaceName ,
string $fileDestination ,
2024-01-23 12:40:13 +05:45
string $toSpaceName ,
2026-07-28 14:23:42 +05:45
TableNode $table ,
) : void {
$this -> copyFileBetweenSpaces (
$user ,
$fileSource ,
$fromSpaceName ,
$fileDestination ,
$toSpaceName ,
false ,
false ,
$table ,
);
}
/**
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
* @param boolean $isSourceVault
* @param boolean $isDestinationVault
* @param TableNode|null $table
*
* @return void
* @throws GuzzleException
*/
private function copyFileBetweenSpaces (
string $user ,
string $fileSource ,
string $fromSpaceName ,
string $fileDestination ,
string $toSpaceName ,
? bool $isSourceVault = false ,
? bool $isDestinationVault = false ,
2025-06-24 11:39:50 +02:00
? TableNode $table = null ,
2024-12-24 09:30:42 +05:45
) : void {
2026-07-28 14:23:42 +05:45
$space = $this -> getSpaceByName ( $user , $fromSpaceName , $isSourceVault );
2024-12-24 09:30:42 +05:45
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
2025-06-19 15:34:02 +05:45
$toSpaceName ,
2026-07-28 14:23:42 +05:45
$isDestinationVault ,
2024-12-24 09:30:42 +05:45
);
2024-01-23 12:40:13 +05:45
if ( $table !== null ) {
$this -> featureContext -> verifyTableNodeColumns (
$table ,
2025-06-19 15:34:02 +05:45
[ 'header' , 'value' ],
2024-01-23 12:40:13 +05:45
);
foreach ( $table as $row ) {
$headers [ $row [ 'header' ]] = $this -> featureContext -> substituteInLineCodes ( $row [ 'value' ]);
}
}
2025-09-22 13:50:45 +05:45
$sourcePath = explode ( '/' , ltrim ( $fileSource , "/" ));
foreach ( $sourcePath as $key => $part ) {
$sourcePath [ $key ] = \rawurlencode ( $part );
}
$encodedName = implode ( '/' , $sourcePath );
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $encodedName " ;
2024-09-17 17:11:20 +05:45
2026-09-18 17:10:39 +05:45
// With OCIS_ASYNC_UPLOADS=true in CI, file may still be in postprocessing while copying it.
// And the copy operation just returns 500 status code
// So retrying the copy operation
$retried = 0 ;
do {
$response = $this -> copyFilesAndFoldersRequest ( $user , $fullUrl , $headers );
if ( $response -> getStatusCode () !== 500 ) {
break ;
}
$retried ++ ;
\sleep ( 1 );
} while ( $retried < STANDARD_RETRY_COUNT );
$this -> featureContext -> setResponse ( $response );
2022-07-14 16:59:36 +05:45
}
2022-10-13 20:23:08 +02:00
/**
* @When /^user "([^"]*)" overwrites file "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" while (copying|moving)\s? using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
* @param string $action
*
* @return void
* @throws GuzzleException
*/
public function userOverwritesFileFromAndToSpaceBetweenSpaces (
string $user ,
string $fileSource ,
string $fromSpaceName ,
string $fileDestination ,
string $toSpaceName ,
2025-06-19 15:34:02 +05:45
string $action ,
2024-12-24 09:30:42 +05:45
) : void {
2022-10-13 20:23:08 +02:00
$space = $this -> getSpaceByName ( $user , $fromSpaceName );
2024-12-24 09:30:42 +05:45
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
2025-06-19 15:34:02 +05:45
$toSpaceName ,
2024-12-24 09:30:42 +05:45
);
2022-10-13 20:23:08 +02:00
$headers [ 'Overwrite' ] = 'T' ;
2024-09-17 17:11:20 +05:45
$encodedName = \rawurlencode ( ltrim ( $fileSource , "/" ));
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $encodedName " ;
2024-09-17 17:11:20 +05:45
2022-10-13 20:23:08 +02:00
if ( $action === 'copying' ) {
2022-12-05 22:27:51 +05:45
$response = $this -> copyFilesAndFoldersRequest ( $user , $fullUrl , $headers );
2022-10-13 20:23:08 +02:00
} else {
2022-12-05 22:27:51 +05:45
$response = $this -> moveFilesAndFoldersRequest ( $user , $fullUrl , $headers );
2022-10-13 20:23:08 +02:00
}
2022-12-05 22:27:51 +05:45
$this -> featureContext -> setResponse ( $response );
$this -> featureContext -> pushToLastHttpStatusCodesArray ();
2022-10-13 20:23:08 +02:00
}
2022-08-24 11:30:51 +05:45
/**
2024-12-10 14:14:26 +05:45
* @Then /^user "([^"]*)" (should|should not) be able to download file "([^"]*)" from space "([^"]*)"$/
2022-08-24 11:30:51 +05:45
*
* @param string $user
2024-12-10 14:14:26 +05:45
* @param string $shouldOrNot
2022-08-24 11:30:51 +05:45
* @param string $fileName
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
2024-12-02 17:10:32 +05:45
public function userShouldOrShouldNotBeAbleToDownloadFileFromSpace (
2022-08-24 11:30:51 +05:45
string $user ,
2024-12-10 14:14:26 +05:45
string $shouldOrNot ,
2022-08-24 11:30:51 +05:45
string $fileName ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2024-12-02 17:10:32 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2025-02-25 14:04:22 +05:45
if ( $spaceName === "Shares"
&& $this -> featureContext -> getDavPathVersion () !== WebDavHelper :: DAV_VERSION_SPACES
) {
$fileName = "Shares/ $fileName " ;
}
2024-12-24 09:30:42 +05:45
$response = $this -> featureContext -> downloadFileAsUserUsingPassword (
$user ,
$fileName ,
2024-12-02 17:10:32 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
null ,
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-12-24 09:30:42 +05:45
);
2024-12-10 14:14:26 +05:45
if ( $shouldOrNot === 'should' ) {
2026-04-16 21:53:40 +03:00
// Async uploads (OCIS_ASYNC_UPLOADS=true) may leave the file in
// postprocessing state briefly. Retry on HTTP 425 (Too Early).
$retries = 10 ;
while ( $response -> getStatusCode () === 425 && $retries > 0 ) {
\sleep ( 1 );
$response = $this -> featureContext -> downloadFileAsUserUsingPassword (
$user ,
$fileName ,
$this -> featureContext -> getPasswordForUser ( $user ),
null ,
$spaceId ,
);
$retries -- ;
}
2024-12-10 14:14:26 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
__METHOD__ . "Expected response status code is 200 but got " . $response -> getStatusCode (),
2025-06-19 15:34:02 +05:45
$response ,
2024-12-10 14:14:26 +05:45
);
} else {
Assert :: assertGreaterThanOrEqual (
400 ,
$response -> getStatusCode (),
__METHOD__
2025-06-19 15:34:02 +05:45
. ' download must fail' ,
2024-12-10 14:14:26 +05:45
);
Assert :: assertLessThanOrEqual (
499 ,
$response -> getStatusCode (),
__METHOD__
. ' 4xx error expected but got status code "'
2025-06-19 15:34:02 +05:45
. $response -> getStatusCode () . '"' ,
2024-12-10 14:14:26 +05:45
);
}
2022-08-24 11:30:51 +05:45
}
2022-08-04 13:11:51 +02:00
/**
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
*
* @return void
* @throws GuzzleException
*/
public function userMovesFileFromAndToSpaceBetweenSpaces (
string $user ,
string $fileSource ,
string $fromSpaceName ,
string $fileDestination ,
2025-06-19 15:34:02 +05:45
string $toSpaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2022-08-04 13:11:51 +02:00
$space = $this -> getSpaceByName ( $user , $fromSpaceName );
2024-12-24 09:30:42 +05:45
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
2025-06-19 15:34:02 +05:45
$toSpaceName ,
2024-12-24 09:30:42 +05:45
);
2024-09-17 17:11:20 +05:45
$encodedName = \rawurlencode ( ltrim ( $fileSource , "/" ));
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $encodedName " ;
2024-09-17 17:11:20 +05:45
2022-12-05 22:27:51 +05:45
$this -> featureContext -> setResponse ( $this -> moveFilesAndFoldersRequest ( $user , $fullUrl , $headers ));
$this -> featureContext -> pushToLastHttpStatusCodesArray ();
2022-08-04 13:11:51 +02:00
}
2022-07-22 10:14:06 +05:45
2022-07-14 16:59:36 +05:45
/**
2023-04-21 14:59:50 +05:45
* returns a URL for destination with spacename
2022-07-14 16:59:36 +05:45
*
* @param string $user
* @param string $fileDestination
* @param string $spaceName
2026-07-28 14:23:42 +05:45
* @param boolean $isVault
2023-09-26 18:04:48 +05:45
* @param string|null $endPath
2022-07-14 16:59:36 +05:45
*
* @return string
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function destinationHeaderValueWithSpaceName (
string $user ,
string $fileDestination ,
string $spaceName ,
2026-07-28 14:23:42 +05:45
bool $isVault = false ,
2025-06-24 11:39:50 +02:00
? string $endPath = null ,
2024-12-24 09:30:42 +05:45
) : string {
2026-07-28 14:23:42 +05:45
$space = $this -> getSpaceByName ( $user , $spaceName , $isVault );
2022-08-18 17:20:57 +05:45
$fileDestination = $this -> escapePath ( \ltrim ( $fileDestination , "/" ));
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
return " $baseUrl / $davPath / $fileDestination " ;
2022-07-14 16:59:36 +05:45
}
/**
* COPY request for files|folders
*
* @param string $user
* @param string $fullUrl
* @param array $headers
*
2022-12-05 22:27:51 +05:45
* @return ResponseInterface
2022-07-14 16:59:36 +05:45
* @throws GuzzleException
*/
2022-12-05 22:27:51 +05:45
public function copyFilesAndFoldersRequest ( string $user , string $fullUrl , array $headers ) : ResponseInterface {
2026-07-28 14:23:42 +05:45
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$access_token = $this -> featureContext -> getOcisUserToken ( $user )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $access_token ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2022-12-05 22:27:51 +05:45
return HttpRequestHelper :: sendRequest (
$fullUrl ,
'COPY' ,
$user ,
2026-07-28 14:23:42 +05:45
$password ,
2022-12-05 22:27:51 +05:45
$headers ,
2022-07-14 16:59:36 +05:45
);
}
2023-09-26 18:04:48 +05:45
/**
2024-11-13 15:54:16 +05:45
* @When /^user "([^"]*)" (copies|moves) file with id "([^"]*)" as "([^"]*)" into folder "([^"]*)" inside space "([^"]*)"$/
2023-09-26 18:04:48 +05:45
*
* @param string $user
2023-10-03 16:40:58 +05:45
* @param string $actionType
2024-11-13 15:54:16 +05:45
* @param string $fileId
2023-09-26 18:04:48 +05:45
* @param string $destinationFile
2024-11-13 15:54:16 +05:45
* @param string $destinationFolder
2023-09-26 18:04:48 +05:45
* @param string $toSpaceName
*
* @throws GuzzleException
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userCopiesOrMovesFileWithIdAsIntoFolderInsideSpace (
string $user ,
string $actionType ,
string $fileId ,
string $destinationFile ,
string $destinationFolder ,
2025-06-19 15:34:02 +05:45
string $toSpaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2024-01-04 18:00:04 +05:45
$destinationFile = \trim ( $destinationFile , "/" );
2024-11-13 15:54:16 +05:45
$destinationFolder = \trim ( $destinationFolder , "/" );
$fileDestination = $destinationFolder . '/' . $this -> escapePath ( $destinationFile );
2023-10-27 15:11:32 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
2024-09-17 17:11:20 +05:45
$sourceDavPath = WebdavHelper :: getDavPath ( $this -> featureContext -> getDavPathVersion ());
2023-10-27 15:11:32 +05:45
if ( $toSpaceName === 'Shares' ) {
2024-01-04 18:00:04 +05:45
$sharesPath = $this -> featureContext -> getSharesMountPath ( $user , $fileDestination );
2024-09-17 17:11:20 +05:45
$davPath = WebDavHelper :: getDavPath ( $this -> featureContext -> getDavPathVersion ());
$headers [ 'Destination' ] = " $baseUrl / $davPath / $sharesPath " ;
2023-10-27 15:11:32 +05:45
} else {
2024-12-24 09:30:42 +05:45
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
$toSpaceName ,
2026-07-28 14:23:42 +05:45
false ,
2025-06-19 15:34:02 +05:45
$fileId ,
2024-12-24 09:30:42 +05:45
);
2023-10-27 15:11:32 +05:45
}
2024-09-17 17:11:20 +05:45
$fullUrl = " $baseUrl / $sourceDavPath / $fileId " ;
2023-10-03 16:40:58 +05:45
if ( $actionType === 'copies' ) {
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> copyFilesAndFoldersRequest ( $user , $fullUrl , $headers ),
2024-12-24 09:30:42 +05:45
);
2024-11-13 15:54:16 +05:45
} else {
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> moveFilesAndFoldersRequest ( $user , $fullUrl , $headers ),
2024-12-24 09:30:42 +05:45
);
2023-10-03 16:40:58 +05:45
}
2023-09-26 18:04:48 +05:45
}
2024-11-13 15:54:16 +05:45
/**
* @Given /^user "([^"]*)" renames file with id "([^"]*)" to "([^"]*)" inside space "([^"]*)"$/
*
* @param string $user
* @param string $fileId
* @param string $destinationFile
* @param string $spaceName
*
* @throws GuzzleException
* @return void
*/
public function userRenamesFileWithIdToInsideSpace (
string $user ,
string $fileId ,
string $destinationFile ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-11-13 15:54:16 +05:45
) : void {
$destinationFile = \trim ( $destinationFile , "/" );
$fileDestination = $this -> escapePath ( $destinationFile );
$baseUrl = $this -> featureContext -> getBaseUrl ();
$sourceDavPath = WebdavHelper :: getDavPath ( $this -> featureContext -> getDavPathVersion ());
if ( $spaceName === 'Shares' ) {
$sharesPath = $this -> featureContext -> getSharesMountPath ( $user , $fileDestination );
$davPath = WebDavHelper :: getDavPath ( $this -> featureContext -> getDavPathVersion ());
$headers [ 'Destination' ] = " $baseUrl / $davPath / $sharesPath " ;
} else {
2024-12-24 09:30:42 +05:45
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
$spaceName ,
2026-07-28 14:23:42 +05:45
false ,
2025-06-19 15:34:02 +05:45
$fileId ,
2024-12-24 09:30:42 +05:45
);
2024-11-13 15:54:16 +05:45
}
$fullUrl = " $baseUrl / $sourceDavPath / $fileId " ;
$this -> featureContext -> setResponse ( $this -> moveFilesAndFoldersRequest ( $user , $fullUrl , $headers ));
}
2024-10-16 12:02:26 +05:45
/**
2024-11-07 15:58:26 +05:45
* @Given /^user "([^"]*)" has (copied|moved) file with id "([^"]*)" as "([^"]*)" into folder "([^"]*)" inside space "([^"]*)"$/
2024-10-16 12:02:26 +05:45
*
* @param string $user
* @param string $actionType
2024-11-07 15:58:26 +05:45
* @param string $fileId
2024-10-16 12:02:26 +05:45
* @param string $destinationFile
2024-11-07 15:58:26 +05:45
* @param string $destinationFolder
2024-10-16 12:02:26 +05:45
* @param string $spaceName
*
* @throws GuzzleException
* @return void
*/
public function userHasCopiedOrMovedFileInsideSpaceUsingFileId (
string $user ,
string $actionType ,
2024-11-07 15:58:26 +05:45
string $fileId ,
2024-10-16 12:02:26 +05:45
string $destinationFile ,
2024-11-07 15:58:26 +05:45
string $destinationFolder ,
2024-10-16 12:02:26 +05:45
string $spaceName ,
) : void {
$destinationFile = \trim ( $destinationFile , "/" );
2024-11-07 15:58:26 +05:45
$destinationFolder = \trim ( $destinationFolder , "/" );
$fileDestination = $destinationFolder . '/' . $this -> escapePath ( $destinationFile );
2024-10-16 12:02:26 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
$sourceDavPath = WebdavHelper :: getDavPath ( $this -> featureContext -> getDavPathVersion ());
if ( $spaceName === 'Shares' ) {
$sharesPath = $this -> featureContext -> getSharesMountPath ( $user , $fileDestination );
$davPath = WebDavHelper :: getDavPath ( $this -> featureContext -> getDavPathVersion ());
$headers [ 'Destination' ] = " $baseUrl / $davPath / $sharesPath " ;
} else {
2024-12-24 09:30:42 +05:45
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
$spaceName ,
2026-07-28 14:23:42 +05:45
false ,
2025-06-19 15:34:02 +05:45
$fileId ,
2024-12-24 09:30:42 +05:45
);
2024-10-16 12:02:26 +05:45
}
$fullUrl = " $baseUrl / $sourceDavPath / $fileId " ;
if ( $actionType === 'copied' ) {
2026-08-17 10:46:51 +05:45
// while performing copy operation,
// sometime it will return 500 error.
// So we need to retry the copy operation.
$maxAttempts = 3 ;
for ( $attempt = 1 ; $attempt <= $maxAttempts ; $attempt ++ ) {
$response = $this -> copyFilesAndFoldersRequest ( $user , $fullUrl , $headers );
if ( $response -> getStatusCode () !== 500 ) {
break ;
}
if ( $attempt < $maxAttempts ) {
\sleep ( 1 );
}
}
2024-10-16 12:02:26 +05:45
} else {
$response = $this -> moveFilesAndFoldersRequest ( $user , $fullUrl , $headers );
}
Assert :: assertEquals (
201 ,
$response -> getStatusCode (),
2025-06-19 15:34:02 +05:45
"Expected response status code should be 201" ,
2024-10-16 12:02:26 +05:45
);
}
2024-11-07 15:58:26 +05:45
/**
* @Given /^user "([^"]*)" has renamed file with id "([^"]*)" to "([^"]*)" inside space "([^"]*)"$/
*
* @param string $user
* @param string $fileId
* @param string $destinationFile
* @param string $spaceName
*
* @throws GuzzleException
* @return void
*/
public function userHasRenamedFileInsideSpaceUsingFileId (
string $user ,
string $fileId ,
string $destinationFile ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-11-07 15:58:26 +05:45
) : void {
$destinationFile = \trim ( $destinationFile , "/" );
$fileDestination = $this -> escapePath ( $destinationFile );
$baseUrl = $this -> featureContext -> getBaseUrl ();
$sourceDavPath = WebdavHelper :: getDavPath ( $this -> featureContext -> getDavPathVersion ());
if ( $spaceName === 'Shares' ) {
$sharesPath = $this -> featureContext -> getSharesMountPath ( $user , $fileDestination );
$davPath = WebDavHelper :: getDavPath ( $this -> featureContext -> getDavPathVersion ());
$headers [ 'Destination' ] = " $baseUrl / $davPath / $sharesPath " ;
} else {
2024-12-24 09:30:42 +05:45
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
$spaceName ,
2026-07-28 14:23:42 +05:45
false ,
2025-06-19 15:34:02 +05:45
$fileId ,
2024-12-24 09:30:42 +05:45
);
2024-11-07 15:58:26 +05:45
}
$fullUrl = " $baseUrl / $sourceDavPath / $fileId " ;
$response = $this -> moveFilesAndFoldersRequest ( $user , $fullUrl , $headers );
Assert :: assertEquals (
201 ,
$response -> getStatusCode (),
2025-06-19 15:34:02 +05:45
"Expected response status code should be 201" ,
2024-11-07 15:58:26 +05:45
);
}
2024-02-15 21:26:17 +05:45
/**
2024-09-17 17:11:20 +05:45
* @When /^user "([^"]*)" tries to move (?:file|folder) "([^"]*)" of space "([^"]*)" to (space|folder) "([^"]*)" using its id in destination path$/
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" of space "([^"]*)" to (folder) "([^"]*)" using its id in destination path$/
2024-02-15 21:26:17 +05:45
*
* @param string $user
* @param string $source
* @param string $sourceSpace
* @param string $destinationType
* @param string $destinationName
*
* @throws GuzzleException
* @return void
*/
public function userMovesFileToResourceUsingItsIdAsDestinationPath (
string $user ,
string $source ,
string $sourceSpace ,
string $destinationType ,
2025-06-19 15:34:02 +05:45
string $destinationName ,
2024-02-15 21:26:17 +05:45
) : void {
$source = \trim ( $source , "/" );
$baseUrl = $this -> featureContext -> getBaseUrl ();
2024-09-17 17:11:20 +05:45
$davPathVersion = $this -> featureContext -> getDavPathVersion ();
2024-10-21 12:24:50 +05:45
$suffixPath = $user ;
2024-09-17 17:11:20 +05:45
if ( $davPathVersion === WebDavHelper :: DAV_VERSION_SPACES ) {
2024-10-21 12:24:50 +05:45
$suffixPath = $this -> getSpaceIdByName ( $user , $sourceSpace );
2024-02-15 21:26:17 +05:45
}
2024-10-21 12:24:50 +05:45
$sourceDavPath = WebDavHelper :: getDavPath ( $davPathVersion , $suffixPath );
2024-09-17 17:11:20 +05:45
$fullUrl = " $baseUrl / $sourceDavPath / $source " ;
2024-02-15 21:26:17 +05:45
if ( $destinationType === "space" ) {
$destinationId = $this -> getSpaceIdByName ( $user , $destinationName );
} else {
$destinationId = $this -> getResourceId ( $user , $sourceSpace , $destinationName );
}
2024-09-17 17:11:20 +05:45
$destinationDavPath = WebDavHelper :: getDavPath ( $davPathVersion );
$headers [ 'Destination' ] = " $baseUrl / $destinationDavPath / $destinationId " ;
2024-02-15 21:26:17 +05:45
$response = $this -> moveFilesAndFoldersRequest ( $user , $fullUrl , $headers );
$this -> featureContext -> setResponse ( $response );
}
2021-12-02 00:01:52 +01:00
/**
2026-07-28 14:23:42 +05:45
* @Given /^user "([^"]*)" has uploaded a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)"(| in vault)?$/
2021-12-02 00:01:52 +01:00
*
* @param string $user
* @param string $spaceName
* @param string $fileContent
* @param string $destination
2026-07-28 14:23:42 +05:45
* @param string $isVault
2021-12-02 00:01:52 +01:00
*
2023-10-11 16:15:31 +05:45
* @return array
2022-05-11 15:04:12 +05:45
* @throws GuzzleException
2021-12-02 00:01:52 +01:00
*/
2021-12-21 13:47:15 +05:45
public function userHasUploadedFile (
string $user ,
string $spaceName ,
string $fileContent ,
2025-06-19 15:34:02 +05:45
string $destination ,
2026-07-28 14:23:42 +05:45
string $isVault ,
2023-08-18 09:58:25 +05:45
) : array {
2026-07-28 14:23:42 +05:45
$isVault = trim ( $isVault ) === "in vault" ;
$space = $this -> getSpaceByName ( $user , $spaceName , $isVault );
2024-12-24 09:30:42 +05:45
$response = $this -> featureContext -> uploadFileWithContent (
$user ,
$fileContent ,
$destination ,
2025-02-17 17:44:48 +05:45
$space [ "id" ],
2025-06-19 15:34:02 +05:45
true ,
2024-12-24 09:30:42 +05:45
);
2023-10-11 16:15:31 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ([ '201' , '204' ], "" , $response );
return $response -> getHeader ( 'oc-fileid' );
2021-12-02 00:01:52 +01:00
}
2021-12-19 22:21:24 +01:00
/**
2023-02-17 09:18:53 +01:00
* @When /^user "([^"]*)" shares a space "([^"]*)" with settings:$/
* @When /^user "([^"]*)" updates the space "([^"]*)" with settings:$/
2021-12-19 22:21:24 +01:00
*
* @param string $user
* @param string $spaceName
2023-02-17 09:18:53 +01:00
* @param TableNode $table
2021-12-19 22:21:24 +01:00
*
2021-12-21 13:47:15 +05:45
* @return void
2021-12-19 22:21:24 +01:00
* @throws GuzzleException
*/
public function sendShareSpaceRequest (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2021-12-21 13:47:15 +05:45
) : void {
2023-03-15 09:27:45 +05:45
$rows = $table -> getRowsHash ();
$this -> featureContext -> setResponse ( $this -> shareSpace ( $user , $spaceName , $rows ));
}
/**
* @param string $user
* @param string $spaceName
* @param array $rows
*
* @return ResponseInterface
*
* @throws GuzzleException
*/
public function shareSpace ( string $user , string $spaceName , array $rows ) : ResponseInterface {
2021-12-19 22:21:24 +01:00
$space = $this -> getSpaceByName ( $user , $spaceName );
2022-08-11 10:02:27 +05:45
$availableRoleToAssignToShareSpace = [ 'manager' , 'editor' , 'viewer' ];
2023-02-22 09:21:57 +05:45
if ( isset ( $rows [ 'role' ]) && ! \in_array ( \strtolower ( $rows [ 'role' ]), $availableRoleToAssignToShareSpace )) {
2023-02-17 09:18:53 +01:00
throw new Error ( "The Selected " . $rows [ 'role' ] . " Cannot be Found" );
2022-08-11 10:02:27 +05:45
}
2023-02-22 09:21:57 +05:45
$rows [ "role" ] = \array_key_exists ( "role" , $rows ) ? $rows [ "role" ] : "viewer" ;
2023-02-17 09:18:53 +01:00
$rows [ "shareType" ] = \array_key_exists ( "shareType" , $rows ) ? $rows [ "shareType" ] : 7 ;
$rows [ "expireDate" ] = \array_key_exists ( "expireDate" , $rows ) ? $rows [ "expireDate" ] : null ;
2022-01-20 18:17:30 +01:00
$body = [
2023-02-17 09:18:53 +01:00
"space_ref" => $space [ "id" ],
"shareType" => $rows [ "shareType" ],
"shareWith" => $rows [ "shareWith" ],
"role" => $rows [ "role" ],
2025-06-19 10:46:56 +05:45
"expireDate" => $rows [ "expireDate" ],
2022-01-20 18:17:30 +01:00
];
2021-12-19 22:21:24 +01:00
2024-10-08 12:26:40 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . $this -> ocsApiUrl ;
2023-03-15 09:27:45 +05:45
return $this -> sendPostRequestToUrl (
$fullUrl ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2023-09-06 16:07:53 +05:45
$body ,
2022-03-27 21:36:13 +02:00
);
}
2023-03-15 09:27:45 +05:45
/**
* @When /^user "([^"]*)" expires the (user|group) share of space "([^"]*)" for (?:user|group) "([^"]*)"$/
*
* @param string $user
* @param string $shareType
* @param string $spaceName
* @param string $memberUser
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userExpiresTheShareOfSpaceForUser (
string $user ,
string $shareType ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $memberUser ,
2025-06-19 12:15:41 +05:45
) : void {
2026-10-01 16:37:56 +05:45
$rows [ 'expireDate' ] = $this -> featureContext -> formatExpiryDateTime ( 'Y-m-d\\TH:i:sP' );
2023-03-15 09:27:45 +05:45
$rows [ 'shareWith' ] = $memberUser ;
$rows [ 'shareType' ] = ( $shareType === 'user' ) ? 7 : 8 ;
$this -> featureContext -> setResponse ( $this -> shareSpace ( $user , $spaceName , $rows ));
}
2022-03-27 21:36:13 +02:00
/**
* @param string $user
* @param string $spaceName
2023-02-01 09:55:51 +01:00
* @param TableNode $table
2022-03-27 21:36:13 +02:00
*
2023-10-17 11:41:47 +05:45
* @return ResponseInterface
2022-03-27 21:36:13 +02:00
* @throws GuzzleException
*/
2023-02-01 09:55:51 +01:00
public function createShareResource (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
2023-02-01 09:55:51 +01:00
$rows = $table -> getRowsHash ();
$rows [ "path" ] = \array_key_exists ( "path" , $rows ) ? $rows [ "path" ] : null ;
$rows [ "shareType" ] = \array_key_exists ( "shareType" , $rows ) ? $rows [ "shareType" ] : 0 ;
$rows [ "role" ] = \array_key_exists ( "role" , $rows ) ? $rows [ "role" ] : 'viewer' ;
$rows [ "expireDate" ] = \array_key_exists ( "expireDate" , $rows ) ? $rows [ "expireDate" ] : null ;
2022-03-27 21:36:13 +02:00
$body = [
2023-02-01 09:55:51 +01:00
"space_ref" => $this -> getResourceId ( $user , $spaceName , $rows [ "path" ]),
"shareWith" => $rows [ "shareWith" ],
"shareType" => $rows [ "shareType" ],
"expireDate" => $rows [ "expireDate" ],
2025-06-19 10:46:56 +05:45
"role" => $rows [ "role" ],
2022-03-27 21:36:13 +02:00
];
2024-02-21 11:14:58 +01:00
// share with custom permission
if ( isset ( $rows [ "permissions" ])) {
$body [ "permissions" ] = $rows [ "permissions" ];
}
2024-10-08 12:26:40 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . $this -> ocsApiUrl ;
2023-10-17 11:41:47 +05:45
$response = $this -> sendPostRequestToUrl (
$fullUrl ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
);
2024-11-29 13:19:54 +05:45
$responseXmlObject = HttpRequestHelper :: getResponseXml ( $response , __METHOD__ );
$sharer = ( string ) $responseXmlObject -> data -> uid_owner ;
$this -> featureContext -> addToCreatedUserGroupshares ( $sharer , $responseXmlObject -> data );
2023-10-17 11:41:47 +05:45
return $response ;
}
/**
* @When /^user "([^"]*)" creates a share inside of space "([^"]*)" with settings:$/
*
* @param string $user
* @param string $spaceName
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
public function userCreatesShareInsideOfSpaceWithSettings (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2023-10-17 11:41:47 +05:45
) : void {
2023-02-01 09:55:51 +01:00
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> createShareResource ( $user , $spaceName , $table ),
2022-03-27 21:36:13 +02:00
);
}
2022-08-31 12:57:15 +05:45
/**
2023-02-01 09:55:51 +01:00
* @Given /^user "([^"]*)" has created a share inside of space "([^"]*)" with settings:$/
2022-08-31 12:57:15 +05:45
*
* @param string $user
* @param string $spaceName
2023-02-01 09:55:51 +01:00
* @param TableNode $table
2022-08-31 12:57:15 +05:45
*
* @return void
* @throws GuzzleException
*/
2023-10-17 11:41:47 +05:45
public function userHasSharedTheFollowingEntityInsideOfSpace (
2022-08-31 12:57:15 +05:45
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2022-08-31 12:57:15 +05:45
) : void {
2023-10-17 11:41:47 +05:45
$response = $this -> createShareResource ( $user , $spaceName , $table );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2022-08-31 12:57:15 +05:45
}
/**
2023-02-01 09:55:51 +01:00
* @When /^user "([^"]*)" changes the last share with settings:$/
2022-08-31 12:57:15 +05:45
*
* @param string $user
2023-02-01 09:55:51 +01:00
* @param TableNode $table
2022-08-31 12:57:15 +05:45
*
* @return void
* @throws GuzzleException
*/
2023-03-15 09:27:45 +05:45
public function changeShareResourceWithSettings (
2022-08-31 12:57:15 +05:45
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2022-08-31 12:57:15 +05:45
) : void {
2023-02-01 09:55:51 +01:00
$rows = $table -> getRowsHash ();
2023-03-15 09:27:45 +05:45
$this -> featureContext -> setResponse ( $this -> updateSharedResource ( $user , $rows ));
}
/**
* @param string $user
* @param array $rows
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws JsonException
*/
2024-12-24 09:30:42 +05:45
public function updateSharedResource ( string $user , array $rows ) : ResponseInterface {
$shareId = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ()
: $this -> featureContext -> getLastCreatedUserGroupShareId ();
2024-10-08 12:26:40 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . $this -> ocsApiUrl . '/' . $shareId ;
2024-12-24 09:30:42 +05:45
return HttpRequestHelper :: sendRequest (
2023-03-15 09:27:45 +05:45
$fullUrl ,
"PUT" ,
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
null ,
2025-06-19 15:34:02 +05:45
$rows ,
2022-08-31 12:57:15 +05:45
);
}
2023-03-15 09:27:45 +05:45
/**
2024-05-13 16:28:53 +05:45
* @When user :user expires the last share of resource :resource inside of the space :spaceName
2023-03-15 09:27:45 +05:45
*
* @param string $user
2024-05-13 16:28:53 +05:45
* @param string $resource
* @param string $spaceName
2023-03-15 09:27:45 +05:45
*
* @return void
2024-05-13 16:28:53 +05:45
* @throws GuzzleException|JsonException
2023-03-15 09:27:45 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userExpiresTheLastShareOfResourceInsideOfTheSpace (
string $user ,
string $resource ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2025-09-10 15:57:27 +05:45
$response = $this -> expireResourceShare ( $user , $resource , $spaceName );
$this -> featureContext -> setResponse ( $response );
}
/**
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return ResponseInterface
* @throws GuzzleException|JsonException
*/
public function expireResourceShare ( string $user , string $resource , string $spaceName ) : ResponseInterface {
2025-03-17 17:20:26 +05:45
$rows [ 'expireDate' ] = $this -> featureContext -> formatExpiryDateTime ( 'Y-m-d\\TH:i:sP' );
2024-05-13 16:28:53 +05:45
if ( $this -> featureContext -> isUsingSharingNG ()) {
2024-05-14 14:22:07 +05:45
$space = $this -> getSpaceByName ( $user , $spaceName );
$itemId = $this -> getResourceId ( $user , $spaceName , $resource );
2024-05-13 16:28:53 +05:45
$body [ 'expirationDateTime' ] = $rows [ 'expireDate' ];
$permissionID = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
2025-02-12 12:43:32 +05:45
$response = GraphHelper :: updateShare (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$space [ "id" ],
$itemId ,
\json_encode ( $body ),
2025-06-19 15:34:02 +05:45
$permissionID ,
2024-05-13 16:28:53 +05:45
);
2025-02-12 12:43:32 +05:45
if ( $response -> getStatusCode () === 200 ) {
2025-06-12 10:59:16 +05:45
$this -> featureContext -> shareNgAddToCreatedUserGroupShares ( $response , $resource , $spaceName );
2025-02-12 12:43:32 +05:45
}
2025-09-10 15:57:27 +05:45
return $response ;
2024-05-13 16:28:53 +05:45
}
2025-09-10 15:57:27 +05:45
$rows [ 'permissions' ] = ( string ) $this -> featureContext -> getLastCreatedUserGroupShare () -> permissions ;
return $this -> updateSharedResource ( $user , $rows );
}
/**
* @Given user :user has expired the last share of resource :resource inside of the space :spaceName
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws GuzzleException|JsonException
*/
public function userHasExpiredTheLastShareOfResourceInsideOfTheSpace (
string $user ,
string $resource ,
string $spaceName ,
) : void {
$response = $this -> expireResourceShare ( $user , $resource , $spaceName );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2023-03-15 09:27:45 +05:45
}
2023-10-17 11:41:47 +05:45
2022-03-27 21:36:13 +02:00
/**
* @param string $user
* @param string $spaceName
2022-08-18 11:23:57 +02:00
* @param TableNode $table
2022-03-27 21:36:13 +02:00
*
2023-10-17 11:41:47 +05:45
* @return ResponseInterface
2022-03-27 21:36:13 +02:00
* @throws GuzzleException
*/
public function createPublicLinkToEntityInsideOfSpaceRequest (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
2022-03-27 21:36:13 +02:00
$space = $this -> getSpaceByName ( $user , $spaceName );
$rows = $table -> getRowsHash ();
$rows [ "path" ] = \array_key_exists ( "path" , $rows ) ? $rows [ "path" ] : null ;
2023-09-18 10:21:35 +02:00
$rows [ "shareType" ] = \array_key_exists ( "shareType" , $rows ) ? $rows [ "shareType" ] : 3 ;
2022-03-27 21:36:13 +02:00
$rows [ "permissions" ] = \array_key_exists ( "permissions" , $rows ) ? $rows [ "permissions" ] : null ;
2024-12-24 09:30:42 +05:45
$rows [ 'password' ] = \array_key_exists ( 'password' , $rows )
? $this -> featureContext -> getActualPassword ( $rows [ 'password' ]) : null ;
2022-03-27 21:36:13 +02:00
$rows [ "name" ] = \array_key_exists ( "name" , $rows ) ? $rows [ "name" ] : null ;
$rows [ "expireDate" ] = \array_key_exists ( "expireDate" , $rows ) ? $rows [ "expireDate" ] : null ;
2022-03-30 21:34:41 +02:00
2022-03-27 21:36:13 +02:00
$body = [
"space_ref" => $space [ 'id' ] . "/" . $rows [ "path" ],
"shareType" => $rows [ "shareType" ],
"permissions" => $rows [ "permissions" ],
"password" => $rows [ "password" ],
"name" => $rows [ "name" ],
2025-06-19 10:46:56 +05:45
"expireDate" => $rows [ "expireDate" ],
2022-03-27 21:36:13 +02:00
];
2024-10-08 12:26:40 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . $this -> ocsApiUrl ;
2021-12-19 22:21:24 +01:00
2025-06-19 12:12:17 +05:45
$response = $this -> sendPostRequestToUrl (
2023-10-17 11:41:47 +05:45
$fullUrl ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
2021-12-21 18:22:32 +01:00
);
2022-08-18 11:23:57 +02:00
2024-11-29 13:19:54 +05:45
$responseXmlObject = HttpRequestHelper :: getResponseXml ( $response , __METHOD__ );
$this -> featureContext -> addToCreatedPublicShares ( $responseXmlObject -> data );
2023-10-17 11:41:47 +05:45
return $response ;
}
/**
* @When /^user "([^"]*)" creates a public link share inside of space "([^"]*)" with settings:$/
*
* @param string $user
* @param string $spaceName
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
public function userCreatesPublicLinkShareInsideOfSpaceWithSettings (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2023-10-17 11:41:47 +05:45
) : void {
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> createPublicLinkToEntityInsideOfSpaceRequest ( $user , $spaceName , $table ),
2023-10-17 11:41:47 +05:45
);
2022-08-18 11:23:57 +02:00
}
/**
* @Given /^user "([^"]*)" has created a public link share inside of space "([^"]*)" with settings:$/
*
* @param string $user
* @param string $spaceName
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
public function userHasCreatedPublicLinkToEntityInsideOfSpaceRequest (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2022-08-18 11:23:57 +02:00
) : void {
2023-10-17 11:41:47 +05:45
$response = $this -> createPublicLinkToEntityInsideOfSpaceRequest ( $user , $spaceName , $table );
2022-08-18 11:23:57 +02:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
2023-10-17 11:41:47 +05:45
200 ,
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-08-18 11:23:57 +02:00
);
2021-12-19 22:21:24 +01:00
}
/**
2023-02-17 09:18:53 +01:00
* @Given /^user "([^"]*)" has shared a space "([^"]*)" with settings:$/
2021-12-19 22:21:24 +01:00
*
* @param string $user
* @param string $spaceName
2023-02-17 09:18:53 +01:00
* @param TableNode $tableNode
2021-12-19 22:21:24 +01:00
*
2021-12-21 13:47:15 +05:45
* @return void
2021-12-19 22:21:24 +01:00
* @throws GuzzleException
*/
public function userHasSharedSpace (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $tableNode ,
2021-12-21 13:47:15 +05:45
) : void {
2023-10-17 11:41:47 +05:45
$rows = $tableNode -> getRowsHash ();
$response = $this -> shareSpace ( $user , $spaceName , $rows );
2021-12-22 09:31:18 +05:45
$expectedHTTPStatus = "200" ;
2021-12-19 22:21:24 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
2022-03-10 09:29:26 +01:00
$expectedHTTPStatus ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be $expectedHTTPStatus " ,
2025-06-19 15:34:02 +05:45
$response ,
2021-12-19 22:21:24 +01:00
);
2022-03-10 09:29:26 +01:00
$expectedOCSStatus = "200" ;
2024-05-09 13:01:41 +05:45
Assert :: assertEquals (
$expectedOCSStatus ,
$this -> ocsContext -> getOCSResponseStatusCode (
2025-06-19 15:34:02 +05:45
$response ,
2024-05-09 13:01:41 +05:45
),
2025-06-19 15:34:02 +05:45
"Expected OCS response status code $expectedOCSStatus " ,
2024-05-09 13:01:41 +05:45
);
2021-12-19 22:21:24 +01:00
}
2023-06-08 16:59:45 +05:45
/**
* @Given user :user has unshared a space :spaceName shared with :recipient
*
* @param string $user
* @param string $spaceName
* @param string $recipient
*
* @return void
* @throws GuzzleException
*/
public function userHasUnsharedASpaceSharedWith (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $recipient ,
2023-06-08 16:59:45 +05:45
) : void {
2023-10-17 11:41:47 +05:45
$response = $this -> sendUnshareSpaceRequest ( $user , $spaceName , $recipient );
2023-06-08 16:59:45 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2023-06-08 16:59:45 +05:45
);
}
2021-12-19 22:21:24 +01:00
/**
* @param string $user
* @param string $spaceName
2023-01-10 12:03:52 +01:00
* @param string $recipient
2021-12-19 22:21:24 +01:00
*
2023-10-17 11:41:47 +05:45
* @return ResponseInterface
2021-12-19 22:21:24 +01:00
* @throws GuzzleException
*/
public function sendUnshareSpaceRequest (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $recipient ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
2021-12-19 22:21:24 +01:00
$space = $this -> getSpaceByName ( $user , $spaceName );
2024-12-24 09:30:42 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl ()
. $this -> ocsApiUrl . "/" . $space [ 'id' ] . "?shareWith=" . $recipient ;
2021-12-19 22:21:24 +01:00
2023-10-17 11:41:47 +05:45
return HttpRequestHelper :: delete (
$fullUrl ,
$user ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
2023-10-17 11:41:47 +05:45
);
}
/**
* @When /^user "([^"]*)" unshares a space "([^"]*)" to (?:user|group) "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $recipient
*
* @return void
* @throws GuzzleException
*/
public function userUnsharesSpace (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $recipient ,
2023-10-17 11:41:47 +05:45
) : void {
2022-01-30 20:50:41 +01:00
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> sendUnshareSpaceRequest ( $user , $spaceName , $recipient ),
2023-10-17 11:41:47 +05:45
);
}
/**
* @param string $user
* @param string $object
* @param string $spaceName
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function removeObjectFromSpace (
string $user ,
string $object ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
$space = $this -> getSpaceByName ( $user , $spaceName );
2024-09-17 17:11:20 +05:45
$encodedName = \rawurlencode ( ltrim ( $object , "/" ));
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $encodedName " ;
2024-09-17 17:11:20 +05:45
2023-10-17 11:41:47 +05:45
return HttpRequestHelper :: delete (
2024-09-17 17:11:20 +05:45
$fullUrl ,
2023-10-17 11:41:47 +05:45
$user ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
2022-01-30 20:50:41 +01:00
);
2021-12-19 22:21:24 +01:00
}
2022-01-25 14:59:15 +01:00
/**
2022-04-12 08:51:35 +02:00
* @When /^user "([^"]*)" removes the (?:file|folder) "([^"]*)" from space "([^"]*)"$/
2022-01-25 14:59:15 +01:00
*
* @param string $user
* @param string $object
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
2023-10-17 11:41:47 +05:45
public function userRemovesFileOrFolderFromSpace (
2022-01-25 14:59:15 +01:00
string $user ,
string $object ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-01-25 14:59:15 +01:00
) : void {
2022-01-30 20:50:41 +01:00
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> removeObjectFromSpace ( $user , $object , $spaceName ),
2022-01-30 20:50:41 +01:00
);
2022-01-25 14:59:15 +01:00
}
2023-06-08 16:59:45 +05:45
/**
2026-07-30 12:07:41 +05:45
* @Given /^user "([^"]*)" has deleted a space "([^"]*)"(| in vault)?$/
2023-06-08 16:59:45 +05:45
*
* @param string $user
* @param string $spaceName
2026-07-30 12:07:41 +05:45
* @param string $isVault
2023-06-08 16:59:45 +05:45
*
* @return void
* @throws GuzzleException
*/
public function userHasDeletedASpaceOwnedByUser (
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2026-07-30 12:07:41 +05:45
string $isVault ,
2024-12-24 09:30:42 +05:45
) : void {
2026-07-30 12:07:41 +05:45
$isVault = trim ( $isVault ) === 'in vault' ;
$response = $this -> deleteSpace ( $user , $spaceName , '' , $isVault );
2023-06-08 16:59:45 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
204 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2023-10-17 11:41:47 +05:45
);
}
/**
* @param string $user
* @param string $spaceName
* @param string $owner
2026-07-30 12:07:41 +05:45
* @param boolean $isVault
2023-10-17 11:41:47 +05:45
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function disableSpace (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2026-07-30 12:07:41 +05:45
bool $isVault = false ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
2026-07-30 12:07:41 +05:45
$space = $this -> getSpaceByName (( $owner !== "" ) ? $owner : $user , $spaceName , $isVault );
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( strtolower ( $user ))[ 'token' ][ 'accessToken' ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2023-10-17 11:41:47 +05:45
return GraphHelper :: disableSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
2026-07-30 12:07:41 +05:45
$password ,
2023-10-17 11:41:47 +05:45
$space [ "id" ],
2026-07-30 12:07:41 +05:45
$headers ,
$isVault ,
2023-06-08 16:59:45 +05:45
);
}
2022-01-25 14:59:15 +01:00
/**
2022-01-30 20:50:41 +01:00
* @When /^user "([^"]*)" disables a space "([^"]*)"$/
2023-02-06 23:48:30 +01:00
* @When /^user "([^"]*)" (?:disables|tries to disable) a space "([^"]*)" owned by user "([^"]*)"$/
2022-01-25 14:59:15 +01:00
*
* @param string $user
* @param string $spaceName
2023-02-06 23:48:30 +01:00
* @param string $owner
2022-01-25 14:59:15 +01:00
*
* @return void
* @throws GuzzleException
*/
2023-10-17 11:41:47 +05:45
public function userDisablesSpace (
2022-01-25 14:59:15 +01:00
string $user ,
2023-02-06 23:48:30 +01:00
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2022-01-25 14:59:15 +01:00
) : void {
2022-01-30 20:50:41 +01:00
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> disableSpace ( $user , $spaceName , $owner ),
2022-01-30 20:50:41 +01:00
);
}
/**
2022-04-12 08:51:35 +02:00
* @Given /^user "([^"]*)" has removed the (?:file|folder) "([^"]*)" from space "([^"]*)"$/
*
* @param string $user
* @param string $object
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
2023-10-17 11:41:47 +05:45
public function userHasRemovedFileOrFolderFromSpace (
2022-04-12 08:51:35 +02:00
string $user ,
string $object ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-04-12 08:51:35 +02:00
) : void {
2023-10-17 11:41:47 +05:45
$response = $this -> removeObjectFromSpace ( $user , $object , $spaceName );
2022-04-12 08:51:35 +02:00
$expectedHTTPStatus = "204" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
$expectedHTTPStatus ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be $expectedHTTPStatus " ,
2025-06-19 15:34:02 +05:45
$response ,
2022-04-12 08:51:35 +02:00
);
}
/**
2026-07-30 12:07:41 +05:45
* @Given /^user "([^"]*)" has disabled a space "([^"]*)"(| in vault)?$/
2022-01-30 20:50:41 +01:00
*
* @param string $user
* @param string $spaceName
2026-07-30 12:07:41 +05:45
* @param string $isVault
2022-01-30 20:50:41 +01:00
*
* @return void
* @throws GuzzleException
*/
public function sendUserHasDisabledSpaceRequest (
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2026-07-30 12:07:41 +05:45
string $isVault ,
2022-01-30 20:50:41 +01:00
) : void {
2026-07-30 12:07:41 +05:45
$isVault = trim ( $isVault ) === 'in vault' ;
$response = $this -> disableSpace ( $user , $spaceName , '' , $isVault );
2022-01-30 20:50:41 +01:00
$expectedHTTPStatus = "204" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
2022-03-10 09:29:26 +01:00
$expectedHTTPStatus ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be $expectedHTTPStatus " ,
2025-06-19 15:34:02 +05:45
$response ,
2023-10-17 11:41:47 +05:45
);
}
2025-10-29 13:25:08 +05:45
/**
* @Given /^user "([^"]*)" has disabled personal space of user "([^"]*)"$/
*
* @param string $user
* @param string $spaceOwnerName
*
* @return void
* @throws GuzzleException
*/
public function userHasDisabledPersonalSpaceOfUser (
string $user ,
string $spaceOwnerName ,
) : void {
$space = $this -> getSpaceByName ( $spaceOwnerName , "Personal" );
$response = GraphHelper :: disableSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$space [ "id" ],
);
$expectedHTTPStatus = "204" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
$expectedHTTPStatus ,
"Expected response status code should be $expectedHTTPStatus " ,
$response ,
);
}
2023-10-17 11:41:47 +05:45
/**
* @param string $user
* @param string $spaceName
* @param string $owner
2026-07-30 12:07:41 +05:45
* @param boolean $isVault
2023-10-17 11:41:47 +05:45
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function deleteSpace (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2026-07-30 12:07:41 +05:45
bool $isVault = false ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
2026-07-30 12:07:41 +05:45
$space = $this -> getSpaceByName (( $owner !== "" ) ? $owner : $user , $spaceName , $isVault );
2023-10-17 11:41:47 +05:45
2026-07-30 12:07:41 +05:45
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( strtolower ( $user ))[ 'token' ][ 'accessToken' ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2023-10-17 11:41:47 +05:45
return GraphHelper :: deleteSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
2026-07-30 12:07:41 +05:45
$password ,
2023-10-17 11:41:47 +05:45
$space [ "id" ],
2026-07-30 12:07:41 +05:45
$headers ,
$isVault ,
2022-01-30 20:50:41 +01:00
);
}
/**
* @When /^user "([^"]*)" deletes a space "([^"]*)"$/
2023-02-06 23:48:30 +01:00
* @When /^user "([^"]*)" (?:deletes|tries to delete) a space "([^"]*)" owned by user "([^"]*)"$/
2022-01-30 20:50:41 +01:00
*
* @param string $user
* @param string $spaceName
2023-05-02 17:25:56 +05:45
* @param string $owner
2022-01-30 20:50:41 +01:00
*
* @return void
* @throws GuzzleException
*/
2023-10-17 11:41:47 +05:45
public function userDeletesSpace (
2022-01-30 20:50:41 +01:00
string $user ,
2023-02-06 23:48:30 +01:00
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2022-01-30 20:50:41 +01:00
) : void {
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> deleteSpace ( $user , $spaceName , $owner ),
2023-10-17 11:41:47 +05:45
);
}
/**
* @param string $user
* @param string $spaceName
* @param string $owner
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function restoreSpace (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
$space = $this -> getSpaceByName (( $owner !== "" ) ? $owner : $user , $spaceName );
return GraphHelper :: restoreSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$space [ "id" ],
2022-01-30 20:50:41 +01:00
);
2022-01-25 14:59:15 +01:00
}
2022-02-07 18:30:28 +01:00
/**
* @When /^user "([^"]*)" restores a disabled space "([^"]*)"$/
2023-02-06 23:48:30 +01:00
* @When /^user "([^"]*)" (?:restores|tries to restore) a disabled space "([^"]*)" owned by user "([^"]*)"$/
2022-02-07 18:30:28 +01:00
*
* @param string $user
* @param string $spaceName
2023-02-06 23:48:30 +01:00
* @param string $owner
2022-02-07 18:30:28 +01:00
*
* @return void
* @throws GuzzleException
*/
2023-10-17 11:41:47 +05:45
public function userRestoresADisabledSpace (
2022-02-07 18:30:28 +01:00
string $user ,
2022-02-10 20:21:22 +01:00
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $owner = '' ,
2022-02-07 18:30:28 +01:00
) : void {
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> restoreSpace ( $user , $spaceName , $owner ),
2022-02-07 18:30:28 +01:00
);
}
/**
2022-04-12 08:51:35 +02:00
* @Given /^user "([^"]*)" has restored a disabled space "([^"]*)"$/
2022-02-07 18:30:28 +01:00
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userHasRestoredSpaceRequest (
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-02-07 18:30:28 +01:00
) : void {
2023-10-17 11:41:47 +05:45
$response = $this -> restoreSpace ( $user , $spaceName );
2022-02-07 18:30:28 +01:00
$expectedHTTPStatus = "200" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
2022-03-10 09:29:26 +01:00
$expectedHTTPStatus ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be $expectedHTTPStatus " ,
2025-06-19 15:34:02 +05:45
$response ,
2023-10-17 11:41:47 +05:45
);
}
/**
* @param string $user
* @param string $spaceName
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function listAllDeletedFilesFromTrash (
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
$space = $this -> getSpaceByName ( $user , $spaceName );
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
2024-12-24 09:30:42 +05:45
$davPath = WebDavHelper :: getDavPath (
WebDavHelper :: DAV_VERSION_SPACES ,
$space [ "id" ],
2025-06-19 15:34:02 +05:45
"trash-bin" ,
2024-12-24 09:30:42 +05:45
);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath " ;
2023-10-17 11:41:47 +05:45
return HttpRequestHelper :: sendRequest (
$fullUrl ,
'PROPFIND' ,
$user ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
2022-02-07 18:30:28 +01:00
);
}
2022-04-12 08:51:35 +02:00
/**
* @When /^user "([^"]*)" lists all deleted files in the trash bin of the space "([^"]*)"$/
2025-06-27 16:55:20 +05:45
* @When /^user "([^"]*)" tries to list all deleted files in the trash bin of the space "([^"]*)"$/
2022-04-12 08:51:35 +02:00
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
2022-05-03 09:48:12 +05:45
public function userListAllDeletedFilesInTrash (
2022-04-12 08:51:35 +02:00
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-04-12 08:51:35 +02:00
) : void {
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> listAllDeletedFilesFromTrash ( $user , $spaceName ),
2022-04-12 08:51:35 +02:00
);
}
2023-07-04 14:43:00 +02:00
/**
* @When /^user "([^"]*)" with admin permission lists all deleted files in the trash bin of the space "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function adminListAllDeletedFilesInTrash (
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-07-04 14:43:00 +02:00
) : void {
2024-10-07 15:03:16 +05:45
// get space by admin user
$space = $this -> getSpaceByName ( $this -> featureContext -> getAdminUserName (), $spaceName );
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
2024-12-24 09:30:42 +05:45
$davPath = WebDavHelper :: getDavPath (
WebDavHelper :: DAV_VERSION_SPACES ,
$space [ "id" ],
2025-06-19 15:34:02 +05:45
"trash-bin" ,
2024-12-24 09:30:42 +05:45
);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath " ;
2023-07-04 14:43:00 +02:00
$this -> featureContext -> setResponse (
2024-12-24 09:30:42 +05:45
HttpRequestHelper :: sendRequest (
$fullUrl ,
'PROPFIND' ,
$user ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
),
2023-07-04 14:43:00 +02:00
);
}
2022-04-12 08:51:35 +02:00
/**
2024-04-26 15:27:00 +05:45
* User gets all objects in the trash of project space
2022-04-12 19:35:05 +05:45
*
2022-09-06 12:32:56 +05:45
* Method "getTrashbinContentFromResponseXml" borrowed from core repository
2022-04-12 08:51:35 +02:00
* and return array like:
* [1] => Array
* (
2024-09-17 17:11:20 +05:45
* [href] => /dav/spaces/trash-bin/spaceId/objectId/
2022-04-12 08:51:35 +02:00
* [name] => deleted folder
* [mtime] => 1649147272
* [original-location] => deleted folder
* )
*
* @param string $user
* @param string $spaceName
*
* @return array
* @throws GuzzleException
*/
public function getObjectsInTrashbin (
string $user ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-04-12 08:51:35 +02:00
) : array {
2023-10-17 11:41:47 +05:45
$response = $this -> listAllDeletedFilesFromTrash ( $user , $spaceName );
2022-04-12 08:51:35 +02:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
207 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 207" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-04-12 08:51:35 +02:00
);
return $this -> trashbinContext -> getTrashbinContentFromResponseXml (
2025-06-19 15:34:02 +05:45
HttpRequestHelper :: getResponseXml ( $response , __METHOD__ ),
2022-04-12 08:51:35 +02:00
);
}
2025-06-27 16:55:20 +05:45
/**
* @param string $user
* @param string $spaceName
* @param string $resource
*
* @return string
* @throws GuzzleException
*/
public function getTrashbinItemHref ( string $user , string $spaceName , string $resource ) : string {
$items = $this -> getObjectsInTrashbin ( $user , $spaceName );
foreach ( $items as $item ) {
if ( $item [ "name" ] === $resource ) {
return $item [ "href" ];
}
}
}
2022-04-12 08:51:35 +02:00
/**
* @Then /^as "([^"]*)" (?:file|folder|entry) "([^"]*)" should (not|)\s?exist in the trashbin of the space "([^"]*)"$/
*
* @param string $user
* @param string $object
* @param string $shouldOrNot (not|)
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
2022-05-03 09:48:12 +05:45
public function checkExistenceOfObjectsInTrashbin (
2022-04-12 08:51:35 +02:00
string $user ,
string $object ,
string $shouldOrNot ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-04-12 08:51:35 +02:00
) : void {
$objectsInTrash = $this -> getObjectsInTrashbin ( $user , $spaceName );
$expectedObject = "" ;
foreach ( $objectsInTrash as $objectInTrash ) {
if ( $objectInTrash [ "name" ] === $object ) {
$expectedObject = $objectInTrash [ "name" ];
}
2022-05-11 15:04:12 +05:45
}
2022-04-12 08:51:35 +02:00
if ( $shouldOrNot === "not" ) {
Assert :: assertEmpty ( $expectedObject , " $object is found in the trash, but should not be there" );
2022-04-12 19:35:05 +05:45
} else {
Assert :: assertNotEmpty ( $expectedObject , " $object is not found in the trash" );
}
2022-04-12 08:51:35 +02:00
}
/**
* @When /^user "([^"]*)" restores the (?:file|folder) "([^"]*)" from the trash of the space "([^"]*)" to "([^"]*)"$/
2025-06-27 16:55:20 +05:45
* @When /^user "([^"]*)" tries to restore the (?:file|folder) "([^"]*)" from the trash of the space "([^"]*)" to "([^"]*)"$/
2022-04-12 08:51:35 +02:00
*
2022-05-11 15:04:12 +05:45
* @param string $user
2025-06-27 16:55:20 +05:45
* @param string $trashResource
2022-05-11 15:04:12 +05:45
* @param string $spaceName
* @param string $destination
2022-04-12 08:51:35 +02:00
*
* @return void
* @throws GuzzleException
2022-05-11 15:04:12 +05:45
* @throws Exception
2022-04-12 08:51:35 +02:00
*/
public function userRestoresSpaceObjectsFromTrashRequest (
string $user ,
2025-06-27 16:55:20 +05:45
string $trashResource ,
2022-04-12 08:51:35 +02:00
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $destination ,
2022-04-12 08:51:35 +02:00
) : void {
2025-06-27 16:55:20 +05:45
$destination = \ltrim ( $destination , "/" );
2022-04-12 08:51:35 +02:00
$space = $this -> getSpaceByName ( $user , $spaceName );
2025-06-27 16:55:20 +05:45
$spaceId = $space [ "id" ];
$spaceOwner = $space [ "spaceCreator" ];
$itemHref = $this -> getTrashbinItemHref ( $spaceOwner , $spaceName , $trashResource );
2022-04-12 08:51:35 +02:00
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
2025-06-27 16:55:20 +05:45
$davPath = WebDavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $spaceId );
2024-10-21 12:24:50 +05:45
$destination = " $baseUrl / $davPath / $destination " ;
2022-04-12 08:51:35 +02:00
$header = [ "Destination" => $destination , "Overwrite" => "F" ];
2025-06-27 16:55:20 +05:45
$fullUrl = $baseUrl . $itemHref ;
2022-04-12 08:51:35 +02:00
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
$fullUrl ,
'MOVE' ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$header ,
2025-06-19 15:34:02 +05:45
"" ,
),
2022-04-12 08:51:35 +02:00
);
}
2022-05-11 09:13:59 +02:00
2023-07-04 14:43:00 +02:00
/**
* @When user :user deletes the file/folder :resource from the trash of the space :spaceName
* @When user :user tries to delete the file/folder :resource from the trash of the space :spaceName
*
* @param string $user
* @param string $object
* @param string $spaceName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userDeletesObjectsFromTrashRequest (
string $user ,
string $object ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2023-07-04 14:43:00 +02:00
) : void {
// find object in trash
$objectsInTrash = $this -> getObjectsInTrashbin ( $user , $spaceName );
$pathToDeletedObject = "" ;
foreach ( $objectsInTrash as $objectInTrash ) {
if ( $objectInTrash [ "name" ] === $object ) {
$pathToDeletedObject = $objectInTrash [ "href" ];
}
}
if ( $pathToDeletedObject === "" ) {
2024-12-24 09:30:42 +05:45
throw new Exception (
2025-06-19 15:34:02 +05:45
__METHOD__ . " Object ' $object ' was not found in the trashbin of space ' $spaceName ' by user ' $user '" ,
2024-12-24 09:30:42 +05:45
);
2023-07-04 14:43:00 +02:00
}
2024-10-08 12:26:40 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . $pathToDeletedObject ;
2023-07-04 14:43:00 +02:00
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
$fullUrl ,
'DELETE' ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
[],
2025-06-19 15:34:02 +05:45
"" ,
),
2023-07-04 14:43:00 +02:00
);
}
2022-05-11 09:13:59 +02:00
/**
2022-05-11 15:04:12 +05:45
* User downloads a preview of the file inside the project space
2022-06-28 15:05:16 +02:00
*
2022-05-11 09:13:59 +02:00
* @When /^user "([^"]*)" downloads the preview of "([^"]*)" of the space "([^"]*)" with width "([^"]*)" and height "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileName
* @param string $spaceName
* @param string $width
* @param string $height
*
2022-09-06 12:32:56 +05:45
* @return void
2022-05-11 09:13:59 +02:00
* @throws GuzzleException
*/
public function downloadPreview (
string $user ,
string $fileName ,
string $spaceName ,
string $width ,
2025-06-19 15:34:02 +05:45
string $height ,
2022-05-11 09:13:59 +02:00
) : void {
$eTag = str_replace ( " \" " , "" , $this -> getETag ( $user , $spaceName , $fileName ));
$urlParameters = [
'scalingup' => 0 ,
2022-05-11 15:04:12 +05:45
'preview' => '1' ,
2022-05-11 09:13:59 +02:00
'a' => '1' ,
'c' => $eTag ,
'x' => $width ,
2025-06-19 10:46:56 +05:45
'y' => $height ,
2022-05-11 09:13:59 +02:00
];
$urlParameters = \http_build_query ( $urlParameters , '' , '&' );
$space = $this -> getSpaceByName ( $user , $spaceName );
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
$davPath = WebDavHelper :: getDavPath ( WebDavHelper :: DAV_VERSION_SPACES , $space [ "id" ]);
2024-10-21 12:24:50 +05:45
$fullUrl = " $baseUrl / $davPath / $fileName ? $urlParameters " ;
2022-05-11 09:13:59 +02:00
$this -> featureContext -> setResponse (
HttpRequestHelper :: get (
$fullUrl ,
$user ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
),
2022-05-11 09:13:59 +02:00
);
}
2022-05-18 11:39:16 +02:00
/**
* @When /^user "([^"]*)" downloads the file "([^"]*)" of the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
2022-06-28 15:05:16 +02:00
* @param string $fileName
2022-05-18 11:39:16 +02:00
* @param string $spaceName
*
2022-09-06 12:32:56 +05:45
* @return void
2022-05-18 11:39:16 +02:00
* @throws GuzzleException
*/
public function downloadFile (
string $user ,
string $fileName ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-06-28 15:05:16 +02:00
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-12-24 09:30:42 +05:45
$response = $this -> featureContext -> downloadFileAsUserUsingPassword (
$user ,
$fileName ,
$this -> featureContext -> getPasswordForUser ( $user ),
[],
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-12-24 09:30:42 +05:45
);
2023-10-11 16:15:31 +05:45
$this -> featureContext -> setResponse ( $response );
2022-05-18 11:39:16 +02:00
}
2022-08-05 16:56:04 +05:45
/**
2022-08-10 12:59:31 +05:45
* @When /^user "([^"]*)" requests the checksum of (?:file|folder|entry) "([^"]*)" in space "([^"]*)" via propfind using the WebDAV API$/
2022-08-05 16:56:04 +05:45
*
* @param string $user
* @param string $path
* @param string $spaceName
*
2022-09-06 12:32:56 +05:45
* @return void
2022-08-05 16:56:04 +05:45
* @throws GuzzleException
*/
public function userRequestsTheChecksumViaPropfindInSpace (
string $user ,
string $path ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-08-05 16:56:04 +05:45
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> checksumContext -> propfindResourceChecksum ( $user , $path , $spaceId ),
2024-12-24 09:30:42 +05:45
);
2022-08-05 16:56:04 +05:45
}
/**
* @When /^user "([^"]*)" uploads file with checksum "([^"]*)" and content "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $checksum
* @param string $content
2022-09-08 13:00:48 +05:45
* @param string $destination
2022-08-05 16:56:04 +05:45
* @param string $spaceName
*
2022-09-06 12:32:56 +05:45
* @return void
2022-08-05 16:56:04 +05:45
* @throws GuzzleException
*/
public function userUploadsFileWithChecksumWithContentInSpace (
string $user ,
string $checksum ,
string $content ,
2022-09-08 13:00:48 +05:45
string $destination ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-08-05 16:56:04 +05:45
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-05-30 17:07:09 +05:45
$this -> featureContext -> setResponse (
2024-12-24 09:30:42 +05:45
$this -> featureContext -> uploadFileWithChecksumAndContent (
$user ,
$checksum ,
$content ,
$destination ,
false ,
2025-06-19 15:34:02 +05:45
$spaceId ,
),
2024-05-30 17:07:09 +05:45
);
2022-08-05 16:56:04 +05:45
}
2022-05-18 11:39:16 +02:00
/**
* @When /^user "([^"]*)" downloads version of the file "([^"]*)" with the index "([^"]*)" of the space "([^"]*)" using the WebDAV API$/
2024-06-24 16:57:36 +05:45
* @When /^user "([^"]*)" tries to download version of the file "([^"]*)" with the index "([^"]*)" of the space "([^"]*)" using the WebDAV API$/
2022-05-18 11:39:16 +02:00
*
* @param string $user
2022-06-28 15:05:16 +02:00
* @param string $fileName
2022-05-18 11:39:16 +02:00
* @param string $index
* @param string $spaceName
*
2022-09-06 12:32:56 +05:45
* @return void
2022-05-18 11:39:16 +02:00
* @throws GuzzleException
*/
public function downloadVersionOfTheFile (
string $user ,
string $fileName ,
string $index ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2022-06-28 15:05:16 +02:00
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> filesVersionsContext -> downloadVersion ( $user , $fileName , $index , $spaceId ),
2024-12-24 09:30:42 +05:45
);
2022-05-18 11:39:16 +02:00
}
2022-07-14 16:59:36 +05:45
2023-04-06 12:52:38 +02:00
/**
2024-06-24 16:57:36 +05:45
* @When user :user tries to get versions of the file :file from the space :space using the WebDAV API
2023-04-06 12:52:38 +02:00
*
* @param string $user
* @param string $file
* @param string $spaceName
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userTriesToDownloadFileVersions ( string $user , string $file , string $spaceName ) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-05-06 11:49:15 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> filesVersionsContext -> getFileVersions ( $user , $file , null , $spaceId ),
2024-05-06 11:49:15 +05:45
);
2023-04-06 12:52:38 +02:00
}
2022-07-14 16:59:36 +05:45
/**
* return the etag for an element inside a space
*
* @param string $user requestor
* @param string $space space name
* @param string $path path to the file
*
* @return string
* @throws GuzzleException
*/
2024-04-26 15:27:00 +05:45
public function userGetsEtagOfElementInASpace ( string $user , string $space , string $path ) : string {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $space );
2024-09-18 11:26:20 +05:45
$xmlObject = $this -> webDavPropertiesContext -> storeEtagOfElement ( $user , $path , '' , $spaceId );
2023-10-05 09:55:11 +05:45
return $this -> featureContext -> getEtagFromResponseXmlObject ( $xmlObject );
2022-07-14 16:59:36 +05:45
}
/**
* saves the etag of an element in a space
*
* @param string $user requestor
* @param string $space space name
* @param string $path path to the file
* @param ?string $storePath path to the file in the store
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function storeEtagOfElementInSpaceForUser (
string $user ,
string $space ,
string $path ,
2025-06-19 15:34:02 +05:45
? string $storePath = "" ,
2024-12-24 09:30:42 +05:45
) : void {
2022-07-14 16:59:36 +05:45
if ( $storePath === "" ) {
$storePath = $path ;
}
$this -> storedEtags [ $user ][ $space ][ $storePath ]
= $this -> userGetsEtagOfElementInASpace (
$user ,
$space ,
$path ,
);
}
/**
* returns stored etag for an element if present
*
* @param string $user
* @param string $space
* @param string $path
*
* @return string
*/
public function getStoredEtagForPathInSpaceOfAUser ( string $user , string $space , string $path ) : string {
Assert :: assertArrayHasKey (
$user ,
$this -> storedEtags ,
__METHOD__ . " No stored etags for user ' $user ' found"
2025-06-19 15:34:02 +05:45
. " \n Found: " . print_r ( $this -> storedEtags , true ),
2022-07-14 16:59:36 +05:45
);
Assert :: assertArrayHasKey (
$space ,
$this -> storedEtags [ $user ],
__METHOD__ . " No stored etags for user ' $user ' with space ' $space ' found"
2025-06-19 15:34:02 +05:45
. " \n Found: " . implode ( ', ' , array_keys ( $this -> storedEtags [ $user ])),
2022-07-14 16:59:36 +05:45
);
Assert :: assertArrayHasKey (
$path ,
$this -> storedEtags [ $user ][ $space ],
__METHOD__ . " No stored etags for user ' $user ' with space ' $space ' with path ' $path ' found"
2025-06-19 15:34:02 +05:45
. '\nFound: ' . print_r ( $this -> storedEtags [ $user ][ $space ], true ),
2022-07-14 16:59:36 +05:45
);
return $this -> storedEtags [ $user ][ $space ][ $path ];
}
/**
2023-06-28 10:56:08 +05:45
* @Then /^these etags (should|should not) have changed$/
2022-07-14 16:59:36 +05:45
*
2023-06-28 10:56:08 +05:45
* @param string $action
2022-07-14 16:59:36 +05:45
* @param TableNode $table
*
2022-09-06 12:32:56 +05:45
* @return void
2022-07-14 16:59:36 +05:45
* @throws GuzzleException
*/
2023-06-28 10:56:08 +05:45
public function theseEtagsShouldShouldNotHaveChanged ( string $action , TableNode $table ) : void {
2022-07-14 16:59:36 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ "user" , "path" , "space" ]);
$this -> featureContext -> verifyTableNodeColumnsCount ( $table , 3 );
$changedEtagCount = 0 ;
$changedEtagMessage = __METHOD__ ;
foreach ( $table -> getColumnsHash () as $row ) {
$user = $row [ 'user' ];
$path = $row [ 'path' ];
$space = $row [ 'space' ];
2023-06-28 10:56:08 +05:45
$etag = $this -> userGetsEtagOfElementInASpace ( $user , $space , $path );
2022-07-14 16:59:36 +05:45
$storedEtag = $this -> getStoredEtagForPathInSpaceOfAUser ( $user , $space , $path );
2023-06-28 10:56:08 +05:45
if ( $action === 'should' && $etag === $storedEtag ) {
$changedEtagCount ++ ;
2024-12-24 09:30:42 +05:45
$changedEtagMessage .=
" \n Expected etag of element ' $path ' for user ' $user ' in space ' $space ' to change, but it did not." ;
2023-06-28 10:56:08 +05:45
}
if ( $action === 'should not' && $etag !== $storedEtag ) {
2022-07-14 16:59:36 +05:45
$changedEtagCount ++ ;
2024-12-24 09:30:42 +05:45
$changedEtagMessage .=
" \n Expected etag of element ' $path ' for user ' $user ' in space ' $space ' to change, but it did not." ;
2022-07-14 16:59:36 +05:45
}
}
Assert :: assertEquals ( 0 , $changedEtagCount , $changedEtagMessage );
}
/**
* @Given /^user "([^"]*)" has stored etag of element "([^"]*)" inside space "([^"]*)"$/
*
2022-09-06 12:32:56 +05:45
* @param string $user
* @param string $path
* @param string $space
*
* @return void
2022-07-14 16:59:36 +05:45
* @throws GuzzleException | Exception
*/
2024-12-24 09:30:42 +05:45
public function userHasStoredEtagOfElementFromSpace ( string $user , string $path , string $space ) : void {
2022-07-14 16:59:36 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
$this -> storeEtagOfElementInSpaceForUser (
$user ,
$space ,
$path ,
);
if ( $this -> storedEtags [ $user ][ $space ][ $path ] === "" || $this -> storedEtags [ $user ][ $space ][ $path ] === null ) {
throw new Exception ( "Expected stored etag to be some string but found null!" );
}
}
/**
* @Given /^user "([^"]*)" has stored etag of element "([^"]*)" on path "([^"]*)" inside space "([^"]*)"$/
*
2022-09-06 15:58:42 +05:45
* @param string $user
* @param string $path
* @param string $storePath
* @param string $space
2022-09-06 12:32:56 +05:45
*
* @return void
2022-07-14 16:59:36 +05:45
* @throws Exception | GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userHasStoredEtagOfElementOnPathFromSpace (
string $user ,
string $path ,
string $storePath ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-12-24 09:30:42 +05:45
) : void {
2022-07-14 16:59:36 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
$this -> storeEtagOfElementInSpaceForUser (
$user ,
$space ,
$path ,
2025-06-19 15:34:02 +05:45
$storePath ,
2022-07-14 16:59:36 +05:45
);
2024-12-24 09:30:42 +05:45
if ( $this -> storedEtags [ $user ][ $space ][ $storePath ] === ""
|| $this -> storedEtags [ $user ][ $space ][ $storePath ] === null
) {
2022-07-14 16:59:36 +05:45
throw new Exception ( "Expected stored etag to be some string but found null!" );
}
}
2022-07-21 17:42:39 +02:00
/**
* @param string $user
* @param string $spaceName
* @param TableNode|null $table
*
2023-10-17 11:41:47 +05:45
* @return ResponseInterface
2022-07-21 17:42:39 +02:00
* @throws GuzzleException
*/
public function sendShareSpaceViaLinkRequest (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
? TableNode $table ,
2023-10-17 11:41:47 +05:45
) : ResponseInterface {
2022-07-21 17:42:39 +02:00
$space = $this -> getSpaceByName ( $user , $spaceName );
$rows = $table -> getRowsHash ();
$rows [ "shareType" ] = \array_key_exists ( "shareType" , $rows ) ? $rows [ "shareType" ] : 3 ;
$rows [ "permissions" ] = \array_key_exists ( "permissions" , $rows ) ? $rows [ "permissions" ] : null ;
2024-12-24 09:30:42 +05:45
$rows [ 'password' ] = \array_key_exists ( 'password' , $rows )
? $this -> featureContext -> getActualPassword ( $rows [ 'password' ]) : null ;
2022-07-21 17:42:39 +02:00
$rows [ "name" ] = \array_key_exists ( "name" , $rows ) ? $rows [ "name" ] : null ;
$rows [ "expireDate" ] = \array_key_exists ( "expireDate" , $rows ) ? $rows [ "expireDate" ] : null ;
2022-07-26 11:27:28 +02:00
2022-07-21 17:42:39 +02:00
$body = [
"space_ref" => $space [ 'id' ],
"shareType" => $rows [ "shareType" ],
"permissions" => $rows [ "permissions" ],
"password" => $rows [ "password" ],
"name" => $rows [ "name" ],
2025-06-19 10:46:56 +05:45
"expireDate" => $rows [ "expireDate" ],
2022-07-21 17:42:39 +02:00
];
2024-10-08 12:26:40 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . $this -> ocsApiUrl ;
2022-07-21 17:42:39 +02:00
2023-10-17 11:41:47 +05:45
$response = $this -> sendPostRequestToUrl (
$fullUrl ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
);
2024-12-24 09:30:42 +05:45
$this -> featureContext -> addToCreatedPublicShares (
2025-06-19 15:34:02 +05:45
HttpRequestHelper :: getResponseXml ( $response , __METHOD__ ) -> data ,
2024-12-24 09:30:42 +05:45
);
2023-10-17 11:41:47 +05:45
return $response ;
}
/**
* @When /^user "([^"]*)" creates a public link share of the space "([^"]*)" with settings:$/
*
* @param string $user
* @param string $spaceName
* @param TableNode|null $table
*
* @return void
* @throws GuzzleException
*/
public function userCreatesAPublicLinkShareOfSpaceWithSettings (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
? TableNode $table ,
2023-10-17 11:41:47 +05:45
) : void {
2022-07-21 17:42:39 +02:00
$this -> featureContext -> setResponse (
2023-10-17 11:41:47 +05:45
$this -> sendShareSpaceViaLinkRequest (
2022-07-21 17:42:39 +02:00
$user ,
2023-10-17 11:41:47 +05:45
$spaceName ,
2025-06-19 15:34:02 +05:45
$table ,
),
2022-07-21 17:42:39 +02:00
);
2022-07-26 11:27:28 +02:00
}
/**
* @Given /^user "([^"]*)" has created a public link share of the space "([^"]*)" with settings:$/
*
* @param string $user
* @param string $spaceName
* @param TableNode|null $table
*
* @return void
* @throws GuzzleException
*/
public function userHasCreatedPublicLinkShareOfSpace (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
? TableNode $table ,
2022-07-26 11:27:28 +02:00
) : void {
2023-10-17 11:41:47 +05:45
$response = $this -> sendShareSpaceViaLinkRequest ( $user , $spaceName , $table );
2022-07-26 11:27:28 +02:00
$expectedHTTPStatus = "200" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
$expectedHTTPStatus ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be $expectedHTTPStatus " ,
2025-06-19 15:34:02 +05:45
$response ,
2022-07-26 11:27:28 +02:00
);
}
/**
* @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain the last created public link$/
2024-05-13 16:28:53 +05:45
* @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain the last created (public link|share) of the file "([^"]*)"$/
2022-07-26 11:27:28 +02:00
*
* @param string $user
* @param string $spaceName
* @param string $shouldOrNot (not|)
2024-05-13 16:28:53 +05:45
* @param string $shareType
2022-08-18 11:23:57 +02:00
* @param string $fileName
2022-07-26 11:27:28 +02:00
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function forUserSpaceShouldContainLinks (
string $user ,
string $spaceName ,
2022-08-18 11:23:57 +02:00
string $shouldOrNot ,
2024-05-13 16:28:53 +05:45
string $shareType = 'public link' ,
2025-06-19 15:34:02 +05:45
string $fileName = '' ,
2022-07-26 11:27:28 +02:00
) : void {
2022-08-23 13:48:30 +02:00
if ( ! empty ( $fileName )) {
2022-08-18 11:23:57 +02:00
$body = $this -> getFileId ( $user , $spaceName , $fileName );
} else {
$space = $this -> getSpaceByName ( $user , $spaceName );
$body = $space [ 'id' ];
}
2022-08-23 10:42:27 +02:00
2022-08-18 11:23:57 +02:00
$url = "/apps/files_sharing/api/v1/shares?reshares=true&space_ref=" . $body ;
2022-07-26 11:27:28 +02:00
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-07-26 11:27:28 +02:00
$user ,
'GET' ,
$url ,
);
$should = ( $shouldOrNot !== "not" );
2024-12-24 09:30:42 +05:45
$responseArray = json_decode (
json_encode ( HttpRequestHelper :: getResponseXml ( $response , __METHOD__ ) -> data ),
true ,
512 ,
2025-06-19 15:34:02 +05:45
JSON_THROW_ON_ERROR ,
2024-12-24 09:30:42 +05:45
);
2022-07-26 11:27:28 +02:00
if ( $should ) {
Assert :: assertNotEmpty ( $responseArray , __METHOD__ . ' Response should contain a link, but it is empty' );
foreach ( $responseArray as $element ) {
2024-05-13 16:28:53 +05:45
if ( $shareType === 'public link' ) {
2024-12-24 09:30:42 +05:45
$expectedLinkId = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareID () :
( string ) $this -> featureContext -> getLastCreatedPublicShare () -> id ;
2024-05-13 16:28:53 +05:45
Assert :: assertEquals ( $element [ "id" ], $expectedLinkId , "link IDs are different" );
} else {
2024-12-24 09:30:42 +05:45
$expectedShareId = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ()
: ( string ) $this -> featureContext -> getLastCreatedUserGroupShareId ();
2024-05-13 16:28:53 +05:45
Assert :: assertEquals ( $element [ "id" ], $expectedShareId , "share IDs are different" );
}
2022-07-26 11:27:28 +02:00
}
} else {
Assert :: assertEmpty ( $responseArray , __METHOD__ . ' Response should be empty' );
}
2022-07-21 17:42:39 +02:00
}
2022-08-16 11:20:46 +05:45
2022-08-09 14:00:02 +05:45
/**
* @When /^user "([^"]*)" gets the following properties of (?:file|folder|entry|resource) "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $resourceName
* @param string $spaceName
* @param TableNode|null $propertiesTable
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function userGetsTheFollowingPropertiesOfFileInsideSpaceUsingTheWebdavApi (
string $user ,
string $resourceName ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $propertiesTable ,
2024-12-24 09:30:42 +05:45
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-12-24 09:30:42 +05:45
$response = $this -> webDavPropertiesContext -> getPropertiesOfFolder (
$user ,
$resourceName ,
$spaceId ,
2025-06-19 15:34:02 +05:45
$propertiesTable ,
2024-12-24 09:30:42 +05:45
);
2023-10-05 09:55:11 +05:45
$this -> featureContext -> setResponse ( $response );
2022-08-09 14:00:02 +05:45
}
2024-06-13 10:58:40 +05:45
/**
* @When /^user "([^"]*)" gets the following extracted properties of (?:file|folder|entry|resource) "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $resourceName
* @param string $spaceName
* @param TableNode|null $propertiesTable
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function userGetsTheFollowingExtractedPropertiesOfFileInsideSpaceUsingTheWebdavApi (
string $user ,
string $resourceName ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $propertiesTable ,
2024-12-24 09:30:42 +05:45
) : void {
2024-06-13 10:58:40 +05:45
// NOTE: extracting properties occurs asynchronously
// short wait is necessary before getting those properties
sleep ( 2 );
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-12-24 09:30:42 +05:45
$response = $this -> webDavPropertiesContext -> getPropertiesOfFolder (
$user ,
$resourceName ,
$spaceId ,
2025-06-19 15:34:02 +05:45
$propertiesTable ,
2024-12-24 09:30:42 +05:45
);
2024-06-13 10:58:40 +05:45
$this -> featureContext -> setResponse ( $response );
}
2022-09-15 09:36:01 +05:45
/**
* @Then /^as user "([^"]*)" (?:file|folder|entry|resource) "([^"]*)" inside space "([^"]*)" should contain a property "([^"]*)" with value "([^"]*)"$/
*
* @param string $user
* @param string $resourceName
* @param string $spaceName
* @param string $property
* @param string $value
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function userGetsTheFollowingPropertiesOfFileInsideSpaceWithValueUsingTheWebdavApi (
string $user ,
string $resourceName ,
string $spaceName ,
string $property ,
2025-06-19 15:34:02 +05:45
string $value ,
2024-12-24 09:30:42 +05:45
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-12-24 09:30:42 +05:45
$this -> webDavPropertiesContext -> checkPropertyOfAFolder (
$user ,
$resourceName ,
$property ,
$value ,
null ,
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-12-24 09:30:42 +05:45
);
2022-09-15 09:36:01 +05:45
}
2022-09-09 14:14:10 +05:45
/**
* @Then /^as user "([^"]*)" (?:file|folder|entry) "([^"]*)" inside space "([^"]*)" (should|should not) be favorited$/
*
* @param string $user
* @param string $path
* @param string $spaceName
* @param string $shouldOrNot
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function asUserFileOrFolderInsideSpaceShouldOrNotBeFavorited (
string $user ,
string $path ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
string $shouldOrNot ,
2024-12-24 09:30:42 +05:45
) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-12-24 09:30:42 +05:45
$this -> favoritesContext -> asUserFileOrFolderShouldBeFavorited (
$user ,
$path ,
( $shouldOrNot === 'should' ) ? 1 : 0 ,
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-12-24 09:30:42 +05:45
);
2022-09-09 14:14:10 +05:45
}
2022-08-26 10:40:30 +05:45
2022-08-31 12:57:15 +05:45
/**
* @When /^user "([^"]*)" favorites element "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $path
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userFavoritesElementInSpaceUsingTheWebdavApi ( string $user , string $path , string $spaceName ) : void {
2024-10-07 15:03:16 +05:45
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
2024-09-18 11:26:20 +05:45
$this -> featureContext -> setResponse ( $this -> favoritesContext -> userFavoritesElement ( $user , $path , $spaceId ));
2022-08-31 12:57:15 +05:45
}
2022-09-05 16:00:16 +05:45
/**
2024-04-26 15:27:00 +05:45
* @Given /^user "([^"]*)" has stored id of (?:file|folder) "([^"]*)" of the space "([^"]*)"$/
2022-09-05 16:00:16 +05:45
*
* @param string $user
* @param string $path
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
*/
2024-04-26 15:27:00 +05:45
public function userHasStoredIdOfPathOfTheSpace ( string $user , string $path , string $spaceName ) : void {
2024-10-07 15:03:16 +05:45
$this -> getSpaceIdByName ( $user , $spaceName );
2024-05-30 17:07:09 +05:45
$this -> featureContext -> setStoredFileID ( $this -> featureContext -> getFileIdForPath ( $user , $path ));
2022-09-05 16:00:16 +05:45
}
/**
* @Then /^user "([^"]*)" (folder|file) "([^"]*)" of the space "([^"]*)" should have the previously stored id$/
*
2024-11-07 15:58:26 +05:45
* @param string $user
2022-09-05 16:00:16 +05:45
* @param string $fileOrFolder
* @param string $path
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
2024-11-07 15:58:26 +05:45
* @throws JsonException
2022-09-05 16:00:16 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userFolderOfTheSpaceShouldHaveThePreviouslyStoredId (
string $user ,
string $fileOrFolder ,
string $path ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2024-10-07 15:03:16 +05:45
$this -> getSpaceIdByName ( $user , $spaceName );
2024-05-30 17:07:09 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
$currentFileID = $this -> featureContext -> getFileIdForPath ( $user , $path );
$storedFileID = $this -> featureContext -> getStoredFileID ();
Assert :: assertEquals (
$currentFileID ,
$storedFileID ,
__METHOD__
2024-12-24 09:30:42 +05:45
. " User ' $user ' $fileOrFolder ' $path ' does not have the previously stored id '"
2025-06-19 15:34:02 +05:45
. $storedFileID . "', but has ' $currentFileID '." ,
2024-05-30 17:07:09 +05:45
);
2022-09-05 16:00:16 +05:45
}
2022-09-09 12:33:21 +02:00
/**
* @Then /^for user "([^"]*)" the search result should contain space "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function searchResultShouldContainSpace ( string $user , string $spaceName ) : void {
// get a response after a Report request (called in the core)
2024-12-24 09:30:42 +05:45
$responseArray = json_decode (
json_encode (
2025-06-19 15:34:02 +05:45
HttpRequestHelper :: getResponseXml ( $this -> featureContext -> getResponse ()) -> xpath ( "//d:response/d:href" ),
2024-12-24 09:30:42 +05:45
),
true ,
512 ,
2025-06-19 15:34:02 +05:45
JSON_THROW_ON_ERROR ,
2024-12-24 09:30:42 +05:45
);
2022-09-09 12:33:21 +02:00
Assert :: assertNotEmpty ( $responseArray , "search result is empty" );
2022-09-15 09:36:01 +05:45
2022-09-09 12:33:21 +02:00
// for mountpoint, id looks a little different than for project space
if ( str_contains ( $spaceName , 'mountpoint' )) {
$splitSpaceName = explode ( "/" , $spaceName );
$space = $this -> getSpaceByName ( $user , $splitSpaceName [ 1 ]);
$splitSpaceId = explode ( "$" , $space [ 'id' ]);
2024-09-17 17:11:20 +05:45
$spaceId = str_replace ( '!' , '%21' , $splitSpaceId [ 1 ]);
2022-09-09 12:33:21 +02:00
} else {
$space = $this -> getSpaceByName ( $user , $spaceName );
2024-09-17 17:11:20 +05:45
$spaceId = $space [ 'id' ];
}
2024-10-21 12:24:50 +05:45
$suffixPath = $user ;
2024-09-17 17:11:20 +05:45
$davPathVersion = $this -> featureContext -> getDavPathVersion ();
if ( $davPathVersion === WebDavHelper :: DAV_VERSION_SPACES ) {
2024-10-21 12:24:50 +05:45
$suffixPath = $spaceId ;
2022-09-09 12:33:21 +02:00
}
2022-09-15 09:36:01 +05:45
2024-10-21 12:24:50 +05:45
$topWebDavPath = "/" . WebDavHelper :: getDavPath ( $davPathVersion , $suffixPath );
2024-09-17 17:11:20 +05:45
2022-09-09 12:33:21 +02:00
$spaceFound = false ;
foreach ( $responseArray as $value ) {
if ( $topWebDavPath === $value [ 0 ]) {
$spaceFound = true ;
}
}
Assert :: assertTrue ( $spaceFound , "response does not contain the space ' $spaceName '" );
}
2022-10-17 13:46:07 +02:00
/**
2024-03-14 09:53:43 +05:45
* @When /^user "([^"]*)" sends PROPFIND request to space "([^"]*)" using the WebDAV API$/
2024-03-13 14:26:37 +05:45
* @When /^user "([^"]*)" sends PROPFIND request to space "([^"]*)" with depth "([^"]*)" using the WebDAV API$/
2024-03-14 09:53:43 +05:45
*
* @param string $user
* @param string $spaceName
* @param ?string $folderDepth
*
* @return void
*
* @throws JsonException
*
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSendsPropfindRequestToSpaceUsingTheWebdavApi (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
? string $folderDepth = "1" ,
2024-12-24 09:30:42 +05:45
) : void {
2024-03-14 09:53:43 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> sendPropfindRequestToSpace ( $user , $spaceName , "" , null , $folderDepth ),
2024-03-14 09:53:43 +05:45
);
}
/**
2024-03-12 15:35:53 +05:45
* @When /^user "([^"]*)" sends PROPFIND request from the space "([^"]*)" to the resource "([^"]*)" with depth "([^"]*)" using the WebDAV API$/
2024-03-18 15:48:31 +05:45
* @When user :user sends PROPFIND request from the space :spaceName to the resource :resource using the WebDAV API
2022-10-17 13:46:07 +02:00
*
* @param string $user
2022-11-28 14:27:41 +05:45
* @param string $spaceName
2024-03-15 14:18:33 +05:45
* @param string $resource
2024-03-18 15:48:31 +05:45
* @param string|null $folderDepth
2022-11-28 14:27:41 +05:45
*
* @return void
2023-11-29 11:25:01 +05:45
*
* @throws JsonException
*
* @throws GuzzleException
2022-11-28 14:27:41 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userSendsPropfindRequestFromTheSpaceToTheResourceWithDepthUsingTheWebdavApi (
string $user ,
string $spaceName ,
string $resource ,
2025-06-19 15:34:02 +05:45
? string $folderDepth = "1" ,
2024-12-24 09:30:42 +05:45
) : void {
2024-10-01 12:58:30 +05:45
$response = $this -> sendPropfindRequestToSpace ( $user , $spaceName , $resource , null , $folderDepth );
$this -> featureContext -> setResponse ( $response );
2023-11-29 11:25:01 +05:45
}
2024-01-24 19:25:20 +01:00
/**
* @When /^user "([^"]*)" sends PROPFIND request to space "([^"]*)" with headers using the WebDAV API$/
*
* @param string $user
* @param string $spaceName
* @param TableNode $headersTable
*
* @return void
*
* @throws JsonException
*
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSendsPropfindRequestToSpaceWithHeaders (
string $user ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $headersTable ,
2024-12-24 09:30:42 +05:45
) : void {
2024-01-24 19:25:20 +01:00
$this -> featureContext -> verifyTableNodeColumns (
$headersTable ,
2025-06-19 15:34:02 +05:45
[ 'header' , 'value' ],
2024-01-24 19:25:20 +01:00
);
2024-04-26 15:27:00 +05:45
$headers = [];
2024-01-24 19:25:20 +01:00
foreach ( $headersTable as $row ) {
$headers [ $row [ 'header' ]] = $row [ 'value' ];
}
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> sendPropfindRequestToSpace ( $user , $spaceName , '' , $headers , '0' ),
2024-01-24 19:25:20 +01:00
);
}
2023-11-29 11:25:01 +05:45
/**
* @param string $user
* @param string $spaceName
* @param string|null $resource
2024-01-24 19:25:20 +01:00
* @param array|null $headers
2024-03-12 15:35:53 +05:45
* @param string|null $folderDepth
2025-01-01 16:00:11 +05:45
* @param bool $federatedShare
2023-11-29 11:25:01 +05:45
*
* @return ResponseInterface
* @throws GuzzleException
*
* @throws JsonException
*/
2024-12-24 09:30:42 +05:45
public function sendPropfindRequestToSpace (
string $user ,
2025-01-01 16:00:11 +05:45
? string $spaceName = "" ,
2024-12-24 09:30:42 +05:45
? string $resource = "" ,
? array $headers = [],
2025-01-01 16:00:11 +05:45
? string $folderDepth = "1" ,
2025-06-19 15:34:02 +05:45
bool $federatedShare = false ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2025-01-01 16:00:11 +05:45
// PROPFIND request to federated share via normal webdav path "remote.php/dav/spaces/{shares-space-id}/{resource}" returns 404 status code
// the federated share is only accessible using "remote-item-id", i.e. "remote.php/dav/spaces/{remote-item-id}"
if ( $federatedShare ) {
$spaceId = $this -> getSharesRemoteItemId ( $user , $resource );
$resource = null ;
} else {
$spaceId = $this -> getSpaceIdByName ( $user , $spaceName );
}
2024-03-12 15:35:53 +05:45
$properties = [
'oc:id' ,
'oc:fileid' ,
'oc:spaceid' ,
'oc:file-parent' ,
'oc:shareid' ,
'oc:name' ,
'd:displayname' ,
'd:getetag' ,
'oc:permissions' ,
'd:resourcetype' ,
'oc:size' ,
'd:getlastmodified' ,
'oc:tags' ,
'oc:favorite' ,
'oc:share-types' ,
'oc:privatelink' ,
'd:getcontenttype' ,
'd:lockdiscovery' ,
2025-06-19 10:46:56 +05:45
'd:activelock' ,
2024-03-12 15:35:53 +05:45
];
2024-10-01 12:58:30 +05:45
$davPathVersion = $this -> featureContext -> getDavPathVersion ();
if ( $spaceName === 'Shares' && $davPathVersion !== WebDavHelper :: DAV_VERSION_SPACES ) {
2024-10-02 12:35:19 +05:45
// for old/new dav paths, append the Shares space path
2024-10-01 12:58:30 +05:45
if ( $resource === '' || $resource === '/' ) {
$resource = $spaceName ;
} else {
2024-10-01 18:07:47 +05:45
$resource = " $spaceName / $resource " ;
2024-10-01 12:58:30 +05:45
}
}
2024-12-24 09:30:42 +05:45
return WebDavHelper :: propfind (
2023-11-29 11:25:01 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
$resource ,
$properties ,
2024-03-12 15:35:53 +05:45
$folderDepth ,
2024-09-18 11:26:20 +05:45
$spaceId ,
2023-11-29 11:25:01 +05:45
"files" ,
2024-10-01 12:58:30 +05:45
$davPathVersion ,
2024-03-12 15:35:53 +05:45
null ,
2025-06-19 15:34:02 +05:45
$headers ,
2022-11-28 14:27:41 +05:45
);
}
/**
2024-10-02 12:35:19 +05:45
* @Then /^as user "([^"]*)" the (?:PROPFIND|REPORT) response should contain a (resource|space) "([^"]*)" with these key and value pairs:$/
2022-12-21 11:19:44 +05:45
*
* @param string $user
2024-10-01 18:07:47 +05:45
* @param string $type # type should be either resource or space
* @param string $resource
2022-12-21 11:19:44 +05:45
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
2024-12-24 09:30:42 +05:45
public function asUsertheXMLResponseShouldContainMountpointWithTheseKeyAndValuePair (
string $user ,
string $type ,
string $resource ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2022-10-25 13:48:01 +02:00
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'key' , 'value' ]);
2024-10-01 12:58:30 +05:45
if ( $this -> featureContext -> getDavPathVersion () === WebDavHelper :: DAV_VERSION_SPACES && $type === 'space' ) {
2024-10-01 18:07:47 +05:45
$space = $this -> getSpaceByName ( $user , $resource );
$resource = $space [ 'id' ];
2024-10-02 12:35:19 +05:45
} elseif ( \preg_match ( GraphHelper :: jsonSchemaRegexToPureRegex ( GraphHelper :: getFileIdRegex ()), $resource )) {
// When using file-id, some characters need to be encoded
$resource = \str_replace ( "!" , "%21" , $resource );
2024-10-01 12:58:30 +05:45
} else {
2024-10-02 14:51:20 +05:45
$encodedPaths = \array_map ( fn ( $path ) => \rawurlencode ( $path ), \explode ( "/" , $resource ));
$resource = \join ( "/" , $encodedPaths );
2024-10-01 12:58:30 +05:45
}
2024-10-02 12:35:19 +05:45
$this -> theXMLResponseShouldContain ( $resource , $table -> getHash ());
2022-12-21 11:19:44 +05:45
}
/**
2024-10-04 16:35:55 +05:45
* @param SimpleXMLElement $responseXmlObject
* @param array $xpaths
* @param string $message
*
* @return string
*/
2024-12-24 09:30:42 +05:45
public function buildXpathErrorMessage (
SimpleXMLElement $responseXmlObject ,
array $xpaths ,
2025-06-19 15:34:02 +05:45
string $message ,
2024-12-24 09:30:42 +05:45
) : string {
2024-10-04 16:35:55 +05:45
return "Using xpaths: \n\t - " . \join ( " \n\t - " , $xpaths )
. " \n "
. $message
. " \n\t "
. "'" . \trim ( $responseXmlObject -> asXML ()) . "'" ;
}
/**
* @param SimpleXMLElement $responseXmlObject
* @param string $siblingXpath
* @param string $siblingToFind
*
* @return string
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function getXpathSiblingValue (
SimpleXMLElement $responseXmlObject ,
string $siblingXpath ,
2025-06-19 15:34:02 +05:45
string $siblingToFind ,
2024-12-24 09:30:42 +05:45
) : string {
2024-10-04 16:35:55 +05:45
$xpaths [] = $siblingXpath . "/preceding-sibling:: $siblingToFind " ;
$xpaths [] = $siblingXpath . "/following-sibling:: $siblingToFind " ;
foreach ( $xpaths as $key => $xpath ) {
$foundSibling = $responseXmlObject -> xpath ( $xpath );
if ( \count ( $foundSibling )) {
break ;
}
}
2024-12-24 09:30:42 +05:45
$errorMessage = $this -> buildXpathErrorMessage (
$responseXmlObject ,
$xpaths ,
2025-06-19 15:34:02 +05:45
"Could not find sibling '< $siblingToFind >' element in the XML response" ,
2024-12-24 09:30:42 +05:45
);
2024-10-04 16:35:55 +05:45
Assert :: assertNotEmpty ( $foundSibling , $errorMessage );
return \preg_quote ( $foundSibling [ 0 ] -> __toString (), "/" );
}
/**
* @param string $resource // can be resource name, space id or file id
* @param array $properties // ["key" => "value"]
2022-12-21 11:19:44 +05:45
*
* @return void
* @throws GuzzleException
2024-10-04 16:35:55 +05:45
* @throws Exception
2022-12-21 11:19:44 +05:45
*/
2024-10-02 12:35:19 +05:45
public function theXMLResponseShouldContain ( string $resource , array $properties ) : void {
2024-11-29 13:19:54 +05:45
$responseXmlObject = HttpRequestHelper :: getResponseXml ( $this -> featureContext -> getResponse (), __METHOD__ );
$hrefs = array_map ( fn ( $href ) => $href -> __toString (), $responseXmlObject -> xpath ( "//d:response/d:href" ));
2024-10-01 12:58:30 +05:45
$currentHref = '' ;
foreach ( $hrefs as $href ) {
2024-10-01 18:07:47 +05:45
if ( \str_ends_with ( \rtrim ( $href , "/" ), "/ $resource " )) {
2024-10-01 12:58:30 +05:45
$currentHref = $href ;
break ;
}
}
2024-10-02 12:35:19 +05:45
foreach ( $properties as $property ) {
$itemToFind = $property [ 'key' ];
// if href is not found, build xpath using oc:name
$xpaths = [];
if ( ! $currentHref ) {
$decodedResource = \urldecode ( $resource );
if ( $property [ 'key' ] === 'oc:name' ) {
$xpath = "//oc:name[text()=' $decodedResource ']" ;
} elseif ( \array_key_exists ( 'oc:shareroot' , $properties )) {
2024-12-24 09:30:42 +05:45
$xpaths [] = "//oc:name[text()=' $resource ']/preceding-sibling::oc:shareroot[text()='"
. $properties [ 'oc:shareroot' ] . "'/preceding-sibling::/" ;
$xpaths [] = "//oc:name[text()=' $resource ']/preceding-sibling::oc:shareroot[text()='"
. $properties [ 'oc:shareroot' ] . "'/following-sibling::/" ;
$xpaths [] = "//oc:name[text()=' $resource ']/following-sibling::oc:shareroot[text()='"
. $properties [ 'oc:shareroot' ] . "'/preceding-sibling::/" ;
$xpaths [] = "//oc:name[text()=' $resource ']/following-sibling::oc:shareroot[text()='"
. $properties [ 'oc:shareroot' ] . "'/following-sibling::/" ;
2024-10-02 12:35:19 +05:45
} else {
$xpaths [] = "//oc:name[text()=' $decodedResource ']/preceding-sibling::" ;
$xpaths [] = "//oc:name[text()=' $decodedResource ']/following-sibling::" ;
}
} else {
$xpath = "//d:href[text()=' $currentHref ']/following-sibling::d:propstat// $itemToFind " ;
}
if ( \count ( $xpaths )) {
// check every xpath
foreach ( $xpaths as $key => $path ) {
$xpath = " { $path }{ $itemToFind } " ;
2024-11-29 13:19:54 +05:45
$foundXmlItem = $responseXmlObject -> xpath ( $xpath );
2024-10-02 12:35:19 +05:45
$xpaths [ $key ] = $xpath ;
if ( \count ( $foundXmlItem )) {
break ;
}
}
} else {
2024-11-29 13:19:54 +05:45
$foundXmlItem = $responseXmlObject -> xpath ( $xpath );
2024-10-02 12:35:19 +05:45
$xpaths [] = $xpath ;
}
2024-10-04 16:35:55 +05:45
Assert :: assertCount (
1 ,
$foundXmlItem ,
2024-12-24 09:30:42 +05:45
$this -> buildXpathErrorMessage (
$responseXmlObject ,
$xpaths ,
2025-06-19 15:34:02 +05:45
"Found multiple elements for '< $itemToFind >' in the XML response" ,
),
2024-10-04 16:35:55 +05:45
);
2023-09-01 16:42:35 +05:45
Assert :: assertNotEmpty (
2024-10-01 12:58:30 +05:45
$foundXmlItem ,
2024-12-24 09:30:42 +05:45
$this -> buildXpathErrorMessage (
$responseXmlObject ,
$xpaths ,
2025-06-19 15:34:02 +05:45
"Could not find '< $itemToFind >' element in the XML response" ,
),
2023-09-01 16:42:35 +05:45
);
2024-03-12 15:35:53 +05:45
2024-10-01 12:58:30 +05:45
$actualValue = $foundXmlItem [ 0 ] -> __toString ();
2024-10-04 16:35:55 +05:45
$expectedValue = $property [ 'value' ];
\preg_match_all ( "/%self::[a-z0-9-:]+?%/" , $expectedValue , $selfMatches );
$substituteFunctions = [];
if ( ! empty ( $selfMatches [ 0 ])) {
$siblingXpath = $xpaths [ \count ( $xpaths ) - 1 ];
foreach ( $selfMatches [ 0 ] as $match ) {
$siblingToFind = \ltrim ( $match , "/%self::/" );
$siblingToFind = \rtrim ( $siblingToFind , "/%/" );
$substituteFunctions [] = [
"code" => $match ,
"function" =>
[ $this , "getXpathSiblingValue" ],
2025-06-19 10:46:56 +05:45
"parameter" => [ $responseXmlObject , $siblingXpath , $siblingToFind ],
2024-10-04 16:35:55 +05:45
];
}
}
$expectedValue = $this -> featureContext -> substituteInLineCodes (
$property [ 'value' ],
null ,
[],
$substituteFunctions ,
);
2024-03-12 15:35:53 +05:45
2024-10-01 12:58:30 +05:45
switch ( $itemToFind ) {
2022-10-25 13:48:01 +02:00
case "oc:fileid" :
2024-10-01 18:07:47 +05:45
$expectedValue = GraphHelper :: jsonSchemaRegexToPureRegex ( $expectedValue );
2024-12-24 09:30:42 +05:45
Assert :: assertMatchesRegularExpression (
$expectedValue ,
$actualValue ,
2025-06-19 15:34:02 +05:45
'wrong "fileid" in the response' ,
2024-12-24 09:30:42 +05:45
);
2022-10-25 13:48:01 +02:00
break ;
case "oc:file-parent" :
2024-10-01 18:07:47 +05:45
$expectedValue = GraphHelper :: jsonSchemaRegexToPureRegex ( $expectedValue );
2024-12-24 09:30:42 +05:45
Assert :: assertMatchesRegularExpression (
$expectedValue ,
$actualValue ,
2025-06-19 15:34:02 +05:45
'wrong "file-parent" in the response' ,
2024-12-24 09:30:42 +05:45
);
2022-10-25 13:48:01 +02:00
break ;
2022-11-28 14:27:41 +05:45
case "oc:privatelink" :
2024-10-01 18:07:47 +05:45
$expectedValue = GraphHelper :: jsonSchemaRegexToPureRegex ( $expectedValue );
2024-12-24 09:30:42 +05:45
Assert :: assertMatchesRegularExpression (
$expectedValue ,
$actualValue ,
2025-06-19 15:34:02 +05:45
'wrong "privatelink" in the response' ,
2024-12-24 09:30:42 +05:45
);
2022-11-28 14:27:41 +05:45
break ;
2023-06-08 11:21:28 +05:45
case "oc:tags" :
// The value should be a comma-separated string of tag names.
// We do not care what order they happen to be in, so compare as sorted lists.
2024-10-01 12:58:30 +05:45
$expectedTags = \explode ( "," , $expectedValue );
2024-03-12 15:35:53 +05:45
\sort ( $expectedTags );
$expectedTags = \implode ( "," , $expectedTags );
2024-10-01 12:58:30 +05:45
$actualTags = \explode ( "," , $actualValue );
\sort ( $actualTags );
2024-10-01 18:07:47 +05:45
$actualTags = \implode ( "," , $actualTags );
2024-10-01 12:58:30 +05:45
Assert :: assertEquals ( $expectedTags , $actualTags , "wrong ' $itemToFind ' in the response" );
2023-06-08 11:21:28 +05:45
break ;
2023-10-27 14:45:15 +02:00
case "d:lockdiscovery/d:activelock/d:timeout" :
2024-10-01 12:58:30 +05:45
if ( $expectedValue === "Infinity" ) {
Assert :: assertEquals ( $expectedValue , $actualValue , "wrong ' $itemToFind ' in the response" );
2023-10-27 14:45:15 +02:00
} else {
// some time may be required between a lock and propfind request.
2024-10-01 12:58:30 +05:45
$responseValue = explode ( '-' , $actualValue );
2023-10-27 14:45:15 +02:00
$responseValue = \intval ( $responseValue [ 1 ]);
2024-10-01 12:58:30 +05:45
$expectedValue = explode ( '-' , $expectedValue );
$expectedValue = \intval ( $expectedValue [ 1 ]);
Assert :: assertTrue ( $responseValue >= ( $expectedValue - 3 ));
2023-10-27 14:45:15 +02:00
}
break ;
2024-07-09 17:06:32 +05:45
case "oc:remote-item-id" :
2024-10-01 18:07:47 +05:45
$expectedValue = GraphHelper :: jsonSchemaRegexToPureRegex ( $expectedValue );
2024-12-24 09:30:42 +05:45
Assert :: assertMatchesRegularExpression (
$expectedValue ,
$actualValue ,
2025-06-19 15:34:02 +05:45
'wrong "remote-item-id" in the response' ,
2024-12-24 09:30:42 +05:45
);
2024-07-09 17:06:32 +05:45
break ;
2026-07-02 17:17:32 +05:45
case "oc:spaceid" :
$expectedValue = GraphHelper :: jsonSchemaRegexToPureRegex ( $expectedValue );
Assert :: assertMatchesRegularExpression (
$expectedValue ,
$actualValue ,
'wrong "spaceid" in the response' ,
);
break ;
2022-10-25 13:48:01 +02:00
default :
2024-10-01 12:58:30 +05:45
Assert :: assertEquals ( $expectedValue , $actualValue , "wrong ' $itemToFind ' in the response" );
2022-10-25 13:48:01 +02:00
break ;
}
}
2022-10-17 13:46:07 +02:00
}
2022-12-15 14:20:04 +05:45
2024-04-05 09:06:04 +05:45
/**
* @Then as user :user the key :key from PROPFIND response should match with shared-with-me drive-item-id of share :resource
*
* @param string $user
* @param string $key
* @param string $resource
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function asUserTheKeyFromPropfindResponseShouldMatchWithSharedwithmeDriveitemidOfShare (
string $user ,
string $key ,
2025-06-19 15:34:02 +05:45
string $resource ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-29 13:19:54 +05:45
$responseXmlObject = HttpRequestHelper :: getResponseXml ( $this -> featureContext -> getResponse (), __METHOD__ );
$fileId = $responseXmlObject -> xpath ( "//oc:name[text()=' $resource ']/preceding-sibling:: $key " )[ 0 ] -> __toString ();
2024-04-05 09:06:04 +05:45
$jsonResponse = GraphHelper :: getSharesSharedWithMe (
$this -> featureContext -> getBaseUrl (),
$user ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
2024-04-05 09:06:04 +05:45
);
2024-04-26 15:27:00 +05:45
$driveItemId = '' ;
2024-04-05 09:06:04 +05:45
$jsonResponseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $jsonResponse );
foreach ( $jsonResponseBody -> value as $value ) {
if ( $value -> name === " $resource " ) {
$driveItemId = $value -> id ;
break ;
}
2025-06-19 10:58:37 +05:45
throw new Error ( "Response didn't contain a share $resource " );
2024-04-05 09:06:04 +05:45
}
Assert :: assertEquals ( $fileId , $driveItemId , "File-id ' $fileId ' doesn't match driveItemId ' $driveItemId '" );
}
2022-12-15 16:18:18 +05:45
/**
2022-12-19 15:46:51 +05:45
* @When /^public downloads the folder "([^"]*)" from the last created public link using the public files API$/
2022-12-15 16:18:18 +05:45
*
* @param string $resource
*
* @return void
2024-11-29 13:19:54 +05:45
* @throws GuzzleException
* @throws Exception
2022-12-15 16:18:18 +05:45
*/
2025-06-19 12:15:41 +05:45
public function publicDownloadsTheFolderFromTheLastCreatedPublicLink ( string $resource ) : void {
2024-12-24 09:30:42 +05:45
$token = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ()
: $this -> featureContext -> getLastCreatedPublicShareToken ();
2024-11-29 13:19:54 +05:45
$responseXmlObject = HttpRequestHelper :: getResponseXml (
$this -> featureContext -> listFolder (
$token ,
$resource ,
'0' ,
[ 'oc:fileid' ],
null ,
2025-06-19 15:34:02 +05:45
"public-files" ,
),
2022-12-19 15:46:51 +05:45
);
2024-11-29 13:19:54 +05:45
$resourceId = $responseXmlObject -> xpath ( "//d:response/d:propstat/d:prop/oc:fileid" );
2022-12-19 15:46:51 +05:45
$queryString = 'public-token=' . $token . '&id=' . $resourceId [ 0 ][ 0 ];
2022-12-15 16:18:18 +05:45
$this -> featureContext -> setResponse (
HttpRequestHelper :: get (
2024-09-17 17:11:20 +05:45
$this -> archiverContext -> getArchiverUrl ( $queryString ),
2022-12-15 16:18:18 +05:45
'' ,
2025-06-19 15:34:02 +05:45
'' ,
),
2022-12-15 16:18:18 +05:45
);
}
2023-02-07 16:55:26 +05:45
/**
* @Then the relative quota amount should be :quota_amount
*
* @param string $quotaAmount
*
* @return void
* @throws Exception
*/
public function theRelativeQuotaAmountShouldBe ( string $quotaAmount ) : void {
$data = $this -> ocsContext -> getOCSResponseData ( $this -> featureContext -> getResponse ());
if ( isset ( $data -> quota , $data -> quota -> relative )) {
Assert :: assertEquals (
$data -> quota -> relative ,
$quotaAmount ,
2025-06-19 15:34:02 +05:45
"Expected relative quota amount to be $quotaAmount but found to be $data->quota ->relative" ,
2023-02-07 16:55:26 +05:45
);
2024-11-29 13:19:54 +05:45
return ;
2023-02-07 16:55:26 +05:45
}
2024-11-29 13:19:54 +05:45
Assert :: fail ( "No relative quota amount found in response" );
2023-02-07 16:55:26 +05:45
}
2023-02-09 16:58:39 +01:00
/**
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" granted to (user|group)\s? "([^"]*)" with role "([^"]*)"$/
2023-02-17 09:18:53 +01:00
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" granted to (user|group)\s? "([^"]*)" with role "([^"]*)" and expiration date "([^"]*)"$/
2023-02-09 16:58:39 +01:00
*
* @param string $user
* @param string $spaceName
* @param string $recipientType
* @param string $recipient
* @param string $role
2023-05-02 17:25:56 +05:45
* @param string|null $expirationDate
2023-02-09 16:58:39 +01:00
*
* @return void
*
* @throws GuzzleException
*/
public function theUserShouldHaveSpaceWithRecipient (
string $user ,
string $spaceName ,
string $recipientType ,
string $recipient ,
2023-02-17 09:18:53 +01:00
string $role ,
2025-06-24 11:39:50 +02:00
? string $expirationDate = null ,
2023-02-09 16:58:39 +01:00
) : void {
2025-02-17 17:44:48 +05:45
$response = $this -> listAllMySpaces ( $user );
2023-02-09 16:58:39 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-17 11:41:47 +05:45
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2023-02-09 16:58:39 +01:00
);
2024-12-24 09:30:42 +05:45
Assert :: assertIsArray (
$spaceAsArray = $this -> getSpaceByNameFromResponse ( $spaceName , $response ),
2025-06-19 15:34:02 +05:45
"No space with name $spaceName found" ,
2024-12-24 09:30:42 +05:45
);
$recipientType === 'user' ?
$recipientId = $this -> featureContext -> getUserIdByUserName ( $recipient )
: $recipientId = $this -> featureContext -> getGroupIdByGroupName ( $recipient );
2023-02-10 16:30:07 +05:45
$foundRoleInResponse = false ;
2023-02-09 16:58:39 +01:00
foreach ( $spaceAsArray [ 'root' ][ 'permissions' ] as $permission ) {
2024-12-24 09:30:42 +05:45
if ( isset ( $permission [ 'grantedToIdentities' ][ 0 ][ $recipientType ])
&& $permission [ 'roles' ][ 0 ] === $role
&& $permission [ 'grantedToIdentities' ][ 0 ][ $recipientType ][ 'id' ] === $recipientId
) {
2023-02-10 16:30:07 +05:45
$foundRoleInResponse = true ;
2023-02-22 16:50:38 +05:45
if ( $expirationDate !== null && isset ( $permission [ 'expirationDateTime' ])) {
2026-10-01 16:37:56 +05:45
$expectedExpirationDate = ( new DateTimeImmutable ( $expirationDate ))
-> setTimezone ( $this -> featureContext -> getTestTimezone ())
-> format ( 'Y-m-d' );
$actualExpirationDate = ( new DateTimeImmutable ( $permission [ 'expirationDateTime' ]))
-> setTimezone ( $this -> featureContext -> getTestTimezone ())
-> format ( 'Y-m-d' );
2024-12-24 09:30:42 +05:45
Assert :: assertEquals (
2026-10-01 16:37:56 +05:45
$expectedExpirationDate ,
$actualExpirationDate ,
"Expiration date mismatch" ,
2024-12-24 09:30:42 +05:45
);
2023-02-17 09:18:53 +01:00
}
2023-02-10 16:30:07 +05:45
break ;
2023-02-09 16:58:39 +01:00
}
}
2023-02-10 16:30:07 +05:45
Assert :: assertTrue ( $foundRoleInResponse , "the response does not contain the $recipientType $recipient " );
2023-02-09 16:58:39 +01:00
}
2023-06-30 14:27:53 +05:45
/**
2023-07-24 16:12:22 +05:45
* @When user :user tries to download the space :spaceName owned by user :owner using the WebDAV API
* @When /^user "([^"]*)" (?:downloads|tries to download) the space "([^"]*)" using the WebDAV API$/
2023-06-30 14:27:53 +05:45
*
* @param string $user
* @param string $spaceName
2023-07-24 16:12:22 +05:45
* @param string $owner
2023-06-30 14:27:53 +05:45
*
* @return void
*
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userDownloadsTheSpaceUsingTheWebdavApi ( string $user , string $spaceName , string $owner = '' ) : void {
2023-07-24 16:12:22 +05:45
$space = $this -> getSpaceByName ( $owner ?: $user , $spaceName );
2024-09-17 17:11:20 +05:45
$url = $this -> archiverContext -> getArchiverUrl ( 'id=' . $space [ 'id' ]);
2023-06-30 14:27:53 +05:45
$this -> featureContext -> setResponse (
HttpRequestHelper :: get (
$url ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
),
2023-06-30 14:27:53 +05:45
);
}
2023-10-26 12:59:34 +05:45
/**
* @Given user :sharer has shared resource :path inside space :space with user :sharee
*
* @param $sharer string
* @param $path string
* @param $space string
* @param $sharee string
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userHasSharedResourceInsideSpaceWithUser (
string $sharer ,
string $path ,
string $space ,
2025-06-19 15:34:02 +05:45
string $sharee ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-26 12:59:34 +05:45
$sharer = $this -> featureContext -> getActualUsername ( $sharer );
$resource_id = $this -> getResourceId ( $sharer , $space , $path );
$response = $this -> featureContext -> createShare (
$sharer ,
$path ,
'0' ,
$this -> featureContext -> getActualUsername ( $sharee ),
null ,
null ,
null ,
null ,
null ,
2025-06-19 15:34:02 +05:45
$resource_id ,
2023-10-26 12:59:34 +05:45
);
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2024-05-09 13:01:41 +05:45
$responseStatusCode = $this -> ocsContext -> getOCSResponseStatusCode (
2025-06-19 15:34:02 +05:45
$response ,
2024-05-09 13:01:41 +05:45
);
$statusCodes = [ "100" , "200" ];
Assert :: assertContainsEquals (
$responseStatusCode ,
$statusCodes ,
2024-12-24 09:30:42 +05:45
"OCS status code is not any of the expected values "
2025-06-19 15:34:02 +05:45
. \implode ( "," , $statusCodes ) . " got " . $responseStatusCode ,
2024-05-09 13:01:41 +05:45
);
2023-10-26 12:59:34 +05:45
}
2024-07-16 12:51:47 +05:45
/**
* @When user :user gets the file :file from space :space using the Graph API
*
* @param string $user
* @param string $file
* @param string $space
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userGetsTheDriveItemInSpace ( string $user , string $file , string $space ) : void {
2024-07-16 12:51:47 +05:45
$spaceId = ( $this -> getSpaceByName ( $user , $space ))[ "id" ];
2024-07-16 12:51:47 +05:45
$itemId = '' ;
if ( $space === "Shares" ) {
$itemId = GraphHelper :: getShareMountId (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$file ,
2024-07-16 12:51:47 +05:45
);
} else {
$itemId = $this -> getFileId ( $user , $space , $file );
}
2024-07-16 12:51:47 +05:45
$url = $this -> featureContext -> getBaseUrl () . "/graph/v1.0/drives/ $spaceId /items/ $itemId " ;
// NOTE: extracting properties occurs asynchronously
// short wait is necessary before getting those properties
sleep ( 2 );
$this -> featureContext -> setResponse (
HttpRequestHelper :: get (
$url ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
),
2024-07-16 12:51:47 +05:45
);
}
2025-01-23 15:24:59 +05:45
/**
* @Given /^user "([^"]*)" has expired the membership of user "([^"]*)" from space "([^"]*)"$/
*
* @param string $user
* @param string $memberUser
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userHasExpiredTheMembershipOfUserFromSpace (
string $user ,
string $memberUser ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2025-01-23 15:24:59 +05:45
) : void {
$rows [ 'expireDate' ] = $this -> featureContext -> formatExpiryDateTime ( 'Y-m-d\\TH:i:sP' );
$rows [ 'shareWith' ] = $memberUser ;
$this -> featureContext -> setResponse ( $this -> shareSpace ( $user , $spaceName , $rows ));
}
2021-10-20 17:25:09 +02:00
}