fixes some LDAP testing issues
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 5 Aug 2015 14:24:21 +0000 (16:24 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 5 Aug 2015 17:49:34 +0000 (19:49 +0200)
Change-Id: I88deed26b6f8a49f7e033f4cca372f15068867a5
Reviewed-on: http://gerrit.tine20.com/customers/2092
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Admin/CliTest.php
tests/tine20/Admin/JsonTest.php
tests/tine20/Tinebase/AccountTest.php
tests/tine20/Tinebase/Acl/RolesTest.php
tine20/Tinebase/Group/Ldap.php

index acfd1d4..92ef111 100644 (file)
@@ -52,23 +52,23 @@ class Admin_CliTest extends TestCase
     {
         parent::setUp();
         
-        
         $this->_cli = new Admin_Frontend_Cli();
         
         $this->_usernamesToDelete = array('hmaster', 'hmeister', 'hmoster', 'irmeli', 'testuser', 'm.muster');
-        
+
         $this->_groupsToDelete = new Tinebase_Record_RecordSet('Tinebase_Model_Group');
-        $this->_testGroup['domainuser'] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
-            'name'   => 'domainuser'
-        )));
-        $this->_testGroup['teacher'] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
-            'name'   => 'teacher'
-        )));
-        $this->_testGroup['student'] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
-            'name'   => 'student'
-        )));
-        $this->_groupsToDelete->addRecord($this->_testGroup['teacher']);
-        
+        $testGroups = array('domainuser', 'teacher', 'student');
+        foreach ($testGroups as $group) {
+            try {
+                $this->_testGroup[$group] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
+                    'name' => $group
+                )));
+            } catch (Exception $e) {
+                $this->_testGroup[$group] = Tinebase_Group::getInstance()->getGroupByName($group);
+            }
+            $this->_groupsToDelete->addRecord($this->_testGroup[$group]);
+        }
+
         $this->objects['config'] = '<?xml version="1.0" encoding="UTF-8"?>
         <config>
             <dryrun>0</dryrun>
index 10817bc..58b4cb1 100644 (file)
@@ -135,9 +135,9 @@ class Admin_JsonTest extends TestCase
         if ($data === null) {
             $data = $this->objects['user']->toArray();
         }
+        $this->_usernamesToDelete[] = $data['accountLoginName'];
         $user = $this->_json->saveUser($data);
-        $this->_usernamesToDelete[] = $user['accountLoginName'];
-        
+
         return $user;
     }
     
@@ -170,11 +170,11 @@ class Admin_JsonTest extends TestCase
      */
     public function testGetNonExistentAccountById()
     {
-        $translate = Tinebase_Translation::getTranslation('Tinebase');
+        Tinebase_Translation::getTranslation('Tinebase');
         $id = 12334567;
         
         $this->setExpectedException('Tinebase_Exception_NotFound');
-        $user = Tinebase_User::getInstance()->getUserById($id);
+        Tinebase_User::getInstance()->getUserById($id);
     }
 
     /**
index 35f0dc2..8611b5a 100644 (file)
  */
 
 /**
- * Test class for Tinebase_Group
- * @depricated, some fns might be moved to other testclasses
+ * Test class for Tinebase_User
+ * @deprecated, some fns might be moved to other testclasses
  */
 class Tinebase_AccountTest extends TestCase
 {
     /**
-     * Runs the test methods of this class.
-     *
-     * @access public
-     * @static
-     */
-    public static function main()
-    {
-        $suite  = new PHPUnit_Framework_TestSuite('Tinebase_AccountTest');
-        PHPUnit_TextUI_TestRunner::run($suite);
-    }
-    
-    /**
      * try to add an account
      * @return Tinebase_Model_FullUser
      */
     public function testAddAccount()
     {
+        $this->_usernamesToDelete[] = 'tine20phpunit';
         $account = Tinebase_User::getInstance()->addUser(new Tinebase_Model_FullUser(
             array(
                 'accountLoginName'    => 'tine20phpunit',
@@ -247,14 +236,14 @@ class Tinebase_AccountTest extends TestCase
     public function testDeleteAccount()
     {
         $account = $this->testAddAccount();
-        
+
         Tinebase_User::getInstance()->deleteUser($account);
-        
+
         $this->setExpectedException('Tinebase_Exception_NotFound');
-        
+
         $account = Tinebase_User::getInstance()->getUserById($account, 'Tinebase_Model_FullUser');
     }
-    
+
     /**
      * try to delete multiple accounts
      *
@@ -262,16 +251,16 @@ class Tinebase_AccountTest extends TestCase
     public function testDeleteAccounts()
     {
         $account = $this->testAddAccount();
-        
+
         $todelete = array($account->accountId);
-        
+
         Tinebase_User::getInstance()->deleteUsers($todelete);
-        
+
         $this->setExpectedException('Tinebase_Exception_NotFound');
-        
+
         $account = Tinebase_User::getInstance()->getUserById($account, 'Tinebase_Model_FullUser');
     }
-    
+
     /**
      * try to convert account id and check if correct exceptions are thrown 
      *
@@ -281,7 +270,6 @@ class Tinebase_AccountTest extends TestCase
         $this->setExpectedException('Tinebase_Exception_NotFound');
         
         Tinebase_Model_User::convertUserIdToInt(0);
-        
     }
     
     /**
index d9b4852..d07c702 100644 (file)
@@ -52,6 +52,7 @@ class Tinebase_Acl_RolesTest extends TestCase
         ));
         
         // add account for group / role member tests
+        $this->_usernamesToDelete[] =$this->objects['user']->accountLoginName;
         $this->objects['user'] = Tinebase_User::getInstance()->addUser($this->objects['user']);
         Tinebase_Group::getInstance()->addGroupMember($this->objects['user']->accountPrimaryGroup, $this->objects['user']);
         
@@ -66,7 +67,6 @@ class Tinebase_Acl_RolesTest extends TestCase
      */
     protected function tearDown()
     {
-        Tinebase_User::getInstance()->deleteUser($this->objects['user']->accountId);
         Tinebase_Acl_Roles::getInstance()->resetClassCache();
         
         // cleanup for testHasRight/test disabled app
@@ -147,7 +147,7 @@ class Tinebase_Acl_RolesTest extends TestCase
         $this->testCreateRole();
         
         // create role 2 for test
-        $role2 = Tinebase_Acl_Roles::getInstance()->createRole($this->objects['role_2']);
+        Tinebase_Acl_Roles::getInstance()->createRole($this->objects['role_2']);
         
         // remove role members
         Tinebase_Acl_Roles::getInstance()->setRoleMembers($this->objects['role']->getId(), array());
index 74df7cd..9549af4 100644 (file)
@@ -625,7 +625,7 @@ class Tinebase_Group_Ldap extends Tinebase_Group_Sql implements Tinebase_Group_I
         
         $this->getLdap()->update($dn, $ldapData);
         
-        if ($metaData['cn'] != $ldapData['cn']) {
+        if (isset($metaData['cn']) && $metaData['cn'] != $ldapData['cn']) {
             $newDn = "cn={$ldapData['cn']},{$this->_options['groupsDn']}";
             $this->_ldap->rename($dn, $newDn);
         }