More permissions and attributes tests.
authorJan Schneider <jan@horde.org>
Wed, 5 Jan 2011 17:34:52 +0000 (18:34 +0100)
committerJan Schneider <jan@horde.org>
Wed, 5 Jan 2011 17:34:52 +0000 (18:34 +0100)
framework/Share/test/Horde/Share/Base.php
framework/Share/test/Horde/Share/Sql/Base.php
framework/Share/test/Horde/Share/SqlHierarchical/Base.php

index b5d37ca..434eefe 100644 (file)
@@ -128,15 +128,25 @@ class Horde_Share_Test_Base extends Horde_Test_Case
 
     protected function _getShareById(array $shares)
     {
-        $newshare = self::$share->getShareById($shares[0]->getId());
-        $this->assertInstanceOf('Horde_Share_Object', $newshare);
-        $this->assertEquals($shares[0], $newshare);
-        $newshare = self::$share->getShareById($shares[1]->getId());
-        $this->assertInstanceOf('Horde_Share_Object', $newshare);
-        $this->assertEquals($shares[1], $newshare);
-        $newshare = self::$share->getShareById($shares[2]->getId());
-        $this->assertInstanceOf('Horde_Share_Object', $newshare);
-        $this->assertEquals($shares[2], $newshare);
+        $myshare = self::$share->getShareById($shares[0]->getId());
+        $this->assertInstanceOf('Horde_Share_Object', $myshare);
+        $this->assertEquals($shares[0], $myshare);
+
+        $janeshare = self::$share->getShareById($shares[1]->getId());
+        $this->assertInstanceOf('Horde_Share_Object', $janeshare);
+        $this->assertEquals($shares[1], $janeshare);
+        $this->assertEquals(array('john', 'jane'), $janeshare->listUsers());
+        $this->assertEquals(array('john', 'jane'), $janeshare->listUsers(Horde_Perms::EDIT));
+        $this->assertEquals(array('jane'), $janeshare->listUsers(Horde_Perms::DELETE));
+        $this->assertEquals('Jane\'s Share', $janeshare->get('name'));
+
+        $groupshare = self::$share->getShareById($shares[2]->getId());
+        $this->assertInstanceOf('Horde_Share_Object', $groupshare);
+        $this->assertEquals($shares[2], $groupshare);
+        $this->assertEquals(array('mygroup'), $groupshare->listGroups());
+        $this->assertEquals(array(), $groupshare->listGroups(Horde_Perms::EDIT));
+        $this->assertEquals(array('mygroup'), $groupshare->listGroups(Horde_Perms::DELETE));
+        $this->assertEquals('Group Share', $groupshare->get('name'));
     }
 
     public function getShares(array $shares)
@@ -286,6 +296,68 @@ class Horde_Share_Test_Base extends Horde_Test_Case
         $this->assertArrayHasKey('systemshare', $shares);
     }
 
+    public function removeUserPermissions(array $shareids)
+    {
+        $janeshare = self::$share->getShareById($shareids[1]);
+        $janeshare->removeUserPermission('john', Horde_Perms::EDIT);
+        $janeshare->save();
+
+        // Getting shares from cache.
+        $this->assertEquals(4, count(self::$share->listShares('john', array('perm' => Horde_Perms::READ))));
+        $this->assertEquals(1, count(self::$share->listShares('john', array('perm' => Horde_Perms::EDIT))));
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        // Getting shares from backend.
+        $this->assertEquals(4, count(self::$share->listShares('john', array('perm' => Horde_Perms::READ))));
+        $this->assertEquals(1, count(self::$share->listShares('john', array('perm' => Horde_Perms::EDIT))));
+
+        $janeshare->removeUser('john');
+        $janeshare->save();
+
+        // Getting shares from cache.
+        $this->assertEquals(3, count(self::$share->listShares('john', array('perm' => Horde_Perms::READ))));
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        // Getting shares from backend.
+        $this->assertEquals(3, count(self::$share->listShares('john', array('perm' => Horde_Perms::READ))));
+
+        return $shareids;
+    }
+
+    public function removeGroupPermissions(array $shareids)
+    {
+        $groupshare = self::$share->getShareById($shareids[2]);
+        $groupshare->removeGroupPermission('mygroup', Horde_Perms::DELETE);
+        $groupshare->save();
+
+        // Getting shares from cache.
+        $this->assertEquals(3, count(self::$share->listShares('john', array('perm' => Horde_Perms::READ))));
+        $this->assertEquals(1, count(self::$share->listShares('john', array('perm' => Horde_Perms::DELETE))));
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        // Getting shares from backend.
+        $this->assertEquals(3, count(self::$share->listShares('john', array('perm' => Horde_Perms::READ))));
+        $this->assertEquals(1, count(self::$share->listShares('john', array('perm' => Horde_Perms::DELETE))));
+
+        $groupshare->removeGroup('mygroup');
+        $groupshare->save();
+
+        // Getting shares from cache.
+        $this->assertEquals(2, count(self::$share->listShares('john', array('perm' => Horde_Perms::READ))));
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        // Getting shares from backend.
+        $this->assertEquals(2, count(self::$share->listShares('john', array('perm' => Horde_Perms::READ))));
+    }
+
     public function removeShare(array $share)
     {
         // Getting shares from cache.
index 7787705..31d19af 100644 (file)
@@ -114,6 +114,22 @@ class Horde_Share_Test_Sql_Base extends Horde_Share_Test_Base
     }
 
     /**
+     * @depends testPermissions
+     */
+    public function testRemoveUserPermissions(array $shareids)
+    {
+        return parent::removeUserPermissions($shareids);
+    }
+
+    /**
+     * @depends testRemoveUserPermissions
+     */
+    public function testRemoveGroupPermissions(array $shareids)
+    {
+        parent::removeGroupPermissions($shareids);
+    }
+
+    /**
      * @depends testGetShare
      */
     public function testRemoveShare(array $share)
index 7f4ad25..5a4c1b1 100644 (file)
@@ -138,6 +138,22 @@ class Horde_Share_Test_SqlHierarchical_Base extends Horde_Share_Test_Base
     /**
      * @depends testPermissions
      */
+    public function testRemoveUserPermissions(array $shares)
+    {
+        return parent::removeUserPermissions(array($shares[0]->getId(), $shares[1]->getId(), $shares[2]->getId()));
+    }
+
+    /**
+     * @depends testRemoveUserPermissions
+     */
+    public function testRemoveGroupPermissions(array $shareids)
+    {
+        parent::removeGroupPermissions($shareids);
+    }
+
+    /**
+     * @depends testPermissions
+     */
     public function testRemoveShare(array $share)
     {
         parent::removeShare($share);