<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>
<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 -->
<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>
<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
/**
* Prepare the test setup.
*/
-require_once dirname(__FILE__) . '/Autoload.php';
+require_once dirname(__FILE__) . '/TestBase.php';
/**
* @author Jan Schneider <jan@horde.org>
* @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());
public function testAddShare()
{
- $share = self::$share->newShare('john', 'myshare');
+ $share = parent::baseAddShare();
$this->assertInstanceOf('Horde_Share_Object_Sql', $share);
- self::$share->addShare($share);
}
/**
*/
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();
}
/**
*/
public function testExists()
{
- $this->assertTrue(self::$share->exists('myshare'));
-
- // Reset cache.
- self::$share->resetCache();
-
- $this->assertTrue(self::$share->exists('myshare'));
+ parent::baseExists();
}
/**
*/
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;
}
/**
*/
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);
}
/**
*/
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);
}
/**
*/
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();
}
/**
*/
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();
}
/**
*/
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()
}
}
}
-
-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();
- }
-}
--- /dev/null
+<?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();
+ }
+}