2022-12-21 17:22:22 +05:45
<? php declare ( strict_types = 1 );
/**
* ownCloud
*
* @author Joas Schilling <coding@schilljs.com>
* @author Sergio Bertolin <sbertolin@owncloud.com>
* @author Phillip Davis <phil@jankaritech.com>
* @copyright Copyright (c) 2018, ownCloud GmbH
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
use Behat\Gherkin\Node\PyStringNode ;
use Behat\Gherkin\Node\TableNode ;
use Psr\Http\Message\ResponseInterface ;
use PHPUnit\Framework\Assert ;
2023-06-08 16:59:45 +05:45
use PHPUnit\Framework\ExpectationFailedException ;
2022-12-21 17:22:22 +05:45
use TestHelpers\OcsApiHelper ;
use TestHelpers\SharingHelper ;
use TestHelpers\HttpRequestHelper ;
use TestHelpers\TranslationHelper ;
2024-09-17 17:11:20 +05:45
use TestHelpers\WebDavHelper ;
2024-05-22 17:10:47 +05:45
use GuzzleHttp\Exception\GuzzleException ;
2022-12-21 17:22:22 +05:45
/**
* Sharing trait
*/
trait Sharing {
2023-05-02 17:25:56 +05:45
private int $sharingApiVersion = 1 ;
2022-12-21 17:22:22 +05:45
/**
2023-07-26 12:01:09 +05:45
* @var array
2022-12-21 17:22:22 +05:45
*/
2023-07-26 12:01:09 +05:45
private array $createdUserGroupShares = [];
2022-12-21 17:22:22 +05:45
2023-05-02 17:25:56 +05:45
private ? float $localLastShareTime = null ;
2022-12-21 17:22:22 +05:45
/**
* Defines the fields that can be provided in a share request.
*/
2023-05-02 17:25:56 +05:45
private array $shareFields = [
2022-12-21 17:22:22 +05:45
'path' , 'name' , 'publicUpload' , 'password' , 'expireDate' ,
2025-06-19 10:46:56 +05:45
'expireDateAsString' , 'permissions' , 'shareWith' , 'shareType' ,
2022-12-21 17:22:22 +05:45
];
/**
* Defines the fields that are known and can be tested in a share response.
* Note that ownCloud10 also provides file_parent in responses.
* file_parent is not provided by OCIS/reva.
* There are no known clients that use file_parent.
* The acceptance tests do not test for file_parent.
*
* @var array fields that are possible in a share response
*/
2023-05-02 17:25:56 +05:45
private array $shareResponseFields = [
2022-12-21 17:22:22 +05:45
'id' , 'share_type' , 'uid_owner' , 'displayname_owner' , 'stime' , 'parent' ,
'expiration' , 'token' , 'uid_file_owner' , 'displayname_file_owner' , 'path' ,
'item_type' , 'mimetype' , 'storage_id' , 'storage' , 'item_source' ,
'file_source' , 'file_target' , 'name' , 'url' , 'mail_send' ,
2025-06-19 10:46:56 +05:45
'attributes' , 'permissions' , 'share_with' , 'share_with_displayname' , 'share_with_additional_info' ,
2022-12-21 17:22:22 +05:45
];
/**
2023-08-03 13:51:22 +05:45
* @var array
2022-12-21 17:22:22 +05:45
*/
2023-08-03 13:51:22 +05:45
private array $createdPublicShares = [];
2022-12-21 17:22:22 +05:45
2024-01-02 16:53:47 +05:45
/**
* @var array
*/
private array $shareNgCreatedLinkShares = [];
2024-01-11 11:31:28 +05:45
/**
* @var array
*/
private array $shareNgCreatedUserGroupShares = [];
2022-12-21 17:22:22 +05:45
/**
* @return string
*/
2024-12-24 09:30:42 +05:45
public function getLastCreatedPublicShareToken () : string {
2023-08-03 13:51:22 +05:45
return ( string ) $this -> getLastCreatedPublicShare () -> token ;
2022-12-21 17:22:22 +05:45
}
/**
* @return SimpleXMLElement|null
*/
2024-12-24 09:30:42 +05:45
public function getLastCreatedPublicShare () : ? SimpleXMLElement {
2023-08-03 13:51:22 +05:45
return \end ( $this -> createdPublicShares );
2022-12-21 17:22:22 +05:45
}
/**
2023-08-03 13:51:22 +05:45
* @param SimpleXMLElement $shareData
2022-12-21 17:22:22 +05:45
*
* @return void
*/
2023-08-03 13:51:22 +05:45
public function addToCreatedPublicShares ( SimpleXMLElement $shareData ) : void {
$this -> createdPublicShares [] = $shareData ;
2022-12-21 17:22:22 +05:45
}
2024-01-02 16:53:47 +05:45
/**
* @param ResponseInterface $response
*
* @return void
*/
public function shareNgAddToCreatedLinkShares ( ResponseInterface $response ) : void {
2025-02-14 15:18:01 +05:45
$this -> shareNgCreatedLinkShares [] = $this -> getJsonDecodedResponse ( $response );
2024-01-02 16:53:47 +05:45
}
2025-06-09 14:30:04 +05:45
/**
* @return array
*/
public function shareNgGetCreatedLinkShares () : array {
return $this -> shareNgCreatedLinkShares ;
}
2024-01-02 16:53:47 +05:45
/**
2025-02-14 15:18:01 +05:45
* @return array|null
2024-01-02 16:53:47 +05:45
*/
2025-02-14 15:18:01 +05:45
public function shareNgGetLastCreatedLinkShare () : ? array {
2024-01-02 16:53:47 +05:45
return \end ( $this -> shareNgCreatedLinkShares );
}
2024-01-11 11:31:28 +05:45
/**
* @param ResponseInterface $response
2025-06-12 10:59:16 +05:45
* @param string $resource
* @param string $space
2024-01-11 11:31:28 +05:45
*
* @return void
*/
2025-06-12 10:59:16 +05:45
public function shareNgAddToCreatedUserGroupShares (
ResponseInterface $response ,
string $resource ,
string $space ,
) : void {
$share = $this -> getJsonDecodedResponse ( $response );
if ( \array_key_exists ( "value" , $share )) {
$share = $share [ "value" ][ 0 ];
}
$share [ "resource" ] = $resource ;
$share [ "space" ] = $space ;
$this -> shareNgCreatedUserGroupShares [] = $share ;
2024-01-11 11:31:28 +05:45
}
/**
2025-02-14 15:18:01 +05:45
* @return array|null
2024-01-11 11:31:28 +05:45
*/
2025-02-14 15:18:01 +05:45
public function shareNgGetLastCreatedUserGroupShare () : ? array {
2024-01-11 11:31:28 +05:45
return \end ( $this -> shareNgCreatedUserGroupShares );
}
2025-06-12 10:59:16 +05:45
/**
* @param string $sharer
* @param string $sharee
* @param string $space
* @param string $resource
*
* @return array
*/
public function shareNgGetCreatedUserGroupShare (
string $sharer ,
string $sharee ,
string $space ,
string $resource = '' ,
) : array {
foreach ( $this -> shareNgCreatedUserGroupShares as $share ) {
$shareOwner = $share [ "invitation" ][ "invitedBy" ][ "user" ][ "displayName" ];
$shareReceiver = $share [ "grantedToV2" ][ "user" ][ "displayName" ];
if ( $shareOwner === $this -> getUserDisplayName ( $sharer )
&& $shareReceiver === $this -> getUserDisplayName ( $sharee )
&& $share [ "resource" ] === $resource
&& $share [ "space" ] === $space
) {
return $share ;
}
}
Assert :: fail (
"Share not found: \n " .
" \t sharer: $sharer \n " .
" \t sharee: $sharee \n " .
" \t resource: $resource \n " .
" \t space: $space " ,
);
}
2022-12-21 17:22:22 +05:45
/**
2023-07-26 12:01:09 +05:45
* @param string $sharer
* @param SimpleXMLElement $shareData
*
* @return void
2022-12-21 17:22:22 +05:45
*/
2023-07-26 12:01:09 +05:45
public function addToCreatedUserGroupShares ( string $sharer , SimpleXMLElement $shareData ) : void {
$this -> createdUserGroupShares [ " $sharer " ] = $shareData ;
2022-12-21 17:22:22 +05:45
}
/**
2023-07-26 12:01:09 +05:45
* @return array
2022-12-21 17:22:22 +05:45
*/
2023-07-26 12:01:09 +05:45
public function getCreatedUserGroupShares () : array {
return $this -> createdUserGroupShares ;
2022-12-21 17:22:22 +05:45
}
/**
2023-07-26 12:01:09 +05:45
* @return SimpleXMLElement
2022-12-21 17:22:22 +05:45
*/
2023-07-26 12:01:09 +05:45
public function getLastCreatedUserGroupShare () : SimpleXMLElement {
return \end ( $this -> createdUserGroupShares );
2022-12-21 17:22:22 +05:45
}
/**
* @return void
*/
2024-12-24 09:30:42 +05:45
public function emptyCreatedPublicShares () : void {
2023-08-03 13:51:22 +05:45
$this -> createdPublicShares = [];
2022-12-21 17:22:22 +05:45
}
/**
* @return void
*/
2023-07-26 12:01:09 +05:45
public function emptyCreatedUserGroupShares () : void {
$this -> createdUserGroupShares = [];
2022-12-21 17:22:22 +05:45
}
/**
2023-05-02 17:25:56 +05:45
* @return float|null
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function getLocalLastShareTime () : ? float {
2022-12-21 17:22:22 +05:45
return $this -> localLastShareTime ;
}
/**
* @param string|null $postfix string to append to the end of the path
*
* @return string
*/
2024-12-24 09:30:42 +05:45
public function getSharesEndpointPath ( ? string $postfix = '' ) : string {
2023-05-02 17:25:56 +05:45
return "/apps/files_sharing/api/v $this->sharingApiVersion /shares $postfix " ;
2022-12-21 17:22:22 +05:45
}
2024-01-02 16:53:47 +05:45
/**
* @return string
*/
public function shareNgGetLastCreatedLinkShareID () : string {
$lastResponse = $this -> shareNgGetLastCreatedLinkShare ();
2025-02-14 15:18:01 +05:45
if ( ! isset ( $lastResponse [ 'id' ])) {
2024-01-11 11:31:28 +05:45
throw new Error ( 'Response did not contain share id for the created public link' );
2024-01-02 16:53:47 +05:45
}
2025-02-14 15:18:01 +05:45
return $lastResponse [ 'id' ];
2024-01-02 16:53:47 +05:45
}
2024-01-05 13:57:59 +05:45
/**
* @return string
*/
public function shareNgGetLastCreatedLinkShareToken () : string {
$lastResponse = $this -> shareNgGetLastCreatedLinkShare ();
2025-02-14 15:18:01 +05:45
if ( ! isset ( $lastResponse [ 'link' ][ 'webUrl' ])) {
2024-12-24 09:30:42 +05:45
throw new Error (
'Response did not contain share id '
2025-02-14 15:18:01 +05:45
. $lastResponse [ 'link' ][ 'webUrl' ]
2025-06-19 15:34:02 +05:45
. ' for the created public link' ,
2024-12-24 09:30:42 +05:45
);
2024-01-05 13:57:59 +05:45
}
2025-02-14 15:18:01 +05:45
return substr ( strrchr ( $lastResponse [ 'link' ][ 'webUrl' ], "/" ), 1 );
}
/**
* @param string $permissionId
* @param ResponseInterface $response
*
* @return void
*/
public function shareNgUpdatedCreatedLinkShare ( string $permissionId , ResponseInterface $response ) : void {
foreach ( $this -> shareNgCreatedLinkShares as $key => $share ) {
if ( $share [ 'id' ] === $permissionId ) {
$decodedResponse = $this -> getJsonDecodedResponse ( $response );
$this -> shareNgCreatedLinkShares [ $key ] = $decodedResponse ;
return ;
}
}
2024-01-05 13:57:59 +05:45
}
2024-01-11 11:31:28 +05:45
/**
* @return string
*/
public function shareNgGetLastCreatedUserGroupShareID () : string {
$lastResponse = $this -> shareNgGetLastCreatedUserGroupShare ();
2025-06-12 10:59:16 +05:45
if ( ! isset ( $lastResponse [ 'id' ])) {
2024-01-11 11:31:28 +05:45
throw new Error ( 'Response did not contain share id for the last created share.' );
}
2025-06-12 10:59:16 +05:45
return $lastResponse [ 'id' ];
2025-02-14 15:18:01 +05:45
}
/**
* @param string $permissionId
* @param ResponseInterface $response
*
* @return void
*/
public function shareNgUpdateCreatedUserGroupShare ( string $permissionId , ResponseInterface $response ) : void {
foreach ( $this -> shareNgCreatedUserGroupShares as $key => $share ) {
2025-06-12 10:59:16 +05:45
if ( $share [ 'id' ] === $permissionId ) {
2025-02-14 15:18:01 +05:45
$decodedResponse = $this -> getJsonDecodedResponse ( $response );
$this -> shareNgCreatedUserGroupShares [ $key ][ 'value' ] = $decodedResponse ;
return ;
};
}
2024-01-11 11:31:28 +05:45
}
2022-12-21 17:22:22 +05:45
/**
2024-04-26 15:27:00 +05:45
* Split given permissions string each separated with "," into an array of strings
2022-12-21 17:22:22 +05:45
*
* @param string $str
*
* @return string[]
*/
2024-12-24 09:30:42 +05:45
private function splitPermissionsString ( string $str ) : array {
2022-12-21 17:22:22 +05:45
$str = \trim ( $str );
$permissions = \array_map ( 'trim' , \explode ( ',' , $str ));
/* We use 'all', 'uploadwriteonly' and 'change' in feature files
for readability. Parse into appropriate permissions and return them
without any duplications.*/
if ( \in_array ( 'all' , $permissions , true )) {
$permissions = \array_keys ( SharingHelper :: PERMISSION_TYPES );
}
if ( \in_array ( 'uploadwriteonly' , $permissions , true )) {
// remove 'uploadwriteonly' from $permissions
$permissions = \array_diff ( $permissions , [ 'uploadwriteonly' ]);
$permissions = \array_merge ( $permissions , [ 'create' ]);
}
if ( \in_array ( 'change' , $permissions , true )) {
// remove 'change' from $permissions
$permissions = \array_diff ( $permissions , [ 'change' ]);
$permissions = \array_merge (
$permissions ,
2025-06-19 15:34:02 +05:45
[ 'create' , 'delete' , 'read' , 'update' ],
2022-12-21 17:22:22 +05:45
);
}
return \array_unique ( $permissions );
}
/**
*
* @return int
*
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function getServerShareTimeFromLastResponse () : int {
2024-11-29 13:19:54 +05:45
$stime = HttpRequestHelper :: getResponseXml ( $this -> response , __METHOD__ ) -> xpath ( "//stime" );
2023-05-02 17:25:56 +05:45
if ( $stime ) {
2022-12-21 17:22:22 +05:45
return ( int ) $stime [ 0 ];
}
throw new Exception ( "Last share time (i.e. 'stime') could not be found in the response." );
}
/**
* @return void
*/
2024-12-24 09:30:42 +05:45
private function waitToCreateShare () : void {
2022-12-21 17:22:22 +05:45
if (( $this -> localLastShareTime !== null )
&& (( \microtime ( true ) - $this -> localLastShareTime ) < 1 )
) {
// prevent creating two shares with the same "stime" which is
// based on seconds, this affects share merging order and could
// affect expected test result order
\sleep ( 1 );
}
}
/**
* @param string $user
* @param TableNode|null $body
2023-04-21 14:59:50 +05:45
* TableNode $body should not have any heading and can have the following rows |
2022-12-21 17:22:22 +05:45
* | path | The folder or file path to be shared |
* | name | A (human-readable) name for the share, |
* | | which can be up to 64 characters in length. |
* | publicUpload | Whether to allow public upload to a public |
* | | shared folder. Write true for allowing. |
* | password | The password to protect the public link share with. |
* | expireDate | An expire date for public link shares. |
* | | This argument takes a date string in any format |
* | | that can be passed to strtotime(), for example: |
* | | 'YYYY-MM-DD' or '+ x days'. It will be converted to |
* | | 'YYYY-MM-DD' format before sending |
* | expireDateAsString | An expire date string for public link shares. |
* | | Whatever string is provided will be sent as the |
* | | expire date. For example, use this to test sending |
* | | invalid date strings. |
* | permissions | The permissions to set on the share. |
* | | 1 = read; 2 = update; 4 = create; |
* | | 8 = delete; 16 = share; 31 = all |
2023-12-06 17:00:47 +05:45
* | | 15 = change; 0 = invite |
2022-12-21 17:22:22 +05:45
* | | 4 = uploadwriteonly |
* | | (default: 31, for public shares: 1) |
* | | Pass either the (total) number, |
* | | or the keyword, |
2023-04-21 14:59:50 +05:45
* | | or a comma separated list of keywords |
2022-12-21 17:22:22 +05:45
* | shareWith | The user or group id with which the file should |
* | | be shared. |
* | shareType | The type of the share. This can be one of: |
* | | 0 = user, 1 = group, 3 = public_link, |
* | | 6 = federated (cloud share). |
* | | Pass either the number or the keyword. |
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws Exception
*/
2023-10-03 17:24:47 +05:45
public function createShareWithSettings ( string $user , ? TableNode $body ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$this -> verifyTableNodeRows (
$body ,
[ 'path' ],
2025-06-19 15:34:02 +05:45
$this -> shareFields ,
2022-12-21 17:22:22 +05:45
);
$bodyRows = $body -> getRowsHash ();
$bodyRows [ 'name' ] = \array_key_exists ( 'name' , $bodyRows ) ? $bodyRows [ 'name' ] : null ;
$bodyRows [ 'shareWith' ] = \array_key_exists ( 'shareWith' , $bodyRows ) ? $bodyRows [ 'shareWith' ] : null ;
$bodyRows [ 'shareWith' ] = $this -> getActualUsername ( $bodyRows [ 'shareWith' ]);
2024-12-24 09:30:42 +05:45
$bodyRows [ 'publicUpload' ] = \array_key_exists (
'publicUpload' ,
2025-06-19 15:34:02 +05:45
$bodyRows ,
2024-12-24 09:30:42 +05:45
) ? $bodyRows [ 'publicUpload' ] === 'true' : null ;
$bodyRows [ 'password' ] = \array_key_exists (
'password' ,
2025-06-19 15:34:02 +05:45
$bodyRows ,
2024-12-24 09:30:42 +05:45
) ? $this -> getActualPassword ( $bodyRows [ 'password' ]) : null ;
2022-12-21 17:22:22 +05:45
if ( \array_key_exists ( 'permissions' , $bodyRows )) {
if ( \is_numeric ( $bodyRows [ 'permissions' ])) {
$bodyRows [ 'permissions' ] = ( int ) $bodyRows [ 'permissions' ];
} else {
$bodyRows [ 'permissions' ] = $this -> splitPermissionsString ( $bodyRows [ 'permissions' ]);
}
} else {
$bodyRows [ 'permissions' ] = null ;
}
if ( \array_key_exists ( 'shareType' , $bodyRows )) {
if ( \is_numeric ( $bodyRows [ 'shareType' ])) {
$bodyRows [ 'shareType' ] = ( int ) $bodyRows [ 'shareType' ];
}
} else {
$bodyRows [ 'shareType' ] = null ;
}
Assert :: assertFalse (
isset ( $bodyRows [ 'expireDate' ], $bodyRows [ 'expireDateAsString' ]),
2025-06-19 15:34:02 +05:45
'expireDate and expireDateAsString cannot be set at the same time.' ,
2022-12-21 17:22:22 +05:45
);
$needToParse = \array_key_exists ( 'expireDate' , $bodyRows );
$expireDate = $bodyRows [ 'expireDate' ] ?? $bodyRows [ 'expireDateAsString' ] ?? null ;
$bodyRows [ 'expireDate' ] = $needToParse ? \date ( 'Y-m-d' , \strtotime ( $expireDate )) : $expireDate ;
2023-10-03 17:24:47 +05:45
return $this -> createShare (
2022-12-21 17:22:22 +05:45
$user ,
$bodyRows [ 'path' ],
$bodyRows [ 'shareType' ],
$bodyRows [ 'shareWith' ],
$bodyRows [ 'publicUpload' ],
$bodyRows [ 'password' ],
$bodyRows [ 'permissions' ],
$bodyRows [ 'name' ],
2025-06-19 15:34:02 +05:45
$bodyRows [ 'expireDate' ],
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" creates a share using the sharing API with settings$/
*
* @param string $user
* @param TableNode|null $body {@link createShareWithSettings}
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userCreatesAShareWithSettings ( string $user , ? TableNode $body ) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
2023-10-03 17:24:47 +05:45
$response = $this -> createShareWithSettings (
2022-12-21 17:22:22 +05:45
$user ,
2025-06-19 15:34:02 +05:45
$body ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Given /^user "([^"]*)" has created a share with settings$/
*
* @param string $user
* @param TableNode|null $body {@link createShareWithSettings}
*
* @return void
* @throws Exception
*/
2025-06-19 12:15:41 +05:45
public function userHasCreatedAShareWithSettings ( string $user , ? TableNode $body ) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createShareWithSettings (
2022-12-21 17:22:22 +05:45
$user ,
2025-06-19 15:34:02 +05:45
$body ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
2024-05-22 17:10:47 +05:45
* @param TableNode $body
2022-12-21 17:22:22 +05:45
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-05-22 17:10:47 +05:45
public function createPublicLinkShare ( string $user , TableNode $body ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$rows = $body -> getRows ();
// A public link share is shareType 3
$rows [] = [ 'shareType' , 'public_link' ];
$newBody = new TableNode ( $rows );
2024-05-22 17:10:47 +05:45
return $this -> createShareWithSettings ( $user , $newBody );
}
/**
* @When /^user "([^"]*)" creates a public link share using the sharing API with settings$/
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userCreatesAPublicLinkShareWithSettings ( string $user , TableNode $body ) : void {
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $this -> createPublicLinkShare ( $user , $body ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Given /^user "([^"]*)" has created a public link share with settings$/
*
* @param string $user
2024-05-22 17:10:47 +05:45
* @param TableNode $body
2022-12-21 17:22:22 +05:45
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userHasCreatedAPublicLinkShareWithSettings ( string $user , TableNode $body ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> createPublicLinkShare ( $user , $body );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
$this -> clearStatusCodeArrays ();
}
/**
* @When /^the user creates a public link share using the sharing API with settings$/
*
2024-05-22 17:10:47 +05:45
* @param TableNode $body
2022-12-21 17:22:22 +05:45
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserCreatesAPublicLinkShareWithSettings ( TableNode $body ) : void {
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $this -> createPublicLinkShare ( $this -> currentUser , $body ));
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has created a public link share with settings$/
*
2024-05-22 17:10:47 +05:45
* @param TableNode $body
2022-12-21 17:22:22 +05:45
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserHasCreatedAPublicLinkShareWithSettings ( TableNode $body ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> createPublicLinkShare ( $this -> currentUser , $body );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
* @param string $path
* @param boolean $publicUpload
* @param string|null $sharePassword
* @param string|int|string[]|int[]|null $permissions
* @param string|null $linkName
* @param string|null $expireDate
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function createAPublicShare (
string $user ,
string $path ,
bool $publicUpload = false ,
2025-06-24 11:39:50 +02:00
? string $sharePassword = null ,
2022-12-21 17:22:22 +05:45
$permissions = null ,
? string $linkName = null ,
2025-06-19 15:34:02 +05:45
? string $expireDate = null ,
2023-10-03 17:24:47 +05:45
) : ResponseInterface {
return $this -> createShare (
2022-12-21 17:22:22 +05:45
$user ,
$path ,
'public_link' ,
null , // shareWith
$publicUpload ,
$sharePassword ,
$permissions ,
$linkName ,
2025-06-19 15:34:02 +05:45
$expireDate ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $path
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userCreatesAPublicLinkShareOf ( string $user , string $path ) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAPublicShare ( $user , $path );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)"$/
*
* @param string $user
* @param string $path
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userHasCreatedAPublicLinkShareOf ( string $user , string $path ) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAPublicShare ( $user , $path );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API with (read|update|create|delete|change|uploadwriteonly|share|all) permission(?:s|)$/
*
* @param string $user
* @param string $path
* @param string|int|string[]|int[]|null $permissions
*
* @return void
*/
public function userCreatesAPublicLinkShareOfWithPermission (
string $user ,
string $path ,
2025-06-19 15:34:02 +05:45
$permissions ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAPublicShare ( $user , $path , true , null , $permissions );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)" with (read|update|create|delete|change|uploadwriteonly|share|all) permission(?:s|)$/
*
* @param string $user
* @param string $path
* @param string|int|string[]|int[]|null $permissions
*
* @return void
*/
public function userHasCreatedAPublicLinkShareOfWithPermission (
string $user ,
string $path ,
2025-06-19 15:34:02 +05:45
$permissions ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAPublicShare ( $user , $path , true , null , $permissions );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
* @param string $path
* @param string $expiryDate in a valid date format, e.g. "+30 days"
*
* @return void
*/
public function createPublicLinkShareOfResourceWithExpiry (
string $user ,
string $path ,
2025-06-19 15:34:02 +05:45
string $expiryDate ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$this -> createAPublicShare (
$user ,
$path ,
true ,
null ,
null ,
null ,
2025-06-19 15:34:02 +05:45
$expiryDate ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API with expiry "([^"]*)"$/
*
* @param string $user
* @param string $path
* @param string $expiryDate in a valid date format, e.g. "+30 days"
*
* @return void
*/
public function userCreatesAPublicLinkShareOfWithExpiry (
string $user ,
string $path ,
2025-06-19 15:34:02 +05:45
string $expiryDate ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$this -> createPublicLinkShareOfResourceWithExpiry (
$user ,
$path ,
2025-06-19 15:34:02 +05:45
$expiryDate ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)" with expiry "([^"]*)"$/
*
* @param string $user
* @param string $path
* @param string $expiryDate in a valid date format, e.g. "+30 days"
*
* @return void
*/
public function userHasCreatedAPublicLinkShareOfWithExpiry (
string $user ,
string $path ,
2025-06-19 15:34:02 +05:45
string $expiryDate ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$this -> createPublicLinkShareOfResourceWithExpiry (
$user ,
$path ,
2025-06-19 15:34:02 +05:45
$expiryDate ,
2022-12-21 17:22:22 +05:45
);
$this -> theHTTPStatusCodeShouldBeSuccess ();
}
/**
2024-04-26 15:27:00 +05:45
* @Then /^user "([^"]*)" should not be able to create a public link share of (?:file|folder) "([^"]*)" using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $sharer
* @param string $filepath
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function shouldNotBeAbleToCreatePublicLinkShare ( string $sharer , string $filepath ) : void {
2022-12-21 17:22:22 +05:45
$this -> createAPublicShare ( $sharer , $filepath );
Assert :: assertEquals (
404 ,
$this -> ocsContext -> getOCSResponseStatusCode ( $this -> response ),
__METHOD__
. " Expected response status code is '404' but got '"
. $this -> ocsContext -> getOCSResponseStatusCode ( $this -> response )
2025-06-19 15:34:02 +05:45
. "'" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @param TableNode|null $body
*
2023-12-05 18:43:30 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function updateLastShareByCurrentUser ( ? TableNode $body ) : ResponseInterface {
2023-12-05 18:43:30 +05:45
return $this -> updateLastShareWithSettings ( $this -> currentUser , $body );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^the user updates the last share using the sharing API with$/
*
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserUpdatesTheLastShareWith ( ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> setResponse ( $this -> updateLastShareByCurrentUser ( $body ));
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has updated the last share with$/
*
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserHasUpdatedTheLastShareWith ( ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$response = $this -> updateLastShareByCurrentUser ( $body );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
2023-07-26 12:01:09 +05:45
/**
* Gets the last user share id using the sharer's name
*
* @param string|null $user
*
* @return string
* @throws Exception
*/
public function getLastCreatedUserGroupShareId ( ? string $user = null ) : string {
if ( $user === null ) {
2024-12-24 09:30:42 +05:45
$shareId = $this -> isUsingSharingNG ()
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShare () -> id ;
2024-06-11 11:44:13 +05:45
return ( string ) $shareId ;
2023-07-26 12:01:09 +05:45
}
$createdShares = $this -> getCreatedUserGroupShares ();
if ( isset ( $createdShares [ $user ])) {
return ( string ) $createdShares [ $user ] -> id ;
}
throw new Exception ( __METHOD__ . " user ' $user ' doesn't have a share in the created shares list" );
}
2022-12-21 17:22:22 +05:45
/**
* @param string $user
* @param TableNode|null $body
* @param string|null $shareOwner
* @param bool $updateLastPublicLink
*
2023-12-05 18:43:30 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws Exception
*/
public function updateLastShareWithSettings (
string $user ,
? TableNode $body ,
? string $shareOwner = null ,
2025-06-19 15:34:02 +05:45
? bool $updateLastPublicLink = false ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
if ( $updateLastPublicLink ) {
2024-12-24 09:30:42 +05:45
$share_id = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedLinkShareID () : ( string ) $this -> getLastCreatedPublicShare () -> id ;
2022-12-21 17:22:22 +05:45
} else {
if ( $shareOwner === null ) {
2024-12-24 09:30:42 +05:45
$share_id = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
} else {
2023-07-26 12:01:09 +05:45
$share_id = $this -> getLastCreatedUserGroupShareId ( $shareOwner );
2022-12-21 17:22:22 +05:45
}
}
$this -> verifyTableNodeRows (
$body ,
[],
2025-06-19 15:34:02 +05:45
$this -> shareFields ,
2022-12-21 17:22:22 +05:45
);
$bodyRows = $body -> getRowsHash ();
2023-03-13 13:11:37 +05:45
2022-12-21 17:22:22 +05:45
if ( \array_key_exists ( 'password' , $bodyRows )) {
$bodyRows [ 'password' ] = $this -> getActualPassword ( $bodyRows [ 'password' ]);
}
if ( \array_key_exists ( 'permissions' , $bodyRows )) {
if ( \is_numeric ( $bodyRows [ 'permissions' ])) {
$bodyRows [ 'permissions' ] = ( int ) $bodyRows [ 'permissions' ];
} else {
$bodyRows [ 'permissions' ] = $this -> splitPermissionsString ( $bodyRows [ 'permissions' ]);
$bodyRows [ 'permissions' ] = SharingHelper :: getPermissionSum ( $bodyRows [ 'permissions' ]);
}
}
2023-12-05 18:43:30 +05:45
return OcsApiHelper :: sendRequest (
2022-12-21 17:22:22 +05:45
$this -> getBaseUrl (),
$user ,
$this -> getPasswordForUser ( $user ),
"PUT" ,
$this -> getSharesEndpointPath ( "/ $share_id " ),
$bodyRows ,
2025-06-19 15:34:02 +05:45
$this -> ocsApiVersion ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" updates the last share using the sharing API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userUpdatesTheLastShareWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> setResponse ( $this -> updateLastShareWithSettings ( $user , $body ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" updates the last public link share using the sharing API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userUpdatesTheLastPublicLinkShareWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> response = $this -> updateLastShareWithSettings ( $user , $body , null , true );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Given /^user "([^"]*)" has updated the last share with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userHasUpdatedTheLastShareWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$response = $this -> updateLastShareWithSettings ( $user , $body );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has updated the last public link share with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userHasUpdatedTheLastPublicLinkShareWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$response = $this -> updateLastShareWithSettings ( $user , $body , null , true );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has updated the last share of "([^"]*)" with$/
*
* @param string $user
* @param string $shareOwner
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userHasUpdatedTheLastShareOfWith ( string $user , string $shareOwner , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$response = $this -> updateLastShareWithSettings ( $user , $body , $shareOwner );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
if ( $this -> ocsApiVersion == 1 ) {
2023-12-05 18:43:30 +05:45
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100" , "" , $response );
2022-12-21 17:22:22 +05:45
} elseif ( $this -> ocsApiVersion === 2 ) {
2023-12-05 18:43:30 +05:45
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "200" , "" , $response );
2022-12-21 17:22:22 +05:45
} else {
throw new Exception ( 'Invalid ocs api version used' );
}
}
/**
* @param string $user
* @param string|null $path
* @param string|null $shareType
* @param string|null $shareWith
* @param bool|null $publicUpload
* @param string|null $sharePassword
* @param string|int|string[]|int[]|null $permissions
* @param string|null $linkName
* @param string|null $expireDate
2023-10-26 12:59:34 +05:45
* @param string|null $space_ref
2022-12-21 17:22:22 +05:45
* @param string $sharingApp
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws JsonException
* @throws Exception
*/
public function createShare (
string $user ,
? string $path = null ,
? string $shareType = null ,
? string $shareWith = null ,
? bool $publicUpload = null ,
? string $sharePassword = null ,
$permissions = null ,
? string $linkName = null ,
? string $expireDate = null ,
2023-10-26 12:59:34 +05:45
? string $space_ref = null ,
2025-06-19 15:34:02 +05:45
string $sharingApp = 'files_sharing' ,
2023-10-03 17:24:47 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$userActual = $this -> getActualUsername ( $user );
if ( \is_string ( $permissions ) && ! \is_numeric ( $permissions )) {
$permissions = $this -> splitPermissionsString ( $permissions );
}
$this -> waitToCreateShare ();
2023-10-03 17:24:47 +05:45
$response = SharingHelper :: createShare (
2022-12-21 17:22:22 +05:45
$this -> getBaseUrl (),
$userActual ,
$this -> getPasswordForUser ( $user ),
$path ,
$shareType ,
$shareWith ,
$publicUpload ,
$sharePassword ,
$permissions ,
$linkName ,
$expireDate ,
2023-10-26 12:59:34 +05:45
$space_ref ,
2022-12-21 17:22:22 +05:45
$this -> ocsApiVersion ,
$this -> sharingApiVersion ,
2025-06-19 15:34:02 +05:45
$sharingApp ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
// save the created share data
2023-10-05 10:52:16 +05:45
if (( $response -> getStatusCode () === 200 )
&& \in_array ( $this -> ocsContext -> getOCSResponseStatusCode ( $response ), [ '100' , '200' ])
) {
2024-11-29 13:19:54 +05:45
$responseXmlObject = HttpRequestHelper :: getResponseXml ( $response );
if ( isset ( $responseXmlObject -> data )) {
$shareData = $responseXmlObject -> data ;
2023-08-03 13:51:22 +05:45
if ( $shareType === 'public_link' ) {
$this -> addToCreatedPublicShares ( $shareData );
} else {
2024-11-29 13:19:54 +05:45
$sharer = ( string ) $responseXmlObject -> data -> uid_owner ;
2023-08-03 13:51:22 +05:45
$this -> addToCreatedUserGroupshares ( $sharer , $shareData );
2023-07-26 12:01:09 +05:45
}
2022-12-21 17:22:22 +05:45
}
}
$this -> localLastShareTime = \microtime ( true );
2023-10-03 17:24:47 +05:45
return $response ;
2022-12-21 17:22:22 +05:45
}
/**
* @param string $field
* @param string $value
* @param string $contentExpected
* @param bool $expectSuccess if true then the caller expects that the field
* has the expected content
* emit debugging information if the field is not as expected
*
* @return bool
*/
public function doesFieldValueMatchExpectedContent (
string $field ,
string $value ,
string $contentExpected ,
2025-06-19 15:34:02 +05:45
bool $expectSuccess = true ,
2024-12-24 09:30:42 +05:45
) : bool {
2022-12-21 17:22:22 +05:45
if (( $contentExpected === "ANY_VALUE" )
|| (( $contentExpected === "A_TOKEN" ) && ( \strlen ( $value ) === 15 ))
|| (( $contentExpected === "A_NUMBER" ) && \is_numeric ( $value ))
2024-04-26 15:27:00 +05:45
|| (( $contentExpected === "A_STRING" ) && $value !== "" )
2022-12-21 17:22:22 +05:45
|| (( $contentExpected === "AN_URL" ) && $this -> isAPublicLinkUrl ( $value ))
|| (( $field === 'remote' ) && ( \rtrim ( $value , "/" ) === $contentExpected ))
|| ( $contentExpected === $value )
) {
if ( ! $expectSuccess ) {
echo $field . " is unexpectedly set with value '" . $value . "' \n " ;
}
return true ;
}
return false ;
}
/**
* @param string $field
* @param string|null $contentExpected
* @param bool $expectSuccess if true then the caller expects that the field
* is in the response with the expected content
* so emit debugging information if the field is not correct
* @param SimpleXMLElement|null $data
*
* @return bool
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function isFieldInResponse (
string $field ,
? string $contentExpected ,
bool $expectSuccess = true ,
2025-06-19 15:34:02 +05:45
? SimpleXMLElement $data = null ,
2024-12-24 09:30:42 +05:45
) : bool {
2022-12-21 17:22:22 +05:45
if ( $data === null ) {
2024-11-29 13:19:54 +05:45
$data = HttpRequestHelper :: getResponseXml ( $this -> response , __METHOD__ ) -> data [ 0 ];
2022-12-21 17:22:22 +05:45
}
Assert :: assertIsObject ( $data , __METHOD__ . " data not found in response XML" );
2023-02-01 09:55:51 +01:00
$dateFieldsArrayToConvert = [ 'original_date' , 'new_date' ];
2025-06-19 12:03:03 +05:45
// do not try to convert empty date
2022-12-21 17:22:22 +05:45
if (( string ) \in_array ( $field , \array_merge ( $dateFieldsArrayToConvert )) && ! empty ( $contentExpected )) {
$timestamp = \strtotime ( $contentExpected , $this -> getServerShareTimeFromLastResponse ());
// strtotime returns false if it failed to parse, just leave it as it is in that condition
if ( $timestamp !== false ) {
$contentExpected
= \date (
'Y-m-d' ,
2025-06-19 15:34:02 +05:45
$timestamp ,
2022-12-21 17:22:22 +05:45
) . " 00:00:00" ;
}
}
$contentExpected = ( string ) $contentExpected ;
if ( \count ( $data -> element ) > 0 ) {
$fieldIsSet = false ;
$value = "" ;
foreach ( $data as $element ) {
if ( isset ( $element -> $field )) {
$fieldIsSet = true ;
$value = ( string ) $element -> $field ;
2023-02-01 09:55:51 +01:00
// convert expiration to Y-m-d format. bug #5424
if ( $field === "expiration" ) {
$value = ( preg_split ( "/[\sT]+/" , $value ))[ 0 ];
}
2022-12-21 17:22:22 +05:45
if ( $this -> doesFieldValueMatchExpectedContent (
$field ,
$value ,
$contentExpected ,
2025-06-19 15:34:02 +05:45
$expectSuccess ,
2022-12-21 17:22:22 +05:45
)
) {
return true ;
}
}
}
} else {
$fieldIsSet = isset ( $data -> $field );
if ( $fieldIsSet ) {
$value = ( string ) $data -> $field ;
if ( $this -> doesFieldValueMatchExpectedContent (
$field ,
$value ,
$contentExpected ,
2025-06-19 15:34:02 +05:45
$expectSuccess ,
2022-12-21 17:22:22 +05:45
)
) {
return true ;
}
}
}
if ( $expectSuccess ) {
if ( $fieldIsSet ) {
echo $field . " has unexpected value '" . $value . "' \n " ;
} else {
echo $field . " is not set in response \n " ;
}
}
return false ;
}
/**
* @Then no files or folders should be included in the response
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function checkNoFilesFoldersInResponse () : void {
2024-11-29 13:19:54 +05:45
$data = HttpRequestHelper :: getResponseXml ( $this -> response , __METHOD__ ) -> data [ 0 ];
2022-12-21 17:22:22 +05:45
Assert :: assertIsObject ( $data , __METHOD__ . " data not found in response XML" );
Assert :: assertCount ( 0 , $data );
}
/**
* @Then exactly :count file/files or folder/folders should be included in the response
*
* @param string $count
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function checkCountFilesFoldersInResponse ( string $count ) : void {
2022-12-21 17:22:22 +05:45
$count = ( int ) $count ;
2024-11-29 13:19:54 +05:45
$data = HttpRequestHelper :: getResponseXml ( $this -> response , __METHOD__ ) -> data [ 0 ];
2022-12-21 17:22:22 +05:45
Assert :: assertIsObject ( $data , __METHOD__ . " data not found in response XML" );
Assert :: assertCount ( $count , $data , __METHOD__ . " the response does not contain $count entries" );
}
/**
* @Then /^(?:file|folder|entry) "([^"]*)" should be included in the response$/
*
* @param string $filename
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkSharedFileInResponse ( string $filename ) : void {
2022-12-21 17:22:22 +05:45
$filename = "/" . \ltrim ( $filename , '/' );
Assert :: assertTrue (
$this -> isFieldInResponse ( 'file_target' , " $filename " ),
2025-06-19 15:34:02 +05:45
"'file_target' value ' $filename ' was not found in response" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Then /^(?:file|folder|entry) "([^"]*)" should not be included in the response$/
*
* @param string $filename
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkSharedFileNotInResponse ( string $filename ) : void {
2022-12-21 17:22:22 +05:45
$filename = "/" . \ltrim ( $filename , '/' );
Assert :: assertFalse (
$this -> isFieldInResponse ( 'file_target' , " $filename " , false ),
2025-06-19 15:34:02 +05:45
"'file_target' value ' $filename ' was unexpectedly found in response" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Then /^(?:file|folder|entry) "([^"]*)" should be included as path in the response$/
*
* @param string $filename
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkSharedFileAsPathInResponse ( string $filename ) : void {
2022-12-21 17:22:22 +05:45
$filename = "/" . \ltrim ( $filename , '/' );
Assert :: assertTrue (
$this -> isFieldInResponse ( 'path' , " $filename " ),
2025-06-19 15:34:02 +05:45
"'path' value ' $filename ' was not found in response" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Then /^(?:file|folder|entry) "([^"]*)" should not be included as path in the response$/
*
* @param string $filename
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkSharedFileAsPathNotInResponse ( string $filename ) : void {
2022-12-21 17:22:22 +05:45
$filename = "/" . \ltrim ( $filename , '/' );
Assert :: assertFalse (
$this -> isFieldInResponse ( 'path' , " $filename " , false ),
2025-06-19 15:34:02 +05:45
"'path' value ' $filename ' was unexpectedly found in response" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Then /^(user|group) "([^"]*)" should be included in the response$/
*
* @param string $type
* @param string $user
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkSharedUserOrGroupInResponse ( string $type , string $user ) : void {
2022-12-21 17:22:22 +05:45
if ( $type === 'user' ) {
$user = $this -> getActualUsername ( $user );
}
Assert :: assertTrue (
$this -> isFieldInResponse ( 'share_with' , " $user " ),
2025-06-19 15:34:02 +05:45
"'share_with' value ' $user ' was not found in response" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Then /^user "([^"]*)" should not be included in the response$/
* @Then /^group "([^"]*)" should not be included in the response$/
*
* @param string $userOrGroup
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkSharedUserOrGroupNotInResponse ( string $userOrGroup ) : void {
2022-12-21 17:22:22 +05:45
Assert :: assertFalse (
$this -> isFieldInResponse ( 'share_with' , " $userOrGroup " , false ),
2025-06-19 15:34:02 +05:45
"'share_with' value ' $userOrGroup ' was unexpectedly found in response" ,
2022-12-21 17:22:22 +05:45
);
}
/**
*
2023-10-03 17:24:47 +05:45
* @param string $sharer
2022-12-21 17:22:22 +05:45
* @param string $filepath
2023-10-03 17:24:47 +05:45
* @param string $sharee
2022-12-21 17:22:22 +05:45
* @param string|int|string[]|int[] $permissions
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-10-03 17:24:47 +05:45
public function createAUserShare (
string $sharer ,
2022-12-21 17:22:22 +05:45
string $filepath ,
2023-10-03 17:24:47 +05:45
string $sharee ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2023-10-03 17:24:47 +05:45
) : ResponseInterface {
return $this -> createShare (
$sharer ,
$filepath ,
'0' ,
$this -> getActualUsername ( $sharee ),
null ,
null ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
2023-10-03 17:24:47 +05:45
* @param string $sharer
2022-12-21 17:22:22 +05:45
* @param string $filepath
2023-10-03 17:24:47 +05:45
* @param string $sharee
2022-12-21 17:22:22 +05:45
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function userSharesFileWithUserUsingTheSharingApi (
2023-10-03 17:24:47 +05:45
string $sharer ,
2022-12-21 17:22:22 +05:45
string $filepath ,
2023-10-03 17:24:47 +05:45
string $sharee ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAUserShare (
$sharer ,
2022-12-21 17:22:22 +05:45
$filepath ,
2023-10-03 17:24:47 +05:45
$this -> getActualUsername ( $sharee ),
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" shares the following (?:files|folders|entries) with user "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^user "([^"]*)" shares the following (?:files|folders|entries) with user "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
* @param string $sharer
* @param string $sharee
* @param TableNode $table
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userSharesTheFollowingFilesWithUserUsingTheSharingApi (
string $sharer ,
string $sharee ,
TableNode $table ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumns ( $table , [ "path" ]);
$paths = $table -> getHash ();
foreach ( $paths as $filepath ) {
2024-05-22 17:10:47 +05:45
$response = $this -> createAUserShare (
2022-12-21 17:22:22 +05:45
$sharer ,
$filepath [ "path" ],
2024-05-22 17:10:47 +05:45
$this -> getActualUsername ( $sharee ),
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
}
/**
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))?$/
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)"$/
*
2023-10-03 17:24:47 +05:45
* @param string $sharer
2022-12-21 17:22:22 +05:45
* @param string $filepath
2023-10-03 17:24:47 +05:45
* @param string $sharee
2022-12-21 17:22:22 +05:45
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userHasSharedFileWithUserUsingTheSharingApi (
2023-10-03 17:24:47 +05:45
string $sharer ,
2022-12-21 17:22:22 +05:45
string $filepath ,
2023-10-03 17:24:47 +05:45
string $sharee ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAUserShare (
$sharer ,
2022-12-21 17:22:22 +05:45
$filepath ,
2023-10-03 17:24:47 +05:45
$this -> getActualUsername ( $sharee ),
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with the administrator(?: with permissions (\d+))?$/
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with the administrator with permissions "([^"]*)"$/
*
* @param string $sharer
* @param string $filepath
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function userHasSharedFileWithTheAdministrator (
string $sharer ,
string $filepath ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$admin = $this -> getAdminUsername ();
2024-05-22 17:10:47 +05:45
$response = $this -> createAUserShare (
2022-12-21 17:22:22 +05:45
$sharer ,
$filepath ,
2024-05-22 17:10:47 +05:45
$this -> getActualUsername ( $admin ),
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^the user shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^the user shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
* @param string $filepath
* @param string $user2
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function theUserSharesFileWithUserUsingTheSharingApi (
string $filepath ,
string $user2 ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2025-06-19 12:15:41 +05:45
) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> createAUserShare (
2022-12-21 17:22:22 +05:45
$this -> getCurrentUser (),
2024-05-22 17:10:47 +05:45
$filepath [ "path" ],
$this -> getActualUsername ( $user2 ),
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))?$/
* @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)"$/
*
* @param string $filepath
* @param string $user2
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function theUserHasSharedFileWithUserUsingTheSharingApi (
string $filepath ,
string $user2 ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$user2 = $this -> getActualUsername ( $user2 );
2024-05-22 17:10:47 +05:45
$response = $this -> createAUserShare (
2022-12-21 17:22:22 +05:45
$this -> getCurrentUser (),
$filepath ,
2024-05-22 17:10:47 +05:45
$this -> getActualUsername ( $user2 ),
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^the user shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^the user shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function theUserSharesFileWithGroupUsingTheSharingApi (
string $filepath ,
string $group ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$this -> currentUser ,
$filepath ,
$group ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))?$/
* @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)"$/
*
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function theUserHasSharedFileWithGroupUsingTheSharingApi (
string $filepath ,
string $group ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$this -> currentUser ,
$filepath ,
$group ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
*
* @param string $user
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-10-03 17:24:47 +05:45
public function createAGroupShare (
2022-12-21 17:22:22 +05:45
string $user ,
string $filepath ,
2025-06-19 12:12:17 +05:45
string $group ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2023-10-03 17:24:47 +05:45
) : ResponseInterface {
return $this -> createShare (
$user ,
$filepath ,
'1' ,
$group ,
null ,
null ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)" using the sharing API$/
* @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
*
* @param string $user
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function userSharesFileWithGroupUsingTheSharingApi (
string $user ,
string $filepath ,
string $group ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2025-06-19 12:15:41 +05:45
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$user ,
$filepath ,
$group ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" shares the following (?:files|folders|entries) with group "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^user "([^"]*)" shares the following (?:files|folders|entries) with group "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userSharesTheFollowingFilesWithGroupUsingTheSharingApi (
string $user ,
string $group ,
TableNode $table ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2025-06-19 12:15:41 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumns ( $table , [ "path" ]);
$paths = $table -> getHash ();
foreach ( $paths as $filepath ) {
2024-05-22 17:10:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$user ,
$filepath [ "path" ],
$group ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
}
/**
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)"$/
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))?$/
*
* @param string $user
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function userHasSharedFileWithGroupUsingTheSharingApi (
string $user ,
string $filepath ,
string $group ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2025-06-19 12:15:41 +05:45
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$user ,
$filepath ,
$group ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" tries to update the last share using the sharing API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userTriesToUpdateTheLastShareUsingTheSharingApiWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> response = $this -> updateLastShareWithSettings ( $user , $body );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" tries to update the last public link share using the sharing API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userTriesToUpdateTheLastPublicLinkShareUsingTheSharingApiWith (
string $user ,
2025-06-19 15:34:02 +05:45
? TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2023-12-05 18:43:30 +05:45
$this -> response = $this -> updateLastShareWithSettings ( $user , $body , null , true );
2022-12-21 17:22:22 +05:45
}
/**
2024-04-26 15:27:00 +05:45
* @Then /^user "([^"]*)" should not be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @Then /^user "([^"]*)" should not be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)" with permissions "([^"]*)" using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $sharer
* @param string $filepath
* @param string $userOrGroupShareType
* @param string $sharee
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userTriesToShareFileUsingTheSharingApi (
string $sharer ,
string $filepath ,
string $userOrGroupShareType ,
string $sharee ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$sharee = $this -> getActualUsername ( $sharee );
2023-10-03 17:24:47 +05:45
$response = $this -> createShare (
2022-12-21 17:22:22 +05:45
$sharer ,
$filepath ,
$userOrGroupShareType ,
$sharee ,
null ,
null ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$statusCode = $this -> ocsContext -> getOCSResponseStatusCode ( $response );
2022-12-21 17:22:22 +05:45
Assert :: assertTrue (
( $statusCode == 404 ) || ( $statusCode == 403 ),
2025-06-19 15:34:02 +05:45
"Sharing should have failed with status code 403 or 404 but got status code $statusCode " ,
2022-12-21 17:22:22 +05:45
);
}
/**
2024-04-26 15:27:00 +05:45
* @Then /^user "([^"]*)" should be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @Then /^user "([^"]*)" should be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)" with permissions "([^"]*)" using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $sharer
* @param string $filepath
* @param string $userOrGroupShareType
* @param string $sharee
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userShouldBeAbleToShareUsingTheSharingApi (
string $sharer ,
string $filepath ,
string $userOrGroupShareType ,
string $sharee ,
2025-06-19 15:34:02 +05:45
$permissions = null ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$sharee = $this -> getActualUsername ( $sharee );
2023-10-03 17:24:47 +05:45
$response = $this -> createShare (
2022-12-21 17:22:22 +05:45
$sharer ,
$filepath ,
$userOrGroupShareType ,
$sharee ,
null ,
null ,
2025-06-19 15:34:02 +05:45
$permissions ,
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$statusCode = $this -> ocsContext -> getOCSResponseStatusCode ( $response );
Assert :: assertTrue (
( $statusCode == 100 ) || ( $statusCode == 200 ),
2025-06-19 15:34:02 +05:45
"Sharing should be successful but got ocs status code $statusCode " ,
2023-10-03 17:24:47 +05:45
);
2022-12-21 17:22:22 +05:45
}
/**
* @When /^the user deletes the last share using the sharing API$/
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theUserDeletesLastShareUsingTheSharingAPI () : void {
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $this -> deleteLastShareUsingSharingApiByCurrentUser ());
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has deleted the last share$/
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theUserHasDeletedLastShareUsingTheSharingAPI () : void {
2023-10-02 17:00:04 +05:45
$response = $this -> deleteLastShareUsingSharingApiByCurrentUser ();
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user the user who will do the delete request
* @param string|null $sharer the specific user whose share will be deleted (if specified)
* @param bool $deleteLastPublicLink
*
2023-10-02 17:00:04 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function deleteLastShareUsingSharingApi (
string $user ,
2025-06-24 11:39:50 +02:00
? string $sharer = null ,
2025-06-19 15:34:02 +05:45
bool $deleteLastPublicLink = false ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
if ( $deleteLastPublicLink ) {
2023-08-03 13:51:22 +05:45
$shareId = ( string ) $this -> getLastCreatedPublicShare () -> id ;
2022-12-21 17:22:22 +05:45
} else {
if ( $sharer === null ) {
2024-12-24 09:30:42 +05:45
$shareId = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
} else {
2024-12-24 09:30:42 +05:45
$shareId = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ( $sharer );
2022-12-21 17:22:22 +05:45
}
}
$url = $this -> getSharesEndpointPath ( "/ $shareId " );
2024-05-09 13:01:41 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
"DELETE" ,
2025-06-19 15:34:02 +05:45
$url ,
2022-12-21 17:22:22 +05:45
);
}
/**
2023-10-02 17:00:04 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function deleteLastShareUsingSharingApiByCurrentUser () : ResponseInterface {
2023-10-02 17:00:04 +05:45
return $this -> deleteLastShareUsingSharingApi ( $this -> currentUser );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" deletes the last share using the sharing API$/
* @When /^user "([^"]*)" tries to delete the last share using the sharing API$/
*
* @param string $user
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userDeletesLastShareUsingTheSharingApi ( string $user ) : void {
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $this -> deleteLastShareUsingSharingApi ( $user ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" deletes the last public link share using the sharing API$/
* @When /^user "([^"]*)" tries to delete the last public link share using the sharing API$/
*
* @param string $user
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userDeletesLastPublicLinkShareUsingTheSharingApi ( string $user ) : void {
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $this -> deleteLastShareUsingSharingApi ( $user , null , true ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" deletes the last share of user "([^"]*)" using the sharing API$/
* @When /^user "([^"]*)" tries to delete the last share of user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $sharer
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userDeletesLastShareOfUserUsingTheSharingApi ( string $user , string $sharer ) : void {
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $this -> deleteLastShareUsingSharingApi ( $user , $sharer ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Given /^user "([^"]*)" has deleted the last share$/
*
* @param string $user
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userHasDeletedLastShareUsingTheSharingApi ( string $user ) : void {
2023-10-02 17:00:04 +05:45
$response = $this -> deleteLastShareUsingSharingApi ( $user );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-05-22 17:10:47 +05:45
* @param string $user
* @param string $shareType user|group|link
* @param string|null $language
2022-12-21 17:22:22 +05:45
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-05-22 17:10:47 +05:45
public function getLastShareInfo ( string $user , string $shareType , ? string $language = null ) : ResponseInterface {
if ( $shareType !== "link" ) {
2024-12-24 09:30:42 +05:45
$shareId = $this -> isUsingSharingNg ()
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2024-05-22 17:10:47 +05:45
} else {
2024-12-24 09:30:42 +05:45
$shareId = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedLinkShareID () : ( string ) $this -> getLastCreatedPublicShare () -> id ;
2024-05-22 17:10:47 +05:45
}
if ( $shareId === null ) {
throw new Exception (
2025-06-19 15:34:02 +05:45
__METHOD__ . " last public link share data was not found" ,
2024-05-22 17:10:47 +05:45
);
}
$language = TranslationHelper :: getLanguage ( $language );
return $this -> getShareData ( $user , $shareId , $language );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" gets the info of the last share in language "([^"]*)" using the sharing API$/
* @When /^user "([^"]*)" gets the info of the last share using the sharing API$/
*
* @param string $user username that requests the information (might not be the user that has initiated the share)
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userGetsInfoOfLastShareUsingTheSharingApi ( string $user ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> getLastShareInfo ( $user , "user" );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" gets the info of the last public link share in language "([^"]*)" using the sharing API$/
* @When /^user "([^"]*)" gets the info of the last public link share using the sharing API$/
*
* @param string $user username that requests the information (might not be the user that has initiated the share)
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userGetsInfoOfLastPublicLinkShareUsingTheSharingApi ( string $user ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> getLastShareInfo ( $user , "link" );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Then /^as "([^"]*)" the info about the last share by user "([^"]*)" with user "([^"]*)" should include$/
*
2023-05-02 17:25:56 +05:45
* @param string $requester
2022-12-21 17:22:22 +05:45
* @param string $sharer
* @param string $sharee
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function asLastShareInfoAboutUserSharingWithUserShouldInclude (
2025-06-19 12:12:17 +05:45
string $requester ,
string $sharer ,
string $sharee ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2025-06-19 12:15:41 +05:45
) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> getLastShareInfo ( $requester , "user" );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
$this -> checkTheFieldsOfLastResponseToUser ( $sharer , $sharee , $table );
2022-12-21 17:22:22 +05:45
}
/**
* Get share data of specific share_id
*
* @param string $user
* @param string $share_id
* @param string|null $language
*
2023-10-02 17:00:04 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function getShareData ( string $user , string $share_id , ? string $language = null ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$url = $this -> getSharesEndpointPath ( "/ $share_id " );
$headers = [];
if ( $language !== null ) {
$headers [ 'Accept-Language' ] = $language ;
}
2024-05-09 13:01:41 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
"GET" ,
$url ,
null ,
null ,
2025-06-19 15:34:02 +05:45
$headers ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @param string $user
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function getSharedWithMeShares ( string $user ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$url = "/apps/files_sharing/api/v1/shares?shared_with_me=true" ;
2024-05-22 17:10:47 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
'GET' ,
2025-06-19 15:34:02 +05:45
$url ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
}
/**
* @When user :user gets all the shares shared with him/her using the sharing API
*
* @param string $user
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi ( string $user ) : void {
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $this -> getSharedWithMeShares ( $user ));
2022-12-21 17:22:22 +05:45
}
2023-02-01 09:55:51 +01:00
/**
2024-11-27 11:59:10 +05:45
* @Then as user :user the last share should include the following properties:
2023-02-01 09:55:51 +01:00
*
* @param string $user
* @param TableNode $table
*
* @return void
2024-05-13 16:28:53 +05:45
* @throws Exception
2023-02-01 09:55:51 +01:00
*/
2024-12-24 09:30:42 +05:45
public function userGetsTheLastShareSharedWithHimUsingTheSharingApi ( string $user , TableNode $table ) : void {
2023-02-01 09:55:51 +01:00
$user = $this -> getActualUsername ( $user );
2024-11-27 11:59:10 +05:45
$this -> verifyTableNodeRows ( $table , [], $this -> shareResponseFields );
2024-12-24 09:30:42 +05:45
$share_id = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2024-11-27 11:59:10 +05:45
$response = $this -> getShareData ( $user , $share_id );
$this -> theHTTPStatusCodeShouldBe (
200 ,
"Error getting info of last share for user $user " ,
2025-06-19 15:34:02 +05:45
$response ,
2024-11-27 11:59:10 +05:45
);
$this -> ocsContext -> assertOCSResponseIndicatesSuccess (
__METHOD__ .
' Error getting info of last share for user $user\n' .
$this -> ocsContext -> getOCSResponseStatusMessage (
2025-06-19 15:34:02 +05:45
$response ,
2024-11-27 11:59:10 +05:45
) . '"' ,
2025-06-19 15:34:02 +05:45
$response ,
2024-11-27 11:59:10 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> checkTheFields ( $user , $table , $response );
2023-02-01 09:55:51 +01:00
}
2022-12-21 17:22:22 +05:45
/**
2023-05-05 15:05:47 +05:45
* @When /^user "([^"]*)" gets the (|pending)\s?(user|group|user and group|public link) shares shared with (?:him|her) using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $pending
* @param string $shareType
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userGetsFilteredSharesSharedWithHimUsingTheSharingApi (
string $user ,
string $pending ,
2025-06-19 15:34:02 +05:45
string $shareType ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
if ( $pending === "pending" ) {
$pendingClause = "&state=" . SharingHelper :: SHARE_STATES [ 'pending' ];
} else {
$pendingClause = "" ;
}
if ( $shareType === 'public link' ) {
$shareType = 'public_link' ;
}
if ( $shareType === 'user and group' ) {
$rawShareTypes = SharingHelper :: SHARE_TYPES [ 'user' ] . "," . SharingHelper :: SHARE_TYPES [ 'group' ];
} else {
$rawShareTypes = SharingHelper :: SHARE_TYPES [ $shareType ];
}
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
'GET' ,
$this -> getSharesEndpointPath (
2025-06-19 15:34:02 +05:45
"?shared_with_me=true" . $pendingClause . "&share_types=" . $rawShareTypes ,
),
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
2023-05-05 15:05:47 +05:45
* @When /^user "([^"]*)" gets all the shares shared with (?:him|her|them) that are received as (?:file|folder|entry) "([^"]*)" using the provisioning API$/
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $path
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllSharesSharedWithHimFromFileOrFolderUsingTheProvisioningApi (
string $user ,
2025-06-19 15:34:02 +05:45
string $path ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$url = "/apps/files_sharing/api/"
2023-05-02 17:25:56 +05:45
. "v $this->sharingApiVersion /shares?shared_with_me=true&path= $path " ;
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
'GET' ,
2025-06-19 15:34:02 +05:45
$url ,
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
2023-06-28 10:56:08 +05:45
* @param string|null $endpointPath
2022-12-21 17:22:22 +05:45
*
2023-06-28 10:56:08 +05:45
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
2022-12-21 17:22:22 +05:45
*/
2023-06-28 10:56:08 +05:45
public function getAllShares (
string $user ,
2025-06-19 15:34:02 +05:45
? string $endpointPath = null ,
2023-06-28 10:56:08 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
2023-06-28 10:56:08 +05:45
return OcsApiHelper :: sendRequest (
2022-12-21 17:22:22 +05:45
$this -> getBaseUrl (),
$user ,
$this -> getPasswordForUser ( $user ),
"GET" ,
2023-06-28 10:56:08 +05:45
$this -> getSharesEndpointPath ( $endpointPath ),
2022-12-21 17:22:22 +05:45
[],
2025-06-19 15:34:02 +05:45
$this -> ocsApiVersion ,
2022-12-21 17:22:22 +05:45
);
}
/**
2023-06-28 10:56:08 +05:45
* @When /^user "([^"]*)" gets all shares shared by (?:him|her) using the sharing API$/
*
* @param string $user
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllSharesSharedByHimUsingTheSharingApi ( string $user ) : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllshares ( $user ));
}
/**
* @When /^the administrator gets all shares shared by (?:him|her) using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorGetsAllSharesSharedByHimUsingTheSharingApi () : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $this -> getAdminUsername ()));
2022-12-21 17:22:22 +05:45
}
/**
2023-05-05 15:05:47 +05:45
* @When /^user "([^"]*)" gets the (user|group|user and group|public link) shares shared by (?:him|her) using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $shareType
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userGetsFilteredSharesSharedByHimUsingTheSharingApi ( string $user , string $shareType ) : void {
2022-12-21 17:22:22 +05:45
if ( $shareType === 'public link' ) {
$shareType = 'public_link' ;
}
if ( $shareType === 'user and group' ) {
$rawShareTypes = SharingHelper :: SHARE_TYPES [ 'user' ] . "," . SharingHelper :: SHARE_TYPES [ 'group' ];
} else {
$rawShareTypes = SharingHelper :: SHARE_TYPES [ $shareType ];
}
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $user , "?share_types=" . $rawShareTypes ));
2022-12-21 17:22:22 +05:45
}
/**
2023-05-05 15:05:47 +05:45
* @When user :user gets all the shares of the file :path using the sharing API
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $path
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllTheSharesFromTheFileUsingTheSharingApi ( string $user , string $path ) : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $user , "?path= $path " ));
2022-12-21 17:22:22 +05:45
}
/**
2023-05-05 15:05:47 +05:45
* @When user :user gets all the shares with reshares of the file :path using the sharing API
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userGetsAllTheSharesWithResharesFromTheFileUsingTheSharingApi (
string $user ,
2025-06-19 15:34:02 +05:45
string $path ,
2024-12-24 09:30:42 +05:45
) : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $user , "?reshares=true&path= $path " ));
2022-12-21 17:22:22 +05:45
}
/**
* @When user :user gets all the shares inside the folder :path using the sharing API
*
* @param string $user
* @param string $path
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllTheSharesInsideTheFolderUsingTheSharingApi ( string $user , string $path ) : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $user , "?path= $path &subfiles=true" ));
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the response when user "([^"]*)" gets the info of the last public link share should include$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function theResponseWhenUserGetsInfoOfLastPublicLinkShareShouldInclude (
string $user ,
2025-06-19 15:34:02 +05:45
? TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$this -> verifyTableNodeRows ( $body , [], $this -> shareResponseFields );
2023-08-03 13:51:22 +05:45
$this -> getShareData ( $user , ( string ) $this -> getLastCreatedPublicShare () -> id );
2022-12-21 17:22:22 +05:45
$this -> theHTTPStatusCodeShouldBe (
200 ,
2025-06-19 15:34:02 +05:45
"Error getting info of last public link share for user $user " ,
2022-12-21 17:22:22 +05:45
);
$this -> ocsContext -> assertOCSResponseIndicatesSuccess (
__METHOD__ .
' Error getting info of last public link share for user $user\n' .
$this -> ocsContext -> getOCSResponseStatusMessage (
2025-06-19 15:34:02 +05:45
$this -> getResponse (),
) . '"' ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> checkTheFields ( $user , $body );
2022-12-21 17:22:22 +05:45
}
/**
* @Then the information of the last share of user :user should include
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws Exception
*/
public function informationOfLastShareShouldInclude (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
2023-07-26 12:01:09 +05:45
$shareId = $this -> getLastCreatedUserGroupShareId ( $user );
2022-12-21 17:22:22 +05:45
$this -> getShareData ( $user , $shareId );
$this -> theHTTPStatusCodeShouldBe (
200 ,
2025-06-19 15:34:02 +05:45
"Error getting info of last share for user $user with share id $shareId " ,
2022-12-21 17:22:22 +05:45
);
$this -> verifyTableNodeRows ( $body , [], $this -> shareResponseFields );
2024-05-22 17:10:47 +05:45
$this -> checkTheFields ( $user , $body );
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the information for user "((?:[^']*)|(?:[^"]*))" about the received share of (file|folder) "((?:[^']*)|(?:[^"]*))" shared with a (user|group) should include$/
*
* @param string $user
* @param string $fileOrFolder
* @param string $fileName
* @param string $type
* @param TableNode $body should provide share_type
*
* @return void
* @throws Exception
*/
public function theFieldsOfTheResponseForUserForResourceShouldInclude (
string $user ,
string $fileOrFolder ,
string $fileName ,
string $type ,
2025-06-19 15:34:02 +05:45
TableNode $body ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$this -> verifyTableNodeColumnsCount ( $body , 2 );
$fileName = $fileName [ 0 ] === "/" ? $fileName : '/' . $fileName ;
$data = $this -> getAllSharesSharedWithUser ( $user );
Assert :: assertNotEmpty ( $data , 'No shares found for ' . $user );
$bodyRows = $body -> getRowsHash ();
Assert :: assertArrayHasKey ( 'share_type' , $bodyRows , 'share_type is not provided' );
$share_id = null ;
foreach ( $data as $share ) {
if ( $share [ 'file_target' ] === $fileName && $share [ 'item_type' ] === $fileOrFolder ) {
if (( $share [ 'share_type' ] === SharingHelper :: getShareType ( $bodyRows [ 'share_type' ]))
) {
$share_id = $share [ 'id' ];
}
}
}
Assert :: assertNotNull ( $share_id , "Could not find share id for " . $user );
if ( \array_key_exists ( 'expiration' , $bodyRows ) && $bodyRows [ 'expiration' ] !== '' ) {
$bodyRows [ 'expiration' ] = \date ( 'd-m-Y' , \strtotime ( $bodyRows [ 'expiration' ]));
}
$this -> getShareData ( $user , $share_id );
foreach ( $bodyRows as $field => $value ) {
2024-04-26 15:27:00 +05:45
if ( $type === "user" && $field == "share_with" ) {
2022-12-21 17:22:22 +05:45
$value = $this -> getActualUsername ( $value );
}
2024-04-26 15:27:00 +05:45
if ( $field == "uid_owner" ) {
2022-12-21 17:22:22 +05:45
$value = $this -> getActualUsername ( $value );
}
$value = $this -> replaceValuesFromTable ( $field , $value );
Assert :: assertTrue (
$this -> isFieldInResponse ( $field , $value ),
2025-06-19 15:34:02 +05:45
" $field doesn't have value ' $value '" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
* @Then /^the last share_id should be included in the response/
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkingLastShareIDIsIncluded () : void {
$shareId = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
if ( ! $this -> isFieldInResponse ( 'id' , $shareId )) {
Assert :: fail (
2025-06-19 15:34:02 +05:45
"Share id $shareId not found in response" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
* @Then /^the last share id should not be included in the response/
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkLastShareIDIsNotIncluded () : void {
$shareId = $this -> isUsingSharingNG ()
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
if ( $this -> isFieldInResponse ( 'id' , $shareId , false )) {
Assert :: fail (
2025-06-19 15:34:02 +05:45
"Share id $shareId has been found in response" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
* @Then /^the last public link share id should not be included in the response/
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkLastPublicLinkShareIDIsNotIncluded () : void {
2023-08-03 13:51:22 +05:45
$shareId = ( string ) $this -> getLastCreatedPublicShare () -> id ;
2022-12-21 17:22:22 +05:45
if ( $this -> isFieldInResponse ( 'id' , $shareId , false )) {
Assert :: fail (
2025-06-19 15:34:02 +05:45
"Public link share id $shareId has been found in response" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
2024-05-22 17:10:47 +05:45
*
* @param ResponseInterface $response
2022-12-21 17:22:22 +05:45
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function responseShouldNotContainAnyShareIds ( ResponseInterface $response ) : void {
2024-11-29 13:19:54 +05:45
$data = HttpRequestHelper :: getResponseXml ( $response , __METHOD__ ) -> data [ 0 ];
2022-12-21 17:22:22 +05:45
$fieldIsSet = false ;
$receivedShareCount = 0 ;
if ( \count ( $data -> element ) > 0 ) {
foreach ( $data as $element ) {
if ( isset ( $element -> id )) {
$fieldIsSet = true ;
$receivedShareCount += 1 ;
}
}
} else {
if ( isset ( $data -> id )) {
$fieldIsSet = true ;
$receivedShareCount += 1 ;
}
}
Assert :: assertFalse (
$fieldIsSet ,
2025-06-19 15:34:02 +05:45
"response contains $receivedShareCount share ids but should not contain any share ids" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Then user :user should not see the share id of the last share
*
* @param string $user
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userShouldNotSeeShareIdOfLastShare ( string $user ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> getSharedWithMeShares ( $user );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2024-12-24 09:30:42 +05:45
$shareId = $this -> isUsingSharingNG ()
? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2024-05-22 17:10:47 +05:45
if ( $this -> isFieldInResponse ( 'id' , $shareId , false )) {
Assert :: fail (
2025-06-19 15:34:02 +05:45
"Share id $shareId has been found in response" ,
2024-05-22 17:10:47 +05:45
);
}
2022-12-21 17:22:22 +05:45
}
/**
* @Then user :user should not have any received shares
*
* @param string $user
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userShouldNotHaveAnyReceivedShares ( string $user ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> getSharedWithMeShares ( $user );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> responseShouldNotContainAnyShareIds ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the response should contain ([0-9]+) entries$/
*
* @param int $count
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function checkingTheResponseEntriesCount ( int $count ) : void {
2024-11-29 13:19:54 +05:45
$actualCount = \count ( HttpRequestHelper :: getResponseXml ( $this -> response , __METHOD__ ) -> data [ 0 ]);
2022-12-21 17:22:22 +05:45
Assert :: assertEquals (
$count ,
$actualCount ,
2025-06-19 15:34:02 +05:45
"Expected that the response should contain ' $count ' entries but got ' $actualCount ' entries" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Then the fields of the last response to user :user should include
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkFields ( string $user , ? TableNode $body ) : void {
2024-05-22 17:10:47 +05:45
$this -> checkTheFields ( $user , $body );
}
/**
* @param string $user
* @param TableNode|null $body
* @param ResponseInterface|null $response
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function checkTheFields ( string $user , ? TableNode $body , ? ResponseInterface $response = null ) : void {
2023-10-02 17:00:04 +05:45
$response = $response ?? $this -> getResponse ();
2024-11-29 13:19:54 +05:45
$data = HttpRequestHelper :: getResponseXml ( $response , __METHOD__ ) -> data [ 0 ];
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumnsCount ( $body , 2 );
$bodyRows = $body -> getRowsHash ();
$userRelatedFieldNames = [
"owner" ,
"user" ,
"uid_owner" ,
"uid_file_owner" ,
"share_with" ,
"displayname_file_owner" ,
2023-02-02 15:03:46 +05:45
"displayname_owner" ,
"additional_info_owner" ,
2025-06-19 10:46:56 +05:45
"additional_info_file_owner" ,
2022-12-21 17:22:22 +05:45
];
foreach ( $bodyRows as $field => $value ) {
if ( \in_array ( $field , $userRelatedFieldNames )) {
$value = $this -> substituteInLineCodes ( $value , $user );
}
$value = $this -> getActualUsername ( $value );
$value = $this -> replaceValuesFromTable ( $field , $value );
Assert :: assertTrue (
2023-10-02 17:00:04 +05:45
$this -> isFieldInResponse ( $field , $value , true , $data ),
" $field doesn't have value ' $value '" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
2023-06-27 12:50:10 +02:00
* @Then the fields of the last response to user :user and space :space should include
*
* @param string $user
* @param string $space
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkFieldsOfSpaceSharingResponse ( string $user , string $space , ? TableNode $body ) : void {
2023-06-27 12:50:10 +02:00
$this -> verifyTableNodeColumnsCount ( $body , 2 );
2023-07-26 12:01:09 +05:45
2023-06-27 12:50:10 +02:00
$bodyRows = $body -> getRowsHash ();
$userRelatedFieldNames = [
"owner" ,
"user" ,
"uid_owner" ,
"uid_file_owner" ,
"share_with" ,
"displayname_file_owner" ,
"displayname_owner" ,
"additional_info_owner" ,
"additional_info_file_owner" ,
2025-06-19 10:46:56 +05:45
"space_id" ,
2023-06-27 12:50:10 +02:00
];
2024-11-29 13:19:54 +05:45
$response = HttpRequestHelper :: getResponseXml ( $this -> response , __METHOD__ );
2023-08-03 13:51:22 +05:45
$this -> addToCreatedPublicShares ( $response -> data );
2023-06-27 12:50:10 +02:00
foreach ( $bodyRows as $field => $value ) {
if ( \in_array ( $field , $userRelatedFieldNames )) {
$value = $this -> substituteInLineCodes (
$value ,
$user ,
[],
[
[
"code" => "%space_id%" ,
"function" =>
[ $this -> spacesContext , "getSpaceIdByName" ],
2025-06-19 10:46:56 +05:45
"parameter" => [ $user , $space ],
2023-06-27 12:50:10 +02:00
],
],
null ,
2025-06-19 15:34:02 +05:45
null ,
2023-06-27 12:50:10 +02:00
);
if ( $field === "uid_file_owner" ) {
$value = ( explode ( "$" , $value ))[ 1 ];
}
if ( $field === "space_id" ) {
2024-04-26 15:27:00 +05:45
$explodedSpaceId = explode ( "$" , $value );
$value = $explodedSpaceId [ 0 ] . "$" . $explodedSpaceId [ 1 ] . "!" . $explodedSpaceId [ 1 ];
2023-06-27 12:50:10 +02:00
}
}
$value = $this -> getActualUsername ( $value );
$value = $this -> replaceValuesFromTable ( $field , $value );
2023-07-26 12:01:09 +05:45
2023-06-27 12:50:10 +02:00
Assert :: assertTrue (
2023-08-03 13:51:22 +05:45
$this -> isFieldInResponse ( $field , $value , true , $this -> getLastCreatedPublicShare ()),
2025-06-19 15:34:02 +05:45
" $field doesn't have value ' $value '" ,
2023-06-27 12:50:10 +02:00
);
}
}
/**
2022-12-21 17:22:22 +05:45
* @Then /^the fields of the last response (?:to|about) user "([^"]*)" sharing with (?:user|group) "([^"]*)" should include$/
*
* @param string $sharer
* @param string $sharee
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkFieldsOfLastResponseToUser ( string $sharer , string $sharee , ? TableNode $body ) : void {
2024-05-22 17:10:47 +05:45
$this -> checkTheFieldsOfLastResponseToUser ( $sharer , $sharee , $body );
}
/**
* @param string $sharer
* @param string $sharee
* @param TableNode|null $body
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function checkTheFieldsOfLastResponseToUser ( string $sharer , string $sharee , ? TableNode $body ) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumnsCount ( $body , 2 );
$bodyRows = $body -> getRowsHash ();
foreach ( $bodyRows as $field => $value ) {
2024-12-24 09:30:42 +05:45
if ( \in_array (
$field ,
[
"displayname_owner" ,
2025-06-19 10:34:17 +05:45
"displayname_file_owner" ,
"owner" ,
"uid_owner" ,
"uid_file_owner" ,
"additional_info_owner" ,
2025-06-19 10:46:56 +05:45
"additional_info_file_owner" ,
2025-06-19 15:34:02 +05:45
],
2024-12-24 09:30:42 +05:45
)
) {
2022-12-21 17:22:22 +05:45
$value = $this -> substituteInLineCodes ( $value , $sharer );
2024-12-24 09:30:42 +05:45
} elseif ( \in_array (
$field ,
2025-06-19 15:34:02 +05:45
[ "share_with" , "share_with_displayname" , "user" , "share_with_additional_info" ],
2024-12-24 09:30:42 +05:45
)
) {
2022-12-21 17:22:22 +05:45
$value = $this -> substituteInLineCodes ( $value , $sharee );
}
$value = $this -> replaceValuesFromTable ( $field , $value );
Assert :: assertTrue (
$this -> isFieldInResponse ( $field , $value ),
2025-06-19 15:34:02 +05:45
" $field doesn't have value ' $value '" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
* @Then the last response should be empty
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theFieldsOfTheLastResponseShouldBeEmpty () : void {
2024-11-29 13:19:54 +05:45
$data = HttpRequestHelper :: getResponseXml ( $this -> response , __METHOD__ ) -> data [ 0 ];
2022-12-21 17:22:22 +05:45
Assert :: assertEquals (
\count ( $data -> element ),
0 ,
2025-06-19 15:34:02 +05:45
"last response contains data but was expected to be empty" ,
2022-12-21 17:22:22 +05:45
);
}
/**
*
* @return string
*
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function getSharingAttributesFromLastResponse () : string {
2024-11-29 13:19:54 +05:45
$responseXmlObject = HttpRequestHelper :: getResponseXml ( $this -> response , __METHOD__ ) -> data [ 0 ];
$actualAttributesElement = $responseXmlObject -> xpath ( '//attributes' );
2022-12-21 17:22:22 +05:45
2023-05-02 17:25:56 +05:45
if ( $actualAttributesElement ) {
2022-12-21 17:22:22 +05:45
$actualAttributes = ( array ) $actualAttributesElement [ 0 ];
if ( empty ( $actualAttributes )) {
throw new Exception (
2025-06-19 15:34:02 +05:45
"No data inside 'attributes' element in the last response." ,
2022-12-21 17:22:22 +05:45
);
}
return $actualAttributes [ 0 ];
}
throw new Exception ( "No 'attributes' found inside the response of the last share." );
}
/**
* @Then the additional sharing attributes for the response should include
*
* @param TableNode $attributes
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkingAttributesInLastShareResponse ( TableNode $attributes ) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumns ( $attributes , [ 'scope' , 'key' , 'enabled' ]);
$attributes = $attributes -> getHash ();
// change string "true"/"false" to boolean inside array
\array_walk_recursive (
$attributes ,
2025-06-19 12:15:41 +05:45
function ( & $value , $key ) : void {
2022-12-21 17:22:22 +05:45
if ( $key !== 'enabled' ) {
return ;
}
if ( $value === 'true' ) {
$value = true ;
}
if ( $value === 'false' ) {
$value = false ;
}
2025-06-19 15:34:02 +05:45
},
2022-12-21 17:22:22 +05:45
);
$actualAttributes = $this -> getSharingAttributesFromLastResponse ();
// parse json to array
$actualAttributesArray = \json_decode ( $actualAttributes , true );
if ( \json_last_error () !== JSON_ERROR_NONE ) {
$errMsg = \strtolower ( \json_last_error_msg ());
throw new Exception (
"JSON decoding failed because of $errMsg in json \n " .
'Expected data to be json with array of objects. ' .
2025-06-19 15:34:02 +05:45
" \n Received: \n $actualAttributes " ,
2022-12-21 17:22:22 +05:45
);
}
// check if the expected attributes received from table match actualAttributes
foreach ( $attributes as $row ) {
$foundRow = false ;
foreach ( $actualAttributesArray as $item ) {
if (( $item [ 'scope' ] === $row [ 'scope' ])
&& ( $item [ 'key' ] === $row [ 'key' ])
&& ( $item [ 'enabled' ] === $row [ 'enabled' ])
) {
$foundRow = true ;
}
}
Assert :: assertTrue (
$foundRow ,
2025-06-19 15:34:02 +05:45
"Could not find expected attribute with scope '" . $row [ 'scope' ] . "' and key '" . $row [ 'key' ] . "'" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
* @Then the downloading of file :fileName for user :user should fail with error message
*
* @param string $fileName
* @param string $user
* @param PyStringNode $errorMessage
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userDownloadsFailWithMessage ( string $fileName , string $user , PyStringNode $errorMessage ) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
2023-10-11 16:15:31 +05:45
$response = $this -> downloadFileAsUserUsingPassword ( $user , $fileName );
2024-11-29 13:19:54 +05:45
$receivedErrorMessage = HttpRequestHelper :: getResponseXml ( $response , __METHOD__ ) -> xpath ( '//s:message' );
2023-05-02 17:25:56 +05:45
Assert :: assertEquals (
$errorMessage ,
( string ) $receivedErrorMessage [ 0 ],
"Expected error message was ' $errorMessage ' but got '"
2024-04-26 15:27:00 +05:45
. $receivedErrorMessage [ 0 ]
2025-06-19 15:34:02 +05:45
. "'" ,
2023-05-02 17:25:56 +05:45
);
2022-12-21 17:22:22 +05:45
}
/**
* @Then the fields of the last response should not include
*
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkFieldsNotInResponse ( ? TableNode $body ) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumnsCount ( $body , 2 );
$bodyRows = $body -> getRowsHash ();
foreach ( $bodyRows as $field => $value ) {
$value = $this -> replaceValuesFromTable ( $field , $value );
Assert :: assertFalse (
$this -> isFieldInResponse ( $field , $value , false ),
2025-06-19 15:34:02 +05:45
" $field has value $value but should not" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
* Returns shares of a file or folder as a SimpleXMLElement
*
* Note: the "single" SimpleXMLElement may contain one or more actual
2023-04-21 14:59:50 +05:45
* shares (to users, groups or public links etc.). If you access an item directly,
2022-12-21 17:22:22 +05:45
* for example, getShares()->id, then the value of "id" for the first element
* will be returned. To access all the elements, you can loop through the
* returned SimpleXMLElement with "foreach" - it will act like a PHP array
* of elements.
*
* @param string $user
* @param string $path
*
* @return SimpleXMLElement
*/
2024-12-24 09:30:42 +05:45
public function getShares ( string $user , string $path ) : SimpleXMLElement {
2023-12-05 18:43:30 +05:45
$response = OcsApiHelper :: sendRequest (
2022-12-21 17:22:22 +05:45
$this -> getBaseUrl (),
$user ,
$this -> getPasswordForUser ( $user ),
"GET" ,
$this -> getSharesEndpointPath ( "?path= $path " ),
[],
2025-06-19 15:34:02 +05:45
$this -> ocsApiVersion ,
2022-12-21 17:22:22 +05:45
);
2024-11-29 13:19:54 +05:45
return HttpRequestHelper :: getResponseXml ( $response , __METHOD__ ) -> data -> element ;
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^as user "([^"]*)" the public shares of (?:file|folder) "([^"]*)" should be$/
*
* @param string $user
* @param string $path
* @param TableNode|null $TableNode
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkPublicShares ( string $user , string $path , ? TableNode $TableNode ) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
2023-05-24 12:56:43 +05:45
$response = $this -> getShares ( $user , $path );
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumns ( $TableNode , [ 'path' , 'permissions' , 'name' ]);
if ( $TableNode instanceof TableNode ) {
$elementRows = $TableNode -> getHash ();
foreach ( $elementRows as $expectedElementsArray ) {
$nameFound = false ;
2023-05-24 12:56:43 +05:45
foreach ( $response as $elementResponded ) {
2022-12-21 17:22:22 +05:45
if (( string ) $elementResponded -> name [ 0 ] === $expectedElementsArray [ 'name' ]) {
Assert :: assertEquals (
$expectedElementsArray [ 'path' ],
( string ) $elementResponded -> path [ 0 ],
__METHOD__
2024-04-22 11:20:00 +02:00
. " Expected ' { $expectedElementsArray [ 'path' ] } ' but got '"
2023-05-02 17:25:56 +05:45
. $elementResponded -> path [ 0 ]
2025-06-19 15:34:02 +05:45
. "'" ,
2022-12-21 17:22:22 +05:45
);
Assert :: assertEquals (
$expectedElementsArray [ 'permissions' ],
( string ) $elementResponded -> permissions [ 0 ],
__METHOD__
2024-04-22 11:20:00 +02:00
. " Expected ' { $expectedElementsArray [ 'permissions' ] } ' but got '"
2023-05-02 17:25:56 +05:45
. $elementResponded -> permissions [ 0 ]
2025-06-19 15:34:02 +05:45
. "'" ,
2022-12-21 17:22:22 +05:45
);
$nameFound = true ;
break ;
}
}
Assert :: assertTrue (
$nameFound ,
2025-06-19 15:34:02 +05:45
"Shared link name { $expectedElementsArray [ 'name' ] } not found" ,
2022-12-21 17:22:22 +05:45
);
}
}
}
/**
2024-04-26 15:27:00 +05:45
* @Then /^as user "([^"]*)" the (?:file|folder) "([^"]*)" should not have any shares$/
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $path
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function checkPublicSharesAreEmpty ( string $user , string $path ) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
2023-05-24 12:56:43 +05:45
$response = $this -> getShares ( $user , $path );
2025-06-19 12:03:03 +05:45
// It shouldn't have public shares
2022-12-21 17:22:22 +05:45
Assert :: assertEquals (
0 ,
2023-05-24 12:56:43 +05:45
\count ( $response ),
2022-12-21 17:22:22 +05:45
__METHOD__
. " As ' $user ', ' $path ' was expected to have no shares, but got '"
2023-05-24 12:56:43 +05:45
. \count ( $response )
2025-06-19 15:34:02 +05:45
. "' shares present" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @param string $user
* @param string $path to share
* @param string $name of share
*
* @return string|null
*/
2024-12-24 09:30:42 +05:45
public function getPublicShareIDByName ( string $user , string $path , string $name ) : ? string {
2023-05-24 12:56:43 +05:45
$response = $this -> getShares ( $user , $path );
foreach ( $response as $elementResponded ) {
2022-12-21 17:22:22 +05:45
if (( string ) $elementResponded -> name [ 0 ] === $name ) {
return ( string ) $elementResponded -> id [ 0 ];
}
}
return null ;
}
/**
* @param string $user
* @param string $name
* @param string $path
*
2023-10-02 17:00:04 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function deletePublicLinkShareUsingTheSharingApi (
string $user ,
string $name ,
2025-06-19 15:34:02 +05:45
string $path ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$share_id = $this -> getPublicShareIDByName ( $user , $path , $name );
$url = $this -> getSharesEndpointPath ( "/ $share_id " );
2024-05-09 13:01:41 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
"DELETE" ,
2025-06-19 15:34:02 +05:45
$url ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" deletes public link share named "([^"]*)" in (?:file|folder) "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $name
* @param string $path
*
* @return void
*/
public function userDeletesPublicLinkShareNamedUsingTheSharingApi (
string $user ,
string $name ,
2025-06-19 15:34:02 +05:45
string $path ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-02 17:00:04 +05:45
$response = $this -> deletePublicLinkShareUsingTheSharingApi (
2022-12-21 17:22:22 +05:45
$user ,
$name ,
2025-06-19 15:34:02 +05:45
$path ,
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has deleted public link share named "([^"]*)" in (?:file|folder) "([^"]*)"$/
*
* @param string $user
* @param string $name
* @param string $path
*
* @return void
*/
public function userHasDeletedPublicLinkShareNamedUsingTheSharingApi (
string $user ,
string $name ,
2025-06-19 15:34:02 +05:45
string $path ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-02 17:00:04 +05:45
$response = $this -> deletePublicLinkShareUsingTheSharingApi (
2022-12-21 17:22:22 +05:45
$user ,
$name ,
2025-06-19 15:34:02 +05:45
$path ,
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
2024-05-22 17:10:47 +05:45
* @param string|null $state
2022-12-21 17:22:22 +05:45
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function reactToShareOfferedBy (
string $user ,
string $action ,
string $share ,
string $offeredBy ,
2025-06-19 15:34:02 +05:45
? string $state = '' ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$offeredBy = $this -> getActualUsername ( $offeredBy );
2023-05-24 12:56:43 +05:45
$response = $this -> getAllSharesSharedWithUser ( $user );
2022-12-21 17:22:22 +05:45
$shareId = null ;
2023-05-24 12:56:43 +05:45
foreach ( $response as $shareElement ) {
2022-12-21 17:22:22 +05:45
// SharingHelper::SHARE_STATES has the mapping between the words for share states
// like "accepted", "pending",... and the integer constants 0, 1,... that are in
// the "state" field of the share data.
if ( $state === '' ) {
// Any share state is OK
$matchesShareState = true ;
} else {
$requiredStateCode = SharingHelper :: SHARE_STATES [ $state ];
if ( $shareElement [ 'state' ] === $requiredStateCode ) {
$matchesShareState = true ;
} else {
$matchesShareState = false ;
}
}
if ( $matchesShareState
&& ( string ) $shareElement [ 'uid_owner' ] === $offeredBy
&& ( string ) $shareElement [ 'path' ] === $share
) {
$shareId = ( string ) $shareElement [ 'id' ];
break ;
}
}
Assert :: assertNotNull (
$shareId ,
2025-06-19 15:34:02 +05:45
__METHOD__ . " could not find share $share , offered by $offeredBy to $user " ,
2022-12-21 17:22:22 +05:45
);
2023-05-02 17:25:56 +05:45
$url = "/apps/files_sharing/api/v $this->sharingApiVersion " .
2022-12-21 17:22:22 +05:45
"/shares/pending/ $shareId " ;
if ( \substr ( $action , 0 , 7 ) === "decline" ) {
$httpRequestMethod = "DELETE" ;
2023-05-02 17:25:56 +05:45
} else {
// do a POST to accept the share
2022-12-21 17:22:22 +05:45
$httpRequestMethod = "POST" ;
}
2024-05-22 17:10:47 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
$httpRequestMethod ,
2025-06-19 15:34:02 +05:45
$url ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
}
/**
* @When /^user "([^"]*)" (declines|accepts) share "([^"]*)" offered by user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
* @param string|null $state specify 'accepted', 'pending', 'rejected' or 'declined' to only consider shares in that state
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userReactsToShareOfferedBy (
string $user ,
string $action ,
string $share ,
string $offeredBy ,
2025-06-19 15:34:02 +05:45
? string $state = '' ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy (
$user ,
$action ,
$share ,
2025-06-19 15:34:02 +05:45
$offeredBy ,
2024-05-22 17:10:47 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
2024-07-22 16:46:04 +05:45
/**
* @When /^user "([^"]*)" (declines|accepts) the already (?:accepted|declined) share "([^"]*)" offered by user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
* @param string|null $state specify 'accepted', 'pending', 'rejected' or 'declined' to only consider shares in that state
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userAcceptsTheAlreadyAcceptedShareOfferedByUsingTheSharingApi (
string $user ,
string $action ,
string $share ,
string $offeredBy ,
2025-06-19 15:34:02 +05:45
? string $state = '' ,
2024-12-24 09:30:42 +05:45
) : void {
2024-07-22 16:46:04 +05:45
$response = $this -> reactToShareOfferedBy (
$user ,
$action ,
"/Shares/" . \trim ( $share , "/" ),
2025-06-19 15:34:02 +05:45
$offeredBy ,
2024-07-22 16:46:04 +05:45
);
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
}
2022-12-21 17:22:22 +05:45
/**
* @When /^user "([^"]*)" (declines|accepts) the following shares offered by user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $offeredBy
* @param TableNode $table
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userReactsToTheFollowingSharesOfferedBy (
string $user ,
string $action ,
string $offeredBy ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumns ( $table , [ "path" ]);
$paths = $table -> getHash ();
foreach ( $paths as $share ) {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy (
2022-12-21 17:22:22 +05:45
$user ,
$action ,
$share [ "path" ],
2025-06-19 15:34:02 +05:45
$offeredBy ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" (declines|accepts) share with ID "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $share_id
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userReactsToShareWithShareIDOfferedBy ( string $user , string $action , string $share_id ) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$shareId = $this -> substituteInLineCodes ( $share_id , $user );
2023-05-02 17:25:56 +05:45
$url = "/apps/files_sharing/api/v $this->sharingApiVersion " .
2022-12-21 17:22:22 +05:45
"/shares/pending/ $shareId " ;
if ( \substr ( $action , 0 , 7 ) === "decline" ) {
$httpRequestMethod = "DELETE" ;
2023-05-02 17:25:56 +05:45
} else {
// do a POST to accept the share
2022-12-21 17:22:22 +05:45
$httpRequestMethod = "POST" ;
}
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
$httpRequestMethod ,
2025-06-19 15:34:02 +05:45
$url ,
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has (declined|accepted) share "([^"]*)" offered by user "([^"]*)"$/
*
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userHasReactedToShareOfferedBy (
string $user ,
string $action ,
string $share ,
2025-06-19 15:34:02 +05:45
string $offeredBy ,
2024-12-24 09:30:42 +05:45
) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy (
$user ,
$action ,
$share ,
2025-06-19 15:34:02 +05:45
$offeredBy ,
2024-05-22 17:10:47 +05:45
);
2022-12-21 17:22:22 +05:45
if ( $action === 'declined' ) {
$actionText = 'decline' ;
2023-05-02 17:25:56 +05:45
} else {
2022-12-21 17:22:22 +05:45
$actionText = 'accept' ;
}
$this -> theHTTPStatusCodeShouldBe (
200 ,
2024-05-22 17:10:47 +05:45
__METHOD__ . " could not $actionText share $share to $user by $offeredBy " ,
2025-06-19 15:34:02 +05:45
$response ,
2022-12-21 17:22:22 +05:45
);
$this -> emptyLastHTTPStatusCodesArray ();
$this -> emptyLastOCSStatusCodesArray ();
}
/**
* @When /^user "([^"]*)" accepts the (?:first|next|) pending share "([^"]*)" offered by user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $share
* @param string $offeredBy
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userAcceptsThePendingShareOfferedBy ( string $user , string $share , string $offeredBy ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy ( $user , 'accepts' , $share , $offeredBy , 'pending' );
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has accepted the (?:first|next|) pending share "([^"]*)" offered by user "([^"]*)"$/
*
* @param string $user
* @param string $share
* @param string $offeredBy
*
* @return void
* @throws Exception
*/
2025-06-19 12:15:41 +05:45
public function userHasAcceptedThePendingShareOfferedBy ( string $user , string $share , string $offeredBy ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy ( $user , 'accepts' , $share , $offeredBy , 'pending' );
2022-12-21 17:22:22 +05:45
$this -> theHTTPStatusCodeShouldBe (
200 ,
2024-05-22 17:10:47 +05:45
__METHOD__ . " could not accept the pending share $share to $user by $offeredBy " ,
2025-06-19 15:34:02 +05:45
$response ,
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^user "([^"]*)" should be able to (decline|accept) pending share "([^"]*)" offered by user "([^"]*)"$/
*
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
*
* @return void
* @throws Exception
*/
public function userShouldBeAbleToAcceptShareOfferedBy (
string $user ,
string $action ,
string $share ,
2025-06-19 15:34:02 +05:45
string $offeredBy ,
2025-06-19 12:15:41 +05:45
) : void {
2022-12-21 17:22:22 +05:45
if ( $action === 'accept' ) {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy ( $user , 'accepts' , $share , $offeredBy , 'pending' );
$this -> theHTTPStatusCodeShouldBe (
200 ,
__METHOD__ . " could not accept the pending share $share to $user by $offeredBy " ,
2025-06-19 15:34:02 +05:45
$response ,
2024-05-22 17:10:47 +05:45
);
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
// $this->ocsContext->assertOCSResponseIndicatesSuccess();
2022-12-21 17:22:22 +05:45
} elseif ( $action === 'decline' ) {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy ( $user , 'declined' , $share , $offeredBy );
$this -> theHTTPStatusCodeShouldBe (
200 ,
__METHOD__ . " could not decline share $share to $user by $offeredBy " ,
2025-06-19 15:34:02 +05:45
$response ,
2024-05-22 17:10:47 +05:45
);
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
// $this->emptyLastHTTPStatusCodesArray();
// $this->emptyLastOCSStatusCodesArray();
2022-12-21 17:22:22 +05:45
}
}
/**
*
* @Then /^the sharing API should report to user "([^"]*)" that these shares are in the (pending|accepted|declined) state$/
*
* @param string $user
* @param string $state
* @param TableNode $table table with headings that correspond to the attributes
* of the share e.g. "|path|uid_owner|"
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function assertSharesOfUserAreInState ( string $user , string $state , TableNode $table ) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumns ( $table , [ "path" ], $this -> shareResponseFields );
$usersShares = $this -> getAllSharesSharedWithUser ( $user , $state );
foreach ( $table as $row ) {
$found = false ;
2025-06-19 12:03:03 +05:45
// the API returns the path without trailing slash, but we want to
// be able to accept leading and/or trailing slashes in the step definition
2022-12-21 17:22:22 +05:45
$row [ 'path' ] = "/" . \trim ( $row [ 'path' ], "/" );
foreach ( $usersShares as $share ) {
try {
Assert :: assertArrayHasKey ( 'path' , $share );
Assert :: assertEquals ( $row [ 'path' ], $share [ 'path' ]);
$found = true ;
break ;
2023-06-08 16:59:45 +05:45
} catch ( ExpectationFailedException $e ) {
2022-12-21 17:22:22 +05:45
}
}
if ( ! $found ) {
Assert :: fail (
"could not find the share with this attributes " .
2025-06-19 15:34:02 +05:45
\print_r ( $row , true ),
2022-12-21 17:22:22 +05:45
);
}
}
}
/**
*
* @Then /^the sharing API should report to user "([^"]*)" that no shares are in the (pending|accepted|declined) state$/
*
* @param string $user
* @param string $state
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function assertNoSharesOfUserAreInState ( string $user , string $state ) : void {
2022-12-21 17:22:22 +05:45
$usersShares = $this -> getAllSharesSharedWithUser ( $user , $state );
Assert :: assertEmpty (
$usersShares ,
2025-06-19 15:34:02 +05:45
"user has " . \count ( $usersShares ) . " share(s) in the $state state" ,
2022-12-21 17:22:22 +05:45
);
}
2023-05-24 12:56:43 +05:45
/**
2023-06-30 12:22:42 +05:45
* @param string $sharer
* @param string $path
* @param string $sharee
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2023-06-30 12:22:42 +05:45
*/
2024-05-22 17:10:47 +05:45
public function unshareResourceSharedTo ( string $sharer , string $path , string $sharee ) : ResponseInterface {
2023-05-24 12:56:43 +05:45
$sharer = $this -> getActualUsername ( $sharer );
$sharee = $this -> getActualUsername ( $sharee );
$response = $this -> getShares ( $sharer , " $path &share_types=0" );
$shareId = null ;
foreach ( $response as $shareElement ) {
if (( string ) $shareElement -> share_with [ 0 ] === $sharee ) {
$shareId = ( string ) $shareElement -> id ;
break ;
}
}
Assert :: assertNotNull (
$shareId ,
2025-06-19 15:34:02 +05:45
__METHOD__ . " could not find share, offered by $sharer to $sharee " ,
2023-05-24 12:56:43 +05:45
);
2024-05-22 17:10:47 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2023-05-24 12:56:43 +05:45
$sharer ,
'DELETE' ,
2025-06-19 15:34:02 +05:45
'/apps/files_sharing/api/v' . $this -> sharingApiVersion . '/shares/' . $shareId ,
2023-05-24 12:56:43 +05:45
);
2024-05-22 17:10:47 +05:45
}
2024-06-11 11:44:13 +05:45
2024-05-22 17:10:47 +05:45
/**
* @When /^user "([^"]*)" unshares (?:folder|file|entity) "([^"]*)" shared to "([^"]*)"$/
*
* @param string $sharer
* @param string $path
* @param string $sharee
*
* @return void
* @throws JsonException
*/
public function userUnsharesResourceSharedTo ( string $sharer , string $path , string $sharee ) : void {
$response = $this -> unshareResourceSharedTo ( $sharer , $path , $sharee );
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2023-05-24 12:56:43 +05:45
}
2022-12-21 17:22:22 +05:45
/**
* @Then the sharing API should report that no shares are shared with user :user
*
* @param string $user
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function assertThatNoSharesAreSharedWithUser ( string $user ) : void {
2022-12-21 17:22:22 +05:45
$usersShares = $this -> getAllSharesSharedWithUser ( $user );
Assert :: assertEmpty (
$usersShares ,
2025-06-19 15:34:02 +05:45
"user has " . \count ( $usersShares ) . " share(s)" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @When user :user gets share with id :share using the sharing API
*
* @param string $user
* @param string $share_id
*
* @return ResponseInterface|null
*/
2024-12-24 09:30:42 +05:45
public function userGetsTheLastShareWithTheShareIdUsingTheSharingApi (
string $user ,
2025-06-19 15:34:02 +05:45
string $share_id ,
2024-12-24 09:30:42 +05:45
) : ? ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$share_id = $this -> substituteInLineCodes ( $share_id , $user );
$url = $this -> getSharesEndpointPath ( "/ $share_id " );
$this -> response = OcsApiHelper :: sendRequest (
$this -> getBaseUrl (),
$user ,
$this -> getPasswordForUser ( $user ),
"GET" ,
$url ,
[],
2025-06-19 15:34:02 +05:45
$this -> ocsApiVersion ,
2022-12-21 17:22:22 +05:45
);
return $this -> response ;
}
/**
*
* @param string $user
* @param string|null $state pending|accepted|declined|rejected|all
*
* @return array of shares that are shared with this user
* @throws Exception
*/
private function getAllSharesSharedWithUser ( string $user , ? string $state = "all" ) : array {
switch ( $state ) {
case 'pending' :
case 'accepted' :
case 'declined' :
case 'rejected' :
$stateCode = SharingHelper :: SHARE_STATES [ $state ];
break ;
case 'all' :
$stateCode = "all" ;
break ;
default :
throw new InvalidArgumentException (
2025-06-19 15:34:02 +05:45
__METHOD__ . ' invalid "state" given' ,
2022-12-21 17:22:22 +05:45
);
}
$url = $this -> getSharesEndpointPath ( "?format=json&shared_with_me=true&state= $stateCode " );
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
"GET" ,
2025-06-19 15:34:02 +05:45
$url ,
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
if ( $response -> getStatusCode () !== 200 ) {
2022-12-21 17:22:22 +05:45
throw new Exception (
2025-06-19 15:34:02 +05:45
__METHOD__ . " could not retrieve information about shares" ,
2022-12-21 17:22:22 +05:45
);
}
2023-10-02 17:00:04 +05:45
$result = $response -> getBody () -> getContents ();
2022-12-21 17:22:22 +05:45
$usersShares = \json_decode ( $result , true );
if ( ! \is_array ( $usersShares )) {
throw new Exception (
2025-06-19 15:34:02 +05:45
__METHOD__ . " API result about shares is not valid JSON" ,
2022-12-21 17:22:22 +05:45
);
}
return $usersShares [ 'ocs' ][ 'data' ];
}
/**
* Send request for preview of a file in a public link
*
* @param string $fileName
* @param string $token
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function getPublicPreviewOfFile ( string $fileName , string $token ) : ResponseInterface {
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( $this -> getDavPathVersion (), $token , "public-files" );
2024-10-21 12:24:50 +05:45
$url = " $baseUrl / $davPath / $fileName ?preview=1" ;
2024-05-22 17:10:47 +05:45
return HttpRequestHelper :: get (
2022-12-21 17:22:22 +05:45
$url ,
);
}
/**
* @When the public accesses the preview of file :path from the last shared public link using the sharing API
*
* @param string $path
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicAccessesThePreviewOfTheSharedFileUsingTheSharingApi ( string $path ) : void {
$token = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedLinkShareToken () : $this -> getLastCreatedPublicShareToken ();
2024-05-22 17:10:47 +05:45
$response = $this -> getPublicPreviewOfFile ( $path , $token );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When the public accesses the preview of the following files from the last shared public link using the sharing API
*
* @param TableNode $table
*
* @throws Exception
* @return void
*/
public function thePublicAccessesThePreviewOfTheFollowingSharedFileUsingTheSharingApi (
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumns ( $table , [ "path" ]);
$paths = $table -> getHash ();
$this -> emptyLastHTTPStatusCodesArray ();
$this -> emptyLastOCSStatusCodesArray ();
foreach ( $paths as $path ) {
2024-12-24 09:30:42 +05:45
$token = ( $this -> isUsingSharingNG ())
? $this -> shareNgGetLastCreatedLinkShareToken () : $this -> getLastCreatedPublicShareToken ();
2024-05-22 17:10:47 +05:45
$response = $this -> getPublicPreviewOfFile ( $path [ "path" ], $token );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
}
/**
* @param string $user
* @param string $shareServer
* @param string|null $password
*
2023-12-05 18:43:30 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function saveLastSharedPublicLinkShare (
string $user ,
string $shareServer ,
2025-06-19 15:34:02 +05:45
? string $password = "" ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$userPassword = $this -> getPasswordForUser ( $user );
2023-08-03 13:51:22 +05:45
$shareData = $this -> getLastCreatedPublicShare ();
$owner = ( string ) $shareData -> uid_owner ;
$name = $this -> encodePath (( string ) $shareData -> file_target );
2022-12-21 17:22:22 +05:45
$name = \trim ( $name , "/" );
2023-08-03 13:51:22 +05:45
$ownerDisplayName = ( string ) $shareData -> displayname_owner ;
$token = ( string ) $shareData -> token ;
2022-12-21 17:22:22 +05:45
if ( \strtolower ( $shareServer ) == "remote" ) {
$remote = $this -> getRemoteBaseUrl ();
} else {
$remote = $this -> getLocalBaseUrl ();
}
$body [ 'remote' ] = $remote ;
$body [ 'token' ] = $token ;
$body [ 'owner' ] = $owner ;
$body [ 'ownerDisplayName' ] = $ownerDisplayName ;
$body [ 'name' ] = $name ;
$body [ 'password' ] = $password ;
Assert :: assertNotNull (
$token ,
2025-06-19 15:34:02 +05:45
__METHOD__ . " could not find any public share" ,
2022-12-21 17:22:22 +05:45
);
$url = $this -> getBaseUrl () . "/index.php/apps/files_sharing/external" ;
$response = HttpRequestHelper :: post (
$url ,
$user ,
$userPassword ,
null ,
2025-06-19 15:34:02 +05:45
$body ,
2022-12-21 17:22:22 +05:45
);
2023-12-05 18:43:30 +05:45
return $response ;
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has added the public share created from server "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $shareServer
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userHasAddedPublicShareCreatedByUser ( string $user , string $shareServer ) : void {
2022-12-21 17:22:22 +05:45
$this -> saveLastSharedPublicLinkShare ( $user , $shareServer );
$resBody = json_decode ( $this -> response -> getBody () -> getContents ());
$status = '' ;
$message = '' ;
if ( $resBody ) {
$status = $resBody -> status ;
$message = $resBody -> data -> message ;
}
Assert :: assertEquals (
200 ,
$this -> response -> getStatusCode (),
__METHOD__
. " Expected status code is '200' but got '"
. $this -> response -> getStatusCode ()
2025-06-19 15:34:02 +05:45
. "'" ,
2022-12-21 17:22:22 +05:45
);
Assert :: assertNotEquals (
'error' ,
$status ,
__METHOD__
2025-06-19 15:34:02 +05:45
. " \n Failed to save public share. \n ' $message '" ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @param string $user
* @param string $path
* @param string $type
* @param int $permissions
*
* @return array
*/
2024-12-24 09:30:42 +05:45
public function preparePublicQuickLinkPayload (
string $user ,
string $path ,
string $type ,
2025-06-19 15:34:02 +05:45
int $permissions = 1 ,
2024-12-24 09:30:42 +05:45
) : array {
2022-12-21 17:22:22 +05:45
return [
"permissions" => $permissions ,
"expireDate" => "" ,
"shareType" => 3 ,
"itemType" => $type ,
"itemSource" => $this -> getFileIdForPath ( $user , $path ),
"name" => "Public quick link" ,
2025-06-19 12:12:17 +05:45
"attributes" => [
2022-12-21 17:22:22 +05:45
[
"scope" => "files_sharing" ,
"key" => "isQuickLink" ,
2025-06-19 10:46:56 +05:45
"value" => true ,
],
2022-12-21 17:22:22 +05:45
],
2025-06-19 10:46:56 +05:45
"path" => $path ,
2022-12-21 17:22:22 +05:45
];
}
/**
* @Given /^user "([^"]*)" has created a read only public link for (file|folder) "([^"]*)"$/
*
* @param string $user
* @param string $type
* @param string $path
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserHasCreatedAReadOnlyPublicLinkForFileFolder ( string $user , string $type , string $path ) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$userPassword = $this -> getPasswordForUser ( $user );
$requestPayload = $this -> preparePublicQuickLinkPayload ( $user , $path , $type );
$url = $this -> getBaseUrl () . "/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json" ;
$response = HttpRequestHelper :: post (
$url ,
$user ,
$userPassword ,
null ,
2025-06-19 15:34:02 +05:45
$requestPayload ,
2022-12-21 17:22:22 +05:45
);
2023-12-05 18:43:30 +05:45
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" adds the public share created from server "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $shareServer
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userAddsPublicShareCreatedByUser ( string $user , string $shareServer ) : void {
2023-12-05 18:43:30 +05:45
$this -> setResponse ( $this -> saveLastSharedPublicLinkShare ( $user , $shareServer ));
2022-12-21 17:22:22 +05:45
}
/**
* replace values from table
*
* @param string $field
* @param string $value
*
* @return string
*/
2024-12-24 09:30:42 +05:45
public function replaceValuesFromTable ( string $field , string $value ) : string {
2022-12-21 17:22:22 +05:45
if ( \substr ( $field , 0 , 10 ) === "share_with" ) {
$value = \str_replace (
"REMOTE" ,
$this -> getRemoteBaseUrl (),
2025-06-19 15:34:02 +05:45
$value ,
2022-12-21 17:22:22 +05:45
);
$value = \str_replace (
"LOCAL" ,
$this -> getLocalBaseUrl (),
2025-06-19 15:34:02 +05:45
$value ,
2022-12-21 17:22:22 +05:45
);
}
if ( \substr ( $field , 0 , 6 ) === "remote" ) {
$value = \str_replace (
"REMOTE" ,
$this -> getRemoteBaseUrl (),
2025-06-19 15:34:02 +05:45
$value ,
2022-12-21 17:22:22 +05:45
);
$value = \str_replace (
"LOCAL" ,
$this -> getLocalBaseUrl (),
2025-06-19 15:34:02 +05:45
$value ,
2022-12-21 17:22:22 +05:45
);
}
if ( $field === "permissions" ) {
if ( \is_string ( $value ) && ! \is_numeric ( $value )) {
$value = $this -> splitPermissionsString ( $value );
}
$value = ( string ) SharingHelper :: getPermissionSum ( $value );
}
if ( $field === "share_type" ) {
$value = ( string ) SharingHelper :: getShareType ( $value );
}
return $value ;
}
}