Merge branch '2013.10'
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 6 Dec 2013 11:01:20 +0000 (12:01 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 6 Dec 2013 11:01:20 +0000 (12:01 +0100)
Conflicts:
tests/tine20/Calendar/TestCase.php

1  2 
tests/tine20/Calendar/TestCase.php
tests/tine20/Courses/JsonTest.php

@@@ -4,7 -4,7 +4,7 @@@
   * 
   * @package     Calendar
   * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
-  * @copyright   Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
+  * @copyright   Copyright (c) 2009-2013 Metaways Infosystems GmbH (http://www.metaways.de)
   * @author      Cornelius Weiss <c.weiss@metaways.de>
   */
  
@@@ -18,7 -18,7 +18,7 @@@ require_once dirname(dirname(__FILE__)
   * 
   * @package     Calendar
   */
- abstract class Calendar_TestCase extends PHPUnit_Framework_TestCase
+ abstract class Calendar_TestCase extends TestCase
  {
      /**
       * @var Calendar_Backend_Sql SQL Backend in test
      /**
       * @var Tinebase_Model_Container
       */
 -    protected $_testCalendar;
 +    protected $_testCalendar = NULL;
      
      /**
       * @var Tinebase_Record_RecordSet test calendars to be deleted on tearDown
       */
 -    protected $_testCalendars;
 +    protected $_testCalendars = NULL;
      
      /**
       * @var Tinebase_Model_FullUser
       */
 -    protected $_testUser;
 +    protected $_testUser = NULL;
      
      /**
       * @var Addressbook_Model_Contact
       */
 -    protected $_testUserContact;
 +    protected $_testUserContact = NULL;
      
      /**
       * personas
       *
       * @var array
       */
 -    protected $_personas;
 +    protected $_personas = NULL;
      
      /**
       * personas contacts
       * @var array
       */
 -    protected $_personasContacts;
 +    protected $_personasContacts = array();
      
      /**
       * persona calendars
      protected $_personasDefaultCals = array();
      
      /**
-      * transaction id if test is wrapped in an transaction
-      */
-     protected $_transactionId = NULL;
-     
-     /**
       * set up tests
-      *
       */
      public function setUp()
      {
-         $this->_transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
+         parent::setUp();
+         
          $this->_backend = new Calendar_Backend_Sql();
 -        
 -        $this->_personas = Zend_Registry::get('personas');
 -        foreach ($this->_personas as $loginName => $user) {
 -            $defaultCalendarId = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $user->getId());
 -            $this->_personasContacts[$loginName] = Addressbook_Controller_Contact::getInstance()->getContactByUserId($user->getId());
 -            $this->_personasDefaultCals[$loginName] = Tinebase_Container::getInstance()->getContainerById($defaultCalendarId);
 -        }
 -        
          $this->_testUser = Tinebase_Core::getUser();
 -        $this->_testUserContact = Addressbook_Controller_Contact::getInstance()->getContactByUserId($this->_testUser->getId());
 -        $this->_testCalendar = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array(
 -            'name'           => 'PHPUnit test calendar',
 -            'type'           => Tinebase_Model_Container::TYPE_PERSONAL,
 -            'owner_id'       => Tinebase_Core::getUser(),
 -            'backend'        => $this->_backend->getType(),
 -            'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId()
 -        ), true));
 -        
 -        $this->_testCalendars = new Tinebase_Record_RecordSet('Tinebase_Model_Container');
 -        $this->_testCalendars->addRecord($this->_testCalendar);
      }
      
      /**
       * tear down tests
-      *
       */
      public function tearDown()
      {
+         parent::tearDown();
+         
          Calendar_Controller_Event::getInstance()->sendNotifications(false);
          
-         if ($this->_transactionId) {
-             Tinebase_TransactionManager::getInstance()->rollBack();
-         } elseif ($this->_testCalendar !== NULL) {
 -        if (! $this->_transactionId) {
++        if (! $this->_transactionId && $this->_testCalendar !== NULL) {
              $events = $this->_backend->search(new Calendar_Model_EventFilter(array(
                  array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_testCalendars->getId()),
              )), new Tinebase_Model_Pagination(array()));
                  Tinebase_Container::getInstance()->deleteContainer($cal, true);
              }
          }
 +        // do NOT unset _testUser,the tear down of Calendar_Frontend_WebDAV_EventTest still requires _testUser
 +        $this->_testUserContact = NULL;
 +        $this->_testCalendar = NULL;
 +        $this->_testCalendars = NULL;
 +        $this->_personas = NULL;
 +        $this->_personasContacts = array();
 +        $this->_personasDefaultCals = array();
 +    }
 +    
 +    /**
 +     * returns test persons contacts
 +     * 
 +     * @param string $loginName
 +     * @return Addressbook_Model_Contact
 +     */
 +    protected function _getPersonasContacts($loginName)
 +    {
 +        if (!isset($this->_personasContacts[$loginName])) {
 +            $user = $this->_getPersona($loginName);
 +            $this->_personasContacts[$loginName] = Addressbook_Controller_Contact::getInstance()->getContactByUserId($user->getId());
 +        }
 +        return $this->_personasContacts[$loginName];
 +    }
 +    
 +    /**
 +     * returns test persons default calendar
 +     * 
 +     * @param string $loginName
 +     * @return Tinebase_Model_Container
 +     */
 +    protected function _getPersonasDefaultCals($loginName)
 +    {
 +        if (!isset($this->_personasDefaultCals[$loginName])) {
 +            $user = $this->_getPersona($loginName);
 +            $defaultCalendarId = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $user->getId());
 +            $this->_personasDefaultCals[$loginName] = Tinebase_Container::getInstance()->getContainerById($defaultCalendarId);
 +        }
 +        return $this->_personasDefaultCals[$loginName];
 +    }
 +    
 +    /**
 +     * returns all test persons default calendar
 +     * 
 +     * @return array
 +     */
 +    protected function _getAllPersonasDefaultCals()
 +    {
 +        foreach ($this->_getPersonas() as $loginName => $user)
 +        {
 +            $this->_getPersonasDefaultCals($loginName);
 +        }
 +        return $this->_personasDefaultCals;
 +    }
 +    
 +    /** return a test person
 +     * @return 
 +     */
 +    protected function _getPersona($loginName)
 +    {
 +        if ($this->_personas === NULL) {
 +            $this->_getPersonas();
 +        }
 +        return $this->_personas[$loginName];
 +    }
 +    
 +    /**
 +     * returns an array of test persons
 +     * 
 +     * @return array
 +     */
 +    protected function _getPersonas()
 +    {
 +        if ($this->_personas === NULL) {
 +            $this->_personas = Zend_Registry::get('personas');
 +        }
 +        return $this->_personas;
 +    }
 +    
 +    /**
 +     * returns a test user
 +     * 
 +     * @return Tinebase_Model_FullUser
 +     */
 +    protected function _getTestUser()
 +    {
 +        return $this->_testUser;
 +    }
 +    
 +    /**
 +     * returns the test users contact
 +     * 
 +     * @return
 +     */
 +    protected function _getTestUserContact()
 +    {
 +        if ($this->_testUserContact === NULL) {
 +            $this->_testUserContact = Addressbook_Controller_Contact::getInstance()->getContactByUserId($this->_getTestUser()->getId());
 +        }
 +        return $this->_testUserContact;
 +    }
 +    /**
 +     * returns a test calendar set
 +     * 
 +     * @return Tinebase_Record_RecordSet\r
 +     */
 +    protected function _getTestCalendars()
 +    {
 +        if ($this->_testCalendars === NULL) {
 +            $this->_getTestCalendar();
 +        }
 +        return $this->_testCalendars;
 +    }
 +    /**
 +     * returns a test calendar
 +     * 
 +     * @return Tinebase_Model_Container
 +     */
 +    protected function _getTestCalendar()
 +    {
 +        if ($this->_testCalendar === NULL) {
 +            $this->_testCalendar = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array(
 +                    'name'           => 'PHPUnit test calendar',
 +                    'type'           => Tinebase_Model_Container::TYPE_PERSONAL,
 +                    'owner_id'       => Tinebase_Core::getUser(),
 +                    'backend'        => $this->_backend->getType(),
 +                    'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId()
 +            ), true));
 +            
 +            $this->_testCalendars = new Tinebase_Record_RecordSet('Tinebase_Model_Container');
 +            $this->_testCalendars->addRecord($this->_testCalendar);
 +        }
 +        return $this->_testCalendar;
      }
      
      /**
              'description' => 'Early to bed and early to rise, makes a men healthy, wealthy and wise',
              'attendee'    => $this->_getAttendee(),
          
 -            'container_id' => $this->_testCalendar->getId(),
 -            'organizer'    => $this->_testUserContact->getId(),
 +            'container_id' => $this->_getTestCalendar()->getId(),
 +            'organizer'    => $this->_getTestUserContact()->getId(),
              'uid'          => Calendar_Model_Event::generateUID(),
          
              Tinebase_Model_Grants::GRANT_READ    => true,
      {
          return new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
              array(
 -                'user_id'        => $this->_testUserContact->getId(),
 +                'user_id'        => $this->_getTestUserContact()->getId(),
                  'user_type'      => Calendar_Model_Attender::USERTYPE_USER,
                  'role'           => Calendar_Model_Attender::ROLE_REQUIRED,
                  'status_authkey' => Tinebase_Record_Abstract::generateUID(),
              ),
              array(
 -                'user_id'        => $this->_personasContacts['sclever']->getId(),
 +                'user_id'        => $this->_GetPersonasContacts('sclever')->getId(),
                  'user_type'      => Calendar_Model_Attender::USERTYPE_USER,
                  'role'           => Calendar_Model_Attender::ROLE_REQUIRED,
                  'status_authkey' => Tinebase_Record_Abstract::generateUID(),
      }
      
      /**
-      * test needs transaction
-      */
-     protected function _testNeedsTransaction()
-     {
-         if ($this->_transactionId) {
-             Tinebase_TransactionManager::getInstance()->commitTransaction($this->_transactionId);
-             $this->_transactionId = NULL;
-         }
-     }
-     
-     /**
       * get all calendar grants
       * 
       * @param Tinebase_Model_User $user
@@@ -4,9 -4,8 +4,8 @@@
   * 
   * @package     Courses
   * @license     http://www.gnu.org/licenses/agpl.html
-  * @copyright   Copyright (c) 2009-2012 Metaways Infosystems GmbH (http://www.metaways.de)
+  * @copyright   Copyright (c) 2009-2013 Metaways Infosystems GmbH (http://www.metaways.de)
   * @author      Philipp Schüle <p.schuele@metaways.de>
-  * 
   */
  
  /**
@@@ -15,9 -14,9 +14,9 @@@
  require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  
  /**
-  * Test class for Tinebase_Group
+  * Test class for Courses_Frontend_Json
   */
- class Courses_JsonTest extends PHPUnit_Framework_TestCase
+ class Courses_JsonTest extends TestCase
  {
      /**
       * @var Courses_Frontend_Json
      protected $_configGroups = array();
      
      /**
+      * @var Tinebase_Record_RecordSet
+      */
+     protected $_groupsToDelete = null;
+     
+     /**
       * test department
       * 
       * @var Tinebase_Model_Department
       */
      protected $_department = NULL;
-     
-     /**
-      * Runs the test methods of this class.
-      *
-      * @access public
-      * @static
-      */
-     public static function main()
-     {
-         $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Courses Json Tests');
-         PHPUnit_TextUI_TestRunner::run($suite);
-     }
  
      /**
       * Sets up the fixture.
@@@ -58,7 -50,7 +50,7 @@@
       */
      protected function setUp()
      {
-         Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
+         parent::setUp();
          
          $this->_json = new Courses_Frontend_Json();
          
              'name'  => Tinebase_Record_Abstract::generateUID()
          )));
          
+         $this->_groupsToDelete = new Tinebase_Record_RecordSet('Tinebase_Model_Group');
          foreach (array(Courses_Config::INTERNET_ACCESS_GROUP_ON, Courses_Config::INTERNET_ACCESS_GROUP_FILTERED, Courses_Config::STUDENTS_GROUP) as $configgroup) {
              $this->_configGroups[$configgroup] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
                  'name'   => $configgroup
              )));
+             $this->_groupsToDelete->addRecord($this->_configGroups[$configgroup]);
              Courses_Config::getInstance()->set($configgroup, $this->_configGroups[$configgroup]->getId());
          }
          
@@@ -90,7 -84,9 +84,9 @@@
       */
      protected function tearDown()
      {
-         Tinebase_TransactionManager::getInstance()->rollBack();
+         $this->_groupsIdsToDelete = $this->_groupsToDelete->getArrayOfIds();
+         
+         parent::tearDown();
      }
      
      /**
      {
          $course = $this->_getCourseData();
          $courseData = $this->_json->saveCourse($course);
+         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
          
          // checks
          $this->assertEquals($course['description'], $courseData['description']);
      {
          $course = $this->_getCourseData();
          $courseData = $this->_json->saveCourse($course);
+         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
          $courseData = $this->_json->getCourse($courseData['id']);
          
          // checks
      {
          $course = $this->_getCourseData();
          $courseData = $this->_json->saveCourse($course);
+         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
  
          // update Course
          $courseData['description'] = "blubbblubb";
          // create
          $course = $this->_getCourseData();
          $courseData = $this->_json->saveCourse($course);
+         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
          
          // search & check
          $search = $this->_json->searchCourses($this->_getCourseFilter($courseData['name']), $this->_getPaging());
          // create new course with internet access
          $course = $this->_getCourseData();
          $courseData = $this->_json->saveCourse($course);
+         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
          $userId = $courseData['members'][0]['id'];
          $groupMemberships = Tinebase_Group::getInstance()->getGroupMemberships($userId);
          $this->assertTrue(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_ON]->getId(), $groupMemberships), $userId . ' not member of the internet group ' . print_r($groupMemberships, TRUE));
      {
          $course = $this->_getCourseData();
          $courseData = $this->_json->saveCourse($course);
+         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
          
          $result = $this->_json->addNewMember(array(
              'accountFirstName' => 'jams',
      {
          $course = $this->_getCourseData();
          $courseData = $this->_json->saveCourse($course);
+         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
          $teacher = Tinebase_User::getInstance()->getFullUserById($courseData['members'][0]['id']);
          
          $filter = Tinebase_PersistentFilter::getInstance()->getFilterById(
          
          $course = $this->_getCourseData();
          $courseData = $this->_json->saveCourse($course);
+         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
          
          if ($removeGroupList) {
              $group = Admin_Controller_Group::getInstance()->get($courseData['group_id']);
              Addressbook_Controller_List::getInstance()->delete($group->list_id);
          }
          
-         $this->_coursesToDelete[] = $courseData['id'];
-         
          if ($_useJsonImportFn) {
              $tempFileBackend = new Tinebase_TempFile();
              $tempFile = $tempFileBackend->createTempFile($_filename);
          return $definition;
      }
      
 -      /**
 +     /**
       * returns course import definition
       * 
       * @return Tinebase_Model_ImportExportDefinition