2023-12-13 12:34:49 +01:00
<? php declare ( strict_types = 1 );
/**
* @author Viktor Scharf <scharf.vi@gmail.com>
*
* @copyright Copyright (c) 2023, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
use Behat\Behat\Context\Context ;
use Behat\Behat\Hook\Scope\BeforeScenarioScope ;
2024-10-08 12:26:40 +05:45
use Behat\Gherkin\Node\TableNode ;
2024-04-18 15:17:51 +05:45
use GuzzleHttp\Exception\GuzzleException ;
2024-10-08 12:26:40 +05:45
use PHPUnit\Framework\Assert ;
2024-01-02 16:53:47 +05:45
use Psr\Http\Message\ResponseInterface ;
2023-12-13 12:34:49 +01:00
use TestHelpers\GraphHelper ;
2026-07-30 12:07:41 +05:45
use TestHelpers\KeycloakHelper ;
2024-01-24 12:13:54 +05:45
use TestHelpers\WebDavHelper ;
2024-06-24 18:02:40 +05:45
use TestHelpers\HttpRequestHelper ;
2024-10-08 12:26:40 +05:45
use TestHelpers\BehatHelper ;
2023-12-13 12:34:49 +01:00
require_once 'bootstrap.php' ;
/**
* Acceptance test steps related to testing sharing ng features
*/
class SharingNgContext implements Context {
private FeatureContext $featureContext ;
private SpacesContext $spacesContext ;
/**
* This will run before EVERY scenario.
* It will set the properties for this object.
*
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
*/
public function before ( BeforeScenarioScope $scope ) : void {
// Get the environment
$environment = $scope -> getEnvironment ();
// Get all the contexts you need in this context from here
2024-10-08 12:26:40 +05:45
$this -> featureContext = BehatHelper :: getContext ( $scope , $environment , 'FeatureContext' );
$this -> spacesContext = BehatHelper :: getContext ( $scope , $environment , 'SpacesContext' );
2023-12-13 12:34:49 +01:00
}
2024-01-02 16:53:47 +05:45
/**
2024-05-08 15:25:42 +05:45
* Create link share of item (resource) or drive (space) using drives.permissions endpoint
2024-05-08 14:22:52 +05:45
*
2024-01-02 16:53:47 +05:45
* @param string $user
2024-05-08 15:25:42 +05:45
* @param TableNode $body
2024-01-02 16:53:47 +05:45
*
* @return ResponseInterface
* @throws Exception
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-01-02 16:53:47 +05:45
*/
public function createLinkShare ( string $user , TableNode $body ) : ResponseInterface {
$bodyRows = $body -> getRowsHash ();
2024-05-08 14:22:52 +05:45
$resource = $bodyRows [ 'resource' ] ?? "" ;
2026-08-13 14:53:57 +05:45
$isVault = isset ( $bodyRows [ 'storage' ]) && $bodyRows [ 'storage' ] === 'vault' ;
2024-01-02 16:53:47 +05:45
2026-08-13 14:53:57 +05:45
$space = $this -> spacesContext -> getSpaceByName ( $user , $bodyRows [ 'space' ], $isVault );
2024-05-29 16:06:26 +05:45
$spaceId = $space [ 'id' ];
if ( $resource === '' && ! \in_array ( $bodyRows [ 'space' ], [ 'Personal' , 'Shares' ])) {
$itemId = $space [ 'fileId' ];
} else {
2026-08-13 14:53:57 +05:45
$itemId = $this -> spacesContext -> getResourceId ( $user , $bodyRows [ 'space' ], $resource , $isVault );
2024-05-29 16:06:26 +05:45
}
2024-01-02 16:53:47 +05:45
2024-06-12 15:12:56 +05:45
$bodyRows [ 'quickLink' ] = $bodyRows [ 'quickLink' ] ?? false ;
2024-01-02 16:53:47 +05:45
$bodyRows [ 'displayName' ] = $bodyRows [ 'displayName' ] ?? null ;
2024-12-24 09:30:42 +05:45
$bodyRows [ 'expirationDateTime' ] = \array_key_exists ( 'expirationDateTime' , $bodyRows )
? \date ( 'Y-m-d' , \strtotime ( $bodyRows [ 'expirationDateTime' ])) . 'T14:00:00.000Z' : null ;
2024-01-02 16:53:47 +05:45
$bodyRows [ 'password' ] = $bodyRows [ 'password' ] ?? null ;
2025-01-10 12:20:47 +05:45
$permissionsRole = $bodyRows [ 'permissionsRole' ];
$type = GraphHelper :: SHARING_LINK_TYPE_MAPPINGS [ $permissionsRole ] ?? $permissionsRole ;
2024-01-02 16:53:47 +05:45
$body = [
2025-01-10 12:20:47 +05:45
'type' => $type ,
2024-06-12 15:12:56 +05:45
"@libre.graph.quickLink" => filter_var ( $bodyRows [ 'quickLink' ], FILTER_VALIDATE_BOOLEAN ),
2024-01-02 16:53:47 +05:45
'displayName' => $bodyRows [ 'displayName' ],
'expirationDateTime' => $bodyRows [ 'expirationDateTime' ],
2025-06-19 10:46:56 +05:45
'password' => $this -> featureContext -> getActualPassword ( $bodyRows [ 'password' ]),
2024-01-02 16:53:47 +05:45
];
2026-08-13 14:53:57 +05:45
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( $user )[ 'token' ][ 'accessToken' ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2025-02-12 12:43:32 +05:45
$response = GraphHelper :: createLinkShare (
2024-01-02 16:53:47 +05:45
$this -> featureContext -> getBaseUrl (),
$user ,
2026-08-13 14:53:57 +05:45
$password ,
2024-01-02 16:53:47 +05:45
$spaceId ,
$itemId ,
2025-06-19 15:34:02 +05:45
\json_encode ( $body ),
2026-08-13 14:53:57 +05:45
$headers ,
$isVault ,
2024-01-02 16:53:47 +05:45
);
2025-02-12 12:43:32 +05:45
if ( $response -> getStatusCode () == 200 ) {
$this -> featureContext -> shareNgAddToCreatedLinkShares ( $response );
}
return $response ;
2024-01-02 16:53:47 +05:45
}
2024-05-08 14:22:52 +05:45
/**
* Create link share of drive (space) using drives.root endpoint
*
* @param string $user
2024-05-08 15:25:42 +05:45
* @param TableNode $body
2024-05-08 14:22:52 +05:45
*
* @return ResponseInterface
* @throws Exception
* @throws GuzzleException
*/
public function createDriveLinkShare ( string $user , TableNode $body ) : ResponseInterface {
$bodyRows = $body -> getRowsHash ();
$space = $bodyRows [ 'space' ];
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
2025-01-21 11:54:57 +05:45
$permissionsRole = $bodyRows [ 'permissionsRole' ];
2024-06-13 16:39:56 +05:45
$bodyRows [ 'quickLink' ] = $bodyRows [ 'quickLink' ] ?? false ;
2024-05-08 14:22:52 +05:45
$bodyRows [ 'displayName' ] = $bodyRows [ 'displayName' ] ?? null ;
$bodyRows [ 'expirationDateTime' ] = $bodyRows [ 'expirationDateTime' ] ?? null ;
$bodyRows [ 'password' ] = $bodyRows [ 'password' ] ?? null ;
2025-01-21 11:54:57 +05:45
$type = GraphHelper :: SHARING_LINK_TYPE_MAPPINGS [ $permissionsRole ] ?? $permissionsRole ;
2024-05-08 14:22:52 +05:45
$body = [
2025-01-21 11:54:57 +05:45
'type' => $type ,
2024-06-13 16:39:56 +05:45
"@libre.graph.quickLink" => filter_var ( $bodyRows [ 'quickLink' ], FILTER_VALIDATE_BOOLEAN ),
2024-05-08 14:22:52 +05:45
'displayName' => $bodyRows [ 'displayName' ],
'expirationDateTime' => $bodyRows [ 'expirationDateTime' ],
2025-06-19 10:46:56 +05:45
'password' => $this -> featureContext -> getActualPassword ( $bodyRows [ 'password' ]),
2024-05-08 14:22:52 +05:45
];
return GraphHelper :: createDriveShareLink (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
2025-06-19 15:34:02 +05:45
\json_encode ( $body ),
2024-05-08 14:22:52 +05:45
);
}
2023-12-13 12:34:49 +01:00
/**
* @param string $user
* @param string $space
2024-04-26 15:27:00 +05:45
* @param string|null $resource
2024-12-30 16:41:37 +05:45
* @param string|null $query
2023-12-13 12:34:49 +01:00
*
2024-03-04 16:54:01 +05:45
* @return ResponseInterface
2024-04-26 15:27:00 +05:45
* @throws GuzzleException
2023-12-13 12:34:49 +01:00
*/
2024-12-24 09:30:42 +05:45
public function getPermissionsList (
string $user ,
string $space ,
2024-12-30 16:41:37 +05:45
? string $resource = '' ,
2025-06-19 15:34:02 +05:45
? string $query = null ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2025-04-03 18:32:11 +05:45
if ( $space === "Shares" ) {
$spaceId = $this -> spacesContext -> getSharesRemoteItemParentDriveId ( $user , $resource );
$itemId = $this -> spacesContext -> getSharesRemoteItemId ( $user , $resource );
2023-12-13 12:34:49 +01:00
} else {
2025-04-03 18:32:11 +05:45
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$itemId = $this -> spacesContext -> getResourceId ( $user , $space , $resource );
2023-12-13 12:34:49 +01:00
}
2024-03-04 16:54:01 +05:45
return GraphHelper :: getPermissionsList (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
2024-12-30 16:41:37 +05:45
$itemId ,
2025-06-19 15:34:02 +05:45
$query ,
2024-03-04 16:54:01 +05:45
);
}
2025-09-10 15:57:27 +05:45
/**
* @Given /^user "([^"]*)" has triggered the share expiration notification for (?:folder|file) "([^"]*)"$/
*
* @param string $user
* @param string $resource
*
* @return void
* @throws GuzzleException
*/
public function userHasTriggeredTheShareExpirationNotificationForResource (
string $user ,
string $resource ,
) : void {
$response = $this -> getPermissionsList ( $user , "Personal" , $resource );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
}
2024-03-04 16:54:01 +05:45
/**
2025-04-03 18:32:11 +05:45
* @When /^user "([^"]*)" gets permissions list for (?:folder|file) "([^"]*)" of the space "([^"]*)" using the Graph API$/
2024-03-04 16:54:01 +05:45
*
* @param string $user
* @param string $resource
* @param string $space
*
* @return void
2025-04-03 18:32:11 +05:45
* @throws GuzzleException
2024-03-04 16:54:01 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userGetsPermissionsListForResourceOfTheSpaceUsingTheGraphAPI (
string $user ,
string $resource ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-12-24 09:30:42 +05:45
) : void {
2024-03-04 16:54:01 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> getPermissionsList ( $user , $space , $resource ),
2024-03-04 16:54:01 +05:45
);
}
2025-05-23 10:10:20 +05:45
/**
* @When /^user "([^"]*)" (?:tries to list|lists) the permission for (?:folder|file) "([^"]*)" of the space "([^"]*)" shared via (link|invitation) using the Graph API$/
*
* @param string $user
* @param string $resource
* @param string $space
* @param string $shareMethods
*
* @return void
* @throws GuzzleException
*/
public function userGetsPermissionListForResourceOfTheSpaceUsingTheGraphAPI (
string $user ,
string $resource ,
string $space ,
2025-06-19 15:34:02 +05:45
string $shareMethods ,
2025-05-23 10:10:20 +05:45
) : void {
if ( $shareMethods === 'link' ) {
$permissionId = $this -> featureContext -> shareNgGetLastCreatedLinkShareID ();
} else {
$permissionId = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
}
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$itemId = $this -> spacesContext -> getResourceId ( $user , $space , $resource );
$response = GraphHelper :: getSinglePermissionList (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
$itemId ,
2025-06-19 15:34:02 +05:45
$permissionId ,
2025-05-23 10:10:20 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-03-04 16:54:01 +05:45
/**
2024-04-25 12:26:07 +05:45
* @When /^user "([^"]*)" lists the permissions of space "([^"]*)" using permissions endpoint of the Graph API$/
2024-03-04 16:54:01 +05:45
*
* @param string $user
* @param string $space
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userListsThePermissionsOfSpaceUsingTheGraphApi ( string $user , string $space ) : void {
2025-04-03 18:32:11 +05:45
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$itemId = $this -> spacesContext -> getResourceId ( $user , $space , '' );
2023-12-13 12:34:49 +01:00
$this -> featureContext -> setResponse (
2025-04-03 18:32:11 +05:45
GraphHelper :: getPermissionsList (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
$itemId ,
2025-06-19 15:34:02 +05:45
null ,
),
2023-12-13 12:34:49 +01:00
);
}
2023-12-18 13:08:45 +05:45
2024-04-24 18:07:31 +05:45
/**
* @When /^user "([^"]*)" tries to list the permissions of space "([^"]*)" owned by "([^"]*)" using permissions endpoint of the Graph API$/
*
* @param string $user
* @param string $space
* @param string $spaceOwner
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userTriesToListThePermissionsOfSpaceUsingPermissionsEndpointOfTheGraphApi (
string $user ,
string $space ,
2025-06-19 15:34:02 +05:45
string $spaceOwner ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-24 18:07:31 +05:45
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $spaceOwner , $space ))[ "id" ];
$itemId = $this -> spacesContext -> getResourceId ( $spaceOwner , $space , '' );
2024-04-26 14:20:59 +05:45
2024-04-24 18:07:31 +05:45
$this -> featureContext -> setResponse (
GraphHelper :: getPermissionsList (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
2025-06-19 15:34:02 +05:45
$itemId ,
),
2024-04-24 18:07:31 +05:45
);
}
2023-12-18 13:08:45 +05:45
/**
2024-05-08 14:22:52 +05:45
* share the item (resource) or drive (space) using the drives.permissions endpoint
*
2023-12-18 13:08:45 +05:45
* @param string $user
2024-08-09 15:20:40 +05:45
* @param array $shareInfo
2024-01-31 12:26:49 +05:45
* @param string|null $fileId
2024-11-08 18:30:53 +05:45
* @param bool $federatedShare
2023-12-18 13:08:45 +05:45
*
2024-01-11 11:31:28 +05:45
* @return ResponseInterface
*
* @throws JsonException
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2023-12-18 13:08:45 +05:45
* @throws Exception
*/
2024-11-08 18:30:53 +05:45
public function sendShareInvitation (
string $user ,
array $shareInfo ,
2025-06-24 11:39:50 +02:00
? string $fileId = null ,
2025-06-19 15:34:02 +05:45
bool $federatedShare = false ,
2024-11-08 18:30:53 +05:45
) : ResponseInterface {
2026-07-30 12:07:41 +05:45
$isVault = isset ( $shareInfo [ 'storage' ]) && $shareInfo [ 'storage' ] === 'vault' ;
$space = $this -> spacesContext -> getSpaceByName ( $user , $shareInfo [ 'space' ], $isVault );
2024-01-31 16:26:29 +05:45
$spaceId = $space [ 'id' ];
2023-12-18 13:08:45 +05:45
2024-02-01 09:50:54 +05:45
// $fileId is used for trying to share deleted files
2024-01-31 12:26:49 +05:45
if ( $fileId ) {
$itemId = $fileId ;
2024-01-24 15:45:35 +05:45
} else {
2024-08-09 15:20:40 +05:45
$resource = $shareInfo [ 'resource' ] ?? '' ;
2024-01-31 16:26:29 +05:45
// for a disabled and deleted space, resource id is not accessible, so get resource id from the saved response
2024-08-09 15:20:40 +05:45
if ( $resource === '' && ! \in_array ( $shareInfo [ 'space' ], [ 'Personal' , 'Shares' ])) {
2024-01-31 16:26:29 +05:45
$itemId = $space [ 'fileId' ];
} else {
2026-07-30 12:07:41 +05:45
$itemId = $this -> spacesContext -> getResourceId ( $user , $shareInfo [ 'space' ], $resource , $isVault );
2024-01-31 16:26:29 +05:45
}
2024-01-24 15:45:35 +05:45
}
2023-12-18 13:08:45 +05:45
2024-04-26 15:27:00 +05:45
$shareeIds = [];
2024-08-09 15:20:40 +05:45
if ( \array_key_exists ( 'shareeId' , $shareInfo )) {
$shareeIds [] = $shareInfo [ 'shareeId' ];
$shareTypes [] = $shareInfo [ 'shareType' ];
2024-01-24 14:34:06 +05:45
} else {
2024-08-09 15:20:40 +05:45
$sharees = array_map ( 'trim' , explode ( ',' , $shareInfo [ 'sharee' ]));
$shareTypes = array_map ( 'trim' , explode ( ',' , $shareInfo [ 'shareType' ]));
2024-01-24 14:34:06 +05:45
2024-04-18 17:28:38 +05:45
foreach ( $sharees as $index => $sharee ) {
$shareType = $shareTypes [ $index ];
$shareeId = "" ;
if ( $shareType === "user" ) {
$shareeId = $this -> featureContext -> getAttributeOfCreatedUser ( $sharee , 'id' );
2024-11-08 18:30:53 +05:45
if ( $federatedShare ) {
2024-12-24 09:30:42 +05:45
$shareeId = (
$this -> featureContext -> ocmContext -> getAcceptedUserByName (
$user ,
2025-06-19 15:34:02 +05:45
$sharee ,
2024-12-24 09:30:42 +05:45
)
)[ 'user_id' ];
2024-09-24 15:59:10 +02:00
}
2024-04-18 17:28:38 +05:45
} elseif ( $shareType === "group" ) {
$shareeId = $this -> featureContext -> getAttributeOfCreatedGroup ( $sharee , 'id' );
}
// for non-existing group or user, generate random id
$shareeIds [] = $shareeId ?: WebDavHelper :: generateUUIDv4 ();
2024-01-24 14:34:06 +05:45
}
2024-01-15 11:53:08 +05:45
}
2023-12-18 13:08:45 +05:45
2024-08-09 15:20:40 +05:45
$permissionsRole = $shareInfo [ 'permissionsRole' ] ?? null ;
$permissionsAction = $shareInfo [ 'permissionsAction' ] ?? null ;
$expirationDateTime = $shareInfo [ "expirationDateTime" ] ?? null ;
2023-12-21 15:47:37 +05:45
2026-07-30 12:07:41 +05:45
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( $user )[ 'token' ][ 'accessToken' ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2024-01-11 11:31:28 +05:45
$response = GraphHelper :: sendSharingInvitation (
$this -> featureContext -> getBaseUrl (),
$user ,
2026-07-30 12:07:41 +05:45
$password ,
2024-01-11 11:31:28 +05:45
$spaceId ,
$itemId ,
2024-01-15 11:53:08 +05:45
$shareeIds ,
$shareTypes ,
2024-01-11 11:31:28 +05:45
$permissionsRole ,
$permissionsAction ,
2025-06-19 15:34:02 +05:45
$expirationDateTime ,
2026-07-30 12:07:41 +05:45
$headers ,
$isVault ,
2024-01-11 11:31:28 +05:45
);
if ( $response -> getStatusCode () === 200 ) {
2025-06-12 10:59:16 +05:45
$this -> featureContext -> shareNgAddToCreatedUserGroupShares (
$response ,
$shareInfo [ 'resource' ] ?? '' ,
$shareInfo [ 'space' ],
);
2024-01-11 11:31:28 +05:45
}
return $response ;
}
/**
2024-05-08 14:22:52 +05:45
* share the drive (space) using the drives.root endpoint
*
* @param string $user
2025-09-22 13:50:45 +05:45
* @param array $rows
2024-11-08 18:30:53 +05:45
* @param bool $federatedShare
2024-05-08 14:22:52 +05:45
*
* @return ResponseInterface
*
* @throws JsonException
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function sendDriveShareInvitation (
string $user ,
2025-09-22 13:50:45 +05:45
array $rows ,
2025-06-19 15:34:02 +05:45
bool $federatedShare = false ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2024-05-08 14:22:52 +05:45
$shareeIds = [];
2026-07-30 12:07:41 +05:45
$isVault = isset ( $rows [ 'storage' ]) && $rows [ 'storage' ] === 'vault' ;
$space = $this -> spacesContext -> getSpaceByName ( $user , $rows [ 'space' ], $isVault );
2024-05-08 14:22:52 +05:45
$spaceId = $space [ 'id' ];
$sharees = array_map ( 'trim' , explode ( ',' , $rows [ 'sharee' ]));
$shareTypes = array_map ( 'trim' , explode ( ',' , $rows [ 'shareType' ]));
foreach ( $sharees as $index => $sharee ) {
$shareType = $shareTypes [ $index ];
if ( $sharee === "" ) {
// set empty value to $shareeIds
$shareeIds [] = "" ;
continue ;
}
$shareeId = "" ;
if ( $shareType === "user" ) {
$shareeId = $this -> featureContext -> getAttributeOfCreatedUser ( $sharee , 'id' );
2024-11-08 18:30:53 +05:45
if ( $federatedShare ) {
2024-10-02 17:45:26 +02:00
$shareeId = ( $this -> featureContext -> ocmContext -> getAcceptedUserByName ( $user , $sharee ))[ 'user_id' ];
}
2024-05-08 14:22:52 +05:45
} elseif ( $shareType === "group" ) {
$shareeId = $this -> featureContext -> getAttributeOfCreatedGroup ( $sharee , 'id' );
}
// for non-existing group or user, generate random id
$shareeIds [] = $shareeId ?: WebDavHelper :: generateUUIDv4 ();
}
$permissionsRole = $rows [ 'permissionsRole' ] ?? null ;
$permissionsAction = $rows [ 'permissionsAction' ] ?? null ;
2024-05-30 12:51:05 +05:45
$expirationDateTime = $rows [ "expirationDateTime" ] ?? null ;
2024-05-08 14:22:52 +05:45
2026-07-30 12:07:41 +05:45
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( $user )[ 'token' ][ 'accessToken' ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2024-05-08 14:22:52 +05:45
return GraphHelper :: sendSharingInvitationForDrive (
$this -> featureContext -> getBaseUrl (),
$user ,
2026-07-30 12:07:41 +05:45
$password ,
2024-05-08 14:22:52 +05:45
$spaceId ,
$shareeIds ,
$shareTypes ,
$permissionsRole ,
$permissionsAction ,
2025-06-19 15:34:02 +05:45
$expirationDateTime ,
2026-07-30 12:07:41 +05:45
$headers ,
$isVault ,
2024-05-08 14:22:52 +05:45
);
}
/**
* @Given /^user "([^"]*)" has sent the following resource share invitation:$/
2024-01-11 11:31:28 +05:45
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-01-11 11:31:28 +05:45
*/
2024-05-08 14:22:52 +05:45
public function userHasSentTheFollowingResourceShareInvitation ( string $user , TableNode $table ) : void {
$rows = $table -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should be provided in the data-table while sharing a resource" ,
2024-12-24 09:30:42 +05:45
);
2024-08-09 15:20:40 +05:45
$response = $this -> sendShareInvitation ( $user , $rows );
2024-01-11 11:31:28 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2025-09-22 13:50:45 +05:45
// wait till the share is available to the sharee
if ( $rows [ 'shareType' ] === 'user' && $rows [ 'permissionsRole' ] !== 'Denied' ) {
$status = $this -> featureContext -> getUserAutoSyncSetting ( $rows [ 'sharee' ]) ? "enabled" : "disabled" ;
$resourcePaths = explode ( '/' , $rows [ 'resource' ]);
$resource = array_pop ( $resourcePaths );
$this -> waitAndCheckShareSyncStatus ( $rows [ 'sharee' ], $resource , $status );
}
2024-01-11 11:31:28 +05:45
}
2024-11-08 18:30:53 +05:45
/**
* @Given /^user "([^"]*)" has sent the following resource share invitation to federated user:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userHasSentTheFollowingResourceShareInvitationToFederatedUser (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-08 18:30:53 +05:45
$rows = $table -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should be provided in the data-table while sharing a resource" ,
2024-12-24 09:30:42 +05:45
);
2024-11-08 18:30:53 +05:45
$response = $this -> sendShareInvitation ( $user , $rows , null , true );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
}
2024-01-11 11:31:28 +05:45
/**
2024-05-08 14:22:52 +05:45
* @Given /^user "([^"]*)" has sent the following space share invitation:$/
2024-01-11 11:31:28 +05:45
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-01-11 11:31:28 +05:45
*/
2024-05-08 14:22:52 +05:45
public function userHasSentTheFollowingShareShareInvitation ( string $user , TableNode $table ) : void {
$rows = $table -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayNotHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should not be provided in the data-table while sharing a space" ,
2024-12-24 09:30:42 +05:45
);
2025-09-22 13:50:45 +05:45
$response = $this -> sendDriveShareInvitation ( $user , $table -> getRowsHash ());
2024-05-08 14:22:52 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
}
/**
* @When /^user "([^"]*)" sends the following resource share invitation using the Graph API:$/
* @When /^user "([^"]*)" tries to send the following resource share invitation using the Graph API:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userSendsTheFollowingResourceShareInvitationUsingTheGraphApi ( string $user , TableNode $table ) : void {
$rows = $table -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should be provided in the data-table while sharing a resource" ,
2024-12-24 09:30:42 +05:45
);
2023-12-18 13:08:45 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> sendShareInvitation ( $user , $rows ),
2023-12-18 13:08:45 +05:45
);
}
2023-12-20 17:01:02 +05:45
2024-11-08 18:30:53 +05:45
/**
* @When /^user "([^"]*)" sends the following resource share invitation to federated user using the Graph API:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSendsTheFollowingResourceShareInvitationToFederatedUserUsingTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-08 18:30:53 +05:45
$rows = $table -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should be provided in the data-table while sharing a resource" ,
2024-12-24 09:30:42 +05:45
);
2024-11-08 18:30:53 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> sendShareInvitation ( $user , $rows , null , true ),
2024-11-08 18:30:53 +05:45
);
}
2025-02-20 14:51:30 +05:45
/**
* @When user :user sends the following concurrent resource share invitations to federated user using the Graph API:
*
* @param string $user
* @param TableNode $table
*
* @return void
*/
public function userSendsTheFollowingResourcesShareInvitationConcurrentlyToFederatedUserUsingTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2025-02-20 14:51:30 +05:45
) : void {
$results = $this -> sendConcurrentShareInvitation ( $user , $table );
foreach ( $results as $result ) {
$this -> featureContext -> pushToLastHttpStatusCodesArray (( string ) $result -> getStatusCode ());
}
}
/**
* @param string $user
* @param TableNode $table
*
* @return array
* @throws GuzzleException
* @throws JsonException
*/
public function sendConcurrentShareInvitation ( string $user , TableNode $table ) : array {
$table = $table -> getColumnsHash ();
foreach ( $table as $shareInfo ) {
$space = $this -> spacesContext -> getSpaceByName ( $user , $shareInfo [ 'space' ]);
$spaceId = $space [ 'id' ];
$resource = $shareInfo [ 'resource' ] ?? '' ;
$itemId = $this -> spacesContext -> getResourceId ( $user , $shareInfo [ 'space' ], $resource );
$shareeId = (
$this -> featureContext -> ocmContext -> getAcceptedUserByName (
$user ,
2025-06-19 15:34:02 +05:45
$shareInfo [ "sharee" ],
2025-02-20 14:51:30 +05:45
)
)[ 'user_id' ];
$shareType = $shareInfo [ 'shareType' ];
$permissionsRole = $shareInfo [ 'permissionsRole' ] ?? null ;
$roleId = GraphHelper :: getPermissionsRoleIdByName ( $permissionsRole );
$body = [];
$body [ 'recipients' ][] = [
"@libre.graph.recipient.type" => $shareType ,
2025-06-19 10:46:56 +05:45
"objectId" => $shareeId ,
2025-02-20 14:51:30 +05:45
];
$body [ 'roles' ] = [ $roleId ];
$fullUrl = GraphHelper :: getBetaFullUrl (
$this -> featureContext -> getBaseUrl (),
2025-06-19 15:34:02 +05:45
"drives/ $spaceId /items/ $itemId /invite" ,
2025-02-20 14:51:30 +05:45
);
$request = HttpRequestHelper :: createRequest (
$fullUrl ,
"POST" ,
[ 'Content-Type' => 'application/json' ],
2025-06-19 15:34:02 +05:45
\json_encode ( $body ),
2025-02-20 14:51:30 +05:45
);
$requests [] = $request ;
}
$client = HttpRequestHelper :: createClient (
$this -> featureContext -> getActualUsername ( $user ),
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
2025-02-20 14:51:30 +05:45
);
return HttpRequestHelper :: sendBatchRequest ( $requests , $client );
}
2024-02-02 17:50:41 +05:45
/**
2024-05-08 14:22:52 +05:45
* @When /^user "([^"]*)" sends the following space share invitation using permissions endpoint of the Graph API:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSendsTheFollowingSpaceShareInvitationUsingPermissionsEndpointOfTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-08 14:22:52 +05:45
$rows = $table -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayNotHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should not be provided in the data-table while sharing a space" ,
2024-12-24 09:30:42 +05:45
);
2024-05-08 14:22:52 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> sendShareInvitation ( $user , $rows ),
2024-05-08 14:22:52 +05:45
);
}
2024-11-08 18:30:53 +05:45
/**
* @When /^user "([^"]*)" tries to send the following space share invitation to federated user using permissions endpoint of the Graph API:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSendsTheFollowingSpaceShareInvitationToFederatedUserUsingPermissionsEndpointOfTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-08 18:30:53 +05:45
$rows = $table -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayNotHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should not be provided in the data-table while sharing a space" ,
2024-12-24 09:30:42 +05:45
);
2024-11-08 18:30:53 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> sendShareInvitation ( $user , $rows , null , true ),
2024-11-08 18:30:53 +05:45
);
}
2024-05-08 14:22:52 +05:45
/**
2024-11-21 15:31:42 +05:45
* @Given user :user has updated the last resource share with the following properties:
2024-02-02 17:50:41 +05:45
*
* @param string $user
* @param TableNode $table
*
* @return void
*/
2024-11-21 15:31:42 +05:45
public function userHasUpdatedTheLastResourceShareWithTheFollowingProperties ( string $user , TableNode $table ) : void {
$permissionID = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
$response = $this -> updateResourceShare (
$user ,
2025-06-12 10:59:16 +05:45
$table -> getRowsHash (),
2025-06-19 15:34:02 +05:45
$permissionID ,
2024-11-21 15:31:42 +05:45
);
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "Expected response status code should be 200" , $response );
}
2025-06-12 10:59:16 +05:45
/**
* @Given user :user has updated the following resource share:
*
* @param string $user
* @param TableNode $table
*
* @return void
*/
public function userHasUpdatedTheFollowingResourceShare ( string $user , TableNode $table ) : void {
$updateInfo = $table -> getRowsHash ();
$share = $this -> featureContext -> shareNgGetCreatedUserGroupShare (
$user ,
$updateInfo [ "sharee" ],
$updateInfo [ "space" ],
$updateInfo [ "resource" ],
);
$response = $this -> updateResourceShare (
$user ,
$updateInfo ,
$share [ "id" ],
);
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "Failed to update share" , $response );
}
2024-11-21 15:31:42 +05:45
/**
* @When user :user updates the last resource share with the following properties using the Graph API:
*
* @param string $user
* @param TableNode $table
*
* @return void
*/
2025-06-19 12:15:41 +05:45
public function userUpdatesTheLastShareWithFollowingPropertiesUsingGraphApi ( $user , TableNode $table ) : void {
2024-11-21 15:31:42 +05:45
$permissionID = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
2024-02-02 17:50:41 +05:45
$this -> featureContext -> setResponse (
2024-02-08 14:52:22 +05:45
$this -> updateResourceShare (
2024-02-02 17:50:41 +05:45
$user ,
2025-06-12 10:59:16 +05:45
$table -> getRowsHash (),
2025-06-19 15:34:02 +05:45
$permissionID ,
),
2024-02-02 17:50:41 +05:45
);
}
2024-05-08 14:22:52 +05:45
/**
* @When /^user "([^"]*)" updates the space share for (user|group) "([^"]*)" with the following using the Graph API:$/
*
* @param string $user
* @param string $shareType
* @param string $sharee
* @param TableNode $table
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userUpdatesTheSpaceShareForUserOrGroupWithFollowingUsingGraphApi (
string $user ,
string $shareType ,
string $sharee ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2025-06-19 12:15:41 +05:45
) : void {
2024-05-08 14:22:52 +05:45
$permissionID = "" ;
if ( $shareType === "user" ) {
$permissionID = "u:" . $this -> featureContext -> getAttributeOfCreatedUser ( $sharee , 'id' );
} elseif ( $shareType === "group" ) {
$permissionID = "g:" . $this -> featureContext -> getAttributeOfCreatedGroup ( $sharee , 'id' );
}
$this -> featureContext -> setResponse (
$this -> updateResourceShare (
$user ,
2025-06-12 10:59:16 +05:45
$table -> getRowsHash (),
2025-06-19 15:34:02 +05:45
$permissionID ,
),
2024-05-08 14:22:52 +05:45
);
}
2024-02-08 14:52:22 +05:45
/**
* @param string $user
2025-06-12 10:59:16 +05:45
* @param array $updateInfo
2024-02-08 14:52:22 +05:45
* @param string $permissionID
*
* @return ResponseInterface
*/
2025-06-12 10:59:16 +05:45
public function updateResourceShare ( string $user , array $updateInfo , string $permissionID ) : ResponseInterface {
$space = $this -> spacesContext -> getSpaceByName ( $user , $updateInfo [ 'space' ]);
2024-04-30 09:19:45 +05:45
$spaceId = $space [ "id" ];
// for updating role of project space shared, we do not need to provide resource
2025-06-12 10:59:16 +05:45
$resource = $updateInfo [ 'resource' ] ?? '' ;
if ( $resource === '' && ! \in_array ( $updateInfo [ 'space' ], [ 'Personal' , 'Shares' ])) {
2024-04-30 09:19:45 +05:45
$itemId = $space [ 'fileId' ];
} else {
2025-06-12 10:59:16 +05:45
$itemId = $this -> spacesContext -> getResourceId ( $user , $updateInfo [ 'space' ], $resource );
2024-04-30 09:19:45 +05:45
}
2024-02-08 14:52:22 +05:45
$body = [];
2025-06-12 10:59:16 +05:45
if ( \array_key_exists ( 'permissionsRole' , $updateInfo )) {
$body [ 'roles' ] = [ GraphHelper :: getPermissionsRoleIdByName ( $updateInfo [ 'permissionsRole' ])];
2024-02-08 14:52:22 +05:45
}
2025-06-12 10:59:16 +05:45
if ( \array_key_exists ( 'expirationDateTime' , $updateInfo )) {
$body [ 'expirationDateTime' ] = empty ( $updateInfo [ 'expirationDateTime' ])
? null : $updateInfo [ 'expirationDateTime' ];
2024-02-08 14:52:22 +05:45
}
2025-06-19 12:12:17 +05:45
$response = GraphHelper :: updateShare (
2024-02-08 14:52:22 +05:45
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
$itemId ,
\json_encode ( $body ),
2025-06-19 15:34:02 +05:45
$permissionID ,
2024-02-08 14:52:22 +05:45
);
2025-02-12 12:43:32 +05:45
if ( $response -> getStatusCode () === 200 ) {
2025-02-14 15:18:01 +05:45
$this -> featureContext -> shareNgUpdateCreatedUserGroupShare ( $permissionID , $response );
2025-02-12 12:43:32 +05:45
}
return $response ;
2024-02-08 14:52:22 +05:45
}
2024-01-31 12:26:49 +05:45
/**
* @When user :user sends the following share invitation with file-id :fileId using the Graph API:
*
* @param string $user
* @param string $fileId
* @param TableNode $table
*
* @return void
* @throws JsonException
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-01-31 12:26:49 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userSendsTheFollowingShareInvitationWithFileIdUsingTheGraphApi (
string $user ,
string $fileId ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-08-09 15:20:40 +05:45
$rows = $table -> getRowsHash ();
2024-01-31 12:26:49 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> sendShareInvitation ( $user , $rows , $fileId ),
2024-01-31 12:26:49 +05:45
);
}
2023-12-20 17:01:02 +05:45
/**
2024-05-08 14:22:52 +05:45
* @When /^user "([^"]*)" creates the following resource link share using the Graph API:$/
2023-12-20 17:01:02 +05:45
*
* @param string $user
2024-05-08 15:25:42 +05:45
* @param TableNode $body
2023-12-20 17:01:02 +05:45
*
* @return void
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2023-12-20 17:01:02 +05:45
*/
2025-06-19 12:12:17 +05:45
public function userCreatesAPublicLinkShareWithSettings ( string $user , TableNode $body ) : void {
2024-01-02 16:53:47 +05:45
$response = $this -> createLinkShare ( $user , $body );
$this -> featureContext -> setResponse ( $response );
}
2024-05-29 16:06:26 +05:45
/**
* @When /^user "([^"]*)" (?:tries to create|creates) the following space link share using permissions endpoint of the Graph API:$/
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userCreatesTheFollowingSpaceLinkShareUsingPermissionsEndpointOfTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-29 16:06:26 +05:45
$this -> featureContext -> setResponse ( $this -> createLinkShare ( $user , $body ));
}
2025-04-02 12:46:36 +05:45
/**
* @Given user :user has created the following space link share using permissions endpoint of the Graph API:
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws GuzzleException
*/
public function userHasCreatedTheFollowingSpaceLinkShareUsingPermissionsEndpointOfTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $body ,
2025-04-02 12:46:36 +05:45
) : void {
$response = $this -> createLinkShare ( $user , $body );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "Failed while creating public share link!" , $response );
}
2024-01-02 16:53:47 +05:45
/**
2024-05-08 14:22:52 +05:45
* @Given /^user "([^"]*)" has created the following resource link share:$/
2024-01-02 16:53:47 +05:45
*
* @param string $user
2024-05-08 15:25:42 +05:45
* @param TableNode $body
2024-01-02 16:53:47 +05:45
*
* @return void
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-01-02 16:53:47 +05:45
*/
2025-06-19 12:12:17 +05:45
public function userHasCreatedTheFollowingResourceLinkShare ( string $user , TableNode $body ) : void {
2024-05-08 14:22:52 +05:45
$rows = $body -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should be provided in the data-table while sharing a resource" ,
2024-12-24 09:30:42 +05:45
);
2024-01-02 16:53:47 +05:45
$response = $this -> createLinkShare ( $user , $body );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "Failed while creating public share link!" , $response );
}
2024-05-08 14:22:52 +05:45
/**
* @Given /^user "([^"]*)" has created the following space link share:$/
*
* @param string $user
2024-05-08 15:25:42 +05:45
* @param TableNode $body
2024-05-08 14:22:52 +05:45
*
* @return void
* @throws GuzzleException
*/
2025-06-19 12:12:17 +05:45
public function userHasCreatedTheFollowingLinkShare ( string $user , TableNode $body ) : void {
2024-05-08 14:22:52 +05:45
$rows = $body -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayNotHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should not be provided in the data-table while sharing a space" ,
2024-12-24 09:30:42 +05:45
);
2024-05-08 14:22:52 +05:45
$response = $this -> createDriveLinkShare ( $user , $body );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "Failed while creating public share link!" , $response );
$this -> featureContext -> shareNgAddToCreatedLinkShares ( $response );
}
2024-05-17 12:19:09 +05:45
/**
2024-11-21 15:31:42 +05:45
* @Given user :user has updated the last resource/space link share with
2024-05-17 12:19:09 +05:45
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws Exception|GuzzleException
*/
2025-06-19 12:12:17 +05:45
public function userHasUpdatedLastPublicLinkShare ( string $user , TableNode $body ) : void {
2024-05-17 12:19:09 +05:45
$response = $this -> updateLinkShare (
$user ,
$body ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> shareNgGetLastCreatedLinkShareID (),
2024-05-17 12:19:09 +05:45
);
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "Failed while updating public share link!" , $response );
}
2024-01-02 16:53:47 +05:45
/**
2024-05-31 12:36:26 +05:45
* @When user :user updates the last public link share using the permissions endpoint of the Graph API:
2024-01-02 16:53:47 +05:45
*
* @param string $user
2024-05-08 15:25:42 +05:45
* @param TableNode $body
2024-01-02 16:53:47 +05:45
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userUpdatesTheLastPublicLinkShareUsingThePermissionsEndpointOfTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2024-02-02 17:50:41 +05:45
$this -> featureContext -> setResponse (
2024-02-08 14:52:22 +05:45
$this -> updateLinkShare (
2024-02-02 17:50:41 +05:45
$user ,
$body ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> shareNgGetLastCreatedLinkShareID (),
),
2024-02-02 17:50:41 +05:45
);
}
/**
* @param string $user
* @param TableNode $body
* @param string $permissionID
*
* @return ResponseInterface
2024-05-17 12:19:09 +05:45
* @throws GuzzleException
2024-02-02 17:50:41 +05:45
*/
2025-06-19 12:12:17 +05:45
public function updateLinkShare ( string $user , TableNode $body , string $permissionID ) : ResponseInterface {
2023-12-20 17:01:02 +05:45
$bodyRows = $body -> getRowsHash ();
$space = $bodyRows [ 'space' ];
2024-05-31 12:36:26 +05:45
if ( isset ( $bodyRows [ 'resource' ])) {
$itemId = $this -> spacesContext -> getResourceId ( $user , $space , $bodyRows [ 'resource' ]);
} else {
$itemId = $this -> spacesContext -> getResourceId ( $user , $space , $space );
}
2024-02-21 14:54:40 +05:45
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ 'id' ];
2024-02-08 14:52:22 +05:45
$body = [];
2023-12-20 17:01:02 +05:45
2024-02-08 14:52:22 +05:45
if ( \array_key_exists ( 'permissionsRole' , $bodyRows )) {
2025-01-10 12:20:47 +05:45
$body [ 'link' ][ 'type' ] = GraphHelper :: SHARING_LINK_TYPE_MAPPINGS [ $bodyRows [ 'permissionsRole' ]];
2024-02-08 14:52:22 +05:45
}
if ( \array_key_exists ( 'expirationDateTime' , $bodyRows )) {
2024-12-24 09:30:42 +05:45
$body [ 'expirationDateTime' ] = empty ( $bodyRows [ 'expirationDateTime' ])
? null : $bodyRows [ 'expirationDateTime' ];
2024-01-02 16:53:47 +05:45
}
2023-12-20 17:01:02 +05:45
2024-05-17 12:19:09 +05:45
if ( \array_key_exists ( 'displayName' , $bodyRows )) {
$body [ 'displayName' ] = $bodyRows [ 'displayName' ];
}
2025-02-12 12:43:32 +05:45
$response = GraphHelper :: updateShare (
2024-01-05 13:57:59 +05:45
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
$itemId ,
\json_encode ( $body ),
2025-06-19 15:34:02 +05:45
$permissionID ,
2024-01-05 13:57:59 +05:45
);
2025-02-12 12:43:32 +05:45
if ( $response -> getStatusCode () === 200 ) {
2025-02-14 15:18:01 +05:45
$this -> featureContext -> shareNgUpdatedCreatedLinkShare ( $permissionID , $response );
2025-02-12 12:43:32 +05:45
}
return $response ;
2024-01-05 13:57:59 +05:45
}
/**
* @param string $user
2024-05-08 15:25:42 +05:45
* @param TableNode $body
2024-05-17 12:19:09 +05:45
* @param string $permissionID
2024-01-05 13:57:59 +05:45
*
2024-05-17 12:19:09 +05:45
* @return ResponseInterface
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-01-05 13:57:59 +05:45
*/
2025-06-19 12:12:17 +05:45
public function setLinkSharePassword ( string $user , TableNode $body , string $permissionID ) : ResponseInterface {
2024-01-05 13:57:59 +05:45
$bodyRows = $body -> getRowsHash ();
$space = $bodyRows [ 'space' ];
$resource = $bodyRows [ 'resource' ];
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
2024-02-09 14:02:38 +05:45
$itemId = $this -> spacesContext -> getResourceId ( $user , $space , $resource );
2024-01-05 13:57:59 +05:45
if ( \array_key_exists ( 'password' , $bodyRows )) {
$body = [
"password" => $this -> featureContext -> getActualPassword ( $bodyRows [ 'password' ]),
];
} else {
throw new Error ( 'Password is missing to set for share link!' );
}
2025-02-12 12:43:32 +05:45
$response = GraphHelper :: setLinkSharePassword (
2024-01-05 13:57:59 +05:45
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
$itemId ,
\json_encode ( $body ),
2025-06-19 15:34:02 +05:45
$permissionID ,
2024-05-17 12:19:09 +05:45
);
2025-02-12 12:43:32 +05:45
if ( $response -> getStatusCode () === 200 ) {
2025-02-14 15:18:01 +05:45
$this -> featureContext -> shareNgUpdatedCreatedLinkShare ( $permissionID , $response );
2025-02-12 12:43:32 +05:45
}
return $response ;
2024-05-17 12:19:09 +05:45
}
/**
* @Given user :user has set the following password for the last link share:
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws Exception
*/
2025-06-19 12:12:17 +05:45
public function userHasSetTheFollowingPasswordForTheLastLinkShare ( string $user , TableNode $body ) : void {
2024-05-17 12:19:09 +05:45
$response = $this -> setLinkSharePassword (
$user ,
$body ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> shareNgGetLastCreatedLinkShareID (),
2023-12-20 17:01:02 +05:45
);
2024-12-24 09:30:42 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Failed while setting public share link password!" ,
2025-06-19 15:34:02 +05:45
$response ,
2024-12-24 09:30:42 +05:45
);
2024-05-17 12:19:09 +05:45
}
/**
* @When user :user sets the following password for the last link share using the Graph API:
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userSetsOrUpdatesFollowingPasswordForLastLinkShareUsingTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-17 12:19:09 +05:45
$this -> featureContext -> setResponse (
$this -> setLinkSharePassword (
$user ,
$body ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> shareNgGetLastCreatedLinkShareID (),
),
2024-05-17 12:19:09 +05:45
);
2023-12-20 17:01:02 +05:45
}
2024-01-11 11:31:28 +05:45
/**
2024-05-08 14:22:52 +05:45
* Remove user|group|link share of item (resource) or drive (space) using drives.permissions endpoint
*
2024-01-11 11:31:28 +05:45
* @param string $sharer
2024-04-11 09:20:00 +02:00
* @param string $shareType (user|group|link)
2024-01-11 11:31:28 +05:45
* @param string $space
2024-04-11 09:20:00 +02:00
* @param string|null $resource
* @param string|null $recipient
2024-01-11 11:31:28 +05:45
*
2024-01-12 16:04:10 +05:45
* @return ResponseInterface
* @throws GuzzleException
2024-01-11 11:31:28 +05:45
* @throws JsonException
*/
2024-04-18 11:46:19 +02:00
public function removeAccessToSpaceItem (
2024-01-11 11:31:28 +05:45
string $sharer ,
string $shareType ,
2024-01-12 16:04:10 +05:45
string $space ,
2024-04-11 09:20:00 +02:00
? string $resource = null ,
2025-06-19 15:34:02 +05:45
? string $recipient = null ,
2024-01-12 16:04:10 +05:45
) : ResponseInterface {
2024-01-11 11:31:28 +05:45
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $sharer , $space ))[ "id" ];
2024-12-24 09:30:42 +05:45
$itemId = ( isset ( $resource )) ? $this -> spacesContext -> getResourceId ( $sharer , $space , $resource )
: $this -> spacesContext -> getResourceId ( $sharer , $space , $space );
2024-01-12 16:04:10 +05:45
2024-05-08 14:22:52 +05:45
$permissionID = "" ;
// if resource is not provided then it indicates a space share
// and the space shares are not stored
// so build the permission-id using the user or group id
if ( $resource === null ) {
if ( $shareType === "user" ) {
$permissionID = "u:" . $this -> featureContext -> getAttributeOfCreatedUser ( $recipient , 'id' );
} elseif ( $shareType === "group" ) {
$permissionID = "g:" . $this -> featureContext -> getAttributeOfCreatedGroup ( $recipient , 'id' );
}
} else {
$permissionID = ( $shareType === 'link' )
? $this -> featureContext -> shareNgGetLastCreatedLinkShareID ()
: $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
}
2024-01-12 16:04:10 +05:45
return
2024-04-18 11:46:19 +02:00
GraphHelper :: removeAccessToSpaceItem (
2024-01-11 11:31:28 +05:45
$this -> featureContext -> getBaseUrl (),
$sharer ,
$this -> featureContext -> getPasswordForUser ( $sharer ),
$spaceId ,
$itemId ,
2025-06-19 15:34:02 +05:45
$permissionID ,
2024-01-12 16:04:10 +05:45
);
}
/**
2024-05-08 14:22:52 +05:45
* Remove user|group|link from drive (space) using drives.root endpoint
*
2024-04-18 11:46:19 +02:00
* @param string $sharer
* @param string $shareType (user|group|link)
* @param string $space
* @param string|null $recipient
*
* @return ResponseInterface
* @throws GuzzleException
* @throws JsonException
*/
public function removeAccessToSpace (
string $sharer ,
string $shareType ,
string $space ,
2025-06-19 15:34:02 +05:45
? string $recipient = null ,
2024-04-18 11:46:19 +02:00
) : ResponseInterface {
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $sharer , $space ))[ "id" ];
2024-05-08 09:55:48 +05:45
$permissionID = match ( $shareType ) {
2024-04-29 11:59:08 +02:00
'link' => $this -> featureContext -> shareNgGetLastCreatedLinkShareID (),
'user' => 'u:' . $this -> featureContext -> getAttributeOfCreatedUser ( $recipient , 'id' ),
'group' => 'g:' . $this -> featureContext -> getAttributeOfCreatedGroup ( $recipient , 'id' ),
default => throw new Exception ( "shareType ' $shareType ' does not match user|group|link " ),
};
2024-04-18 11:46:19 +02:00
return
GraphHelper :: removeAccessToSpace (
$this -> featureContext -> getBaseUrl (),
$sharer ,
$this -> featureContext -> getPasswordForUser ( $sharer ),
$spaceId ,
2025-06-19 15:34:02 +05:45
$permissionID ,
2024-04-18 11:46:19 +02:00
);
}
2024-05-09 12:25:57 +05:45
/**
* @Given /^user "([^"]*)" has removed the access of (user|group) "([^"]*)" from (?:file|folder|resource) "([^"]*)" of space "([^"]*)"$/
*
* @param string $sharer
* @param string $recipientType (user|group)
* @param string $recipient can be both user or group
* @param string $resource
* @param string $space
*
* @return void
* @throws JsonException
* @throws GuzzleException
*/
public function userHasRemovedAccessOfUserOrGroupFromResourceOfSpace (
string $sharer ,
string $recipientType ,
string $recipient ,
string $resource ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-05-09 12:25:57 +05:45
) : void {
$response = $this -> removeAccessToSpaceItem ( $sharer , $recipientType , $space , $resource );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 204 , "" , $response );
}
2024-04-18 11:46:19 +02:00
/**
* @When /^user "([^"]*)" removes the access of (user|group) "([^"]*)" from (?:file|folder|resource) "([^"]*)" of space "([^"]*)" using the Graph API$/
2024-01-12 16:04:10 +05:45
*
* @param string $sharer
2024-04-11 09:20:00 +02:00
* @param string $recipientType (user|group)
* @param string $recipient can be both user or group
2024-01-12 16:04:10 +05:45
* @param string $resource
* @param string $space
*
* @return void
* @throws JsonException
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-01-12 16:04:10 +05:45
*/
2024-04-18 11:46:19 +02:00
public function userRemovesAccessOfUserOrGroupFromResourceOfSpaceUsingGraphAPI (
2024-01-12 16:04:10 +05:45
string $sharer ,
2024-04-11 09:20:00 +02:00
string $recipientType ,
string $recipient ,
2024-01-12 16:04:10 +05:45
string $resource ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-01-12 16:04:10 +05:45
) : void {
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> removeAccessToSpaceItem ( $sharer , $recipientType , $space , $resource , $recipient ),
2024-04-11 09:20:00 +02:00
);
}
/**
2024-04-18 11:46:19 +02:00
* @When /^user "([^"]*)" removes the access of (user|group) "([^"]*)" from space "([^"]*)" using permissions endpoint of the Graph API$/
2024-04-11 09:20:00 +02:00
*
* @param string $sharer
* @param string $recipientType (user|group)
* @param string $recipient can be both user or group
* @param string $space
*
* @return void
* @throws JsonException
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-04-11 09:20:00 +02:00
*/
2024-04-18 11:46:19 +02:00
public function userRemovesAccessOfUserOrGroupFromSpaceUsingPermissionsEndpointOfGraphAPI (
2024-04-11 09:20:00 +02:00
string $sharer ,
string $recipientType ,
string $recipient ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-04-11 09:20:00 +02:00
) : void {
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> removeAccessToSpaceItem ( $sharer , $recipientType , $space , null , $recipient ),
2024-01-12 16:04:10 +05:45
);
}
2024-05-17 14:19:53 +05:45
/**
* @When /^user "([^"]*)" has removed the last link share of (?:file|folder) "([^"]*)" from space "([^"]*)"$/
*
* @param string $sharer
* @param string $resource
* @param string $space
*
* @return void
* @throws JsonException
* @throws GuzzleException
*/
public function userHasRemovedTheLastLinkShareOfFileOrFolderFromSpace (
string $sharer ,
string $resource ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-05-17 14:19:53 +05:45
) : void {
$response = $this -> removeAccessToSpaceItem ( $sharer , 'link' , $space , $resource );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 204 , "" , $response );
}
2024-01-12 16:04:10 +05:45
/**
2024-04-18 11:46:19 +02:00
* @When /^user "([^"]*)" removes the link of (?:file|folder) "([^"]*)" from space "([^"]*)" using the Graph API$/
2024-01-12 16:04:10 +05:45
*
* @param string $sharer
* @param string $resource
* @param string $space
*
* @return void
* @throws JsonException
* @throws GuzzleException
*/
public function userRemovesSharePermissionOfAResourceInLinkShareUsingGraphAPI (
string $sharer ,
string $resource ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-12-24 09:30:42 +05:45
) : void {
2024-01-12 16:04:10 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> removeAccessToSpaceItem ( $sharer , 'link' , $space , $resource ),
2024-04-18 11:46:19 +02:00
);
}
/**
* @When /^user "([^"]*)" removes the access of (user|group) "([^"]*)" from space "([^"]*)" using root endpoint of the Graph API$/
2024-04-29 11:59:08 +02:00
* @When /^user "([^"]*)" tries to remove the access of (user|group) "([^"]*)" from space "([^"]*)" using root endpoint of the Graph API$/
2024-04-18 11:46:19 +02:00
*
* @param string $sharer
* @param string $recipientType (user|group)
* @param string $recipient can be both user or group
* @param string $space
*
* @return void
* @throws JsonException
2024-04-26 12:26:26 +05:45
* @throws GuzzleException
2024-04-18 11:46:19 +02:00
*/
public function userRemovesAccessOfUserOrGroupFromSpaceUsingGraphAPI (
string $sharer ,
string $recipientType ,
string $recipient ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-04-18 11:46:19 +02:00
) : void {
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> removeAccessToSpace ( $sharer , $recipientType , $space , $recipient ),
2024-04-18 11:46:19 +02:00
);
}
/**
* @When /^user "([^"]*)" removes the link from space "([^"]*)" using root endpoint of the Graph API$/
*
* @param string $sharer
* @param string $space
*
* @return void
* @throws JsonException
* @throws GuzzleException
*/
public function userRemovesLinkFromSpaceUsingRootEndpointOfGraphAPI (
string $sharer ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-18 11:46:19 +02:00
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> removeAccessToSpace ( $sharer , 'link' , $space ),
2024-01-11 11:31:28 +05:45
);
}
2024-01-17 15:59:55 +05:45
/**
2024-04-29 11:59:08 +02:00
* @Given /^user "([^"]*)" has removed the access of (user|group) "([^"]*)" from space "([^"]*)"$/
*
* @param string $sharer
* @param string $recipientType (user|group)
* @param string $recipient can be both user or group
* @param string $space
*
* @return void
* @throws JsonException
* @throws GuzzleException
*/
public function userHasRemovedAccessOfUserOrGroupFromSpace (
string $sharer ,
string $recipientType ,
string $recipient ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-04-29 11:59:08 +02:00
) : void {
$response = $this -> removeAccessToSpace ( $sharer , $recipientType , $space , $recipient );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 204 , "" , $response );
}
2024-05-06 11:17:35 +05:45
/**
* @param string $sharee
* @param string $shareID
2024-07-29 11:43:05 +02:00
* @param bool $hide
2025-02-18 14:56:05 +05:45
* @param bool $federatedShare
2024-05-06 11:17:35 +05:45
*
* @return ResponseInterface
* @throws GuzzleException
* @throws JsonException
*/
2025-02-18 14:56:05 +05:45
public function hideOrUnhideSharedResource (
string $sharee ,
string $shareID ,
bool $hide = true ,
2025-06-19 15:34:02 +05:45
bool $federatedShare = false ,
2025-02-18 14:56:05 +05:45
) : ResponseInterface {
2024-11-29 16:47:02 +05:45
$shareSpaceId = GraphHelper :: SHARES_SPACE_ID ;
2025-02-18 14:56:05 +05:45
if ( $federatedShare ) {
$itemId = $shareID ;
} else {
$itemId = $shareSpaceId . '!' . $shareID ;
}
2024-07-29 11:43:05 +02:00
$body [ '@UI.Hidden' ] = $hide ;
return GraphHelper :: hideOrUnhideShare (
2024-05-06 11:17:35 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $sharee ),
$this -> featureContext -> getPasswordForUser ( $sharee ),
$itemId ,
$shareSpaceId ,
2025-06-19 15:34:02 +05:45
$body ,
2024-05-06 11:17:35 +05:45
);
}
2024-05-03 12:47:35 +05:45
/**
* @Given user :user has disabled sync of last shared resource
*
* @param string $user
*
* @return void
* @throws Exception|GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userHasDisabledSyncOfLastSharedResource ( string $user ) : void {
2024-05-03 12:47:35 +05:45
$shareItemId = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
2024-11-29 16:47:02 +05:45
$shareSpaceId = GraphHelper :: SHARES_SPACE_ID ;
2024-05-03 12:47:35 +05:45
$itemId = $shareSpaceId . '!' . $shareItemId ;
$response = GraphHelper :: disableShareSync (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
$itemId ,
$shareSpaceId ,
);
2024-12-24 09:30:42 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
204 ,
__METHOD__ . " could not disable sync of last share" ,
2025-06-19 15:34:02 +05:45
$response ,
2024-12-24 09:30:42 +05:45
);
2024-05-03 12:47:35 +05:45
}
2024-03-21 14:03:09 +05:45
/**
2024-04-10 12:53:19 +05:45
* @When user :user disables sync of share :share using the Graph API
2024-05-15 12:58:22 +05:45
* @When user :user tries to disable sync of share :share using the Graph API
2024-03-21 14:03:09 +05:45
*
* @param string $user
*
2024-04-10 12:53:19 +05:45
* @return void
* @throws Exception
2024-03-21 14:03:09 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userDisablesSyncOfShareUsingTheGraphApi ( string $user ) : void {
2024-04-10 12:53:19 +05:45
$shareItemId = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
2024-11-29 16:47:02 +05:45
$shareSpaceId = GraphHelper :: SHARES_SPACE_ID ;
2024-04-10 12:53:19 +05:45
$itemId = $shareSpaceId . '!' . $shareItemId ;
$response = GraphHelper :: disableShareSync (
2024-03-21 14:03:09 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
$itemId ,
$shareSpaceId ,
);
2024-04-10 12:53:19 +05:45
$this -> featureContext -> setResponse ( $response );
2024-03-21 14:03:09 +05:45
$this -> featureContext -> pushToLastStatusCodesArrays ();
2024-04-25 14:55:52 +05:45
// disable check for client.synchronize
$this -> featureContext -> rememberUserAutoSyncSetting ( $user , false );
2024-03-21 14:03:09 +05:45
}
2024-03-26 09:35:09 +05:45
2024-05-06 11:17:35 +05:45
/**
* @When user :user hides the shared resource :sharedResource using the Graph API
*
* @param string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userHidesTheSharedResourceUsingTheGraphApi ( string $user ) : void {
2024-05-06 11:17:35 +05:45
$shareItemId = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
2024-07-29 12:30:05 +02:00
$response = $this -> hideOrUnhideSharedResource ( $user , $shareItemId );
2024-05-06 11:17:35 +05:45
$this -> featureContext -> setResponse ( $response );
}
2025-02-18 14:56:05 +05:45
/**
* @When user :user hides the federated share :share using the Graph API
*
* @param string $user
* @param string $share
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userHidesTheFederatedShareUsingTheGraphApi ( string $user , string $share ) : void {
$remoteItemId = $this -> spacesContext -> getSharesRemoteItemId ( $user , $share );
$response = $this -> hideOrUnhideSharedResource ( $user , $remoteItemId , true , true );
$this -> featureContext -> setResponse ( $response );
}
2024-05-06 11:17:35 +05:45
/**
* @Given user :user has hidden the share :sharedResource
*
* @param string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userHasHiddenTheShare ( string $user ) : void {
2024-05-06 11:17:35 +05:45
$shareItemId = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
2024-07-29 12:30:05 +02:00
$response = $this -> hideOrUnhideSharedResource ( $user , $shareItemId );
2024-05-06 11:17:35 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , '' , $response );
}
2024-07-29 11:43:05 +02:00
/**
* @When user :user unhides the shared resource :sharedResource using the Graph API
*
* @param string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userUnhidesTheSharedResourceUsingTheGraphApi ( string $user ) : void {
2024-07-29 11:43:05 +02:00
$shareItemId = $this -> featureContext -> shareNgGetLastCreatedUserGroupShareID ();
2024-07-29 12:30:05 +02:00
$response = $this -> hideOrUnhideSharedResource ( $user , $shareItemId , false );
2024-07-29 11:43:05 +02:00
$this -> featureContext -> setResponse ( $response );
}
2024-03-26 09:35:09 +05:45
/**
2024-04-10 12:53:19 +05:45
* @When user :user enables sync of share :share offered by :offeredBy from :space space using the Graph API
2024-03-26 09:35:09 +05:45
*
* @param string $user
* @param string $share
* @param string $offeredBy
* @param string $space
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userEnablesSyncOfShareUsingTheGraphApi (
string $user ,
string $share ,
string $offeredBy ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-12-24 09:30:42 +05:45
) : void {
2024-03-26 09:35:09 +05:45
$share = ltrim ( $share , '/' );
$itemId = $this -> spacesContext -> getResourceId ( $offeredBy , $space , $share );
2025-06-19 12:12:17 +05:45
$response = GraphHelper :: enableShareSync (
2024-03-26 09:35:09 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
$itemId ,
);
$this -> featureContext -> setResponse ( $response );
2025-02-18 17:03:41 +05:45
}
/**
* @When user :user enables sync of federated share :share using the Graph API
*
* @param string $user
* @param string $share
*
* @return void
* @throws Exception
*/
public function userEnablesSyncOfFederatedShareUsingTheGraphApi (
string $user ,
string $share ,
) : void {
$remoteItemId = $this -> spacesContext -> getSharesRemoteItemId ( $user , $share );
2025-06-19 12:12:17 +05:45
$response = GraphHelper :: enableShareSync (
2025-02-18 17:03:41 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
$remoteItemId ,
);
$this -> featureContext -> setResponse ( $response );
2024-03-26 09:35:09 +05:45
}
2024-04-05 12:20:09 +05:45
2024-04-17 12:12:51 +05:45
/**
2024-05-15 12:58:22 +05:45
* step definition for enabling sync for items for non-existing group|user|space sharer
*
2024-04-26 14:20:59 +05:45
* @When user :user tries to enable share sync of a resource :resource using the Graph API
2024-05-15 12:58:22 +05:45
* @When user :user enables share sync of a resource :resource using the Graph API
2024-04-17 12:12:51 +05:45
*
* @param string $user
2024-04-26 14:20:59 +05:45
* @param string $resource
2024-04-17 12:12:51 +05:45
*
* @return void
2024-04-26 14:20:59 +05:45
* @throws Exception|GuzzleException
2024-04-17 12:12:51 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userTriesToEnableShareSyncOfResourceUsingTheGraphApi ( string $user , string $resource ) : void {
2024-04-29 12:58:31 +05:45
$itemId = ( $resource === 'nonexistent' ) ? WebDavHelper :: generateUUIDv4 () : $resource ;
2024-04-26 14:20:59 +05:45
2025-06-19 12:12:17 +05:45
$response = GraphHelper :: enableShareSync (
2024-04-17 12:12:51 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
2024-05-28 15:36:09 +05:45
$itemId ,
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When user :user tries to disable share sync of a resource :resource using the Graph API
*
* @param string $user
* @param string $resource
*
* @return void
* @throws Exception|GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToDisableShareSyncOfResourceUsingTheGraphApi ( string $user , string $resource ) : void {
2024-11-29 16:47:02 +05:45
$shareSpaceId = GraphHelper :: SHARES_SPACE_ID ;
2024-05-28 15:36:09 +05:45
$shareID = ( $resource === 'nonexistent' ) ? WebDavHelper :: generateUUIDv4 () : $resource ;
$itemId = $shareSpaceId . '!' . $shareID ;
2025-06-19 12:12:17 +05:45
$response = GraphHelper :: disableShareSync (
2024-05-28 15:36:09 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getActualUsername ( $user ),
$this -> featureContext -> getPasswordForUser ( $user ),
2024-04-26 14:20:59 +05:45
$itemId ,
2025-06-19 15:34:02 +05:45
$shareSpaceId ,
2024-04-17 12:12:51 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-06-24 18:02:40 +05:45
/**
* @param string $user
* @param string $resource
2026-08-24 12:01:48 +05:45
* @param boolean $isVault
2024-06-24 18:02:40 +05:45
*
* @return void
* @throws GuzzleException
*/
2026-08-24 12:01:48 +05:45
public function isShareSynced ( string $user , string $resource , bool $isVault = false ) : bool {
2024-06-24 18:02:40 +05:45
$resource = \trim ( $resource , '/' );
2026-08-24 12:01:48 +05:45
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( $user )[ 'token' ][ 'accessToken' ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$user = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $user );
}
2024-06-24 18:02:40 +05:45
$response = GraphHelper :: getSharesSharedWithMe (
$this -> featureContext -> getBaseUrl (),
$user ,
2026-08-24 12:01:48 +05:45
$password ,
$headers ,
$isVault ,
2024-06-24 18:02:40 +05:45
);
$shares = $this -> featureContext -> getJsonDecodedResponse ( $response )[ "value" ];
$syncStatus = false ;
foreach ( $shares as $share ) {
if ( $share [ "name" ] === $resource ) {
$syncStatus = $share [ "@client.synchronize" ];
break ;
}
}
2024-06-24 18:42:04 +05:45
Assert :: assertIsBool ( $syncStatus , "'@client.synchronize' must be a boolean value" );
2024-06-24 18:40:22 +05:45
return $syncStatus ;
2024-06-24 18:02:40 +05:45
}
/**
* @param string $user
* @param string $resource
2024-06-24 18:37:25 +05:45
* @param string $status
2026-08-24 12:01:48 +05:45
* @param boolean $isVault
2024-06-24 18:02:40 +05:45
*
* @return void
2024-06-24 18:37:25 +05:45
* @throws Exception|GuzzleException
2024-06-24 18:02:40 +05:45
*/
2026-08-24 12:01:48 +05:45
public function waitAndCheckShareSyncStatus (
string $user ,
string $resource ,
string $status ,
bool $isVault = false ,
) : void {
2024-06-24 18:37:25 +05:45
$expected = $status === "enabled" ;
2024-06-24 18:02:40 +05:45
2024-06-24 18:37:25 +05:45
// NOTE: Sharing is async so it might take some time for the share to be available.
2024-06-24 18:02:40 +05:45
$retried = 0 ;
do {
2026-08-24 12:01:48 +05:45
$shareSynced = $this -> isShareSynced ( $user , $resource , $isVault );
2024-06-24 18:02:40 +05:45
2024-06-24 18:37:25 +05:45
if ( $shareSynced === $expected ) {
return ;
}
2025-02-17 17:44:48 +05:45
$tryAgain = ! $shareSynced && $retried < HttpRequestHelper :: maxHTTPRequestRetries ();
2024-06-24 18:02:40 +05:45
if ( $tryAgain ) {
$retried += 1 ;
2024-06-24 18:37:25 +05:45
echo "[INFO] Wait for share sync status..." ;
2024-06-24 18:02:40 +05:45
// wait 500ms and try again
\usleep ( 500 * 1000 );
}
} while ( $tryAgain );
2024-06-24 18:37:25 +05:45
Assert :: fail ( "[Timeout] Sync for share ' $resource ' was expected to be ' $status ' but was not" );
}
2024-06-24 18:02:40 +05:45
2024-06-24 18:37:25 +05:45
/**
2025-03-19 13:17:07 +05:45
* @Given /^user "([^"]*)" has a share "([^"]*)" synced$/
2024-06-24 18:37:25 +05:45
*
* @param string $user
* @param string $resource
*
* @return void
* @throws Exception|GuzzleException
*/
public function userHasShareSynced ( string $user , string $resource ) : void {
$this -> waitAndCheckShareSyncStatus ( $user , $resource , "enabled" );
2024-06-24 18:02:40 +05:45
}
2026-08-24 12:01:48 +05:45
/**
* @Then /^user "([^"]*)" should have a share(| in vault)? "([^"]*)" synced$/
*
* @param string $user
* @param string $isVault
* @param string $resource
*
* @return void
* @throws Exception|GuzzleException
*/
public function userShouldHaveShareSynced ( string $user , string $isVault , string $resource ) : void {
$isVault = trim ( $isVault ) === "in vault" ;
$this -> waitAndCheckShareSyncStatus ( $user , $resource , "enabled" , $isVault );
}
2024-04-05 12:20:09 +05:45
/**
* @Then /^user "([^"]*)" should have sync (enabled|disabled) for share "([^"]*)"$/
*
* @param string $user
* @param string $status
* @param string $resource
*
* @return void
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-04-05 12:20:09 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userShouldHaveSyncEnabledOrDisabledForShare ( string $user , string $status , string $resource ) : void {
2024-06-24 18:37:25 +05:45
$this -> waitAndCheckShareSyncStatus ( $user , $resource , $status );
2024-04-05 12:20:09 +05:45
}
2024-04-17 12:00:52 +05:45
/**
2024-06-19 14:50:38 +05:45
* @Then user :user should be able to send the following resource share invitation with all allowed permission roles
2024-04-17 12:00:52 +05:45
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
2024-04-18 15:17:51 +05:45
* @throws GuzzleException
2024-04-17 12:00:52 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userShouldBeAbleToSendShareTheFollowingInvitationWithAllAllowedPermissionRoles (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-17 12:00:52 +05:45
$listPermissionResponse = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
if ( ! isset ( $listPermissionResponse -> { '@libre.graph.permissions.roles.allowedValues' })) {
Assert :: fail (
2024-12-24 09:30:42 +05:45
"The following response does not contain '@libre.graph.permissions.roles.allowedValues' property: \n "
2025-06-19 15:34:02 +05:45
. $listPermissionResponse ,
2024-04-17 12:00:52 +05:45
);
}
Assert :: assertNotEmpty (
$listPermissionResponse -> { '@libre.graph.permissions.roles.allowedValues' },
2025-06-19 15:34:02 +05:45
"'@libre.graph.permissions.roles.allowedValues' should not be empty" ,
2024-04-17 12:00:52 +05:45
);
$allowedPermissionRoles = $listPermissionResponse -> { '@libre.graph.permissions.roles.allowedValues' };
// this info is needed for log to see which roles allowed and which were not when tests fail
$shareInvitationRequestResult = "From the given allowed role lists from the permissions: \n " ;
$areAllSendInvitationSuccessFullForAllowedRoles = true ;
$rows = $table -> getRowsHash ();
2024-04-29 12:54:51 +05:45
// when sending share invitation for a project space, the resource to be shared is project space itself. So resource can be put as empty
$resource = $rows [ 'resource' ] ?? '' ;
2024-04-17 12:00:52 +05:45
$shareType = $rows [ 'shareType' ];
$space = $rows [ 'space' ];
2025-06-19 12:03:03 +05:45
// this details is needed for result logging purpose to determine whether the resource shared is a resource or a project space
2024-04-29 12:54:51 +05:45
$resourceDetail = ( $resource ) ? "resource '" . $resource : "space '" . $space ;
2024-04-17 12:00:52 +05:45
foreach ( $allowedPermissionRoles as $role ) {
2025-06-19 12:03:03 +05:45
// we should be able to send share invitation for each of the role allowed for the files/folders which are listed in permissions (allowed)
2024-04-17 12:00:52 +05:45
$roleAllowed = GraphHelper :: getPermissionNameByPermissionRoleId ( $role -> id );
2024-12-24 09:30:42 +05:45
$responseSendInvitation = $this -> sendShareInvitation (
$user ,
2025-06-19 15:34:02 +05:45
array_merge ( $rows , [ 'permissionsRole' => $roleAllowed ]),
2024-12-24 09:30:42 +05:45
);
$jsonResponseSendInvitation = $this -> featureContext -> getJsonDecodedResponseBodyContent (
2025-06-19 15:34:02 +05:45
$responseSendInvitation ,
2024-12-24 09:30:42 +05:45
);
2024-04-17 12:00:52 +05:45
$httpsStatusCode = $responseSendInvitation -> getStatusCode ();
if ( $httpsStatusCode === 200 && ! empty ( $jsonResponseSendInvitation -> value )) {
// remove the share so that the same user can be share for the next allowed roles
2024-04-18 11:46:19 +02:00
$removePermissionsResponse = $this -> removeAccessToSpaceItem ( $user , $shareType , $space , $resource );
2024-04-17 12:00:52 +05:45
Assert :: assertEquals ( 204 , $removePermissionsResponse -> getStatusCode ());
} else {
$areAllSendInvitationSuccessFullForAllowedRoles = false ;
2024-12-24 09:30:42 +05:45
$shareInvitationRequestResult .= " \t Share invitation for " . $resourceDetail
. "' with role '" . $roleAllowed . "' failed and was not allowed. \n " ;
2024-04-17 12:00:52 +05:45
}
}
Assert :: assertTrue ( $areAllSendInvitationSuccessFullForAllowedRoles , $shareInvitationRequestResult );
}
2024-04-18 15:17:51 +05:45
/**
* @When /^user "([^"]*)" (?:tries to list|lists) the permissions of space "([^"]*)" using root endpoint of the Graph API$/
*
* @param string $user
* @param string $space
*
* @return void
* @throws Exception
* @throws GuzzleException
*
*/
2024-12-24 09:30:42 +05:45
public function userListsThePermissionsOfDriveUsingRootEndPointOFTheGraphApi ( string $user , string $space ) : void {
2024-04-18 15:17:51 +05:45
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$response = GraphHelper :: getDrivePermissionsList (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-04-18 15:17:51 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-04-26 12:26:26 +05:45
2025-05-21 18:02:59 +05:45
/**
* @When /^user "([^"]*)" lists the permission of space "([^"]*)" shared to user "([^"]*)" using root endpoint of the Graph API$/
*
* @param string $user
* @param string $space
* @param string $sharee
*
* @return void
* @throws Exception
* @throws GuzzleException
*
*/
public function userListDrivePermissionViaRootEndpointGraphApi ( string $user , string $space , string $sharee ) : void {
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$permissionID = "u:" . $this -> featureContext -> getAttributeOfCreatedUser ( $sharee , 'id' );
$response = GraphHelper :: getSingleDrivePermissionList (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
2025-06-19 15:34:02 +05:45
$permissionID ,
2025-05-21 18:02:59 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When /^user "([^"]*)" lists the last link permission of space "([^"]*)" using root endpoint of the Graph API$/
*
* @param string $user
* @param string $space
*
* @return void
* @throws Exception
* @throws GuzzleException
*
*/
public function userListsPermissionOfSpaceSharedViaLinkUsingRootEndpointGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
string $space ,
2025-05-21 18:02:59 +05:45
) : void {
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$permissionId = $this -> featureContext -> shareNgGetLastCreatedLinkShareID ();
$response = GraphHelper :: getSingleDrivePermission (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
2025-06-19 15:34:02 +05:45
$permissionId ,
2025-05-21 18:02:59 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-04-26 12:26:26 +05:45
/**
2024-05-08 14:22:52 +05:45
* @When /^user "([^"]*)" (?:tries to send|sends) the following space share invitation using root endpoint of the Graph API:$/
2024-04-26 12:26:26 +05:45
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSendsTheFollowingShareInvitationUsingRootEndPointTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2025-09-22 13:50:45 +05:45
$response = $this -> sendDriveShareInvitation ( $user , $table -> getRowsHash ());
2024-05-08 14:22:52 +05:45
$this -> featureContext -> setResponse ( $response );
2024-05-08 09:55:48 +05:45
}
2024-11-08 18:30:53 +05:45
/**
* @When /^user "([^"]*)" tries to send the following space share invitation to federated user using root endpoint of the Graph API:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSendsTheFollowingShareInvitationToFederatedUserUsingRootEndPointTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2025-09-22 13:50:45 +05:45
$response = $this -> sendDriveShareInvitation ( $user , $table -> getRowsHash (), true );
2024-11-08 18:30:53 +05:45
$this -> featureContext -> setResponse ( $response );
}
2024-05-08 09:55:48 +05:45
/**
* @When user :user updates the last drive share with the following using root endpoint of the Graph API:
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userUpdatesTheLastDriveShareWithTheFollowingUsingRootEndpointOfTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-08 09:55:48 +05:45
$bodyRows = $table -> getRowsHash ();
$permissionID = match ( $bodyRows [ 'shareType' ]) {
'user' => 'u:' . $this -> featureContext -> getAttributeOfCreatedUser ( $bodyRows [ 'sharee' ], 'id' ),
'group' => 'g:' . $this -> featureContext -> getAttributeOfCreatedGroup ( $bodyRows [ 'sharee' ], 'id' ),
default => throw new Exception ( "shareType { $bodyRows [ 'shareType' ] } does not match user|group " ),
};
$space = $bodyRows [ 'space' ];
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$body = [];
if ( \array_key_exists ( 'permissionsRole' , $bodyRows )) {
$body [ 'roles' ] = [ GraphHelper :: getPermissionsRoleIdByName ( $bodyRows [ 'permissionsRole' ])];
}
if ( \array_key_exists ( 'expirationDateTime' , $bodyRows )) {
2024-12-24 09:30:42 +05:45
$body [ 'expirationDateTime' ] = empty ( $bodyRows [ 'expirationDateTime' ])
? null : $bodyRows [ 'expirationDateTime' ];
2024-05-08 09:55:48 +05:45
}
$this -> featureContext -> setResponse (
GraphHelper :: updateDriveShare (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
\json_encode ( $body ),
2025-06-19 15:34:02 +05:45
$permissionID ,
),
2024-05-08 09:55:48 +05:45
);
2024-04-26 12:26:26 +05:45
}
2024-05-10 12:17:15 +05:45
/**
* @When /^user "([^"]*)" (?:tries to create|creates) the following space link share using root endpoint of the Graph API:$/
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userCreatesTheFollowingSpaceLinkShareUsingRootEndpointOfTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-10 12:17:15 +05:45
$rows = $body -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayNotHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should not be provided in the data-table while sharing a space" ,
2024-12-24 09:30:42 +05:45
);
2024-05-10 12:17:15 +05:45
$response = $this -> createDriveLinkShare ( $user , $body );
$this -> featureContext -> setResponse ( $response );
}
2024-05-10 15:46:57 +05:45
/**
* @When user :user sets the following password for the last space link share using root endpoint of the Graph API:
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userSetsTheFollowingPasswordForTheLastSpaceLinkShareUsingRootEndpointOfTheGraphAPI (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-10 15:46:57 +05:45
$rows = $body -> getRowsHash ();
2024-12-24 09:30:42 +05:45
Assert :: assertArrayNotHasKey (
"resource" ,
$rows ,
2025-06-19 15:34:02 +05:45
"'resource' should not be provided in the data-table while setting password in space shared link" ,
2024-12-24 09:30:42 +05:45
);
2024-05-10 15:46:57 +05:45
Assert :: assertArrayHasKey ( "password" , $rows , "'password' is missing in the data-table" );
$body = [
"password" => $this -> featureContext -> getActualPassword ( $rows [ 'password' ]),
];
$space = $rows [ 'space' ];
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$response = GraphHelper :: setDriveLinkSharePassword (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
\json_encode ( $body ),
2025-06-19 15:34:02 +05:45
$this -> featureContext -> shareNgGetLastCreatedLinkShareID (),
2024-05-10 15:46:57 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-05-10 16:28:58 +05:45
/**
* @When user :user tries to remove the link from space :space owned by :owner using root endpoint of the Graph API
*
* @param string $user
* @param string $space
* @param string $spaceOwner
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToRemoveShareLinkOfSpaceOwnedByUsingRootEndpointOfTheGraphApi (
string $user ,
string $space ,
2025-06-19 15:34:02 +05:45
string $spaceOwner ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-10 16:28:58 +05:45
$permissionID = $this -> featureContext -> shareNgGetLastCreatedLinkShareID ();
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $spaceOwner , $space ))[ "id" ];
$response = GraphHelper :: removeAccessToSpace (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId ,
2025-06-19 15:34:02 +05:45
$permissionID ,
2024-05-10 16:28:58 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @Then user :user should not have any :shareType permissions on space :space
*
* @param string $user
* @param string $shareType
* @param string $space
*
* @return void
* @throws GuzzleException
*/
public function userShouldNotHaveAnyPermissionsOnSpace ( string $user , string $shareType , string $space ) : void {
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $space ))[ "id" ];
$response = GraphHelper :: getDrivePermissionsList (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-05-10 16:28:58 +05:45
);
$responseBody = $this -> featureContext -> getJsonDecodedResponse ( $response );
foreach ( $responseBody [ 'value' ] as $value ) {
switch ( $shareType ) {
case $shareType === 'link' :
2024-12-24 09:30:42 +05:45
Assert :: assertArrayNotHasKey (
'link' ,
$value ,
2025-06-19 15:34:02 +05:45
$space . ' space should not have any link permissions but found ' . print_r ( $value , true ),
2024-12-24 09:30:42 +05:45
);
2024-05-10 16:28:58 +05:45
break ;
case $shareType === "share" :
2024-12-24 09:30:42 +05:45
Assert :: assertArrayNotHasKey (
'grantedToV2' ,
$value ,
2025-06-19 15:34:02 +05:45
$space . ' space should not have any share permissions but found ' . print_r ( $value , true ),
2024-12-24 09:30:42 +05:45
);
2024-05-10 16:28:58 +05:45
break ;
default :
Assert :: fail ( 'Invalid share type has been specified' );
}
}
}
2024-05-15 10:51:55 +05:45
/**
* @Then user :user should be able to send the following space share invitation with all allowed permission roles using root endpoint of the Graph API
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws GuzzleException
2024-12-24 09:30:42 +05:45
* @codingStandardsIgnoreStart
2024-05-15 10:51:55 +05:45
*/
2024-12-24 09:30:42 +05:45
public function userShouldBeAbleToSendTheFollowingSpaceShareInvitationWithAllAllowedPermissionRolesUsingRootEndpointOFTheGraphApi (
// @codingStandardsIgnoreEnd
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-15 10:51:55 +05:45
$listPermissionResponse = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
if ( ! isset ( $listPermissionResponse -> { '@libre.graph.permissions.roles.allowedValues' })) {
Assert :: fail (
2024-12-24 09:30:42 +05:45
"The following response does not contain '@libre.graph.permissions.roles.allowedValues' property: \n "
2025-06-19 15:34:02 +05:45
. $listPermissionResponse ,
2024-05-15 10:51:55 +05:45
);
}
Assert :: assertNotEmpty (
$listPermissionResponse -> { '@libre.graph.permissions.roles.allowedValues' },
2025-06-19 15:34:02 +05:45
"'@libre.graph.permissions.roles.allowedValues' should not be empty" ,
2024-05-15 10:51:55 +05:45
);
$allowedPermissionRoles = $listPermissionResponse -> { '@libre.graph.permissions.roles.allowedValues' };
// this info is needed for log to see which roles allowed and which were not when tests fail
$shareInvitationRequestResult = "From the given allowed role lists from the permissions: \n " ;
$areAllSendInvitationSuccessFullForAllowedRoles = true ;
$rows = $table -> getRowsHash ();
$shareType = $rows [ 'shareType' ];
$space = $rows [ 'space' ];
$recipient = $rows [ 'sharee' ];
foreach ( $allowedPermissionRoles as $role ) {
// we should be able to send share invitation for each of the roles allowed which are listed in permissions (allowed)
$roleAllowed = GraphHelper :: getPermissionNameByPermissionRoleId ( $role -> id );
2024-12-24 09:30:42 +05:45
$responseSendInvitation = $this -> sendDriveShareInvitation (
$user ,
2025-09-22 13:50:45 +05:45
array_merge ( $rows , [ 'permissionsRole' => $roleAllowed ]),
2024-12-24 09:30:42 +05:45
);
$jsonResponseSendInvitation = $this -> featureContext -> getJsonDecodedResponseBodyContent (
2025-06-19 15:34:02 +05:45
$responseSendInvitation ,
2024-12-24 09:30:42 +05:45
);
2024-05-15 10:51:55 +05:45
$httpsStatusCode = $responseSendInvitation -> getStatusCode ();
if ( $httpsStatusCode === 200 && ! empty ( $jsonResponseSendInvitation -> value )) {
// remove the share so that the same user can be share for the next allowed roles
$removePermissionsResponse = $this -> removeAccessToSpace ( $user , $shareType , $space , $recipient );
Assert :: assertEquals ( 204 , $removePermissionsResponse -> getStatusCode ());
} else {
$areAllSendInvitationSuccessFullForAllowedRoles = false ;
2024-12-24 09:30:42 +05:45
$shareInvitationRequestResult .= " \t Share invitation for " . $space . "' with role '"
. $roleAllowed . "' failed and was not allowed. \n " ;
2024-05-15 10:51:55 +05:45
}
}
Assert :: assertTrue ( $areAllSendInvitationSuccessFullForAllowedRoles , $shareInvitationRequestResult );
}
/**
* @When user :user tries to list the permissions of space :space owned by :spaceOwner using root endpoint of the Graph API
*
* @param string $user
* @param string $space
* @param string $spaceOwner
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToListThePermissionsOfSpaceOwnedByUsingRootEndpointOfTheGraphApi (
string $user ,
string $space ,
2025-06-19 15:34:02 +05:45
string $spaceOwner ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-15 10:51:55 +05:45
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $spaceOwner , $space ))[ "id" ];
$response = GraphHelper :: getDrivePermissionsList (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-05-15 10:51:55 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-05-30 17:06:46 +05:45
/**
2024-05-24 09:43:47 +05:45
* @When user :user removes the last link share of space :space using permissions endpoint of the Graph API
2024-05-30 17:06:46 +05:45
*
* @param string $user
* @param string $space
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userRemovesTheLastLinkShareOfSpaceUsingPermissionsEndpointOfGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-12-24 09:30:42 +05:45
) : void {
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> removeAccessToSpaceItem ( $user , 'link' , $space , '' ),
2024-12-24 09:30:42 +05:45
);
2024-05-30 17:06:46 +05:45
}
2024-08-07 16:34:44 +05:45
/**
* @param string $share
* @param string $sharee
* @param string $sharer
2024-11-29 16:47:02 +05:45
* @param string $space
* @param bool $shouldExist
2024-11-27 12:51:20 +05:45
* @param bool $federatedShare
2025-03-19 13:17:07 +05:45
* @param string $role compares share role if provided
2026-08-24 12:01:48 +05:45
* @param boolean $isVault
2024-08-07 16:34:44 +05:45
*
* @return void
* @throws GuzzleException
* @throws JsonException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkIfShareExists (
string $share ,
string $sharee ,
string $sharer ,
2025-03-19 13:17:07 +05:45
string $space = '' ,
2024-12-24 09:30:42 +05:45
bool $shouldExist = true ,
2025-03-19 13:17:07 +05:45
bool $federatedShare = false ,
2025-06-19 15:34:02 +05:45
string $role = '' ,
2026-08-24 12:01:48 +05:45
bool $isVault = false ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-29 16:47:02 +05:45
$share = \ltrim ( $share , "/" );
2025-03-19 13:17:07 +05:45
$wasOrNot = $shouldExist ? "was not" : "was" ;
2026-08-24 12:01:48 +05:45
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( $sharee )[ 'token' ][ 'accessToken' ];
$headers [ "Authorization" ] = "Bearer " . $accessToken ;
$sharee = null ;
$password = null ;
} else {
$password = $this -> featureContext -> getPasswordForUser ( $sharee );
}
2024-11-27 12:51:20 +05:45
if ( ! $federatedShare ) {
2025-03-19 13:17:07 +05:45
if ( \strtolower ( $space ) === "personal" ) {
$remoteDriveAlias = "personal/" . \strtolower ( $sharer );
} else {
$remoteDriveAlias = "project/" . \strtolower ( $space );
}
2024-11-27 12:51:20 +05:45
// check share mountpoint
$response = GraphHelper :: getMySpaces (
$this -> featureContext -> getBaseUrl (),
$sharee ,
2026-08-24 12:01:48 +05:45
$password ,
2025-06-19 15:34:02 +05:45
"" ,
2026-08-24 12:01:48 +05:45
[],
$headers ,
$isVault ,
2024-11-27 12:51:20 +05:45
);
$driveList = HttpRequestHelper :: getJsonDecodedResponseBodyContent ( $response ) -> value ;
$foundShareMountpoint = false ;
foreach ( $driveList as $drive ) {
2024-12-24 09:30:42 +05:45
if ( $drive -> driveType === "mountpoint"
&& $drive -> name === $share
&& $drive -> root -> remoteItem -> driveAlias === $remoteDriveAlias
) {
2024-11-27 12:51:20 +05:45
$foundShareMountpoint = true ;
}
2024-08-07 16:34:44 +05:45
}
2024-12-24 09:30:42 +05:45
Assert :: assertSame (
$shouldExist ,
$foundShareMountpoint ,
2025-06-19 15:34:02 +05:45
"Share mountpoint ' $share ' $wasOrNot found in the following drives list. \n " . json_encode ( $driveList ),
2024-12-24 09:30:42 +05:45
);
2024-08-07 16:34:44 +05:45
}
// check share in shared-with-me list
$response = GraphHelper :: getSharesSharedWithMe (
$this -> featureContext -> getBaseUrl (),
$sharee ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $sharee ),
2026-08-24 12:01:48 +05:45
$headers ,
$isVault ,
2024-08-07 16:34:44 +05:45
);
$sharedWithMeList = HttpRequestHelper :: getJsonDecodedResponseBodyContent ( $response ) -> value ;
$foundShareInSharedWithMe = false ;
foreach ( $sharedWithMeList as $item ) {
2024-11-29 16:47:02 +05:45
if ( $item -> name === $share ) {
foreach ( $item -> remoteItem -> permissions as $permission ) {
$shareCreator = $permission -> invitation -> invitedBy -> user -> displayName ;
if ( $shareCreator === $this -> featureContext -> getDisplayNameForUser ( $sharer )) {
$foundShareInSharedWithMe = true ;
2025-03-19 13:17:07 +05:45
if ( $shouldExist && $role ) {
$actualRoleId = $permission -> roles [ 0 ];
$actualRole = GraphHelper :: getPermissionNameByPermissionRoleId ( $actualRoleId );
Assert :: assertSame (
$role ,
$actualRole ,
2025-06-19 15:34:02 +05:45
"Expected role ' $role ' for share ' $share ' but found ' $actualRole '." ,
2025-03-19 13:17:07 +05:45
);
}
2024-11-29 16:47:02 +05:45
break ;
}
}
break ;
2024-08-07 16:34:44 +05:45
}
}
2024-12-24 09:30:42 +05:45
Assert :: assertSame (
$shouldExist ,
$foundShareInSharedWithMe ,
2025-06-19 15:34:02 +05:45
"Share ' $share ' $wasOrNot found in the shared-with-me list. \n " . json_encode ( $sharedWithMeList ),
2024-12-24 09:30:42 +05:45
);
2024-08-07 16:34:44 +05:45
}
/**
2024-12-04 16:29:59 +05:45
* @Then /^user "([^"]*)" (should|should not) have a share "([^"]*)" shared by user "([^"]*)" from space "([^"]*)"$/
2024-08-07 16:34:44 +05:45
*
* @param string $sharee
2024-12-04 16:29:59 +05:45
* @param string $shouldOrNot
2024-08-07 16:34:44 +05:45
* @param string $share
* @param string $sharer
2024-11-29 16:47:02 +05:45
* @param string $space
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userShouldHaveShareSharedByUserFromSpace (
string $sharee ,
string $shouldOrNot ,
string $share ,
string $sharer ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-12-24 09:30:42 +05:45
) : void {
2024-12-04 16:29:59 +05:45
$this -> checkIfShareExists ( $share , $sharee , $sharer , $space , $shouldOrNot === "should" );
2024-08-07 16:34:44 +05:45
}
2024-08-09 15:20:40 +05:45
2026-10-05 14:31:31 +05:45
/**
* @Then /^user "([^"]*)" should have a share "([^"]*)" with permissions role "([^"]*)" shared by user "([^"]*)" from space "([^"]*)"$/
*
* @param string $sharee
* @param string $share
* @param string $role
* @param string $sharer
* @param string $space
*
* @return void
*/
public function userShouldHaveShareWithPermissionsRole (
string $sharee ,
string $share ,
string $role ,
string $sharer ,
string $space ,
) : void {
$this -> checkIfShareExists ( $share , $sharee , $sharer , $space , true , false , $role );
}
2025-03-19 13:17:07 +05:45
/**
* @Then user :sharee should have the following resource shares:
*
* @param string $sharee
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userShouldHaveTheFollowingResourceShares ( string $sharee , TableNode $table ) : void {
$shares = $table -> getColumnsHash ();
// set default space to personal if not provided
$space = $shares [ 0 ][ 'space' ] ?? 'personal' ;
foreach ( $shares as $share ) {
2026-08-24 12:01:48 +05:45
$isVault = isset ( $share [ 'storage' ]) && $share [ 'storage' ] === 'vault' ;
2025-03-19 13:17:07 +05:45
$this -> checkIfShareExists (
$share [ "resource" ],
$sharee ,
$share [ "sharer" ],
$space ,
true ,
false ,
$share [ "permissionsRole" ],
2026-08-24 12:01:48 +05:45
$isVault ,
2025-03-19 13:17:07 +05:45
);
}
}
2024-11-27 12:51:20 +05:45
/**
* @Then /^user "([^"]*)" (should|should not) have a federated share "([^"]*)" shared by user "([^"]*)" from space "([^"]*)"$/
*
* @param string $sharee
* @param string $shouldOrNot
* @param string $share
* @param string $sharer
* @param string $space
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userShouldOrShouldNotHaveFederatedShareSharedByUserFromSpace (
string $sharee ,
string $shouldOrNot ,
string $share ,
string $sharer ,
2025-06-19 15:34:02 +05:45
string $space ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-27 12:51:20 +05:45
$this -> checkIfShareExists ( $share , $sharee , $sharer , $space , $shouldOrNot === "should" , true );
}
2024-08-09 15:20:40 +05:45
/**
* @Given /^user "([^"]*)" has shared the following (?:files|folders) from space "([^"]*)" with user "([^"]*)" and role "([^"]*)":$/
*
* @param string $sharer
* @param string $space
* @param string $sharee
* @param string $role
* @param TableNode $table
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userHasSharedTheFollowingFilesFromSpaceWithUserAndRole (
string $sharer ,
string $space ,
string $sharee ,
string $role ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2024-08-09 15:20:40 +05:45
$rows = $table -> getRows ();
foreach ( $rows as $row ) {
if ( isset ( $row [ 0 ])) {
$shareData = [
'resource' => $row [ 0 ],
'space' => $space ,
'sharee' => $sharee ,
'shareType' => 'user' ,
'permissionsRole' => $role ,
];
$response = $this -> sendShareInvitation ( $sharer , $shareData );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
}
}
}
/**
2024-12-04 09:51:51 +05:45
* @Then /^the json response (should|should not) contain the following shares:$/
2024-08-09 15:20:40 +05:45
*
2024-12-04 09:51:51 +05:45
* @param string $shouldOrNot
2024-08-09 15:20:40 +05:45
* @param TableNode $table
*
* @return void
*/
2024-12-04 09:51:51 +05:45
public function theJsonResponseShouldOrShouldNotContainTheFollowingShares (
string $shouldOrNot ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-04 09:51:51 +05:45
) : void {
2024-08-09 15:20:40 +05:45
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
$resourceNames = [];
if ( isset ( $responseBody -> value ) && \is_array ( $responseBody -> value )) {
foreach ( $responseBody -> value as $item ) {
if ( isset ( $item -> name )) {
$resourceNames [] = $item -> name ;
}
}
}
$expectedShares = $table -> getColumn ( 0 );
foreach ( $expectedShares as $expectedShare ) {
2024-12-04 09:51:51 +05:45
if ( $shouldOrNot === "should not" ) {
Assert :: assertFalse (
\in_array ( $expectedShare , $resourceNames ),
2025-06-19 15:34:02 +05:45
"The share ' $expectedShare ' was found in the response." ,
2024-12-04 09:51:51 +05:45
);
} else {
Assert :: assertTrue (
\in_array ( $expectedShare , $resourceNames ),
2025-06-19 15:34:02 +05:45
"The share ' $expectedShare ' was not found in the response." ,
2024-12-04 09:51:51 +05:45
);
}
2024-08-09 15:20:40 +05:45
}
}
2024-12-30 16:41:37 +05:45
2026-10-07 16:03:09 +02:00
/**
* @Then /^the last share invitation should have an expiration date approximately "([^"]*)" days from now$/
*
* @param string $days
*
* @return void
*/
public function theLastShareInvitationShouldHaveAnExpirationDateApproximatelyDaysFromNow (
string $days ,
) : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
Assert :: assertTrue (
isset ( $responseBody -> value [ 0 ] -> expirationDateTime ),
"Expected the created share to have an 'expirationDateTime' but none was returned: \n "
. print_r ( $responseBody , true ),
);
$actual = new DateTime ( $responseBody -> value [ 0 ] -> expirationDateTime );
$expected = ( new DateTime ()) -> modify ( "+" . ( int ) $days . " days" );
$diffSeconds = \abs ( $actual -> getTimestamp () - $expected -> getTimestamp ());
// allow a 1-minute tolerance to absorb request/processing latency, matching the
// backend unit test's own tolerance (BeTemporally("~", expectedDefault, time.Minute))
Assert :: assertLessThanOrEqual (
60 ,
$diffSeconds ,
"Expected an expiration date approximately $days days from now ("
. $expected -> format ( DATE_ATOM ) . "), but got " . $actual -> format ( DATE_ATOM )
. " (difference of { $diffSeconds } s)" ,
);
}
2025-01-08 14:41:16 +05:45
/**
2025-04-03 18:32:11 +05:45
* @When /^user "([^"]*)" lists permissions with following filters for (?:folder|file) "([^"]*)" of the space "([^"]*)" using the Graph API:$/
2025-01-08 14:41:16 +05:45
*
* @param string $user
* @param string $resource
* @param string $space
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
public function userListsPermissionsWithFollowingFiltersForFileOrFolderOfTheSpaceUsingTheGraphApi (
string $user ,
string $resource ,
string $space ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2025-01-08 14:41:16 +05:45
) : void {
$query = implode ( '&' , $table -> getColumn ( 0 ));
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> getPermissionsList ( $user , $space , $resource , $query ),
2025-01-08 14:41:16 +05:45
);
}
2025-04-03 18:32:11 +05:45
/**
2025-04-11 13:00:24 +05:45
* @Then for user :user file/folder :resource should have the following shares:
2025-04-03 18:32:11 +05:45
*
* @param string $user
* @param string $resource
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function userGetsAllTheSharesOfTheResource (
string $user ,
string $resource ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2025-04-03 18:32:11 +05:45
) : void {
$permission = $this -> getPermissionsList ( $user , "Shares" , $resource );
$jsonBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $permission );
$errors = [];
foreach ( $table -> getHash () as $row ) {
$expectedRoleId = GraphHelper :: getPermissionsRoleIdByName ( $row [ 'permissionsRole' ]);
if ( $row [ 'shareType' ] === 'user' ) {
$expectedSharee = $this -> featureContext -> getDisplayNameForUser ( $row [ 'sharee' ]);
} else {
$expectedSharee = $row [ 'sharee' ];
}
$found = false ;
foreach ( $jsonBody -> value as $share ) {
$actualSharee = '' ;
if ( $row [ 'shareType' ] === 'user' ) {
if ( isset ( $share -> grantedToV2 -> user -> displayName )) {
$actualSharee = $share -> grantedToV2 -> user -> displayName ;
}
} else {
if ( isset ( $share -> grantedToV2 -> group -> displayName )) {
$actualSharee = $share -> grantedToV2 -> group -> displayName ;
}
}
if ( $actualSharee === $expectedSharee ) {
$found = true ;
if ( $share -> roles [ 0 ] !== $expectedRoleId ) {
$errors [] = "Expected user $actualSharee share role id to be ' $expectedRoleId '
but found ' $share->roles [0]'" ;
}
break ;
}
}
if ( ! $found ) {
$errors [] = "Expected sharee ' $expectedSharee ' to be present but found ' $actualSharee '" ;
}
}
if ( ! empty ( $errors )) {
Assert :: fail ( implode ( " \n " , $errors ));
}
}
2025-06-09 14:30:04 +05:45
/**
* @Then the last :shareCount link shares should have the same id
*
* @param string $shareCount
*
* @return void
* @throws GuzzleException
*/
public function theLastLinkSharesShouldHaveTheSameID ( string $shareCount ) : void {
$shares = $this -> featureContext -> shareNgGetCreatedLinkShares ();
$shares = \array_slice ( $shares , - ( int ) $shareCount );
$lastShareId = null ;
foreach ( $shares as $share ) {
if ( $lastShareId === null ) {
$lastShareId = $share [ 'id' ];
} else {
Assert :: assertSame (
$lastShareId ,
$share [ 'id' ],
2025-06-19 15:34:02 +05:45
"Link share id is not the same. Expected ' $lastShareId ' but found ' $share[id] '" ,
2025-06-09 14:30:04 +05:45
);
}
}
}
2023-12-13 12:34:49 +01:00
}