--- /dev/null
+<?php
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/TestBase.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_SqlHierarchicalTest extends Horde_Share_TestBase
+{
+ protected static $db;
+
+ public function testSetTable()
+ {
+ $this->assertEquals('test_shares', self::$share->getTable());
+ self::$share->setTable('foo');
+ $this->assertEquals('foo', self::$share->getTable());
+ self::$share->setTable('test_shares');
+ }
+
+ public function testSetStorage()
+ {
+ self::$share->setStorage(self::$db);
+ $this->assertEquals(self::$db, self::$share->getStorage());
+ }
+
+ public function testAddShare()
+ {
+ $share = parent::baseAddShare();
+ $this->assertInstanceOf('Horde_Share_Object_Sql_Hierarchical', $share);
+ return $share->getId();
+ }
+
+ /**
+ * @depends testAddShare
+ */
+ public function testPermissions($myshareid)
+ {
+ $shareids = parent::basePermissions($myshareid);
+ return array(self::$share->getShareById($shareids[0]),
+ self::$share->getShareById($shareids[1]),
+ self::$share->getShareById($shareids[2]));
+ }
+
+ /**
+ * @depends testAddShare
+ */
+ public function testExists()
+ {
+ $this->markTestSkipped('Not supported by hierarchical driver.');
+ }
+
+ /**
+ * @depends testPermissions
+ */
+ public function testCountShares()
+ {
+ parent::baseCountShares();
+ }
+
+ /**
+ * @depends testPermissions
+ */
+ public function testGetShare()
+ {
+ $this->markTestSkipped('Not supported by hierarchical driver.');
+ }
+
+ /**
+ * @depends testPermissions
+ */
+ public function testGetShareById(array $shares)
+ {
+ parent::baseGetShareById($shares);
+ }
+
+ /**
+ * @depends testPermissions
+ */
+ 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->assertInstanceOf('Horde_Share_Object_Sql_Hierarchical', $newshares[0]);
+ $this->assertInstanceOf('Horde_Share_Object_Sql_Hierarchical', $newshares[1]);
+ $this->assertInstanceOf('Horde_Share_Object_Sql_Hierarchical', $newshares[2]);
+ $this->assertEquals($newshares[0], $shares[0]);
+ $this->assertEquals($newshares[1], $shares[1]);
+ $this->assertEquals($newshares[2], $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->assertInstanceOf('Horde_Share_Object_Sql_Hierarchical', $newshares[$shares[0]->getId()]);
+ $this->assertInstanceOf('Horde_Share_Object_Sql_Hierarchical', $newshares[$shares[1]->getId()]);
+ $this->assertInstanceOf('Horde_Share_Object_Sql_Hierarchical', $newshares[$shares[2]->getId()]);
+ $this->assertEquals($newshares[$shares[0]->getId()], $shares[0]);
+ $this->assertEquals($newshares[$shares[1]->getId()], $shares[1]);
+ $this->assertEquals($newshares[$shares[2]->getId()], $shares[2]);
+ }
+
+ /**
+ * @depends testPermissions
+ */
+ public function testListAllShares()
+ {
+ $this->markTestSkipped('Not supported by hierarchical driver.');
+ }
+
+ /**
+ * @depends testPermissions
+ */
+ public function testListSystemShares()
+ {
+ $this->markTestSkipped('Not supported by hierarchical driver.');
+ }
+
+ /**
+ * @depends testPermissions
+ */
+ public function testRemoveShare(array $share)
+ {
+ parent::baseRemoveShare($share);
+ }
+
+ public static function setUpBeforeClass()
+ {
+ if (!extension_loaded('pdo') ||
+ !in_array('sqlite', PDO::getAvailableDrivers())) {
+ return;
+ }
+
+ self::$db = new Horde_Db_Adapter_Pdo_Sqlite(array('dbname' => ':memory:'));
+ //self::$db->setLogger(new Horde_Log_Logger(new Horde_Log_Handler_Stream(STDOUT)));
+ $migration = new Horde_Db_Migration_Base(self::$db);
+
+ $t = $migration->createTable('test_shares', array('primaryKey' => 'share_id'));
+ //$t->column('share_id', 'integer', array('null' => false, 'autoincrement' => true));
+ $t->column('share_owner', 'string', array('limit' => 255));
+ $t->column('share_flags', 'integer', array('default' => 0, 'null' => false));
+ $t->column('share_parents', 'string', array('limit' => 255));
+ $t->column('perm_creator', 'integer', array('default' => 0, 'null' => false));
+ $t->column('perm_default', 'integer', array('default' => 0, 'null' => false));
+ $t->column('perm_guest', 'integer', array('default' => 0, 'null' => false));
+ $t->column('attribute_name', 'string', array('limit' => 255));
+ $t->column('attribute_desc', 'string', array('limit' => 255));
+ $t->end();
+
+ $migration->addIndex('test_shares', array('share_owner'));
+ $migration->addIndex('test_shares', array('perm_creator'));
+ $migration->addIndex('test_shares', array('perm_default'));
+ $migration->addIndex('test_shares', array('perm_guest'));
+ $migration->addIndex('test_shares', array('share_parents'));
+
+ $t = $migration->createTable('test_shares_groups');
+ $t->column('share_id', 'integer', array('null' => false));
+ $t->column('group_uid', 'string', array('limit' => 255, 'null' => false));
+ $t->column('perm', 'integer', array('null' => false));
+ $t->end();
+
+ $migration->addIndex('test_shares_groups', array('share_id'));
+ $migration->addIndex('test_shares_groups', array('group_uid'));
+ $migration->addIndex('test_shares_groups', array('perm'));
+
+ $t = $migration->createTable('test_shares_users');
+ $t->column('share_id', 'integer', array('null' => false));
+ $t->column('user_uid', 'string', array('limit' => 255));
+ $t->column('perm', 'integer', array('null' => false));
+ $t->end();
+
+ $migration->addIndex('test_shares_users', array('share_id'));
+ $migration->addIndex('test_shares_users', array('user_uid'));
+ $migration->addIndex('test_shares_users', array('perm'));
+
+ $migration->migrate('up');
+
+ $group = new Horde_Group_Test();
+ self::$share = new Horde_Share_Sql_Hierarchical('test', 'john', new Horde_Perms(), $group);
+ self::$share->setStorage(self::$db);
+
+ // FIXME
+ $GLOBALS['injector'] = new Horde_Injector(new Horde_Injector_TopLevel());
+ $GLOBALS['injector']->setInstance('Horde_Group', $group);
+ }
+
+ public static function tearDownAfterClass()
+ {
+ if (self::$db) {
+ $migration = new Horde_Db_Migration_Base(self::$db);
+ $migration->dropTable('test_shares');
+ $migration->dropTable('test_shares_groups');
+ $migration->dropTable('test_shares_users');
+ }
+ }
+
+ public function setUp()
+ {
+ if (!self::$db) {
+ $this->markTestSkipped('No sqlite extension or no sqlite PDO driver.');
+ }
+ }
+}
return $share;
}
- /**
- * @depends testAddShare
- */
- public function basePermissions()
+ public function basePermissions($myshareid)
{
// System share.
$share = self::$share->newShare(null, 'systemshare');
$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));
+ $janeshare = self::$share->newShare('jane', 'janeshare');
+ $janeshare->addUserPermission('john', Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT);
+ $janeshare->save();
+ $this->assertTrue($janeshare->hasPermission('john', Horde_Perms::SHOW));
+ $this->assertTrue($janeshare->hasPermission('john', Horde_Perms::READ));
+ $this->assertTrue($janeshare->hasPermission('john', Horde_Perms::EDIT));
+ $this->assertFalse($janeshare->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));
+ $groupshare = self::$share->newShare('jane', 'groupshare');
+ $groupshare->addGroupPermission('mygroup', Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::DELETE);
+ $groupshare->save();
+ $this->assertTrue($groupshare->hasPermission('john', Horde_Perms::SHOW));
+ $this->assertTrue($groupshare->hasPermission('john', Horde_Perms::READ));
+ $this->assertFalse($groupshare->hasPermission('john', Horde_Perms::EDIT));
+ $this->assertTrue($groupshare->hasPermission('john', Horde_Perms::DELETE));
// Foreign share without permissions.
$share = self::$share->newShare('jane', 'noshare');
$share->save();
+
+ return array($myshareid, $janeshare->getId(), $groupshare->getId());
}
- /**
- * @depends testAddShare
- */
public function baseExists()
{
$this->assertTrue(self::$share->exists('myshare'));
$this->assertTrue(self::$share->exists('myshare'));
}
- /**
- * @depends testPermissions
- */
public function baseCountShares()
{
// Getting shares from cache.
$this->assertEquals(2, self::$share->countShares('john', Horde_Perms::EDIT));
}
- /**
- * @depends testPermissions
- */
public function baseGetShare()
{
$share = self::$share->getShare('myshare');
$this->assertEquals($newshares['groupshare'], $shares[2]);
}
- /**
- * @depends testPermissions
- */
public function baseListAllShares()
{
// Getting shares from cache.
$this->assertArrayHasKey('noshare', $shares);
}
- /**
- * @depends testPermissions
- */
public function baseListSystemShares()
{
// Getting shares from cache.
public function baseRemoveShare(array $share)
{
self::$share->removeShare($share[0]);
- $this->assertEquals(4, count(self::$share->listAllShares()));
+ try {
+ self::$share->getShareById($share[0]->getId());
+ $this->fail('Share ' . $share[0]->getId() . ' should be removed by now.');
+ } catch (Horde_Exception_NotFound $e) {
+ }
// Reset cache.
self::$share->resetCache();
- $this->assertEquals(4, count(self::$share->listAllShares()));
+ try {
+ self::$share->getShareById($share[0]->getId());
+ $this->fail('Share ' . $share[0]->getId() . ' should be removed by now.');
+ } catch (Horde_Exception_NotFound $e) {
+ }
}
}