@@ -3406,7 +3406,117 @@ public function testAcceptRejectShareOperationError($method, $target, $targetExi
34063406 }
34073407
34083408 /**
3409- * @dataProvider providesShareAttributes
3409+ * @dataProvider providesTestAttributes
3410+ */
3411+ public function testSettingAttributes ($ attributes , $ expectedAttributeObject ) {
3412+ $ share = $ this ->newShare ();
3413+ $ this ->shareManager ->method ('newShare ' )->willReturn ($ share );
3414+
3415+ $ share ->setShareOwner ('shareOwner ' );
3416+
3417+ $ ocs = $ this ->mockFormatShare ();
3418+ $ ocs ->expects (self ::once ())->method ('formatShare ' )->willReturnCallback (static function (IShare $ share ) {
3419+ return [
3420+ 'permissions ' => $ share ->getPermissions (),
3421+ 'attributes ' => $ share ->getAttributes ()
3422+ ];
3423+ });
3424+
3425+ $ this ->request
3426+ ->method ('getParam ' )
3427+ ->willReturnMap ([
3428+ ['path ' , null , 'valid-path ' ],
3429+ ['permissions ' , null , 1 ],
3430+ ['attributes ' , null , $ attributes ],
3431+ ['shareType ' , $ this ->any (), Share::SHARE_TYPE_USER ],
3432+ ['shareWith ' , null , 'validUser ' ],
3433+ ]);
3434+
3435+ $ userFolder = $ this ->createMock ('\OCP\Files\Folder ' );
3436+ $ this ->rootFolder ->expects ($ this ->once ())
3437+ ->method ('getUserFolder ' )
3438+ ->with ('currentUser ' )
3439+ ->willReturn ($ userFolder );
3440+
3441+ $ path = $ this ->createMock ('\OCP\Files\File ' );
3442+ $ storage = $ this ->createMock ('OCP\Files\Storage ' );
3443+ $ storage ->method ('instanceOfStorage ' )
3444+ ->with ('OCA\Files_Sharing\External\Storage ' )
3445+ ->willReturn (false );
3446+ $ path ->method ('getStorage ' )->willReturn ($ storage );
3447+ $ userFolder ->expects ($ this ->once ())
3448+ ->method ('get ' )
3449+ ->with ('valid-path ' )
3450+ ->willReturn ($ path );
3451+
3452+ $ this ->userManager ->method ('userExists ' )->with ('validUser ' )->willReturn (true );
3453+
3454+ $ path ->expects ($ this ->once ())
3455+ ->method ('lock ' )
3456+ ->with (ILockingProvider::LOCK_SHARED );
3457+ $ path ->expects ($ this ->once ())
3458+ ->method ('unlock ' )
3459+ ->with (ILockingProvider::LOCK_SHARED );
3460+
3461+ $ this ->shareManager ->method ('createShare ' )->will ($ this ->returnArgument (0 ));
3462+
3463+ $ result = $ ocs ->createShare ();
3464+
3465+ $ this ->assertEquals (1 , $ result ->getData ()['permissions ' ]);
3466+ $ this ->assertEquals ($ expectedAttributeObject , $ result ->getData ()['attributes ' ]->toArray ());
3467+ }
3468+
3469+ public function providesTestAttributes () {
3470+ return [
3471+ [
3472+ [
3473+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'value ' => 'true ' ]
3474+ ],
3475+ [
3476+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'enabled ' => 'true ' ]
3477+ ],
3478+ ],
3479+ [
3480+ [
3481+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'value ' => 'false ' ]
3482+ ],
3483+ [
3484+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'enabled ' => 'false ' ]
3485+ ],
3486+ ],
3487+ [
3488+ [
3489+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'value ' => null ]
3490+ ],
3491+ [],
3492+ ],
3493+ [
3494+ [
3495+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'enabled ' => true ]
3496+ ],
3497+ [
3498+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'enabled ' => true ]
3499+ ],
3500+ ],
3501+ [
3502+ [
3503+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'enabled ' => false ]
3504+ ],
3505+ [
3506+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'enabled ' => false ]
3507+ ],
3508+ ],
3509+ [
3510+ [
3511+ ['scope ' => 'permissions ' , 'key ' => 'download ' , 'enabled ' => null ]
3512+ ],
3513+ [],
3514+ ],
3515+ ];
3516+ }
3517+
3518+ /**
3519+ * @dataProvider providesPermissionsViaAttributes
34103520 */
34113521 public function testPermissionsViaAttributes ($ expectedPermission , $ attributes ) {
34123522 $ share = $ this ->newShare ();
@@ -3465,28 +3575,28 @@ public function testPermissionsViaAttributes($expectedPermission, $attributes) {
34653575 $ this ->assertEquals ($ expectedPermission , $ result ->getData ()['permissions ' ]);
34663576 }
34673577
3468- public function providesShareAttributes () {
3578+ public function providesPermissionsViaAttributes () {
34693579 return [
34703580 [
34713581 \OCP \Constants::PERMISSION_READ , [
3472- ['scope ' => 'ownCloud ' , 'key ' => 'read ' , 'value ' => 'true ' ]
3473- ]
3582+ ['scope ' => 'ownCloud ' , 'key ' => 'read ' , 'value ' => 'true ' ]
3583+ ]
34743584 ],
34753585 [
34763586 \OCP \Constants::PERMISSION_ALL , [
3477- ['scope ' => 'ownCloud ' , 'key ' => 'create ' , 'value ' => 'true ' ],
3478- ['scope ' => 'ownCloud ' , 'key ' => 'read ' , 'value ' => 'true ' ],
3479- ['scope ' => 'ownCloud ' , 'key ' => 'update ' , 'value ' => 'true ' ],
3480- ['scope ' => 'ownCloud ' , 'key ' => 'delete ' , 'value ' => 'true ' ],
3481- ['scope ' => 'ownCloud ' , 'key ' => 'share ' , 'value ' => 'true ' ],
3482- ]
3587+ ['scope ' => 'ownCloud ' , 'key ' => 'create ' , 'value ' => 'true ' ],
3588+ ['scope ' => 'ownCloud ' , 'key ' => 'read ' , 'value ' => 'true ' ],
3589+ ['scope ' => 'ownCloud ' , 'key ' => 'update ' , 'value ' => 'true ' ],
3590+ ['scope ' => 'ownCloud ' , 'key ' => 'delete ' , 'value ' => 'true ' ],
3591+ ['scope ' => 'ownCloud ' , 'key ' => 'share ' , 'value ' => 'true ' ],
3592+ ]
34833593 ],
34843594 [
34853595 \OCP \Constants::PERMISSION_CREATE | \OCP \Constants::PERMISSION_READ | \OCP \Constants::PERMISSION_SHARE , [
3486- ['scope ' => 'ownCloud ' , 'key ' => 'create ' , 'value ' => 'true ' ],
3487- ['scope ' => 'ownCloud ' , 'key ' => 'read ' , 'value ' => 'true ' ],
3488- ['scope ' => 'ownCloud ' , 'key ' => 'share ' , 'value ' => 'true ' ],
3489- ]
3596+ ['scope ' => 'ownCloud ' , 'key ' => 'create ' , 'value ' => 'true ' ],
3597+ ['scope ' => 'ownCloud ' , 'key ' => 'read ' , 'value ' => 'true ' ],
3598+ ['scope ' => 'ownCloud ' , 'key ' => 'share ' , 'value ' => 'true ' ],
3599+ ]
34903600 ],
34913601 ];
34923602 }
0 commit comments