Move backend independent tests to a base class.
authorJan Schneider <jan@horde.org>
Mon, 3 Jan 2011 14:20:41 +0000 (15:20 +0100)
committerJan Schneider <jan@horde.org>
Mon, 3 Jan 2011 14:20:41 +0000 (15:20 +0100)
framework/Share/package.xml
framework/Share/test/Horde/Share/SqlTest.php
framework/Share/test/Horde/Share/TestBase.php [new file with mode: 0644]

index e40a1e8..a1d51c9 100644 (file)
@@ -11,8 +11,8 @@ owns or has access to.</description>
   <email>chuck@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-12-16</date>
- <time>22:49:36</time>
+ <date>2011-01-03</date>
+ <time>15:20:05</time>
  <version>
   <release>0.0.4</release>
   <api>0.0.4</api>
@@ -321,7 +321,9 @@ owns or has access to.</description>
     <dir name="Horde">
      <dir name="Share">
       <file name="AllTests.php" role="test" />
+      <file name="Autoload.php" role="test" />
       <file name="SqlTest.php" role="test" />
+      <file name="TestBase.php" role="test" />
      </dir> <!-- /test/Horde/Share -->
     </dir> <!-- /test/Horde -->
    </dir> <!-- /test -->
@@ -448,7 +450,9 @@ owns or has access to.</description>
    <install as="locale/zh_TW/LC_MESSAGES/Horde_Share.mo" name="locale/zh_TW/LC_MESSAGES/Horde_Share.mo" />
    <install as="locale/zh_TW/LC_MESSAGES/Horde_Share.po" name="locale/zh_TW/LC_MESSAGES/Horde_Share.po" />
    <install as="Horde/Share/AllTests.php" name="test/Horde/Share/AllTests.php" />
+   <install as="Horde/Share/Autoload.php" name="test/Horde/Share/Autoload.php" />
    <install as="Horde/Share/SqlTest.php" name="test/Horde/Share/SqlTest.php" />
+   <install as="Horde/Share/TestBase.php" name="test/Horde/Share/TestBase.php" />
   </filelist>
  </phprelease>
  <changelog>
@@ -517,7 +521,7 @@ Initial release as a PEAR package
     <release>beta</release>
     <api>beta</api>
    </stability>
-   <date>2010-12-16</date>
+   <date>2011-01-03</date>
    <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
    <notes>
 * Converted to Horde 4 coding standards
index 720a191..3003fdc 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * Prepare the test setup.
  */
-require_once dirname(__FILE__) . '/Autoload.php';
+require_once dirname(__FILE__) . '/TestBase.php';
 
 /**
  * @author     Jan Schneider <jan@horde.org>
@@ -12,17 +12,10 @@ require_once dirname(__FILE__) . '/Autoload.php';
  * @copyright  2010 The Horde Project (http://www.horde.org/)
  * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
  */
-class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
+class Horde_Share_SqlTest extends Horde_Share_TestBase
 {
     protected static $db;
 
-    protected static $share;
-
-    public function testGetApp()
-    {
-        $this->assertEquals('test', self::$share->getApp());
-    }
-
     public function testSetTable()
     {
         $this->assertEquals('test_shares', self::$share->getTable());
@@ -39,9 +32,8 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
 
     public function testAddShare()
     {
-        $share = self::$share->newShare('john', 'myshare');
+        $share = parent::baseAddShare();
         $this->assertInstanceOf('Horde_Share_Object_Sql', $share);
-        self::$share->addShare($share);
     }
 
     /**
@@ -49,39 +41,7 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
      */
     public function testPermissions()
     {
-        // System share.
-        $share = self::$share->newShare(null, 'systemshare');
-        $perm = $share->getPermission();
-        $this->assertInstanceOf('Horde_Perms_Permission', $perm);
-        $perm->addDefaultPermission(Horde_Perms::SHOW | Horde_Perms::READ);
-        $share->setPermission($perm);
-        $share->save();
-        $this->assertTrue($share->hasPermission('john', Horde_Perms::SHOW));
-        $this->assertTrue($share->hasPermission('john', Horde_Perms::READ));
-        $this->assertFalse($share->hasPermission('john', Horde_Perms::EDIT));
-        $this->assertFalse($share->hasPermission('john', Horde_Perms::DELETE));
-
-        // Foreign share with user permissions.
-        $share = self::$share->newShare('jane', 'janeshare');
-        $share->addUserPermission('john', Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT);
-        $share->save();
-        $this->assertTrue($share->hasPermission('john', Horde_Perms::SHOW));
-        $this->assertTrue($share->hasPermission('john', Horde_Perms::READ));
-        $this->assertTrue($share->hasPermission('john', Horde_Perms::EDIT));
-        $this->assertFalse($share->hasPermission('john', Horde_Perms::DELETE));
-
-        // Foreign share with group permissions.
-        $share = self::$share->newShare('jane', 'groupshare');
-        $share->addGroupPermission('mygroup', Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::DELETE);
-        $share->save();
-        $this->assertTrue($share->hasPermission('john', Horde_Perms::SHOW));
-        $this->assertTrue($share->hasPermission('john', Horde_Perms::READ));
-        $this->assertFalse($share->hasPermission('john', Horde_Perms::EDIT));
-        $this->assertTrue($share->hasPermission('john', Horde_Perms::DELETE));
-
-        // Foreign share without permissions.
-        $share = self::$share->newShare('jane', 'noshare');
-        $share->save();
+        parent::basePermissions();
     }
 
     /**
@@ -89,12 +49,7 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
      */
     public function testExists()
     {
-        $this->assertTrue(self::$share->exists('myshare'));
-
-        // Reset cache.
-        self::$share->resetCache();
-
-        $this->assertTrue(self::$share->exists('myshare'));
+        parent::baseExists();
     }
 
     /**
@@ -102,33 +57,19 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
      */
     public function testCountShares()
     {
-        // Getting shares from cache.
-        $this->assertEquals(4, self::$share->countShares('john'));
-        $this->assertEquals(2, self::$share->countShares('john', Horde_Perms::EDIT));
-
-        // Reset cache.
-        self::$share->resetCache();
-
-        // Getting shares from backend.
-        $this->assertEquals(4, self::$share->countShares('john'));
-        $this->assertEquals(2, self::$share->countShares('john', Horde_Perms::EDIT));
+        parent::baseCountShares();
     }
 
     /**
-     * @depends testAddShare
+     * @depends testPermissions
      */
     public function testGetShare()
     {
-        $share = self::$share->getShare('myshare');
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $share);
-
-        // Reset cache.
-        self::$share->resetCache();
-
-        $share = self::$share->getShare('myshare');
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $share);
-
-        return array($share, self::$share->getShare('janeshare'), self::$share->getShare('groupshare'));
+        $shares = parent::baseGetShare();
+        $this->assertInstanceOf('Horde_Share_Object_Sql', $shares[0]);
+        $this->assertInstanceOf('Horde_Share_Object_Sql', $shares[1]);
+        $this->assertInstanceOf('Horde_Share_Object_Sql', $shares[2]);
+        return $shares;
     }
 
     /**
@@ -136,28 +77,7 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
      */
     public function testGetShareById(array $shares)
     {
-        $newshare = self::$share->getShareById($shares[0]->getId());
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshare);
-        $this->assertEquals($shares[0], $newshare);
-        $newshare = self::$share->getShareById($shares[1]->getId());
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshare);
-        $this->assertEquals($shares[1], $newshare);
-        $newshare = self::$share->getShareById($shares[2]->getId());
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshare);
-        $this->assertEquals($shares[2], $newshare);
-
-        // Reset cache.
-        self::$share->resetCache();
-
-        $newshare = self::$share->getShareById($shares[0]->getId());
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshare);
-        $this->assertEquals($shares[0], $newshare);
-        $newshare = self::$share->getShareById($shares[1]->getId());
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshare);
-        $this->assertEquals($shares[1], $newshare);
-        $newshare = self::$share->getShareById($shares[2]->getId());
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshare);
-        $this->assertEquals($shares[2], $newshare);
+        parent::baseGetShareById($shares);
     }
 
     /**
@@ -165,34 +85,7 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
      */
     public function testGetShares(array $shares)
     {
-        $newshares = self::$share->getShares(array($shares[0]->getId(), $shares[1]->getId(), $shares[2]->getId()));
-        $this->assertType('array', $newshares);
-        $this->assertEquals(3, count($newshares));
-        $this->assertArrayHasKey('myshare', $newshares);
-        $this->assertArrayHasKey('janeshare', $newshares);
-        $this->assertArrayHasKey('groupshare', $newshares);
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshares['myshare']);
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshares['janeshare']);
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshares['groupshare']);
-        $this->assertEquals($newshares['myshare'], $shares[0]);
-        $this->assertEquals($newshares['janeshare'], $shares[1]);
-        $this->assertEquals($newshares['groupshare'], $shares[2]);
-
-        // Reset cache.
-        self::$share->resetCache();
-
-        $newshares = self::$share->getShares(array($shares[0]->getId(), $shares[1]->getId(), $shares[2]->getId()));
-        $this->assertType('array', $newshares);
-        $this->assertEquals(3, count($newshares));
-        $this->assertArrayHasKey('myshare', $newshares);
-        $this->assertArrayHasKey('janeshare', $newshares);
-        $this->assertArrayHasKey('groupshare', $newshares);
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshares['myshare']);
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshares['janeshare']);
-        $this->assertInstanceOf('Horde_Share_Object_Sql', $newshares['groupshare']);
-        $this->assertEquals($newshares['myshare'], $shares[0]);
-        $this->assertEquals($newshares['janeshare'], $shares[1]);
-        $this->assertEquals($newshares['groupshare'], $shares[2]);
+        parent::baseGetShares($shares);
     }
 
     /**
@@ -200,28 +93,7 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
      */
     public function testListAllShares()
     {
-        // Getting shares from cache.
-        $shares = self::$share->listAllShares();
-        $this->assertType('array', $shares);
-        $this->assertEquals(5, count($shares));
-        $this->assertArrayHasKey('myshare', $shares);
-        $this->assertArrayHasKey('systemshare', $shares);
-        $this->assertArrayHasKey('janeshare', $shares);
-        $this->assertArrayHasKey('groupshare', $shares);
-        $this->assertArrayHasKey('noshare', $shares);
-
-        // Reset cache.
-        self::$share->resetCache();
-
-        // Getting shares from backend.
-        $shares = self::$share->listAllShares();
-        $this->assertType('array', $shares);
-        $this->assertEquals(5, count($shares));
-        $this->assertArrayHasKey('myshare', $shares);
-        $this->assertArrayHasKey('systemshare', $shares);
-        $this->assertArrayHasKey('janeshare', $shares);
-        $this->assertArrayHasKey('groupshare', $shares);
-        $this->assertArrayHasKey('noshare', $shares);
+        parent::baseListAllShares();
     }
 
     /**
@@ -229,20 +101,7 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
      */
     public function testListSystemShares()
     {
-        // Getting shares from cache.
-        $shares = self::$share->listSystemShares();
-        $this->assertType('array', $shares);
-        $this->assertEquals(1, count($shares));
-        $this->assertArrayHasKey('systemshare', $shares);
-
-        // Reset cache.
-        self::$share->resetCache();
-
-        // Getting shares from backend.
-        $shares = self::$share->listSystemShares();
-        $this->assertType('array', $shares);
-        $this->assertEquals(1, count($shares));
-        $this->assertArrayHasKey('systemshare', $shares);
+        parent::baseListSystemShares();
     }
 
     /**
@@ -250,13 +109,7 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
      */
     public function testRemoveShare(array $share)
     {
-        self::$share->removeShare($share[0]);
-        $this->assertEquals(4, count(self::$share->listAllShares()));
-
-        // Reset cache.
-        self::$share->resetCache();
-
-        $this->assertEquals(4, count(self::$share->listAllShares()));
+        parent::baseRemoveShare($share);
     }
 
     public static function setUpBeforeClass()
@@ -336,23 +189,3 @@ class Horde_Share_SqlTest extends PHPUnit_Framework_TestCase
         }
     }
 }
-
-class Horde_Group_Test extends Horde_Group {
-    public function __construct()
-    {
-    }
-
-    public function __wakeup()
-    {
-    }
-
-    public function userIsInGroup($user, $gid, $subgroups = true)
-    {
-        return $user == 'john' && $gid == 'mygroup';
-    }
-
-    public function getGroupMemberships($user, $parentGroups = false)
-    {
-        return $user == 'john' ? array('mygroup' => 'mygroup') : array();
-    }
-}
diff --git a/framework/Share/test/Horde/Share/TestBase.php b/framework/Share/test/Horde/Share/TestBase.php
new file mode 100644 (file)
index 0000000..a14afc0
--- /dev/null
@@ -0,0 +1,257 @@
+<?php
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/Autoload.php';
+
+/**
+ * @author     Jan Schneider <jan@horde.org>
+ * @category   Horde
+ * @package    Share
+ * @subpackage UnitTests
+ * @copyright  2010 The Horde Project (http://www.horde.org/)
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ */
+class Horde_Share_TestBase extends PHPUnit_Framework_TestCase
+{
+    protected static $share;
+
+    public function testGetApp()
+    {
+        $this->assertEquals('test', self::$share->getApp());
+    }
+
+    public function baseAddShare()
+    {
+        $share = self::$share->newShare('john', 'myshare');
+        $this->assertInstanceOf('Horde_Share_Object', $share);
+        self::$share->addShare($share);
+        return $share;
+    }
+
+    /**
+     * @depends testAddShare
+     */
+    public function basePermissions()
+    {
+        // System share.
+        $share = self::$share->newShare(null, 'systemshare');
+        $perm = $share->getPermission();
+        $this->assertInstanceOf('Horde_Perms_Permission', $perm);
+        $perm->addDefaultPermission(Horde_Perms::SHOW | Horde_Perms::READ);
+        $share->setPermission($perm);
+        $share->save();
+        $this->assertTrue($share->hasPermission('john', Horde_Perms::SHOW));
+        $this->assertTrue($share->hasPermission('john', Horde_Perms::READ));
+        $this->assertFalse($share->hasPermission('john', Horde_Perms::EDIT));
+        $this->assertFalse($share->hasPermission('john', Horde_Perms::DELETE));
+
+        // Foreign share with user permissions.
+        $share = self::$share->newShare('jane', 'janeshare');
+        $share->addUserPermission('john', Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT);
+        $share->save();
+        $this->assertTrue($share->hasPermission('john', Horde_Perms::SHOW));
+        $this->assertTrue($share->hasPermission('john', Horde_Perms::READ));
+        $this->assertTrue($share->hasPermission('john', Horde_Perms::EDIT));
+        $this->assertFalse($share->hasPermission('john', Horde_Perms::DELETE));
+
+        // Foreign share with group permissions.
+        $share = self::$share->newShare('jane', 'groupshare');
+        $share->addGroupPermission('mygroup', Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::DELETE);
+        $share->save();
+        $this->assertTrue($share->hasPermission('john', Horde_Perms::SHOW));
+        $this->assertTrue($share->hasPermission('john', Horde_Perms::READ));
+        $this->assertFalse($share->hasPermission('john', Horde_Perms::EDIT));
+        $this->assertTrue($share->hasPermission('john', Horde_Perms::DELETE));
+
+        // Foreign share without permissions.
+        $share = self::$share->newShare('jane', 'noshare');
+        $share->save();
+    }
+
+    /**
+     * @depends testAddShare
+     */
+    public function baseExists()
+    {
+        $this->assertTrue(self::$share->exists('myshare'));
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        $this->assertTrue(self::$share->exists('myshare'));
+    }
+
+    /**
+     * @depends testPermissions
+     */
+    public function baseCountShares()
+    {
+        // Getting shares from cache.
+        $this->assertEquals(4, self::$share->countShares('john'));
+        $this->assertEquals(2, self::$share->countShares('john', Horde_Perms::EDIT));
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        // Getting shares from backend.
+        $this->assertEquals(4, self::$share->countShares('john'));
+        $this->assertEquals(2, self::$share->countShares('john', Horde_Perms::EDIT));
+    }
+
+    /**
+     * @depends testPermissions
+     */
+    public function baseGetShare()
+    {
+        $share = self::$share->getShare('myshare');
+        $this->assertInstanceOf('Horde_Share_Object', $share);
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        $share = self::$share->getShare('myshare');
+        $this->assertInstanceOf('Horde_Share_Object', $share);
+
+        return array($share, self::$share->getShare('janeshare'), self::$share->getShare('groupshare'));
+    }
+
+    public function baseGetShareById(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);
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        $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);
+    }
+
+    public function baseGetShares(array $shares)
+    {
+        $newshares = self::$share->getShares(array($shares[0]->getId(), $shares[1]->getId(), $shares[2]->getId()));
+        $this->assertType('array', $newshares);
+        $this->assertEquals(3, count($newshares));
+        $this->assertArrayHasKey('myshare', $newshares);
+        $this->assertArrayHasKey('janeshare', $newshares);
+        $this->assertArrayHasKey('groupshare', $newshares);
+        $this->assertInstanceOf('Horde_Share_Object', $newshares['myshare']);
+        $this->assertInstanceOf('Horde_Share_Object', $newshares['janeshare']);
+        $this->assertInstanceOf('Horde_Share_Object', $newshares['groupshare']);
+        $this->assertEquals($newshares['myshare'], $shares[0]);
+        $this->assertEquals($newshares['janeshare'], $shares[1]);
+        $this->assertEquals($newshares['groupshare'], $shares[2]);
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        $newshares = self::$share->getShares(array($shares[0]->getId(), $shares[1]->getId(), $shares[2]->getId()));
+        $this->assertType('array', $newshares);
+        $this->assertEquals(3, count($newshares));
+        $this->assertArrayHasKey('myshare', $newshares);
+        $this->assertArrayHasKey('janeshare', $newshares);
+        $this->assertArrayHasKey('groupshare', $newshares);
+        $this->assertInstanceOf('Horde_Share_Object', $newshares['myshare']);
+        $this->assertInstanceOf('Horde_Share_Object', $newshares['janeshare']);
+        $this->assertInstanceOf('Horde_Share_Object', $newshares['groupshare']);
+        $this->assertEquals($newshares['myshare'], $shares[0]);
+        $this->assertEquals($newshares['janeshare'], $shares[1]);
+        $this->assertEquals($newshares['groupshare'], $shares[2]);
+    }
+
+    /**
+     * @depends testPermissions
+     */
+    public function baseListAllShares()
+    {
+        // Getting shares from cache.
+        $shares = self::$share->listAllShares();
+        $this->assertType('array', $shares);
+        $this->assertEquals(5, count($shares));
+        $this->assertArrayHasKey('myshare', $shares);
+        $this->assertArrayHasKey('systemshare', $shares);
+        $this->assertArrayHasKey('janeshare', $shares);
+        $this->assertArrayHasKey('groupshare', $shares);
+        $this->assertArrayHasKey('noshare', $shares);
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        // Getting shares from backend.
+        $shares = self::$share->listAllShares();
+        $this->assertType('array', $shares);
+        $this->assertEquals(5, count($shares));
+        $this->assertArrayHasKey('myshare', $shares);
+        $this->assertArrayHasKey('systemshare', $shares);
+        $this->assertArrayHasKey('janeshare', $shares);
+        $this->assertArrayHasKey('groupshare', $shares);
+        $this->assertArrayHasKey('noshare', $shares);
+    }
+
+    /**
+     * @depends testPermissions
+     */
+    public function baseListSystemShares()
+    {
+        // Getting shares from cache.
+        $shares = self::$share->listSystemShares();
+        $this->assertType('array', $shares);
+        $this->assertEquals(1, count($shares));
+        $this->assertArrayHasKey('systemshare', $shares);
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        // Getting shares from backend.
+        $shares = self::$share->listSystemShares();
+        $this->assertType('array', $shares);
+        $this->assertEquals(1, count($shares));
+        $this->assertArrayHasKey('systemshare', $shares);
+    }
+
+    public function baseRemoveShare(array $share)
+    {
+        self::$share->removeShare($share[0]);
+        $this->assertEquals(4, count(self::$share->listAllShares()));
+
+        // Reset cache.
+        self::$share->resetCache();
+
+        $this->assertEquals(4, count(self::$share->listAllShares()));
+    }
+}
+
+class Horde_Group_Test extends Horde_Group {
+    public function __construct()
+    {
+    }
+
+    public function __wakeup()
+    {
+    }
+
+    public function userIsInGroup($user, $gid, $subgroups = true)
+    {
+        return $user == 'john' && $gid == 'mygroup';
+    }
+
+    public function getGroupMemberships($user, $parentGroups = false)
+    {
+        return $user == 'john' ? array('mygroup' => 'mygroup') : array();
+    }
+}