66namespace Tests \Richdocuments ;
77
88use OCA \Richdocuments \AppConfig ;
9+ use OCA \Richdocuments \Capabilities ;
910use OCA \Richdocuments \PermissionManager ;
1011use OCP \Files \Node ;
1112use OCP \IConfig ;
@@ -136,24 +137,25 @@ public static function dataWatermarkTagIds(): array {
136137
137138 /** @dataProvider dataWatermarkTagIds */
138139 public function testShouldWatermarkOptionLinkTags (array $ objectTagIds , array $ watermarkTagIds ): void {
139- $ node = $ this ->createMock (Node::class );
140- $ share = $ this ->createMock (IShare::class );
140+ $ node = $ this ->createNodeMock ( );
141+ $ share = $ this ->createShareMock (IShare::TYPE_LINK );
141142 $ userId = 'testUserId ' ;
142143
144+ $ this ->appConfig ->expects ($ this ->any ())
145+ ->method ('getMimeTypes ' )
146+ ->willReturn (Capabilities::MIMETYPES );
147+
143148 $ this ->config
144- ->expects ($ this ->exactly (5 ))
145149 ->method ('getAppValue ' )
146150 ->willReturnMap ([
147151 [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_enabled ' , 'no ' , 'yes ' ],
148152 [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_linkAll ' , 'no ' , 'no ' ],
149153 [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_linkRead ' , 'no ' , 'no ' ],
150154 [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_linkSecure ' , 'no ' , 'no ' ],
151155 [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_linkTags ' , 'no ' , 'yes ' ],
156+ [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_shareTalkPublic ' , 'no ' , 'no ' ],
152157 ]);
153158
154- $ node ->expects ($ this ->once ())->method ('getId ' )->willReturn ('testFileId ' );
155- $ node ->expects ($ this ->once ())->method ('isUpdateable ' )->willReturn (false );
156-
157159 $ share ->expects ($ this ->once ())->method ('getHideDownload ' )->willReturn (true );
158160 $ share ->expects ($ this ->once ())->method ('getAttributes ' )->willReturn (null );
159161 $ share ->expects ($ this ->once ())->method ('getShareType ' )->willReturn (IShare::TYPE_LINK );
@@ -167,12 +169,14 @@ public function testShouldWatermarkOptionLinkTags(array $objectTagIds, array $wa
167169
168170 /** @dataProvider dataWatermarkTagIds */
169171 public function testShouldWatermarkOptionAllTags (array $ objectTagIds , array $ watermarkTagIds ): void {
170- $ node = $ this ->createMock (Node::class);
171- $ share = $ this ->createMock (IShare::class);
172+ $ node = $ this ->createNodeMock ();
172173 $ userId = 'testUserId ' ;
173174
175+ $ this ->appConfig ->expects ($ this ->any ())
176+ ->method ('getMimeTypes ' )
177+ ->willReturn (Capabilities::MIMETYPES );
178+
174179 $ this ->config
175- ->expects ($ this ->exactly (6 ))
176180 ->method ('getAppValue ' )
177181 ->willReturnMap ([
178182 [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_enabled ' , 'no ' , 'yes ' ],
@@ -183,13 +187,55 @@ public function testShouldWatermarkOptionAllTags(array $objectTagIds, array $wat
183187 [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_allTags ' , 'no ' , 'yes ' ],
184188 ]);
185189
186- $ node ->expects ($ this ->once ())->method ('getId ' )->willReturn ('testFileId ' );
187- $ node ->expects ($ this ->once ())->method ('isUpdateable ' )->willReturn (false );
188190 $ this ->systemTagMapper ->expects ($ this ->once ())->method ('getTagIdsForObjects ' )->willReturn (['testFileId ' => $ objectTagIds ]);
189191 $ this ->appConfig ->expects ($ this ->once ())->method ('getAppValueArray ' )->willReturn ($ watermarkTagIds );
190192
191193 $ result = $ this ->permissionManager ->shouldWatermark ($ node , $ userId , null );
192194
193195 $ this ->assertTrue ($ result );
194196 }
197+
198+ public function testShouldWatermarkOptionTalkPublic (): void {
199+ $ node = $ this ->createNodeMock ();
200+ $ share = $ this ->createShareMock (IShare::TYPE_ROOM );
201+ $ userId = null ;
202+
203+ $ this ->appConfig ->expects ($ this ->any ())
204+ ->method ('getMimeTypes ' )
205+ ->willReturn (Capabilities::MIMETYPES );
206+
207+ $ this ->config
208+ ->method ('getAppValue ' )
209+ ->willReturnMap ([
210+ [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_enabled ' , 'no ' , 'yes ' ],
211+ [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_linkAll ' , 'no ' , 'no ' ],
212+ [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_linkRead ' , 'no ' , 'no ' ],
213+ [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_linkSecure ' , 'no ' , 'no ' ],
214+ [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_linkTags ' , 'no ' , 'no ' ],
215+ [AppConfig::WATERMARK_APP_NAMESPACE , 'watermark_shareTalkPublic ' , 'no ' , 'yes ' ],
216+ ]);
217+ $ result = $ this ->permissionManager ->shouldWatermark ($ node , $ userId , $ share );
218+
219+ $ this ->assertTrue ($ result );
220+ }
221+
222+ private function createNodeMock (): Node {
223+ $ node = $ this ->createMock (Node::class);
224+ $ node ->expects ($ this ->any ())->method ('getMimetype ' )->willReturn ('application/vnd.oasis.opendocument.spreadsheet ' );
225+ $ node ->expects ($ this ->any ())->method ('getId ' )->willReturn ('testFileId ' );
226+ $ node ->expects ($ this ->any ())->method ('isUpdateable ' )->willReturn (false );
227+ return $ node ;
228+ }
229+
230+ private function createShareMock (?int $ shareType ): ?IShare {
231+ if ($ shareType === null ) {
232+ return null ;
233+ }
234+
235+ $ share = $ this ->createMock (IShare::class);
236+ $ share ->expects ($ this ->any ())->method ('getHideDownload ' )->willReturn (true );
237+ $ share ->expects ($ this ->any ())->method ('getAttributes ' )->willReturn (null );
238+ $ share ->expects ($ this ->any ())->method ('getShareType ' )->willReturn ($ shareType );
239+ return $ share ;
240+ }
195241}
0 commit comments