* @package Tinebase
* @subpackage Group
* @license http://www.gnu.org/licenses/agpl.html
- * @copyright Copyright (c) 2008-2009 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright Copyright (c) 2008-2015 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Lars Kneschke <l.kneschke@metaways.de>
*/
*/
require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
-if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Tinebase_Group_SqlTest::main');
-}
-
/**
* Test class for Tinebase_Group
*/
/**
* ldap user backend
*
- * @var Tinebase_User_LDAP
+ * @var Tinebase_User_Ldap
*/
protected $_userLDAP = NULL;
protected $objects = array();
/**
- * Runs the test methods of this class.
- *
- * @access public
- * @static
- */
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite('Tinebase_Group_SqlTest');
- PHPUnit_TextUI_TestRunner::run($suite);
- }
-
- /**
* Sets up the fixture.
* This method is called before a test is executed.
*
*/
protected function setUp()
{
+ if (Tinebase_User::getConfiguredBackend() !== Tinebase_User::LDAP) {
+ $this->markTestSkipped('LDAP backend not enabled');
+ }
+
$this->_groupLDAP = Tinebase_Group::factory(Tinebase_Group::LDAP);
$this->_userLDAP = Tinebase_User::factory(Tinebase_User::LDAP);
$this->_groupSQL = Tinebase_Group::factory(Tinebase_Group::SQL);
'accountFirstName' => 'PHPUnit',
'accountEmailAddress' => 'phpunit@metaways.de'
));
+
+ $this->objects['groups'] = new Tinebase_Record_RecordSet('Tinebase_Model_Group');
+ $this->objects['users'] = new Tinebase_Record_RecordSet('Tinebase_Model_FullUser');
}
/**
*/
protected function tearDown()
{
-
+ if (Tinebase_User::getConfiguredBackend() !== Tinebase_User::LDAP) {
+ return;
+ }
+
+ $this->_groupLDAP->deleteGroups($this->objects['groups']);
+ if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+ . ' Deleting users: ' . print_r($this->objects['users']->toArray(), true));
+
+ $this->_userLDAP->deleteUsers($this->objects['users']->getArrayOfIds());
}
/**
* try to add a group
*
+ * @return Tinebase_Model_Group
*/
public function testAddGroup()
{
$group = $this->_groupLDAP->addGroup($this->objects['initialGroup']);
+ $this->objects['groups']->addRecord($group);
$this->assertNotNull($group->id);
$this->assertEquals($this->objects['initialGroup']->name, $group->name);
+ return $group;
}
/**
*/
public function testGetGroups()
{
+ $this->testAddGroup();
$groups = $this->_groupLDAP->getGroups('phpunit');
$this->assertEquals(1, count($groups));
*/
public function testGetGroupByName()
{
+ $this->testAddGroup();
$group = $this->_groupLDAP->getGroupByName('tine20phpunit');
$this->assertEquals($this->objects['initialGroup']->name, $group->name);
*/
public function testGetGroupById()
{
+ $this->testAddGroup();
$group = $this->_groupLDAP->getGroupByName($this->objects['initialGroup']->name);
$group = $this->_groupLDAP->getGroupById($group->getId());
*/
public function testSetGroupMembers()
{
- $group = $this->_groupLDAP->getGroupByName('tine20phpunit');
-
- $this->objects['initialAccount']->accountPrimaryGroup = $group->getId();
- try {
- $user = $this->_userLDAP->addUser($this->objects['initialAccount']);
- } catch (Exception $e) {
- $user = $this->_userLDAP->getUserByLoginName($this->objects['initialAccount']->accountLoginName);
- }
-
+ $group = $this->testAddGroup();
+
+ $user = $this->_addUserToGroup($group);
$this->_groupLDAP->setGroupMembers($group, array($user));
$groupMembers = $this->_groupLDAP->getGroupMembers($group);
$this->_userLDAP->deleteUser($user);
}
+
+ protected function _addUserToGroup($group)
+ {
+ $this->objects['initialAccount']->accountPrimaryGroup = $group->getId();
+ $user = $this->_userLDAP->addUser($this->objects['initialAccount']);
+ $this->objects['users']->addRecord($user);
+ return $user;
+ }
/**
* test setting no group members
*/
public function testSetNoGroupMembers()
{
- $group = $this->_groupLDAP->getGroupByName('tine20phpunit');
-
+ $group = $this->testAddGroup();
+
$this->objects['initialAccount']->accountPrimaryGroup = $group->getId();
- try {
- $user = $this->_userLDAP->addUser($this->objects['initialAccount']);
- } catch (Exception $e) {
- $user = $this->_userLDAP->getUserByLoginName($this->objects['initialAccount']->accountLoginName);
- }
-
+ $user = $this->_userLDAP->addUser($this->objects['initialAccount']);
+ $this->objects['users']->addRecord($user);
+
$this->_groupLDAP->setGroupMembers($group, array($user));
$this->_groupLDAP->setGroupMembers($group, array());
*/
public function testAddGroupMember()
{
- $group = $this->_groupLDAP->getGroupByName('tine20phpunit');
-
+ $group = $this->testAddGroup();
+
$this->objects['initialAccount']->accountPrimaryGroup = $group->getId();
- try {
- $user = $this->_userLDAP->addUser($this->objects['initialAccount']);
- } catch (Exception $e) {
- $user = $this->_userLDAP->getUserByLoginName($this->objects['initialAccount']->accountLoginName);
- }
+ $user = $this->_userLDAP->addUser($this->objects['initialAccount']);
+ $this->objects['users']->addRecord($user);
$this->_groupLDAP->addGroupMember($group, $user);
*/
public function testRemoveGroupMember()
{
- $group = $this->_groupLDAP->getGroupByName('tine20phpunit');
-
+ $group = $this->testAddGroup();
+
$this->objects['initialAccount']->accountPrimaryGroup = $group->getId();
- try {
- $user = $this->_userLDAP->addUser($this->objects['initialAccount']);
- } catch (Exception $e) {
- $user = $this->_userLDAP->getUserByLoginName($this->objects['initialAccount']->accountLoginName);
- }
+ $user = $this->_userLDAP->addUser($this->objects['initialAccount']);
+ $this->objects['users']->addRecord($user);
$this->_groupLDAP->addGroupMember($group, $user);
*/
public function testUpdateGroup()
{
- $group = $this->_groupLDAP->getGroupByName($this->objects['initialGroup']->name);
+ $group = $this->testAddGroup();
$this->objects['updatedGroup']->id = $group->getId();
$group = $this->_groupLDAP->updateGroup($this->objects['updatedGroup']);
*/
public function testDeleteGroups()
{
- $group = $this->_groupLDAP->getGroupByName($this->objects['updatedGroup']->name);
+ $group = $this->testAddGroup();
$this->_groupLDAP->deleteGroups($group->getId());
$this->setExpectedException('Exception');
$group = $this->_groupLDAP->getGroupById($group->getId());
}
-}
-
-if (PHPUnit_MAIN_METHOD == 'Tinebase_Group_SqlTest::main') {
- Tinebase_Group_SqlTest::main();
+ /**
+ * @see 0009852: improve cache cleaning after LDAP sync
+ */
+ public function testSyncGroups()
+ {
+ $defaultUserGroup = Tinebase_Group::getInstance()->getDefaultGroup();
+
+ $group = $this->testAddGroup();
+ $user = $this->_addUserToGroup($group);
+
+ // add user to group (only in LDAP)
+ $this->_groupLDAP->addGroupMemberInSyncBackend($defaultUserGroup->getId(), $user);
+
+ // trigger caching
+ $memberships = $this->_groupLDAP->getGroupMembers($defaultUserGroup);
+ $this->assertFalse(in_array($user->getId(), $memberships));
+
+ // sync users
+ Tinebase_User::syncUsers(array('syncContactData' => TRUE));
+
+ // check group memberships
+ $memberships = $this->_groupLDAP->getGroupMembers($defaultUserGroup);
+ $this->assertTrue(in_array($user->getId(), $memberships), 'group memberships not updated: ' . print_r($memberships, true));
+ }
}
}
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
- . ' Created user backend of type ' . $backendType);
+ . ' Created user backend of type ' . get_class($result));
return $result;
}
self::syncContactData($syncedUser, $options);
- // sync group memberships
Tinebase_Group::syncMemberships($syncedUser);
-
+
return $syncedUser;
}
-
+
/**
- * import contactdata(phone, address, fax, birthday. photo)
+ * import contact data(phone, address, fax, birthday. photo)
*
* @param Tinebase_Model_FullUser $syncedUser
* @param array $options
} catch (Addressbook_Exception_NotFound $aenf) {
self::createContactForSyncedUser($syncedUser);
$syncedUser = Tinebase_User::getInstance()->updateUserInSqlBackend($syncedUser);
+
} catch (Tinebase_Exception_NotFound $tenf) {
if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
. ' Contact information seems to be missing in sync backend');
self::_syncDeletedUsers($users);
}
- // @todo this should be improved: only the cache of synced users + group memberships should be cleaned
- if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
- . ' Finished synchronizing users. Clearing cache after user sync ...');
- Tinebase_Core::getCache()->clean();
+ if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+ . ' Finished synchronizing users.');
}
/**