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 ;
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 ;
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 ;
2021-10-20 17:25:09 +02:00
use TestHelpers\SetupHelper ;
2022-04-25 11:35:50 +02:00
use TestHelpers\GraphHelper ;
2021-10-20 17:25:09 +02:00
use PHPUnit\Framework\Assert ;
require_once 'bootstrap.php' ;
/**
* Context for ocis spaces specific steps
*/
class SpacesContext implements Context {
2021-11-11 12:15:15 +05:45
/**
* @var FeatureContext
*/
private FeatureContext $featureContext ;
2021-12-21 13:47:15 +05:45
/**
* @var OCSContext
*/
private OCSContext $ocsContext ;
2022-04-12 08:51:35 +02:00
/**
* @var TrashbinContext
*/
private TrashbinContext $trashbinContext ;
2022-08-09 14:00:02 +05:45
/**
* @var WebDavPropertiesContext
*/
private WebDavPropertiesContext $webDavPropertiesContext ;
2022-09-01 14:19:11 +05:45
/**
* @var FavoritesContext
*/
private FavoritesContext $favoritesContext ;
2022-09-08 13:00:48 +05:45
/**
* @var ChecksumContext
*/
private ChecksumContext $checksumContext ;
2023-02-22 09:21:57 +05:45
2022-09-14 13:38:15 +05:45
/**
* @var FilesVersionsContext
*/
private FilesVersionsContext $filesVersionsContext ;
2022-12-15 14:20:04 +05:45
2023-02-16 16:34:13 +01:00
/**
* @var GraphContext
*/
private GraphContext $graphContext ;
2021-12-22 09:49:44 +05:45
/**
* @var string
*/
private string $baseUrl ;
2021-11-11 12:19:54 +05:45
/**
* @var array key is space name and value is the username that created the space
*/
private array $createdSpaces ;
2022-03-27 21:36:13 +02:00
/**
* @var string
*/
2022-05-11 15:04:12 +05:45
private string $ocsApiUrl = '/ocs/v2.php/apps/files_sharing/api/v1/shares' ;
2022-03-27 21:36:13 +02:00
2022-05-11 09:13:59 +02:00
/**
* @var string
*/
2022-05-11 15:04:12 +05:45
private string $davSpacesUrl = '/remote.php/dav/spaces/' ;
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" => [
* ...
* ]
* ]
*/
private $storedEtags = [];
2021-11-11 12:19:54 +05:45
/**
* @param string $spaceName
*
* @return string name of the user that created the space
* @throws Exception
*/
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 ];
}
/**
* @param string $spaceName
* @param string $spaceCreator
*
* @return void
*/
public function setSpaceCreator ( string $spaceName , string $spaceCreator ) : void {
$this -> createdSpaces [ $spaceName ] = $spaceCreator ;
}
2022-08-23 10:42:27 +02:00
private array $availableSpaces = [];
2021-11-11 12:15:15 +05:45
2022-07-21 17:42:39 +02:00
private array $lastPublicLinkData = [];
2021-11-11 12:15:15 +05:45
/**
* @return array
*/
public function getAvailableSpaces () : array {
return $this -> availableSpaces ;
}
/**
* @param array $availableSpaces
*
* @return void
*/
public function setAvailableSpaces ( array $availableSpaces ) : void {
$this -> availableSpaces = $availableSpaces ;
}
/**
* response content parsed from XML to an array
*
* @var array
*/
private array $responseXml = [];
/**
* @return array
*/
public function getResponseXml () : array {
return $this -> responseXml ;
}
/**
* @param array $responseXml
*
* @return void
*/
public function setResponseXml ( array $responseXml ) : void {
$this -> responseXml = $responseXml ;
}
/**
* space id from last propfind request
*
* @var string
*/
private string $responseSpaceId ;
/**
* 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
*
* @return array
*
* @throws Exception
*/
public function getSpaceByNameFromResponse ( string $name ) : array {
2021-11-17 15:07:25 +05:45
$response = json_decode (( string ) $this -> featureContext -> getResponse () -> getBody (), true , 512 , JSON_THROW_ON_ERROR );
2021-11-11 12:15:15 +05:45
$spaceAsArray = $response ;
if ( isset ( $response [ 'name' ]) && $response [ 'name' ] === $name ) {
return $response ;
}
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
* The method finds available spaces to the user and returns the space by spaceName
2021-12-02 10:05:28 +01:00
*
2021-12-02 00:01:52 +01:00
* @param string $user
* @param string $spaceName
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
*/
2021-12-14 10:10:13 +05:45
public function getSpaceByName ( string $user , string $spaceName ) : array {
2022-07-14 16:59:36 +05:45
if ( $spaceName === "Personal" ) {
$spaceName = $this -> featureContext -> getUserDisplayName ( $user );
}
2022-08-04 13:11:51 +02:00
if ( strtolower ( $user ) === 'admin' ) {
$this -> theUserListsAllAvailableSpacesUsingTheGraphApi ( $user );
} else {
$this -> theUserListsAllHisAvailableSpacesUsingTheGraphApi ( $user );
}
2021-11-11 12:15:15 +05:45
$spaces = $this -> getAvailableSpaces ();
2021-12-14 10:10:13 +05:45
Assert :: assertIsArray ( $spaces [ $spaceName ], "Space with name $spaceName for user $user not found" );
Assert :: assertNotEmpty ( $spaces [ $spaceName ][ "root" ][ "webDavUrl" ], "WebDavUrl for space with name $spaceName for user $user not found" );
return $spaces [ $spaceName ];
2021-11-11 12:15:15 +05:45
}
2022-09-01 14:28:53 +05:45
/**
* This method sets space id by Space Name
* This is currently used to set space id from ocis in core so that we can reuse available resource (code) and avoid duplication
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function setSpaceIDByName ( string $user , string $spaceName ) : void {
$space = $this -> getSpaceByName ( $user , $spaceName );
2022-09-14 13:38:15 +05:45
Assert :: assertIsArray ( $space , "Space with name $spaceName not found" );
Assert :: assertNotEmpty ( $space [ "root" ][ "webDavUrl" ], "WebDavUrl for space with name $spaceName not found" );
2022-09-01 14:28:53 +05:45
WebDavHelper :: $SPACE_ID_FROM_OCIS = $space [ 'id' ];
}
2022-04-29 22:22:41 +02:00
/**
* The method finds available spaces to the manager user and returns the space by spaceName
*
* @param string $user
* @param string $spaceName
*
* @return array
2022-05-11 15:04:12 +05:45
* @throws GuzzleException
2022-04-29 22:22:41 +02:00
*/
public function getSpaceByNameManager ( string $user , string $spaceName ) : array {
$this -> theUserListsAllAvailableSpacesUsingTheGraphApi ( $user );
$spaces = $this -> getAvailableSpaces ();
2022-07-29 10:28:37 +05:45
Assert :: assertArrayHasKey ( $spaceName , $spaces , "Space with name ' $spaceName ' for user ' $user ' not found" );
Assert :: assertIsArray ( $spaces [ $spaceName ], "Data for space with name ' $spaceName ' for user ' $user ' not found" );
Assert :: assertNotEmpty ( $spaces [ $spaceName ][ "root" ][ "webDavUrl" ], "WebDavUrl for space with name ' $spaceName ' for user ' $user ' not found" );
2022-04-29 22:22:41 +02:00
return $spaces [ $spaceName ];
}
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
*
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
*/
2022-03-30 21:34:41 +02:00
public function getFileData ( string $user , string $spaceName , string $fileName ) : ResponseInterface {
2022-03-10 09:29:26 +01:00
$space = $this -> getSpaceByName ( $user , $spaceName );
2022-05-11 09:13:59 +02:00
$fullUrl = $this -> baseUrl . $this -> davSpacesUrl . $space [ "id" ] . "/" . $fileName ;
2022-03-30 21:34:41 +02:00
2022-12-05 22:27:51 +05:45
return HttpRequestHelper :: get (
$fullUrl ,
"" ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
[],
"{}"
2022-03-10 09:29:26 +01:00
);
}
/**
* The method returns fileId
*
* @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 getFileId ( string $user , string $spaceName , string $fileName ) : string {
2022-03-30 21:34:41 +02:00
$fileData = $this -> getFileData ( $user , $spaceName , $fileName ) -> 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
*
* @return string
* @throws GuzzleException
*/
2023-02-01 09:55:51 +01:00
public function getResourceId ( string $user , string $spaceName , string $folderName ) : string {
2022-10-17 13:46:07 +02:00
$space = $this -> getSpaceByName ( $user , $spaceName );
// For a level 1 folder, the parent is space so $folderName = ''
if ( $folderName === $space [ "name" ]) {
$folderName = '' ;
}
$fullUrl = $this -> baseUrl . $this -> davSpacesUrl . $space [ "id" ] . "/" . $folderName ;
2022-12-05 22:27:51 +05:45
$response = HttpRequestHelper :: sendRequest (
$fullUrl ,
$this -> featureContext -> getStepLineRef (),
'PROPFIND' ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
[ 'Depth' => '0' ],
2022-10-17 13:46:07 +02:00
);
2022-12-05 22:27:51 +05:45
$responseArray = json_decode ( json_encode ( $this -> featureContext -> getResponseXml ( $response ) -> xpath ( "//d:response/d:propstat/d:prop/oc:fileid" )), true , 512 , JSON_THROW_ON_ERROR );
2022-10-17 13:46:07 +02:00
Assert :: assertNotEmpty ( $responseArray , "the PROPFIND response for $folderName is empty" );
return $responseArray [ 0 ][ 0 ];
}
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 {
$this -> setSpaceIDByName ( $user , $spaceName );
$response = WebDavHelper :: propfind (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
"" ,
[ 'oc:privatelink' ],
"" ,
"0" ,
"files" ,
WebDavHelper :: DAV_VERSION_SPACES
);
$responseArray = json_decode ( json_encode ( $this -> featureContext -> getResponseXml ( $response ) -> xpath ( "//d:response/d:propstat/d:prop/oc:privatelink" )), true , 512 , JSON_THROW_ON_ERROR );
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 ();
2022-03-10 09:29:26 +01:00
return $fileData [ "Etag" ][ 0 ];
}
2022-08-18 11:23:57 +02:00
/**
* using method from core to set share data
2022-08-23 10:42:27 +02:00
*
2022-08-18 11:23:57 +02:00
* @return void
*/
public function setLastShareData () : void {
// set last response as PublicShareData
$this -> featureContext -> setLastPublicShareData ( $this -> featureContext -> getResponseXml ( null , __METHOD__ ));
// set last shareId if ShareData exists
if ( isset ( $this -> featureContext -> getLastPublicShareData () -> data )) {
$this -> featureContext -> setLastPublicLinkShareId (( string ) $this -> featureContext -> getLastPublicShareData () -> data [ 0 ] -> id );
}
}
2021-11-11 12:15:15 +05:45
/**
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
*
* @throws Exception
*/
public function setUpScenario ( BeforeScenarioScope $scope ) : void {
// Get the environment
$environment = $scope -> getEnvironment ();
// Get all the contexts you need in this context
$this -> featureContext = $environment -> getContext ( 'FeatureContext' );
2021-12-21 13:47:15 +05:45
$this -> ocsContext = $environment -> getContext ( 'OCSContext' );
2022-04-12 08:51:35 +02:00
$this -> trashbinContext = $environment -> getContext ( 'TrashbinContext' );
2022-08-09 14:00:02 +05:45
$this -> webDavPropertiesContext = $environment -> getContext ( 'WebDavPropertiesContext' );
2022-09-01 14:19:11 +05:45
$this -> favoritesContext = $environment -> getContext ( 'FavoritesContext' );
2022-09-08 13:00:48 +05:45
$this -> checksumContext = $environment -> getContext ( 'ChecksumContext' );
2022-09-14 13:38:15 +05:45
$this -> filesVersionsContext = $environment -> getContext ( 'FilesVersionsContext' );
2023-02-16 16:34:13 +01:00
$this -> graphContext = $environment -> getContext ( 'GraphContext' );
2021-12-21 13:47:15 +05:45
// Run the BeforeScenario function in OCSContext to set it up correctly
$this -> ocsContext -> before ( $scope );
2021-12-22 09:49:44 +05:45
$this -> baseUrl = \trim ( $this -> featureContext -> getBaseUrl (), "/" );
2021-11-11 12:15:15 +05:45
SetupHelper :: init (
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword (),
2021-12-22 09:49:44 +05:45
$this -> baseUrl ,
2021-11-11 12:15:15 +05:45
$this -> featureContext -> getOcPath ()
);
}
2022-08-04 13:11:51 +02:00
/**
* @AfterScenario
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function cleanDataAfterTests () : void {
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 {
$query = " \$ filter=driveType eq project" ;
2022-08-04 13:11:51 +02:00
$userAdmin = $this -> featureContext -> getAdminUsername ();
2022-08-23 13:48:30 +02:00
$this -> theUserListsAllAvailableSpacesUsingTheGraphApi (
$userAdmin ,
$query
);
$drives = $this -> getAvailableSpaces ();
foreach ( $drives as $value ) {
2022-09-07 16:52:26 +02:00
if ( ! \array_key_exists ( "deleted" , $value [ "root" ])) {
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 ),
$value [ "id" ]
2022-12-05 22:27:51 +05:45
);
}
GraphHelper :: deleteSpace (
$this -> featureContext -> getBaseUrl (),
$userAdmin ,
$this -> featureContext -> getPasswordForUser ( $userAdmin ),
$value [ "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 string $xRequestId
* @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 ,
string $xRequestId = '' ,
array $headers = []
) : ResponseInterface {
return HttpRequestHelper :: post ( $fullUrl , $xRequestId , $user , $password , $headers , $body );
}
/**
* Send Graph Create Folder Request
*
* @param string $fullUrl
* @param string $method
* @param string $user
* @param string $password
* @param string $xRequestId
* @param array $headers
*
* @return ResponseInterface
*
* @throws GuzzleException
*/
public function sendCreateFolderRequest (
string $fullUrl ,
string $method ,
string $user ,
string $password ,
string $xRequestId = '' ,
array $headers = []
) : ResponseInterface {
return HttpRequestHelper :: sendRequest ( $fullUrl , $xRequestId , $method , $user , $password , $headers );
}
2021-11-11 12:15:15 +05:45
/**
* @When /^user "([^"]*)" lists all available spaces via the GraphApi$/
2022-07-08 05:18:40 +02:00
* @When /^user "([^"]*)" lists all available spaces via the GraphApi 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 {
2021-11-11 12:15:15 +05:45
$this -> featureContext -> setResponse (
2022-08-31 15:11:31 +02:00
GraphHelper :: getMySpaces (
$this -> featureContext -> getBaseUrl (),
2021-11-11 12:15:15 +05:45
$user ,
2022-07-08 05:18:40 +02:00
$this -> featureContext -> getPasswordForUser ( $user ),
"?" . $query
2021-11-11 12:15:15 +05:45
)
);
$this -> rememberTheAvailableSpaces ();
}
2022-04-29 22:22:41 +02:00
/**
2023-02-06 23:48:30 +01:00
* The method is used on the administration setting tab, which only the Admin user and the Space admin user have access to
*
* @When /^user "([^"]*)" lists all spaces via the GraphApi$/
* @When /^user "([^"]*)" lists all spaces via the GraphApi with query "([^"]*)"$/
* @When /^user "([^"]*)" tries to list all spaces via the GraphApi$/
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 {
2023-02-06 23:48:30 +01:00
$this -> featureContext -> setResponse (
GraphHelper :: getAllSpaces (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
"?" . $query
)
2022-04-29 22:22:41 +02:00
);
2023-02-06 23:48:30 +01:00
$this -> rememberTheAvailableSpaces ();
2022-04-29 22:22:41 +02:00
}
2022-01-18 16:42:30 +01:00
/**
* @When /^user "([^"]*)" looks up the single space "([^"]*)" via the GraphApi 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
*/
2023-02-22 10:09:19 +01:00
public function theUserLooksUpTheSingleSpaceUsingTheGraphApiByUsingItsId ( string $user , string $spaceName , string $ownerUser = '' ) : void {
$space = $this -> getSpaceByName (( $ownerUser !== "" ) ? $ownerUser : $user , $spaceName );
2022-01-18 16:42:30 +01:00
Assert :: assertIsArray ( $space );
Assert :: assertNotEmpty ( $spaceId = $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-02-22 10:09:19 +01:00
$space [ "id" ]
2022-01-18 16:42:30 +01:00
)
);
}
2021-11-11 12:15:15 +05:45
/**
* @When /^user "([^"]*)" creates a space "([^"]*)" of type "([^"]*)" with the default quota using the GraphApi$/
*
* @param string $user
* @param string $spaceName
* @param string $spaceType
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserCreatesASpaceUsingTheGraphApi (
string $user ,
string $spaceName ,
string $spaceType
) : void {
$space = [ "Name" => $spaceName , "driveType" => $spaceType ];
$body = json_encode ( $space , JSON_THROW_ON_ERROR );
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
GraphHelper :: createSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body
)
);
2022-08-31 09:57:44 +02:00
2021-11-11 12:19:54 +05:45
$this -> setSpaceCreator ( $spaceName , $user );
2021-11-11 12:15:15 +05:45
}
/**
* @When /^user "([^"]*)" creates a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)" using the GraphApi$/
*
* @param string $user
* @param string $spaceName
* @param string $spaceType
* @param int $quota
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserCreatesASpaceWithQuotaUsingTheGraphApi (
string $user ,
string $spaceName ,
string $spaceType ,
int $quota
) : void {
$space = [ "Name" => $spaceName , "driveType" => $spaceType , "quota" => [ "total" => $quota ]];
$body = json_encode ( $space );
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
GraphHelper :: createSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body
)
);
2021-11-11 12:19:54 +05:45
$this -> setSpaceCreator ( $spaceName , $user );
2021-11-11 12:15:15 +05:45
}
/**
* Remember the available Spaces
*
2022-12-05 22:27:51 +05:45
* @param ResponseInterface|null $response
*
2021-11-11 12:15:15 +05:45
* @return void
*
* @throws Exception
*/
2022-12-05 22:27:51 +05:45
public function rememberTheAvailableSpaces ( ? ResponseInterface $response = null ) : void {
if ( $response ) {
$rawBody = $response -> getBody () -> getContents ();
} else {
$rawBody = $this -> featureContext -> getResponse () -> getBody () -> getContents ();
}
2021-11-11 12:15:15 +05:45
$drives = json_decode ( $rawBody , true , 512 , JSON_THROW_ON_ERROR );
if ( isset ( $drives [ "value" ])) {
$drives = $drives [ "value" ];
}
$spaces = [];
foreach ( $drives as $drive ) {
$spaces [ $drive [ "name" ]] = $drive ;
}
$this -> setAvailableSpaces ( $spaces );
}
/**
* @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 ,
string $foldersPath = ''
2021-11-11 12:15:15 +05:45
) : void {
2022-09-14 13:38:15 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
2021-11-11 12:15:15 +05:45
$this -> featureContext -> setResponse (
2022-09-14 13:38:15 +05:45
WebDavHelper :: propfind (
$this -> featureContext -> getBaseUrl (),
2021-11-11 12:15:15 +05:45
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2022-09-14 13:38:15 +05:45
$foldersPath ,
[],
2022-07-21 17:42:39 +02:00
'' ,
2022-09-14 13:38:15 +05:45
'infinity' ,
'files' ,
WebDavHelper :: DAV_VERSION_SPACES
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
*/
public function userSendsPatchRequestToTheSpaceOfUserWithData ( string $user , string $spaceName , string $owner , string $data ) : void {
$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 ,
$data
)
);
}
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 ,
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 ,
);
2022-09-14 13:38:15 +05:45
WebDavHelper :: $SPACE_ID_FROM_OCIS = '' ;
2021-11-11 12:15:15 +05:45
}
2021-11-11 12:19:54 +05:45
/**
* @Then /^the space "([^"]*)" should (not|)\s?contain these (?:files|entries):$/
*
* @param string $spaceName
* @param string $shouldOrNot (not|)
* @param TableNode $expectedFiles
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function theSpaceShouldContainEntries (
string $spaceName ,
string $shouldOrNot ,
TableNode $expectedFiles
2021-12-21 13:47:15 +05:45
) : void {
2022-09-14 13:38:15 +05:45
$spaceCreator = $this -> getSpaceCreator ( $spaceName );
$space = $this -> getSpaceByName ( $spaceCreator , $spaceName );
2021-11-11 12:19:54 +05:45
$this -> theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi (
2022-09-14 13:38:15 +05:45
$spaceCreator ,
2021-11-11 12:19:54 +05:45
$spaceName
);
2022-09-14 13:38:15 +05:45
WebDavHelper :: $SPACE_ID_FROM_OCIS = $space [ 'id' ];
$this -> featureContext -> propfindResultShouldContainEntries (
2021-11-11 12:19:54 +05:45
$shouldOrNot ,
$expectedFiles ,
);
2022-09-14 13:38:15 +05:45
WebDavHelper :: $SPACE_ID_FROM_OCIS = '' ;
2021-11-11 12:19:54 +05:45
}
2021-11-12 10:41:31 +05:45
/**
* @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain these (?:files|entries):$/
*
* @param string $user
* @param string $spaceName
* @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 ,
string $shouldOrNot ,
TableNode $expectedFiles
2021-12-21 13:47:15 +05:45
) : void {
2022-09-14 13:38:15 +05:45
$space = $this -> getSpaceByName ( $user , $spaceName );
2021-11-12 10:41:31 +05:45
$this -> theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi (
$user ,
$spaceName
);
2022-09-14 13:38:15 +05:45
WebDavHelper :: $SPACE_ID_FROM_OCIS = $space [ 'id' ];
$this -> featureContext -> propfindResultShouldContainEntries ( $shouldOrNot , $expectedFiles , $user , 'PROPFIND' );
WebDavHelper :: $SPACE_ID_FROM_OCIS = '' ;
2022-01-25 14:59:15 +01:00
}
/**
* @Then /^for user "([^"]*)" folder "([^"]*)" of the space "([^"]*)" should (not|)\s?contain these (?:files|entries):$/
*
* @param string $user
* @param string $folderPath
* @param string $spaceName
* @param string $shouldOrNot (not|)
* @param TableNode $expectedFiles
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function folderOfTheSpaceShouldContainEntries (
string $user ,
string $folderPath ,
string $spaceName ,
string $shouldOrNot ,
TableNode $expectedFiles
) : void {
2022-09-14 13:38:15 +05:45
$space = $this -> getSpaceByName ( $user , $spaceName );
2022-01-25 14:59:15 +01:00
$this -> theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi (
$user ,
$spaceName ,
$folderPath
);
2022-09-14 13:38:15 +05:45
WebDavHelper :: $SPACE_ID_FROM_OCIS = $space [ 'id' ];
$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' ,
2022-01-25 14:59:15 +01:00
$folderPath
2021-11-12 10:41:31 +05:45
);
2022-09-14 13:38:15 +05:45
WebDavHelper :: $SPACE_ID_FROM_OCIS = '' ;
2021-11-12 10:41:31 +05:45
}
2022-03-30 21:34:41 +02:00
/**
* @Then /^for user "([^"]*)" the content of the file "([^"]*)" of the space "([^"]*)" should be "([^"]*)"$/
*
* @param string $user
* @param string $file
* @param string $spaceName
* @param string $fileContent
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function checkFileContent (
string $user ,
string $file ,
string $spaceName ,
string $fileContent
) : void {
$actualFileContent = $this -> getFileData ( $user , $spaceName , $file ) -> getBody () -> getContents ();
Assert :: assertEquals ( $fileContent , $actualFileContent , " $file does not contain $fileContent " );
}
2021-11-11 12:15:15 +05:45
/**
2022-03-10 09:29:26 +01:00
* @Then /^the json responded should contain a space "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )(?:|(?:with description file|with space image) "([^"]*)" )with these key and value pairs:$/
2022-09-06 12:32:56 +05:45
*
2021-11-11 12:15:15 +05:45
* @param string $spaceName
2022-09-06 15:58:42 +05:45
* @param string|null $userName
* @param string|null $fileName
2023-02-07 11:53:14 +01:00
* @param string|null $groupName
2021-11-11 12:15:15 +05:45
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function jsonRespondedShouldContain (
string $spaceName ,
2022-09-06 15:58:42 +05:45
? string $userName = null ,
? string $fileName = null ,
2023-02-07 11:53:14 +01:00
? string $groupName = null ,
2021-11-11 12:15:15 +05:45
TableNode $table
) : void {
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'key' , 'value' ]);
Assert :: assertIsArray ( $spaceAsArray = $this -> getSpaceByNameFromResponse ( $spaceName ), "No space with name $spaceName found" );
foreach ( $table -> getHash () as $row ) {
// remember the original Space Array
$original = $spaceAsArray ;
$row [ 'value' ] = $this -> featureContext -> substituteInLineCodes (
$row [ 'value' ],
$this -> featureContext -> getCurrentUser (),
[],
[
[
"code" => "%space_id%" ,
"function" =>
2022-03-30 21:34:41 +02:00
[ $this , "getSpaceIdByNameFromResponse" ],
2021-11-11 12:15:15 +05:45
"parameter" => [ $spaceName ]
2022-02-10 20:21:22 +01:00
],
2022-03-10 09:29:26 +01:00
[
"code" => "%file_id%" ,
"function" =>
2022-03-30 21:34:41 +02:00
[ $this , "getFileId" ],
2022-03-10 09:29:26 +01:00
"parameter" => [ $userName , $spaceName , $fileName ]
],
[
"code" => "%eTag%" ,
"function" =>
2022-03-30 21:34:41 +02:00
[ $this , "getETag" ],
2022-03-10 09:29:26 +01:00
"parameter" => [ $userName , $spaceName , $fileName ]
2023-02-07 11:53:14 +01:00
]
2023-02-16 16:34:13 +01:00
],
$groupName ,
$userName
2021-11-11 12:15:15 +05:45
);
$segments = explode ( "@@@" , $row [ "key" ]);
// traverse down in the array
foreach ( $segments as $segment ) {
$arrayKeyExists = \array_key_exists ( $segment , $spaceAsArray );
$key = $row [ "key" ];
Assert :: assertTrue ( $arrayKeyExists , "The key $key does not exist on the response" );
if ( $arrayKeyExists ) {
$spaceAsArray = $spaceAsArray [ $segment ];
}
}
Assert :: assertEquals ( $row [ "value" ], $spaceAsArray );
// set the spaceArray to the point before traversing
$spaceAsArray = $original ;
}
}
2022-02-17 11:21:07 +01:00
/**
2022-07-08 05:18:40 +02:00
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" with these key and value pairs:$/
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" (?:owned by|granted to) "([^"]*)" with these key and value pairs:$/
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" (?:with description file|with space image) "([^"]*)" with these key and value pairs:$/
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" (?:owned by|granted to) "([^"]*)" (?:with description file|with space image) "([^"]*)" with these key and value pairs:$/
2022-02-17 11:21:07 +01:00
*
2022-07-08 05:18:40 +02:00
* @param string $user
2022-02-17 11:21:07 +01:00
* @param string $spaceName
2022-09-06 15:58:42 +05:45
* @param string|null $grantedUser
* @param string|null $fileName
2022-07-08 05:18:40 +02:00
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function userHasSpaceWith (
string $user ,
string $spaceName ,
2022-09-06 15:58:42 +05:45
? string $grantedUser = null ,
? string $fileName = null ,
2022-07-08 05:18:40 +02:00
TableNode $table
) : void {
$this -> theUserListsAllHisAvailableSpacesUsingTheGraphApi ( $user );
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200"
);
2023-02-07 11:53:14 +01:00
$this -> jsonRespondedShouldContain ( $spaceName , $grantedUser , $fileName , null , $table );
}
/**
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" granted to group "([^"]*)" with these key and value pairs:$/
*
* @param string $user
* @param string $spaceName
* @param string $grantedGroup
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function userHasSpaceGrantedToGroup (
string $user ,
string $spaceName ,
string $grantedGroup ,
TableNode $table
) : void {
$this -> theUserListsAllHisAvailableSpacesUsingTheGraphApi ( $user );
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200"
);
$this -> jsonRespondedShouldContain ( $spaceName , null , null , $grantedGroup , $table );
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 ,
2022-02-17 11:21:07 +01:00
string $role
) : void {
2022-07-08 05:18:40 +02:00
$this -> theUserListsAllHisAvailableSpacesUsingTheGraphApi ( $user );
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200"
);
2022-02-17 11:21:07 +01:00
Assert :: assertIsArray ( $spaceAsArray = $this -> getSpaceByNameFromResponse ( $spaceName ), "No space with name $spaceName found" );
$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
/**
2022-01-13 15:28:33 +01:00
* @Then /^the json responded 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 (
string $spaceName
) : void {
Assert :: assertEmpty ( $this -> getSpaceByNameFromResponse ( $spaceName ), "space $spaceName should not be available for a user" );
}
2022-07-08 05:18:40 +02:00
/**
* @Then /^the user "([^"]*)" should not have a space called "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws Exception
*/
public function usershouldNotHaveSpace (
string $user ,
string $spaceName
) : void {
$this -> theUserListsAllHisAvailableSpacesUsingTheGraphApi ( $user );
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200"
);
$this -> jsonRespondedShouldNotContain ( $spaceName );
}
2022-01-13 15:28:33 +01:00
/**
* @Then /^the json responded should (not|only|)\s?contain spaces of type "([^"]*)"$/
*
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 ,
string $type
) : void {
Assert :: assertNotEmpty (
$spaces = json_decode (
( string ) $this -> featureContext
-> getResponse () -> getBody (),
true ,
512 ,
JSON_THROW_ON_ERROR
)
);
$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 ,
int $count
) : 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
/**
2022-01-25 14:59:15 +01:00
* @When /^user "([^"]*)" creates a (?:folder|subfolder) "([^"]*)" in space "([^"]*)" using the WebDav Api$/
2021-11-11 12:15:15 +05:45
*
* @param string $user
* @param string $folder
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
*/
public function theUserCreatesAFolderUsingTheGraphApi (
string $user ,
string $folder ,
string $spaceName
) : void {
2022-01-25 14:59:15 +01:00
$exploded = explode ( '/' , $folder );
$path = '' ;
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 ] . '/' ;
$this -> theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi ( $user , $path , $spaceName );
2022-05-11 15:04:12 +05:45
}
2021-12-02 00:01:52 +01:00
}
2021-12-19 22:21:24 +01:00
/**
2022-01-25 14:59:15 +01:00
* @Given /^user "([^"]*)" has created a (?:folder|subfolder) "([^"]*)" in space "([^"]*)"$/
2021-12-19 22:21:24 +01:00
*
* @param string $user
* @param string $folder
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
*/
public function theUserHasCreateAFolderUsingTheGraphApi (
string $user ,
string $folder ,
string $spaceName
) : void {
2021-12-21 13:47:15 +05:45
$this -> theUserCreatesAFolderUsingTheGraphApi ( $user , $folder , $spaceName );
2021-12-19 22:21:24 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
201 ,
"Expected response status code should be 201"
);
}
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 ,
2021-12-21 13:47:15 +05:45
string $ownerUser = ''
2021-12-02 00:01:52 +01:00
) : void {
2021-12-21 13:47:15 +05:45
if ( $ownerUser === '' ) {
$ownerUser = $user ;
}
2022-09-14 13:38:15 +05:45
$this -> setSpaceIDByName ( $ownerUser , $spaceName );
$this -> featureContext -> userCreatesFolder ( $user , $folder );
2021-11-11 12:15:15 +05:45
}
/**
* @When /^user "([^"]*)" uploads a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $spaceName
* @param string $content
* @param string $destination
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserUploadsAFileToSpace (
string $user ,
string $spaceName ,
string $content ,
string $destination
) : void {
2022-09-14 13:38:15 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> featureContext -> uploadFileWithContent ( $user , $content , $destination );
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 ,
string $destination
) : void {
2022-09-14 13:38:15 +05:45
$this -> setSpaceIDByName ( $ownerUser , $spaceName );
$this -> featureContext -> uploadFileWithContent ( $user , $content , $destination );
2021-11-11 12:15:15 +05:45
}
2021-11-19 18:24:43 +01:00
/**
2023-01-04 17:00:59 +05:45
* @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)"$/
2023-02-06 23:48:30 +01:00
* @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/
2021-11-19 18:24:43 +01:00
*
* @param string $user
* @param string $spaceName
* @param string $newName
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 updateSpaceName (
string $user ,
string $spaceName ,
2023-02-06 23:48:30 +01:00
string $newName ,
string $owner = ''
2021-11-19 18:24:43 +01:00
) : void {
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
$bodyData = [ "Name" => $newName ];
$body = json_encode ( $bodyData , JSON_THROW_ON_ERROR );
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
GraphHelper :: updateSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
$spaceId
)
);
2021-11-19 18:24:43 +01:00
}
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 ,
string $owner = ''
2022-03-10 09:29:26 +01:00
) : void {
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" ];
}
2022-03-10 09:29:26 +01:00
$bodyData = [ "description" => $newDescription ];
$body = json_encode ( $bodyData , JSON_THROW_ON_ERROR );
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
GraphHelper :: updateSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
$spaceId
)
);
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 ,
string $newDescription
) : void {
$this -> updateSpaceDescription ( $user , $spaceName , $newDescription );
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200"
);
}
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 ,
string $owner = ''
2021-11-19 18:24:43 +01:00
) : void {
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
$bodyData = [ "quota" => [ "total" => $newQuota ]];
$body = json_encode ( $bodyData , JSON_THROW_ON_ERROR );
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
GraphHelper :: updateSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
$spaceId
)
);
2021-11-19 18:24:43 +01:00
}
2022-08-10 09:40:26 +05:45
/**
* @Given /^user "([^"]*)" has changed the quota of the personal space of "([^"]*)" space to "([^"]*)"$/
2022-12-08 11:01:03 +01:00
* @Given /^user "([^"]*)" has changed the quota of the "([^"]*)" 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 ,
int $newQuota
) : void {
$this -> updateSpaceQuota ( $user , $spaceName , $newQuota );
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200"
);
}
2022-12-14 14:13:55 +05:45
2022-03-10 09:29:26 +01:00
/**
* @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 updateSpaceSpecialSection (
string $user ,
string $file ,
string $type ,
string $spaceName
) : void {
$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 );
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
GraphHelper :: updateSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body ,
$spaceId
)
);
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 ,
string $spaceName
) : void {
$this -> updateSpaceSpecialSection ( $user , $file , $type , $spaceName );
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200"
);
}
2021-12-02 00:01:52 +01:00
/**
* @Given /^user "([^"]*)" has created a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $spaceType
* @param int $quota
*
* @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 ,
int $quota
) : void {
2021-12-02 00:01:52 +01:00
$space = [ "Name" => $spaceName , "driveType" => $spaceType , "quota" => [ "total" => $quota ]];
$body = json_encode ( $space );
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
GraphHelper :: createSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body
)
);
2021-12-02 00:01:52 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
2021-12-02 10:05:28 +01:00
201 ,
2021-12-02 00:01:52 +01:00
"Expected response status code should be 201 (Created)"
);
}
2022-03-10 09:29:26 +01:00
/**
2022-04-12 08:51:35 +02:00
* @Given /^user "([^"]*)" has created a space "([^"]*)" with the default quota using the GraphApi$/
2022-03-10 09:29:26 +01:00
*
* @param string $user
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserHasCreatedASpaceByDefaultUsingTheGraphApi (
string $user ,
string $spaceName
) : void {
$space = [ "Name" => $spaceName ];
$body = json_encode ( $space , JSON_THROW_ON_ERROR );
2022-08-31 15:11:31 +02:00
$this -> featureContext -> setResponse (
GraphHelper :: createSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body
)
);
2022-12-21 11:19:44 +05:45
$this -> setSpaceCreator ( $spaceName , $user );
2022-03-10 09:29:26 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
201 ,
"Expected response status code should be 201 (Created)"
);
}
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 ,
string $spaceName
) : void {
$space = $this -> getSpaceByName ( $user , $spaceName );
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
$spaceName
);
$fullUrl = $space [ "root" ][ "webDavUrl" ] . '/' . ltrim ( $fileSource , "/" );
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
/**
* @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
2022-08-18 17:20:57 +05:45
* @throws GuzzleException
2022-08-04 13:11:51 +02:00
*/
public function userMovesFileWithinSpaceUsingTheWebDAVAPI (
string $user ,
string $fileSource ,
string $fileDestination ,
string $spaceName
) : void {
$space = $this -> getSpaceByName ( $user , $spaceName );
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName (
$user ,
$fileDestination ,
$spaceName
);
2022-08-18 17:20:57 +05:45
$fileSource = $this -> escapePath ( \trim ( $fileSource , "/" ));
$fullUrl = $space [ "root" ][ "webDavUrl" ] . '/' . $fileSource ;
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-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 ,
string $spaceName
) : void {
$this -> userMovesFileWithinSpaceUsingTheWebDAVAPI (
$user ,
$fileSource ,
$fileDestination ,
$spaceName
);
$this -> featureContext -> theHTTPStatusCodeShouldBe (
201 ,
__METHOD__ . "Expected response status code should be 201 (Created) \n " .
"Actual response status code was: " . $this -> featureContext -> getResponse () -> getStatusCode () . " \n " .
"Actual response body was: " . $this -> featureContext -> getResponse () -> getBody ()
);
}
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 ,
$this -> featureContext -> getStepLineRef (),
'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
/**
* @When /^user "([^"]*)" copies (?: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 userCopiesFileFromAndToSpaceBetweenSpaces (
string $user ,
string $fileSource ,
string $fromSpaceName ,
string $fileDestination ,
string $toSpaceName
) : void {
$space = $this -> getSpaceByName ( $user , $fromSpaceName );
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName ( $user , $fileDestination , $toSpaceName );
$fullUrl = $space [ "root" ][ "webDavUrl" ] . '/' . ltrim ( $fileSource , "/" );
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-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 ,
string $action
) : void {
$space = $this -> getSpaceByName ( $user , $fromSpaceName );
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName ( $user , $fileDestination , $toSpaceName );
$headers [ 'Overwrite' ] = 'T' ;
$fullUrl = $space [ "root" ][ "webDavUrl" ] . '/' . ltrim ( $fileSource , "/" );
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
/**
2022-08-24 11:31:26 +05:45
* @Then /^user "([^"]*)" should not be able to download file "([^"]*)" from space "([^"]*)"$/
2022-08-24 11:30:51 +05:45
*
* @param string $user
* @param string $fileName
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userShouldNotBeAbleToDownloadFileInsideSpace (
string $user ,
string $fileName ,
string $spaceName
) : void {
2022-11-23 16:25:20 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
2022-09-14 13:38:15 +05:45
$this -> featureContext -> downloadFileAsUserUsingPassword ( $user , $fileName , $this -> featureContext -> getPasswordForUser ( $user ));
2022-08-24 11:30:51 +05:45
Assert :: assertGreaterThanOrEqual (
400 ,
$this -> featureContext -> getResponse () -> getStatusCode (),
__METHOD__
. ' download must fail'
);
Assert :: assertLessThanOrEqual (
499 ,
$this -> featureContext -> getResponse () -> getStatusCode (),
__METHOD__
. ' 4xx error expected but got status code "'
. $this -> featureContext -> getResponse () -> getStatusCode () . '"'
);
}
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 ,
string $toSpaceName
) : void {
$space = $this -> getSpaceByName ( $user , $fromSpaceName );
$headers [ 'Destination' ] = $this -> destinationHeaderValueWithSpaceName ( $user , $fileDestination , $toSpaceName );
$fullUrl = $space [ "root" ][ "webDavUrl" ] . '/' . \ltrim ( $fileSource , "/" );
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
/**
* returns a url for destination with spacename
*
* @param string $user
* @param string $fileDestination
* @param string $spaceName
*
* @return string
* @throws GuzzleException
*/
public function destinationHeaderValueWithSpaceName ( string $user , string $fileDestination , string $spaceName ) : string {
$space = $this -> getSpaceByName ( $user , $spaceName );
2022-08-18 17:20:57 +05:45
$fileDestination = $this -> escapePath ( \ltrim ( $fileDestination , "/" ));
return $space [ "root" ][ "webDavUrl" ] . '/' . $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 {
return HttpRequestHelper :: sendRequest (
$fullUrl ,
$this -> featureContext -> getStepLineRef (),
'COPY' ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$headers ,
2022-07-14 16:59:36 +05:45
);
}
2021-12-02 00:01:52 +01:00
/**
* @Given /^user "([^"]*)" has uploaded a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $fileContent
* @param string $destination
*
* @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 userHasUploadedFile (
string $user ,
string $spaceName ,
string $fileContent ,
string $destination
) : void {
2021-12-02 00:01:52 +01:00
$this -> theUserListsAllHisAvailableSpacesUsingTheGraphApi ( $user );
2022-09-14 13:38:15 +05:45
$this -> theUserUploadsAFileToSpace ( $user , $spaceName , $fileContent , $destination );
2021-12-02 00:01:52 +01:00
$this -> featureContext -> theHTTPStatusCodeShouldBeOr ( 201 , 204 );
}
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 ,
2023-02-17 09:18:53 +01:00
TableNode $table
2021-12-21 13:47:15 +05:45
) : void {
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-17 09:18:53 +01:00
$rows = $table -> getRowsHash ();
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" ],
"expireDate" => $rows [ "expireDate" ]
2022-01-20 18:17:30 +01:00
];
2021-12-19 22:21:24 +01:00
2022-03-27 21:36:13 +02:00
$fullUrl = $this -> baseUrl . $this -> ocsApiUrl ;
$this -> featureContext -> setResponse (
2022-07-21 17:42:39 +02:00
$this -> sendPostRequestToUrl (
2022-03-27 21:36:13 +02:00
$fullUrl ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body
)
);
}
/**
2023-02-01 09:55:51 +01:00
* @When /^user "([^"]*)" creates a share inside of space "([^"]*)" with settings:$/
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-02-01 09:55:51 +01:00
* @return void
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 ,
TableNode $table
) : void {
$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" ],
"role" => $rows [ "role" ]
2022-03-27 21:36:13 +02:00
];
$fullUrl = $this -> baseUrl . $this -> ocsApiUrl ;
2023-02-01 09:55:51 +01:00
$this -> featureContext -> setResponse (
$this -> sendPostRequestToUrl (
$fullUrl ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body
)
2022-03-27 21:36:13 +02:00
);
2023-02-01 09:55:51 +01:00
$this -> setLastShareData ();
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-02-01 09:55:51 +01:00
public function hasSharedTheFollowingEntityInsideOfSpace (
2022-08-31 12:57:15 +05:45
string $user ,
string $spaceName ,
2023-02-01 09:55:51 +01:00
TableNode $table
2022-08-31 12:57:15 +05:45
) : void {
2023-02-01 09:55:51 +01:00
$this -> createShareResource ( $user , $spaceName , $table );
Assert :: assertEquals (
$this -> featureContext -> getResponse () -> getStatusCode (),
200 ,
"Expected response status code should be 200"
);
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-02-01 09:55:51 +01:00
public function changeShareResource (
2022-08-31 12:57:15 +05:45
string $user ,
2023-02-01 09:55:51 +01:00
TableNode $table
2022-08-31 12:57:15 +05:45
) : void {
2023-02-01 09:55:51 +01:00
$shareId = $this -> featureContext -> getLastPublicLinkShareId ();
$rows = $table -> getRowsHash ();
$rows [ "role" ] = \array_key_exists ( "role" , $rows ) ? $rows [ "role" ] : 'viewer' ;
$rows [ "expireDate" ] = \array_key_exists ( "expireDate" , $rows ) ? $rows [ "expireDate" ] : null ;
$body = [
"expireDate" => $rows [ "expireDate" ],
];
$fullUrl = $this -> baseUrl . $this -> ocsApiUrl . '/' . $shareId ;
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
$fullUrl ,
"" ,
"PUT" ,
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
null ,
$body
)
2022-08-31 12:57:15 +05:45
);
}
2022-03-27 21:36:13 +02:00
/**
* @When /^user "([^"]*)" creates a public link share inside of space "([^"]*)" with settings:$/
*
* @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
*
* @return void
* @throws GuzzleException
*/
public function createPublicLinkToEntityInsideOfSpaceRequest (
string $user ,
string $spaceName ,
2022-08-18 11:23:57 +02:00
TableNode $table
2022-03-27 21:36:13 +02:00
) : void {
$space = $this -> getSpaceByName ( $user , $spaceName );
$rows = $table -> getRowsHash ();
$rows [ "path" ] = \array_key_exists ( "path" , $rows ) ? $rows [ "path" ] : null ;
$rows [ "shareType" ] = \array_key_exists ( "shareType" , $rows ) ? $rows [ "shareType" ] : null ;
$rows [ "permissions" ] = \array_key_exists ( "permissions" , $rows ) ? $rows [ "permissions" ] : null ;
$rows [ "password" ] = \array_key_exists ( "password" , $rows ) ? $rows [ "password" ] : null ;
$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" ],
"expireDate" => $rows [ "expireDate" ]
];
$fullUrl = $this -> baseUrl . $this -> ocsApiUrl ;
2021-12-19 22:21:24 +01:00
2021-12-21 18:22:32 +01:00
$this -> featureContext -> setResponse (
2022-07-21 17:42:39 +02:00
$this -> sendPostRequestToUrl (
2021-12-21 18:22:32 +01:00
$fullUrl ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body
)
);
2022-08-18 11:23:57 +02:00
$this -> setLastShareData ();
}
/**
* @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 ,
TableNode $table
) : void {
$this -> createPublicLinkToEntityInsideOfSpaceRequest ( $user , $spaceName , $table );
$expectedHTTPStatus = "200" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
$expectedHTTPStatus ,
"Expected response status code should be $expectedHTTPStatus "
);
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 ,
2023-02-17 09:18:53 +01:00
TableNode $tableNode
2021-12-21 13:47:15 +05:45
) : void {
2023-02-17 09:18:53 +01:00
$this -> sendShareSpaceRequest ( $user , $spaceName , $tableNode );
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 ,
2021-12-21 13:47:15 +05:45
"Expected response status code should be $expectedHTTPStatus "
2021-12-19 22:21:24 +01:00
);
2022-03-10 09:29:26 +01:00
$expectedOCSStatus = "200" ;
2021-12-21 13:47:15 +05:45
$this -> ocsContext -> theOCSStatusCodeShouldBe ( $expectedOCSStatus , "Expected OCS response status code $expectedOCSStatus " );
2021-12-19 22:21:24 +01:00
}
/**
2023-01-10 12:03:52 +01:00
* @When /^user "([^"]*)" unshares a space "([^"]*)" to (?:user|group) "([^"]*)"$/
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
*
2021-12-21 13:47:15 +05:45
* @return void
2021-12-19 22:21:24 +01:00
* @throws GuzzleException
*/
public function sendUnshareSpaceRequest (
string $user ,
string $spaceName ,
2023-01-10 12:03:52 +01:00
string $recipient
2021-12-21 13:47:15 +05:45
) : void {
2021-12-19 22:21:24 +01:00
$space = $this -> getSpaceByName ( $user , $spaceName );
2023-01-10 12:03:52 +01:00
$fullUrl = $this -> baseUrl . $this -> ocsApiUrl . "/" . $space [ 'id' ] . "?shareWith=" . $recipient ;
2021-12-19 22:21:24 +01:00
2022-01-30 20:50:41 +01:00
$this -> featureContext -> setResponse (
HttpRequestHelper :: delete (
$fullUrl ,
"" ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user )
)
);
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
*/
public function sendRemoveObjectFromSpaceRequest (
string $user ,
string $object ,
string $spaceName
) : void {
$space = $this -> getSpaceByName ( $user , $spaceName );
2022-08-16 11:20:46 +05:45
$spaceWebDavUrl = $space [ "root" ][ "webDavUrl" ] . '/' . ltrim ( $object , "/" );
2022-01-30 20:50:41 +01:00
$this -> featureContext -> setResponse (
HttpRequestHelper :: delete (
$spaceWebDavUrl ,
"" ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user )
)
);
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
*/
2022-01-30 20:50:41 +01:00
public function sendDisableSpaceRequest (
2022-01-25 14:59:15 +01:00
string $user ,
2023-02-06 23:48:30 +01:00
string $spaceName ,
string $owner = ''
2022-01-25 14:59:15 +01:00
) : void {
2023-02-06 23:48:30 +01:00
$space = $this -> getSpaceByName (( $owner !== "" ) ? $owner : $user , $spaceName );
2022-01-30 20:50:41 +01:00
$this -> featureContext -> setResponse (
2022-08-31 15:11:31 +02:00
GraphHelper :: disableSpace (
$this -> featureContext -> getBaseUrl (),
2022-01-30 20:50:41 +01:00
$user ,
2022-08-31 15:11:31 +02:00
$this -> featureContext -> getPasswordForUser ( $user ),
$space [ "id" ]
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
*/
public function sendUserHasRemovedObjectFromSpaceRequest (
string $user ,
string $object ,
string $spaceName
) : void {
$this -> sendRemoveObjectFromSpaceRequest ( $user , $object , $spaceName );
$expectedHTTPStatus = "204" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
$expectedHTTPStatus ,
"Expected response status code should be $expectedHTTPStatus "
);
}
/**
* @Given /^user "([^"]*)" has disabled a space "([^"]*)"$/
2022-01-30 20:50:41 +01:00
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function sendUserHasDisabledSpaceRequest (
string $user ,
string $spaceName
) : void {
$this -> sendDisableSpaceRequest ( $user , $spaceName );
$expectedHTTPStatus = "204" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
2022-03-10 09:29:26 +01:00
$expectedHTTPStatus ,
2022-01-30 20:50:41 +01:00
"Expected response status code should be $expectedHTTPStatus "
);
}
/**
* @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-02-06 23:48:30 +01:00
* @param string $owner
2022-01-30 20:50:41 +01:00
*
* @return void
* @throws GuzzleException
*/
public function sendDeleteSpaceRequest (
string $user ,
2023-02-06 23:48:30 +01:00
string $spaceName ,
$owner = ''
2022-01-30 20:50:41 +01:00
) : void {
2023-02-06 23:48:30 +01:00
$space = $this -> getSpaceByName (( $owner !== "" ) ? $owner : $user , $spaceName );
2022-09-02 15:30:55 +05:45
2022-01-30 20:50:41 +01:00
$this -> featureContext -> setResponse (
2022-08-31 15:11:31 +02:00
GraphHelper :: deleteSpace (
$this -> featureContext -> getBaseUrl (),
2022-01-30 20:50:41 +01:00
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2022-09-02 15:30:55 +05:45
$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
*/
public function sendRestoreSpaceRequest (
string $user ,
2022-02-10 20:21:22 +01:00
string $spaceName ,
2023-02-06 23:48:30 +01:00
string $owner = ''
2022-02-07 18:30:28 +01:00
) : void {
2023-02-06 23:48:30 +01:00
$space = $this -> getSpaceByName (( $owner !== "" ) ? $owner : $user , $spaceName );
2022-02-07 18:30:28 +01:00
$this -> featureContext -> setResponse (
2022-08-31 15:11:31 +02:00
GraphHelper :: restoreSpace (
$this -> featureContext -> getBaseUrl (),
2022-02-07 18:30:28 +01:00
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2022-08-31 15:11:31 +02:00
$space [ "id" ]
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 ,
string $spaceName
) : void {
$this -> sendRestoreSpaceRequest ( $user , $spaceName );
$expectedHTTPStatus = "200" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
2022-03-10 09:29:26 +01:00
$expectedHTTPStatus ,
2022-02-07 18:30:28 +01:00
"Expected response status code should be $expectedHTTPStatus "
);
}
2022-04-12 08:51:35 +02:00
/**
* @When /^user "([^"]*)" lists all deleted files in the trash bin of the space "([^"]*)"$/
*
* @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 ,
string $spaceName
) : void {
$space = $this -> getSpaceByName ( $user , $spaceName );
2022-05-11 09:13:59 +02:00
$fullUrl = $this -> baseUrl . $this -> davSpacesUrl . "trash-bin/" . $space [ "id" ];
2022-04-12 08:51:35 +02:00
$this -> featureContext -> setResponse (
2022-09-29 12:40:02 +05:45
HttpRequestHelper :: sendRequest ( $fullUrl , '' , 'PROPFIND' , $user , $this -> featureContext -> getPasswordForUser ( $user ))
2022-04-12 08:51:35 +02:00
);
}
/**
2022-04-12 19:35:05 +05:45
* User get all objects in the trash of project space
*
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
* (
* [href] => /remote.php/dav/spaces/trash-bin/spaceId/objectId/
* [name] => deleted folder
* [mtime] => 1649147272
* [original-location] => deleted folder
* )
*
* @param string $user
* @param string $spaceName
*
* @return array
* @throws GuzzleException
*/
public function getObjectsInTrashbin (
string $user ,
string $spaceName
) : array {
2022-05-03 09:48:12 +05:45
$this -> userListAllDeletedFilesInTrash ( $user , $spaceName );
2022-04-12 08:51:35 +02:00
$this -> featureContext -> theHTTPStatusCodeShouldBe (
207 ,
"Expected response status code should be 207"
);
return $this -> trashbinContext -> getTrashbinContentFromResponseXml (
$this -> featureContext -> getResponseXml ( $this -> featureContext -> getResponse ())
);
}
/**
* @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 ,
string $spaceName
) : 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 "([^"]*)"$/
*
2022-05-11 15:04:12 +05:45
* @param string $user
* @param string $object
* @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 ,
string $object ,
string $spaceName ,
string $destination
) : void {
$space = $this -> getSpaceByName ( $user , $spaceName );
// find object in trash
$objectsInTrash = $this -> getObjectsInTrashbin ( $user , $spaceName );
2022-05-11 15:04:12 +05:45
$pathToDeletedObject = "" ;
2022-04-12 08:51:35 +02:00
foreach ( $objectsInTrash as $objectInTrash ) {
if ( $objectInTrash [ "name" ] === $object ) {
$pathToDeletedObject = $objectInTrash [ "href" ];
}
2022-05-11 15:04:12 +05:45
}
if ( $pathToDeletedObject === "" ) {
throw new Exception ( __METHOD__ . " Object ' $object ' was not found in the trashbin of user ' $user ' space ' $spaceName '" );
}
2022-04-12 08:51:35 +02:00
2022-05-11 09:13:59 +02:00
$destination = $this -> baseUrl . $this -> davSpacesUrl . $space [ "id" ] . $destination ;
2022-04-12 08:51:35 +02:00
$header = [ "Destination" => $destination , "Overwrite" => "F" ];
$fullUrl = $this -> baseUrl . $pathToDeletedObject ;
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
$fullUrl ,
"" ,
'MOVE' ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$header ,
""
)
);
}
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 ,
string $height
) : 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 ,
'y' => $height
];
$urlParameters = \http_build_query ( $urlParameters , '' , '&' );
$space = $this -> getSpaceByName ( $user , $spaceName );
$fullUrl = $this -> baseUrl . $this -> davSpacesUrl . $space [ 'id' ] . '/' . $fileName . '?' . $urlParameters ;
$this -> featureContext -> setResponse (
HttpRequestHelper :: get (
$fullUrl ,
"" ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user )
)
);
}
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 ,
string $spaceName
2022-06-28 15:05:16 +02:00
) : void {
2022-09-14 13:38:15 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> featureContext -> downloadFileAsUserUsingPassword ( $user , $fileName , $this -> featureContext -> getPasswordForUser ( $user ));
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 ,
string $spaceName
) : void {
2022-09-08 13:00:48 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> checksumContext -> userRequestsTheChecksumOfViaPropfind ( $user , $path );
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 ,
2022-08-05 16:56:04 +05:45
string $spaceName
) : void {
2022-09-08 13:00:48 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> featureContext -> userUploadsAFileWithChecksumAndContentTo ( $user , $checksum , $content , $destination );
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$/
*
* @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 ,
string $spaceName
2022-06-28 15:05:16 +02:00
) : void {
2022-09-14 13:38:15 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> filesVersionsContext -> downloadVersion ( $user , $fileName , $index );
WebDavHelper :: $SPACE_ID_FROM_OCIS = '' ;
2022-05-18 11:39:16 +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
*/
public function userGetsEtagOfElementInASpace ( string $user , string $space , string $path ) {
2022-09-14 13:38:15 +05:45
$this -> setSpaceIDByName ( $user , $space );
$this -> webDavPropertiesContext -> storeEtagOfElement ( $user , $path );
2022-07-14 16:59:36 +05:45
return $this -> featureContext -> getEtagFromResponseXmlObject ();
}
/**
* 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
*/
public function storeEtagOfElementInSpaceForUser ( string $user , string $space , string $path , ? string $storePath = "" ) : void {
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"
. " \n Found: " . print_r ( $this -> storedEtags , true )
);
Assert :: assertArrayHasKey (
$space ,
$this -> storedEtags [ $user ],
__METHOD__ . " No stored etags for user ' $user ' with space ' $space ' found"
. " \n Found: " . implode ( ', ' , array_keys ( $this -> storedEtags [ $user ]))
);
Assert :: assertArrayHasKey (
$path ,
$this -> storedEtags [ $user ][ $space ],
__METHOD__ . " No stored etags for user ' $user ' with space ' $space ' with path ' $path ' found"
. '\nFound: ' . print_r ( $this -> storedEtags [ $user ][ $space ], true )
);
return $this -> storedEtags [ $user ][ $space ][ $path ];
}
/**
* @Then /^these etags should have changed$/
*
2022-09-06 12:32:56 +05:45
* @param TableNode $table
*
* @return void
2022-07-14 16:59:36 +05:45
* @throws GuzzleException
*/
public function theseEtagsShouldHaveChanged ( TableNode $table ) : void {
$this -> featureContext -> verifyTableNodeColumns ( $table , [ "user" , "path" , "space" ]);
$this -> featureContext -> verifyTableNodeColumnsCount ( $table , 3 );
$unchangedEtagCount = 0 ;
$unchangedEtagMessage = __METHOD__ ;
foreach ( $table -> getColumnsHash () as $row ) {
$user = $row [ 'user' ];
$path = $row [ 'path' ];
$space = $row [ 'space' ];
$etag = $this -> userGetsEtagOfElementInASpace ( $user , $space , $path );
$storedEtag = $this -> getStoredEtagForPathInSpaceOfAUser ( $user , $space , $path );
if ( $etag === $storedEtag ) {
$unchangedEtagCount ++ ;
$unchangedEtagMessage .= " \n Expected etag of element ' $path ' for user ' $user ' in space ' $space ' to change, but it did not." ;
}
}
Assert :: assertEquals ( 0 , $unchangedEtagCount , $unchangedEtagMessage );
}
/**
* @Then /^these etags should not have changed$/
*
* @param TableNode $table
*
2022-09-06 12:32:56 +05:45
* @return void
2022-07-14 16:59:36 +05:45
* @throws GuzzleException
*/
public function theseEtagsShouldNotHaveChanged ( TableNode $table ) : void {
$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' ];
$actualEtag = $this -> userGetsEtagOfElementInASpace ( $user , $space , $path );
$storedEtag = $this -> getStoredEtagForPathInSpaceOfAUser ( $user , $space , $path );
if ( $actualEtag !== $storedEtag ) {
$changedEtagCount ++ ;
$changedEtagMessage .= " \n Expected etag of element ' $path ' for user ' $user ' in space ' $space ' not to change, but it did." ;
}
}
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
*/
public function userHasStoredEtagOfElementFromSpace ( string $user , string $path , string $space ) : void {
$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
*/
2022-09-06 15:58:42 +05:45
public function userHasStoredEtagOfElementOnPathFromSpace ( string $user , string $path , string $storePath , string $space ) : void {
2022-07-14 16:59:36 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
$this -> storeEtagOfElementInSpaceForUser (
$user ,
$space ,
$path ,
$storePath
);
if ( $this -> storedEtags [ $user ][ $space ][ $storePath ] === "" || $this -> storedEtags [ $user ][ $space ][ $storePath ] === null ) {
throw new Exception ( "Expected stored etag to be some string but found null!" );
}
}
2022-07-21 17:42:39 +02:00
/**
* @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 sendShareSpaceViaLinkRequest (
string $user ,
string $spaceName ,
? TableNode $table
) : void {
$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 ;
$rows [ "password" ] = \array_key_exists ( "password" , $rows ) ? $rows [ "password" ] : null ;
$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" ],
"expireDate" => $rows [ "expireDate" ]
];
$fullUrl = $this -> baseUrl . $this -> ocsApiUrl ;
$this -> featureContext -> setResponse (
$this -> sendPostRequestToUrl (
$fullUrl ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$body
)
);
2022-07-26 11:27:28 +02:00
2022-08-18 11:23:57 +02:00
$this -> setLastShareData ();
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 ,
? TableNode $table
) : void {
$this -> sendShareSpaceViaLinkRequest ( $user , $spaceName , $table );
$expectedHTTPStatus = "200" ;
$this -> featureContext -> theHTTPStatusCodeShouldBe (
$expectedHTTPStatus ,
"Expected response status code should be $expectedHTTPStatus "
);
$this -> featureContext -> setLastPublicLinkShareId (( string ) $this -> featureContext -> getLastPublicShareData () -> data [ 0 ] -> id );
}
/**
* @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain the last created public link$/
2022-08-18 11:23:57 +02:00
* @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain the last created public link of the file "([^"]*)"$/
* @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain the last created share of the file "([^"]*)"$/
2022-07-26 11:27:28 +02:00
*
* @param string $user
* @param string $spaceName
* @param string $shouldOrNot (not|)
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 ,
string $fileName = ''
2022-07-26 11:27:28 +02:00
) : void {
2022-08-18 11:23:57 +02:00
$body = '' ;
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
$this -> ocsContext -> userSendsHTTPMethodToOcsApiEndpointWithBody (
$user ,
'GET' ,
$url ,
);
$should = ( $shouldOrNot !== "not" );
2022-08-04 13:11:51 +02:00
$responseArray = json_decode ( json_encode ( $this -> featureContext -> getResponseXml () -> data ), true , 512 , JSON_THROW_ON_ERROR );
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 ) {
$expectedLinkId = $this -> featureContext -> getLastPublicLinkShareId ();
Assert :: assertEquals ( $element [ "id" ], $expectedLinkId , "link IDs are different" );
}
} 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 ,
TableNode $propertiesTable
) : void {
2022-09-08 15:03:35 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> webDavPropertiesContext -> userGetsPropertiesOfFolder ( $user , $resourceName , $propertiesTable );
2022-08-09 14:00:02 +05:45
}
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 ,
string $value
) : void {
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> webDavPropertiesContext -> asUserFolderShouldContainAPropertyWithValue ( $user , $resourceName , $property , $value );
}
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
*/
public function asUserFileOrFolderInsideSpaceShouldOrNotBeFavorited ( string $user , string $path , string $spaceName , string $shouldOrNot ) : void {
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> favoritesContext -> asUserFileOrFolderShouldBeFavorited ( $user , $path , ( $shouldOrNot === 'should' ) ? 1 : 0 );
}
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 {
2022-09-01 14:28:53 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> favoritesContext -> userFavoritesElement ( $user , $path );
2022-08-31 12:57:15 +05:45
}
2022-09-05 16:00:16 +05:45
/**
* @Given /^user "([^"]*)" has stored id of (file|folder) "([^"]*)" of the space "([^"]*)"$/
*
* @param string $user
* @param string $fileOrFolder
* @param string $path
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
*/
public function userHasStoredIdOfPathOfTheSpace ( string $user , string $fileOrFolder , string $path , string $spaceName ) : void {
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> featureContext -> userStoresFileIdForPath ( $user , $fileOrFolder , $path );
}
/**
* @Then /^user "([^"]*)" (folder|file) "([^"]*)" of the space "([^"]*)" should have the previously stored id$/
*
* @param string|null $user
* @param string $fileOrFolder
* @param string $path
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
*/
public function userFolderOfTheSpaceShouldHaveThePreviouslyStoredId ( string $user , string $fileOrFolder , string $path , string $spaceName ) : void {
$this -> setSpaceIDByName ( $user , $spaceName );
$this -> featureContext -> userFileShouldHaveStoredId ( $user , $fileOrFolder , $path );
}
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)
$responseArray = json_decode ( json_encode ( $this -> featureContext -> getResponseXml () -> xpath ( "//d:response/d:href" )), true , 512 , JSON_THROW_ON_ERROR );
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' ]);
$topWebDavPath = "/remote.php/dav/spaces/" . str_replace ( '!' , '%21' , $splitSpaceId [ 1 ]);
} else {
$space = $this -> getSpaceByName ( $user , $spaceName );
$topWebDavPath = "/remote.php/dav/spaces/" . $space [ 'id' ];
}
2022-09-15 09:36:01 +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
/**
2022-11-28 14:27:41 +05:45
* @When /^user "([^"]*)" sends PROPFIND request to space "([^"]*)" using the WebDAV API$/
2023-01-17 12:41:56 +01:00
* @When /^user "([^"]*)" sends PROPFIND request from the space "([^"]*)" to the 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
2023-01-17 12:41:56 +01:00
* @param ?string $resource
2022-11-28 14:27:41 +05:45
*
* @throws GuzzleException
*
* @return void
*/
2023-01-17 12:41:56 +01:00
public function userSendsPropfindRequestToSpace ( string $user , string $spaceName , ? string $resource = "" ) : void {
2022-11-28 14:27:41 +05:45
$this -> setSpaceIDByName ( $user , $spaceName );
2023-01-17 12:41:56 +01:00
$properties = [ 'oc:permissions' , 'oc:fileid' , 'oc:share-types' , 'oc:privatelink' , 'd:resourcetype' , 'oc:size' , 'oc:name' , 'd:getcontenttype' , 'oc:tags' ];
2022-11-28 14:27:41 +05:45
$this -> featureContext -> setResponse (
WebDavHelper :: propfind (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
2023-01-17 12:41:56 +01:00
$resource ,
2022-11-28 14:27:41 +05:45
$properties ,
"" ,
"0" ,
"files" ,
WebDavHelper :: DAV_VERSION_SPACES
)
);
}
/**
2022-12-21 11:19:44 +05:45
* @Then /^the "([^"]*)" response should contain a space "([^"]*)" with these key and value pairs:$/
2022-11-28 14:27:41 +05:45
*
* @param string $method # method should be either PROPFIND or REPORT
2022-10-17 13:46:07 +02:00
* @param string $space
2022-10-25 13:48:01 +02:00
* @param TableNode $table
2022-10-17 13:46:07 +02:00
*
* @return void
* @throws GuzzleException
2022-11-28 14:27:41 +05:45
* @throws JsonException
2022-10-17 13:46:07 +02:00
*/
2022-12-21 11:19:44 +05:45
public function theResponseShouldContainSpace ( string $method , string $space , TableNode $table ) : void {
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'key' , 'value' ]);
$this -> theResponseShouldContain ( $method , $this -> getSpaceCreator ( $space ), $space , $table );
}
/**
* @Then /^the "([^"]*)" response to user "([^"]*)" should contain a mountpoint "([^"]*)" with these key and value pairs:$/
*
* @param string $method # method should be either PROPFIND or REPORT
* @param string $user
* @param string $mountPoint
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function theResponseShouldContainMountPoint ( string $method , string $user , string $mountPoint , TableNode $table ) : void {
2022-10-25 13:48:01 +02:00
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'key' , 'value' ]);
2022-12-21 11:19:44 +05:45
$this -> theResponseShouldContain ( $method , $user , $mountPoint , $table );
}
/**
* @param string $method # method should be either PROPFIND or REPORT
* @param string $user
2022-12-21 18:32:56 +05:45
* @param string $spaceNameOrMountPoint # an entity inside a space, or the space name itself
2022-12-21 11:19:44 +05:45
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
2022-12-21 18:32:56 +05:45
public function theResponseShouldContain ( string $method , string $user , string $spaceNameOrMountPoint , TableNode $table ) : void {
2022-10-25 13:48:01 +02:00
$xmlRes = $this -> featureContext -> getResponseXml ();
foreach ( $table -> getHash () as $row ) {
$findItem = $row [ 'key' ];
$responseValue = $xmlRes -> xpath ( "//d:response/d:propstat/d:prop/ $findItem " )[ 0 ] -> __toString ();
Assert :: assertNotEmpty ( $responseValue , "response doesn't contain $findItem or empty" );
$value = str_replace ( 'UUIDof:' , '' , $row [ 'value' ]);
switch ( $findItem ) {
case "oc:fileid" :
2022-11-28 14:27:41 +05:45
$resourceType = $xmlRes -> xpath ( "//d:response/d:propstat/d:prop/d:getcontenttype" )[ 0 ] -> __toString ();
if ( $method === 'PROPFIND' ) {
if ( ! $resourceType ) {
2023-02-01 09:55:51 +01:00
Assert :: assertEquals ( $this -> getResourceId ( $user , $spaceNameOrMountPoint , $value ), $responseValue , 'wrong fileId in the response' );
2022-11-28 14:27:41 +05:45
} else {
2022-12-21 18:32:56 +05:45
Assert :: assertEquals ( $this -> getFileId ( $user , $spaceNameOrMountPoint , $value ), $responseValue , 'wrong fileId in the response' );
2022-11-28 14:27:41 +05:45
}
2022-10-25 13:48:01 +02:00
} else {
2022-11-28 14:27:41 +05:45
if ( $resourceType === 'httpd/unix-directory' ) {
2023-02-01 09:55:51 +01:00
Assert :: assertEquals ( $this -> getResourceId ( $user , $spaceNameOrMountPoint , $value ), $responseValue , 'wrong fileId in the response' );
2022-11-28 14:27:41 +05:45
} else {
2022-12-21 18:32:56 +05:45
Assert :: assertEquals ( $this -> getFileId ( $user , $spaceNameOrMountPoint , $value ), $responseValue , 'wrong fileId in the response' );
2022-11-28 14:27:41 +05:45
}
2022-10-25 13:48:01 +02:00
}
break ;
case "oc:file-parent" :
2023-02-01 09:55:51 +01:00
Assert :: assertEquals ( $this -> getResourceId ( $user , $spaceNameOrMountPoint , $value ), $responseValue , 'wrong file-parentId in the response' );
2022-10-25 13:48:01 +02:00
break ;
2022-11-28 14:27:41 +05:45
case "oc:privatelink" :
2022-12-21 18:32:56 +05:45
Assert :: assertEquals ( $this -> getPrivateLink ( $user , $spaceNameOrMountPoint ), $responseValue , 'cannot find private link for space or resource in the response' );
2022-11-28 14:27:41 +05:45
break ;
2022-10-25 13:48:01 +02:00
default :
Assert :: assertEquals ( $value , $responseValue , "wrong $findItem in the response" );
break ;
}
}
2022-10-17 13:46:07 +02:00
}
2022-12-15 14:20:04 +05:45
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
2022-12-19 15:46:51 +05:45
* @throws GuzzleException|JsonException
2022-12-15 16:18:18 +05:45
*/
2022-12-19 15:46:51 +05:45
public function publicDownloadsTheFolderFromTheLastCreatedPublicLink ( string $resource ) {
2022-12-15 16:18:18 +05:45
$token = $this -> featureContext -> getLastPublicShareToken ();
2022-12-19 15:46:51 +05:45
$response = $this -> featureContext -> listFolderAndReturnResponseXml (
$token ,
$resource ,
'0' ,
[ 'oc:fileid' ],
$this -> featureContext -> getDavPathVersion () === 1 ? "public-files" : "public-files-new"
);
$resourceId = json_decode ( json_encode ( $response -> xpath ( "//d:response/d:propstat/d:prop/oc:fileid" )), true , 512 , JSON_THROW_ON_ERROR );
$queryString = 'public-token=' . $token . '&id=' . $resourceId [ 0 ][ 0 ];
2022-12-15 16:18:18 +05:45
$this -> featureContext -> setResponse (
HttpRequestHelper :: get (
$this -> featureContext -> getBaseUrl () . '/archiver?' . $queryString ,
'' ,
'' ,
'' ,
)
);
}
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 ,
"Expected relative quota amount to be $quotaAmount but found to be $data->quota ->relative"
);
} else {
throw new Exception (
"No relative quota amount found in responseXml"
);
}
}
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-02-17 09:18:53 +01:00
* @param string $expirationDate
2023-02-09 16:58:39 +01:00
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserShouldHaveSpaceWithRecipient (
string $user ,
string $spaceName ,
string $recipientType ,
string $recipient ,
2023-02-17 09:18:53 +01:00
string $role ,
string $expirationDate = null
2023-02-09 16:58:39 +01:00
) : void {
$this -> theUserListsAllHisAvailableSpacesUsingTheGraphApi ( $user );
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200"
);
Assert :: assertIsArray ( $spaceAsArray = $this -> getSpaceByNameFromResponse ( $spaceName ), "No space with name $spaceName found" );
2023-02-16 16:34:13 +01:00
$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 ) {
2023-02-10 16:30:07 +05:45
if ( isset ( $permission [ 'grantedToIdentities' ][ 0 ][ $recipientType ]) && $permission [ 'roles' ][ 0 ] === $role && $permission [ 'grantedToIdentities' ][ 0 ][ $recipientType ][ 'id' ] === $recipientId ) {
$foundRoleInResponse = true ;
2023-02-22 16:50:38 +05:45
if ( $expirationDate !== null && isset ( $permission [ 'expirationDateTime' ])) {
2023-02-17 09:18:53 +01:00
Assert :: assertEquals ( $expirationDate , ( preg_split ( "/[\sT]+/" , $permission [ 'expirationDateTime' ]))[ 0 ], " $expirationDate is different in the response" );
}
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
}
2021-10-20 17:25:09 +02:00
}