@@ -30,6 +30,7 @@ class RichDocumentsContext implements Context {
3030 private $ fileIds = [];
3131 /** @var array List of templates fetched for a given file type */
3232 private $ templates = [];
33+ private array $ directoryListing = [];
3334
3435 /** @BeforeScenario */
3536 public function gatherContexts (BeforeScenarioScope $ scope ) {
@@ -75,6 +76,47 @@ public function userOpens($user, $file) {
7576 Assert::assertNotEmpty ($ this ->wopiToken );
7677 }
7778
79+ /**
80+ * @When the download button for :path will be visible to :user
81+ */
82+ public function downloadButtonIsVisible (string $ path , string $ user ): void {
83+ $ this ->downloadButtonIsNotVisibleOrNot ($ path , $ user , true );
84+ }
85+
86+ /**
87+ * @When the download button for :path will not be visible to :user
88+ */
89+ public function downloadButtonIsNotVisible (string $ path , string $ user ): void {
90+ $ this ->downloadButtonIsNotVisibleOrNot ($ path , $ user , false );
91+ }
92+
93+ private function downloadButtonIsNotVisibleOrNot (string $ path , string $ user , bool $ isVisible ): void {
94+ $ hideDownloadProperty = '{http://nextcloud.org/ns}hide-download ' ;
95+ $ this ->serverContext ->usingWebAsUser ($ user );
96+ $ fileInfo = $ this ->filesContext ->listFolder ($ path , 0 , [$ hideDownloadProperty ]);
97+
98+ if ($ isVisible ) {
99+ Assert::assertTrue (!isset ($ fileInfo [$ hideDownloadProperty ]) || $ fileInfo [$ hideDownloadProperty ] === 'false ' );
100+ } else {
101+ Assert::assertTrue (isset ($ fileInfo [$ hideDownloadProperty ]), 'property is not set ' );
102+ Assert::assertTrue ($ fileInfo [$ hideDownloadProperty ] === 'true ' , 'property is not true ' );
103+ Assert::assertTrue (isset ($ fileInfo [$ hideDownloadProperty ]) && $ fileInfo [$ hideDownloadProperty ] === 'true ' );
104+ }
105+ }
106+
107+ /**
108+ * @When the download button for :path will not be visible in the last link share
109+ */
110+ public function theDownloadButtonWillNotBeVisibleInLastLinkShare (string $ path ): void {
111+ $ hideDownloadProperty = '{http://nextcloud.org/ns}hide-download ' ;
112+ $ this ->serverContext ->usingWebAsUser ();
113+ $ shareToken = $ this ->sharingContext ->getLastShareData ()['token ' ];
114+ $ davClient = $ this ->filesContext ->getPublicSabreClient ($ shareToken );
115+ $ result = $ davClient ->propFind ($ path , ['{http://nextcloud.org/ns}hide-download ' ], 1 );
116+ $ fileInfo = $ result [array_key_first ($ result )];
117+ Assert::assertTrue (!isset ($ fileInfo [$ hideDownloadProperty ]) || $ fileInfo [$ hideDownloadProperty ] === 'true ' );
118+ }
119+
78120 public function generateTokenWithApi ($ user , $ fileId , ?string $ shareToken = null , ?string $ path = null , ?string $ guestName = null ) {
79121 $ this ->serverContext ->usingWebAsUser ($ user );
80122 $ this ->serverContext ->sendJSONRequest ('POST ' , '/index.php/apps/richdocuments/token ' , [
@@ -248,4 +290,26 @@ public function renameFileTo($user, $file, $newName) {
248290
249291 $ this ->wopiContext ->collaboraRenamesTo ($ fileId , $ newName );
250292 }
293+
294+ /**
295+ * @When admin enables secure view
296+ */
297+ public function enableSecureView (): void {
298+ $ this ->serverContext ->actAsAdmin (function () {
299+ $ watermarkKeysToEnable = [
300+ 'watermark_enabled ' ,
301+ 'watermark_linkAll ' ,
302+ 'watermark_shareRead ' ,
303+ ];
304+
305+ foreach ($ watermarkKeysToEnable as $ configKey ) {
306+ $ this ->serverContext ->sendOCSRequest (
307+ 'POST ' ,
308+ 'apps/provisioning_api/api/v1/config/apps/files/ ' . $ configKey ,
309+ ['value ' => 'yes ' ],
310+ );
311+ $ this ->serverContext ->assertHttpStatusCode (200 );
312+ }
313+ });
314+ }
251315}
0 commit comments