Merge branch '2013.10' into 2014.11
[tine20] / tests / tine20 / Calendar / Controller / EventTests.php
index d848696..8e31c14 100644 (file)
@@ -21,11 +21,6 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
     protected $_controller;
     
     /**
-     * @var Tinebase_Model_Container
-     */
-    protected $_testCalendar;
-    
-    /**
      * (non-PHPdoc)
      * @see Calendar_TestCase::setUp()
      */
@@ -48,7 +43,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         
         $this->assertEquals($event->description, $persistentEvent->description);
         $this->assertTrue($event->dtstart->equals($persistentEvent->dtstart));
-        $this->assertEquals(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE), $persistentEvent->originator_tz);
+        $this->assertEquals(Tinebase_Core::getUserTimezone(), $persistentEvent->originator_tz);
         
         return $persistentEvent;
     }
@@ -63,7 +58,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $event->dtend = null;
         
         $persistentEvent = $this->_controller->create($event);
-        $persistentEvent->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
+        $persistentEvent->setTimezone(Tinebase_Core::getUserTimezone());
         $this->assertEquals('2009-04-06 23:59:59', $persistentEvent->dtend->toString());
     }
     
@@ -90,7 +85,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
     {
         $persistentEvent = $this->testCreateEvent();
         
-        $currentTz = Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
+        $currentTz = Tinebase_Core::getUserTimezone();
         Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, 'farfaraway');
         
         $persistentEvent->summary = 'Lunchtime';
@@ -101,7 +96,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $updatedEvent->dtstart->addHour(1);
         $updatedEvent->dtend->addHour(1);
         $secondUpdatedEvent = $this->_controller->update($updatedEvent);
-        $this->assertEquals(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE), $secondUpdatedEvent->originator_tz, 'originator_tz must be adopted if dtsart is updatet!');
+        $this->assertEquals(Tinebase_Core::getUserTimezone(), $secondUpdatedEvent->originator_tz, 'originator_tz must be adopted if dtsart is updatet!');
     
         Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, $currentTz);
     }
@@ -145,7 +140,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $event->attendee = $this->_getAttendee();
         $event->attendee[1] = new Calendar_Model_Attender(array(
             'user_type' => Calendar_Model_Attender::USERTYPE_USER,
-            'user_id'   => $this->_personasContacts['pwulf']->getId(),
+            'user_id'   => $this->_getPersonasContacts('pwulf')->getId(),
         ));
         
         $persistentEvent = $this->_controller->create($event);
@@ -173,7 +168,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
             
         $pwulf = $updatedEvent->attendee
             ->filter('user_type', Calendar_Model_Attender::USERTYPE_USER)
-            ->filter('user_id', $this->_personasContacts['pwulf']->getId())
+            ->filter('user_id', $this->_getPersonasContacts('pwulf')->getId())
             ->getFirstRecord();
 
         $this->assertEquals(Calendar_Model_Attender::STATUS_DECLINED, $currentUser->status, 'current users status must not be touched');
@@ -204,7 +199,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $event->attendee = $this->_getAttendee();
         $event->attendee[1] = new Calendar_Model_Attender(array(
             'user_type' => Calendar_Model_Attender::USERTYPE_USER,
-            'user_id'   => $this->_personasContacts['pwulf']->getId()
+            'user_id'   => $this->_getPersonasContacts('pwulf')->getId()
         ));
         
         $persistendEvent = $this->_controller->create($event);
@@ -228,30 +223,30 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $event1 = $this->_getEvent();
         $event1->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
             array('user_id' => Tinebase_Core::getUser()->contact_id),
-            array('user_id' => $this->_personasContacts['pwulf']->getId())
+            array('user_id' => $this->_getPersonasContacts('pwulf')->getId())
         ));
         $persistentEvent1 = $this->_controller->create($event1);
         
         $event2 = $this->_getEvent();
         $event2->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
             array('user_id' => Tinebase_Core::getUser()->contact_id),
-            array('user_id' => $this->_personasContacts['sclever']->getId()),
+            array('user_id' => $this->_getPersonasContacts('sclever')->getId()),
         ));
         $persistentEvent2 = $this->_controller->create($event2);
         
         $event3 = $this->_getEvent();
         $event3->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
             array('user_id' => Tinebase_Core::getUser()->contact_id),
-            array('user_id' => $this->_personasContacts['sclever']->getId()),
+            array('user_id' => $this->_getPersonasContacts('sclever')->getId()),
         ));
         $persistentEvent3 = $this->_controller->create($event3);
         
         // test sclever
         $filter = new Calendar_Model_EventFilter(array(
-            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
+            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()),
             array('field' => 'attender'    , 'operator' => 'equals', 'value' => array(
                 'user_type' => Calendar_Model_Attender::USERTYPE_USER,
-                'user_id'   => $this->_personasContacts['sclever']->getId()
+                'user_id'   => $this->_getPersonasContacts('sclever')->getId()
             )),
         ));
         $eventsFound = $this->_controller->search($filter, new Tinebase_Model_Pagination());
@@ -259,10 +254,10 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         
         // test pwulf
         $filter = new Calendar_Model_EventFilter(array(
-            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
+            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()),
             array('field' => 'attender'    , 'operator' => 'equals', 'value' => array(
                 'user_type' => Calendar_Model_Attender::USERTYPE_USER,
-                'user_id'   => $this->_personasContacts['pwulf']->getId()
+                'user_id'   => $this->_getPersonasContacts('pwulf')->getId()
             )),
         ));
         $eventsFound = $this->_controller->search($filter, new Tinebase_Model_Pagination());
@@ -270,15 +265,15 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         
         // test sclever OR pwulf
         $filter = new Calendar_Model_EventFilter(array(
-            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
+            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()),
             array('field' => 'attender'    , 'operator' => 'in',     'value' => array(
                 array(
                     'user_type' => Calendar_Model_Attender::USERTYPE_USER,
-                    'user_id'   => $this->_personasContacts['sclever']->getId()
+                    'user_id'   => $this->_getPersonasContacts('sclever')->getId()
                 ),
                 array (
                     'user_type' => Calendar_Model_Attender::USERTYPE_USER,
-                    'user_id'   => $this->_personasContacts['pwulf']->getId()
+                    'user_id'   => $this->_getPersonasContacts('pwulf')->getId()
                 )
             )),
         ));
@@ -291,16 +286,16 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $event = $this->_getEvent();
         $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
             array('user_id' => Tinebase_Core::getUser()->contact_id),
-            array('user_id' => $this->_personasContacts['sclever']->getId())
+            array('user_id' => $this->_getPersonasContacts('sclever')->getId())
         ));
         $persistentEvent = $this->_controller->create($event);
         
         $filter = new Calendar_Model_EventFilter(array(
-            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
+            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()),
             array('field' => 'attender'    , 'operator' => 'in',     'value' => array(
                 array(
                     'user_type' => Calendar_Model_AttenderFilter::USERTYPE_MEMBEROF,
-                    'user_id'   => $this->_personas['sclever']->accountPrimaryGroup
+                    'user_id'   => $this->_getPersona('sclever')->accountPrimaryGroup
                 )
             )),
         ));
@@ -319,7 +314,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         }
     
         $filter = new Calendar_Model_EventFilter(array(
-                array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
+                array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()),
                 array('field' => 'attender'    , 'operator' => 'notin',  'value' => array(
                         array(
                                 'user_type' => Calendar_Model_Attender::USERTYPE_USER,
@@ -339,8 +334,8 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
     {
         $event = $this->_getEvent();
         $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
-            array('user_id' => $this->_personasContacts['sclever']->getId()),
-            array('user_id' => $this->_personasContacts['pwulf']->getId())
+            array('user_id' => $this->_getPersonasContacts('sclever')->getId()),
+            array('user_id' => $this->_getPersonasContacts('pwulf')->getId())
         ));
         $persistentEvent = $this->_controller->create($event);
         
@@ -369,7 +364,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
             'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId()
         ), true));
         
-        $this->_testCalendars->addRecord($testCal);
+        $this->_getTestCalendars()->addRecord($testCal);
         
         // create event in testcal
         $event = $this->_getEvent();
@@ -384,7 +379,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $events = $this->_controller->search(new Calendar_Model_EventFilter(array(
             array('field' => 'attender', 'operator' => 'equals', 'value' => array(
                 'user_type' => Calendar_Model_Attender::USERTYPE_USER,
-                'user_id'   => $this->_testUserContact->getId()
+                'user_id'   => $this->_getTestUserContact()->getId()
             ))
         )), NULL, FALSE, FALSE);
         
@@ -397,15 +392,15 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         
         $event = $this->_getEvent();
         $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['sclever']->getId()),
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['pwulf']->getId())
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('sclever')->getId()),
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('pwulf')->getId())
         ));
         $persistentEvent = $this->_controller->create($event);
         
         $conflictEvent = $this->_getEvent();
         $conflictEvent->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['sclever']->getId()),
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['pwulf']->getId())
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('sclever')->getId()),
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('pwulf')->getId())
         ));
         
         try {
@@ -432,8 +427,8 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         
         $conflictEvent = $this->_getEvent();
         $conflictEvent->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['sclever']->getId()),
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['pwulf']->getId())
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('sclever')->getId()),
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('pwulf')->getId())
         ));
         
         try {
@@ -457,8 +452,8 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $nonConflictEvent = $this->_getEvent();
         $nonConflictEvent->transp = Calendar_Model_Event::TRANSP_TRANSP;
         $nonConflictEvent->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['sclever']->getId()),
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['pwulf']->getId())
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('sclever')->getId()),
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('pwulf')->getId())
         ));
         
         $this->_controller->create($nonConflictEvent, TRUE);
@@ -473,8 +468,8 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         
         $nonConflictEvent = $this->_getEvent();
         $nonConflictEvent->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['sclever']->getId()),
-            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_personasContacts['pwulf']->getId())
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('sclever')->getId()),
+            array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('pwulf')->getId())
         ));
         
         $this->_controller->create($nonConflictEvent, TRUE);
@@ -670,10 +665,10 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         // assert test condition
         $pwulf = $persistentEvent->attendee
             ->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)
-            ->filter('user_id', $this->_personasContacts['pwulf']->getId());
+            ->filter('user_id', $this->_getPersonasContacts('pwulf')->getId());
         $this->assertEquals(0, count($pwulf), 'invalid test condition, pwulf should not be member or admin group');
         
-        Admin_Controller_Group::getInstance()->addGroupMember($defaultAdminGroup->getId(), $this->_personasContacts['pwulf']->account_id);
+        Admin_Controller_Group::getInstance()->addGroupMember($defaultAdminGroup->getId(), $this->_getPersonasContacts('pwulf')->account_id);
         if (isset(Tinebase_Core::getConfig()->actionqueue)) {
             Tinebase_ActionQueue::getInstance()->processQueue(10000);
         }
@@ -682,11 +677,11 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         // assert pwulf is in
         $pwulf = $loadedEvent->attendee
             ->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)
-            ->filter('user_id', $this->_personasContacts['pwulf']->getId());
+            ->filter('user_id', $this->_getPersonasContacts('pwulf')->getId());
         $this->assertEquals(1, count($pwulf), 'pwulf is not attender of event, but should be');
         
         
-        Admin_Controller_Group::getInstance()->removeGroupMember($defaultAdminGroup->getId(), $this->_personasContacts['pwulf']->account_id);
+        Admin_Controller_Group::getInstance()->removeGroupMember($defaultAdminGroup->getId(), $this->_getPersonasContacts('pwulf')->account_id);
         if (isset(Tinebase_Core::getConfig()->actionqueue)) {
             Tinebase_ActionQueue::getInstance()->processQueue(10000);
         }
@@ -695,12 +690,12 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         // assert pwulf is missing
         $pwulf = $loadedEvent->attendee
             ->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)
-            ->filter('user_id', $this->_personasContacts['pwulf']->getId());
+            ->filter('user_id', $this->_getPersonasContacts('pwulf')->getId());
         $this->assertEquals(0, count($pwulf), 'pwulf is attender of event, but not should be');
         
         // Test the same with update
         $group = Admin_Controller_Group::getInstance()->get($defaultAdminGroup->getId());
-        $group->members = array_merge(Admin_Controller_Group::getInstance()->getGroupMembers($defaultAdminGroup->getId()), array(array_value('pwulf', Zend_Registry::get('personas'))->getId()));
+        $group->members = array_merge(Admin_Controller_Group::getInstance()->getGroupMembers($defaultAdminGroup->getId()), array(Tinebase_Helper::array_value('pwulf', Zend_Registry::get('personas'))->getId()));
         Admin_Controller_Group::getInstance()->update($group);
         if (isset(Tinebase_Core::getConfig()->actionqueue)) {
             Tinebase_ActionQueue::getInstance()->processQueue(10000);
@@ -710,10 +705,10 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $loadedEvent = $this->_controller->get($persistentEvent->getId());
         $pwulf = $loadedEvent->attendee
             ->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)
-            ->filter('user_id', $this->_personasContacts['pwulf']->getId());
+            ->filter('user_id', $this->_getPersonasContacts('pwulf')->getId());
         $this->assertEquals(1, count($pwulf), 'pwulf is not attender of event, but should be (via update)');
         
-        $group->members = array_diff(Admin_Controller_Group::getInstance()->getGroupMembers($defaultAdminGroup->getId()), array(array_value('pwulf', Zend_Registry::get('personas'))->getId()));
+        $group->members = array_diff(Admin_Controller_Group::getInstance()->getGroupMembers($defaultAdminGroup->getId()), array(Tinebase_Helper::array_value('pwulf', Zend_Registry::get('personas'))->getId()));
         Admin_Controller_Group::getInstance()->update($group);
         if (isset(Tinebase_Core::getConfig()->actionqueue)) {
             Tinebase_ActionQueue::getInstance()->processQueue(10000);
@@ -722,7 +717,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $loadedEvent = $this->_controller->get($persistentEvent->getId());
         $pwulf = $loadedEvent->attendee
             ->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER)
-            ->filter('user_id', $this->_personasContacts['pwulf']->getId());
+            ->filter('user_id', $this->_getPersonasContacts('pwulf')->getId());
         $this->assertEquals(0, count($pwulf), 'pwulf is attender of event, but not should be');
     }
     
@@ -836,7 +831,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         }
         
         $events = $this->_backend->search(new Calendar_Model_EventFilter(array(
-            array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_testCalendars->getId()),
+            array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_getTestCalendars()->getId()),
         )), new Tinebase_Model_Pagination(array()));
         
         $oldSeries = $events->filter('rrule_until', '/.+/', TRUE)->getFirstRecord();
@@ -861,7 +856,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         }
         
         $events = $this->_backend->search(new Calendar_Model_EventFilter(array(
-            array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_testCalendars->getId()),
+            array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_getTestCalendars()->getId()),
         )), new Tinebase_Model_Pagination(array()));
         
         $newSeries = $events->filter('rrule_until', '/^$/', TRUE)->getFirstRecord();
@@ -940,7 +935,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
             'originator_tz' => 'Europe/Berlin',
             'rrule'         => 'FREQ=DAILY;INTERVAL=1;UNTIL=2009-04-02 21:59:59',
             'exdate'        => '2009-03-27 18:00:00,2009-03-31 17:00:00',
-            'container_id'  => $this->_testCalendar->getId(),
+            'container_id'  => $this->_getTestCalendar()->getId(),
             Tinebase_Model_Grants::GRANT_EDIT     => true,
         ));
         
@@ -1019,7 +1014,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         
         $this->_controller->delete($persistentEvent->getId());
         
-        $contentSeq = Tinebase_Container::getInstance()->getContentSequence($this->_testCalendar);
+        $contentSeq = Tinebase_Container::getInstance()->getContentSequence($this->_getTestCalendar());
         $this->assertEquals(3, $contentSeq, 'container content seq should be increased 3 times!');
         
         $this->setExpectedException('Tinebase_Exception_NotFound');
@@ -1277,7 +1272,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $persistentEvent = $this->testCreateEvent();
         
         $events = $this->_controller->search(new Calendar_Model_EventFilter(array(
-            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
+            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()),
             array('field' => 'period', 'operator' => 'within', 'value' => array(
                 'from'  => '2009-04-07',
                 'until' => '2010-04-07'
@@ -1303,7 +1298,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
             'dtend'       => '2009-04-06 13:30:00',
             'description' => 'Wieslaw Brudzinski: Das Gesetz garantiert zwar die Mittagspause, aber nicht das Mittagessen...',
         
-            'container_id' => $this->_testCalendar->getId(),
+            'container_id' => $this->_getTestCalendar()->getId(),
             Tinebase_Model_Grants::GRANT_EDIT    => true,
         ));
         
@@ -1368,7 +1363,7 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
             'dtend'       => '2014-04-06 19:00:00',
             'description' => 'Guten Appetit',
             
-            'container_id' => $this->_testCalendar->getId(),
+            'container_id' => $this->_getTestCalendar()->getId(),
             Tinebase_Model_Grants::GRANT_EDIT    => true,
             'customfields' => array('unittest' => 'Hello')
         ));