/**
  * (non-PHPdoc)
  * @see ActiveSync/ActiveSync_TestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     $iphone = ActiveSync_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_IPHONE);
     $iphone->owner_id = $this->_testUser->getId();
     $this->objects['deviceIPhone'] = ActiveSync_Controller_Device::getInstance()->create($iphone);
 }
 /**
  * (non-PHPdoc)
  * @see ActiveSync/ActiveSync_TestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     // replace email to make current user organizer and attendee
     $this->_testXMLInput = str_replace('*****@*****.**', Tinebase_Core::getUser()->accountEmailAddress, $this->_testXMLInput);
     $event = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'summary' => 'SyncTest', 'dtstart' => Tinebase_DateTime::now()->addMonth(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'dtend' => Tinebase_DateTime::now()->addMonth(1)->addHour(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'originator_tz' => 'Europe/Berlin', 'container_id' => $this->_getContainerWithSyncGrant()->getId(), Tinebase_Model_Grants::GRANT_EDIT => true, 'attendee' => new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_id' => Tinebase_Core::getUser()->contact_id, 'user_type' => Calendar_Model_Attender::USERTYPE_USER, 'status' => Calendar_Model_Attender::STATUS_ACCEPTED)))));
     $event = Calendar_Controller_Event::getInstance()->create($event);
     $this->objects['event'] = $event;
     $event2MonthsBack = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'summary' => 'SyncTest', 'dtstart' => Tinebase_DateTime::now()->subMonth(2)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'dtend' => Tinebase_DateTime::now()->subMonth(2)->addHour(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'originator_tz' => 'Europe/Berlin', 'container_id' => $this->_getContainerWithSyncGrant()->getId(), Tinebase_Model_Grants::GRANT_EDIT => true));
     $event = Calendar_Controller_Event::getInstance()->create($event2MonthsBack);
     $this->objects['event2MonthsBack'] = $event;
     $eventDaily = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'summary' => 'SyncTest', 'dtstart' => Tinebase_DateTime::now()->addMonth(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'dtend' => Tinebase_DateTime::now()->addMonth(1)->addHour(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'originator_tz' => 'Europe/Berlin', 'rrule' => 'FREQ=DAILY;INTERVAL=1;UNTIL=' . Tinebase_DateTime::now()->addMonth(1)->addDay(6)->setHour(22)->setMinute(59)->setSecond(59)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'container_id' => $this->_getContainerWithSyncGrant()->getId(), Tinebase_Model_Grants::GRANT_EDIT => true));
     $eventDaily = Calendar_Controller_Event::getInstance()->create($eventDaily);
     // compute recurset
     $recurSet = Calendar_Model_Rrule::computeRecurrenceSet($eventDaily, new Tinebase_Record_RecordSet('Calendar_Model_Event'), $eventDaily->dtstart, $eventDaily->rrule_until);
     // first deleted instance
     Calendar_Controller_Event::getInstance()->createRecurException($recurSet[0], true);
     // second deleted instance
     Calendar_Controller_Event::getInstance()->createRecurException($recurSet[1], true);
     // first exception instance
     $recurSet[2]->dtstart->addHour(2);
     $recurSet[2]->dtend->addHour(2);
     $recurSet[2]->summary = 'Test Exception 1';
     Calendar_Controller_Event::getInstance()->createRecurException($recurSet[2]);
     // first exception instance
     $recurSet[3]->dtstart->addHour(3);
     $recurSet[3]->dtend->addHour(3);
     $recurSet[3]->summary = 'Test Exception 2';
     Calendar_Controller_Event::getInstance()->createRecurException($recurSet[3]);
     // reread event from database again
     $eventDaily = Calendar_Controller_Event::getInstance()->get($eventDaily);
     #var_dump($eventDaily->toArray());
     $this->objects['eventDaily'] = $eventDaily;
     Tinebase_Core::getPreference('ActiveSync')->setValue(ActiveSync_Preference::DEFAULTCALENDAR, $this->_getContainerWithSyncGrant()->getId());
     ########### define test filter
     $filterBackend = new Tinebase_PersistentFilter_Backend_Sql();
     try {
         $filter = $filterBackend->getByProperty('Calendar Sync Test', 'name');
     } catch (Tinebase_Exception_NotFound $e) {
         $filter = new Tinebase_Model_PersistentFilter(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'account_id' => Tinebase_Core::getUser()->getId(), 'model' => 'Calendar_Model_EventFilter', 'filters' => array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getContainerWithSyncGrant()->getId())), 'name' => 'Calendar Sync Test', 'description' => 'Created by unit test'));
         $filter = $filterBackend->create($filter);
     }
     $this->objects['filter'] = $filter;
     ########### define test devices
     $palm = ActiveSync_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_WEBOS);
     $palm->owner_id = $this->_testUser->getId();
     $palm->calendarfilter_id = $this->objects['filter']->getId();
     $this->objects['deviceWebOS'] = ActiveSync_Controller_Device::getInstance()->create($palm);
     $iphone = ActiveSync_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_IPHONE);
     $iphone->owner_id = $this->_testUser->getId();
     $iphone->calendarfilter_id = $this->objects['filter']->getId();
     $this->objects['deviceIPhone'] = ActiveSync_Controller_Device::getInstance()->create($iphone);
 }
 /**
  * (non-PHPdoc)
  * @see ActiveSync/ActiveSync_TestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     Syncroton_Registry::setDatabase(Tinebase_Core::getDb());
     Syncroton_Registry::setTransactionManager(Tinebase_TransactionManager::getInstance());
     Syncroton_Registry::set(Syncroton_Registry::DEVICEBACKEND, new Syncroton_Backend_Device(Tinebase_Core::getDb(), SQL_TABLE_PREFIX . 'acsync_'));
     Syncroton_Registry::set(Syncroton_Registry::FOLDERBACKEND, new Syncroton_Backend_Folder(Tinebase_Core::getDb(), SQL_TABLE_PREFIX . 'acsync_'));
     Syncroton_Registry::set(Syncroton_Registry::SYNCSTATEBACKEND, new Syncroton_Backend_SyncState(Tinebase_Core::getDb(), SQL_TABLE_PREFIX . 'acsync_'));
     Syncroton_Registry::set(Syncroton_Registry::CONTENTSTATEBACKEND, new Syncroton_Backend_Content(Tinebase_Core::getDb(), SQL_TABLE_PREFIX . 'acsync_'));
     Syncroton_Registry::set(Syncroton_Registry::POLICYBACKEND, new Syncroton_Backend_Policy(Tinebase_Core::getDb(), SQL_TABLE_PREFIX . 'acsync_'));
     Syncroton_Registry::set('loggerBackend', Tinebase_Core::getLogger());
     Syncroton_Registry::setContactsDataClass('Addressbook_Frontend_ActiveSync');
     Syncroton_Registry::setCalendarDataClass('Calendar_Frontend_ActiveSync');
     Syncroton_Registry::setEmailDataClass('Felamimail_Frontend_ActiveSync');
     Syncroton_Registry::setTasksDataClass('Tasks_Frontend_ActiveSync');
     $this->_device = Syncroton_Registry::getDeviceBackend()->create(ActiveSync_TestCase::getTestDevice());
 }
    /**
     * testAddAlarm
     * 
     * @see 0008230: added alarm to event on iOS 6.1 -> description removed
     */
    public function testAddAlarm()
    {
        $syncrotonFolder = $this->testCreateFolder();
        $event = ActiveSync_TestCase::getTestEvent();
        $event->summary = 'testtermin';
        $event->description = 'some text';
        $event->dtstart = new Tinebase_DateTime('2013-10-22 16:00:00');
        $event->dtend = new Tinebase_DateTime('2013-10-22 17:00:00');
        $event = Calendar_Controller_Event::getInstance()->create($event);
        $xml = new SimpleXMLElement('
          <ApplicationData>
            <Timezone xmlns="uri:Calendar">xP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAFAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAMAAAAAAAAAxP///w==</Timezone>
            <AllDayEvent xmlns="uri:Calendar">0</AllDayEvent>
            <BusyStatus xmlns="uri:Calendar">2</BusyStatus>
            <DtStamp xmlns="uri:Calendar">20131021T142015Z</DtStamp>
            <EndTime xmlns="uri:Calendar">20131022T170000Z</EndTime>
            <Reminder xmlns="uri:Calendar">60</Reminder>
            <Sensitivity xmlns="uri:Calendar">0</Sensitivity>
            <Subject xmlns="uri:Calendar">testtermin</Subject>
            <StartTime xmlns="uri:Calendar">20131022T160000Z</StartTime>
            <UID xmlns="uri:Calendar">' . $event->uid . '</UID>
            <MeetingStatus xmlns="uri:Calendar">1</MeetingStatus>
            <Attendees xmlns="uri:Calendar">
              <Attendee>
                <Name>' . Tinebase_Core::getUser()->accountDisplayName . '</Name>
                <Email>' . Tinebase_Core::getUser()->accountEmailAddress . '</Email>
                <AttendeeType>1</AttendeeType>
              </Attendee>
            </Attendees>
          </ApplicationData>
        ');
        $syncrotonEvent = new Syncroton_Model_Event($xml);
        $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), $event->creation_time);
        $serverId = $controller->updateEntry($syncrotonFolder->serverId, $event->getId(), $syncrotonEvent);
        $updatedEvent = Calendar_Controller_Event::getInstance()->get($serverId);
        $this->assertEquals(1, count($updatedEvent->alarms));
        $this->assertEquals($event->description, $updatedEvent->description, 'description mismatch: ' . print_r($updatedEvent->toArray(), true));
    }
 /**
  * test sync of existing events folder
  */
 public function testPingForEvents()
 {
     $personalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Tinebase_Core::getUser(), 'Calendar', Tinebase_Core::getUser(), Tinebase_Model_Grants::GRANT_EDIT)->getFirstRecord();
     // first do a foldersync
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <FolderSync xmlns="uri:FolderHierarchy"><SyncKey>0</SyncKey></FolderSync>');
     $folderSync = new Syncroton_Command_FolderSync($doc, $this->_device, $this->_device->policykey);
     $folderSync->handle();
     $folderSync->getResponse();
     // request initial synckey
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections><Collection><Class>Calendar</Class><SyncKey>0</SyncKey><CollectionId>' . $personalContainer->getId() . '</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize><Options><FilterType>4</FilterType><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options></Collection></Collections></Sync>');
     $sync = new Syncroton_Command_Sync($doc, $this->_device, $this->_device->policykey);
     $sync->handle();
     $syncDoc = $sync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     // now do the first sync
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections><Collection><Class>Calendar</Class><SyncKey>1</SyncKey><CollectionId>' . $personalContainer->getId() . '</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize><Options><FilterType>4</FilterType><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options></Collection></Collections></Sync>');
     $sync = new Syncroton_Command_Sync($doc, $this->_device, $this->_device->policykey);
     $sync->handle();
     $syncDoc = $sync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     sleep(1);
     // add a test event
     $event = ActiveSync_TestCase::getTestEvent($personalContainer);
     $event = Calendar_Controller_Event::getInstance()->create($event);
     // and now we can start the ping request
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Ping xmlns="uri:Ping"><HeartBeatInterval>10</HeartBeatInterval><Folders><Folder><Id>' . $personalContainer->getId() . '</Id><Class>Calendar</Class></Folder></Folders></Ping>');
     $ping = new Syncroton_Command_Ping($doc, $this->_device, null);
     $ping->handle();
     $responseDoc = $ping->getResponse();
     #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('Ping', 'uri:Ping');
     $nodes = $xpath->query('//Ping:Ping/Ping:Status');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertEquals(Syncroton_Command_Ping::STATUS_CHANGES_FOUND, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//Ping:Ping/Ping:Folders/Ping:Folder');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertEquals($personalContainer->getId(), $nodes->item(0)->nodeValue, $responseDoc->saveXML());
 }
 /**
  * return active device
  * 
  * @param string $_deviceType
  * @return ActiveSync_Model_Device
  */
 protected function _getDevice($_deviceType)
 {
     if (!isset($this->objects['devices'][$_deviceType])) {
         $this->objects['devices'][$_deviceType] = Syncroton_Registry::getDeviceBackend()->create(ActiveSync_TestCase::getTestDevice($_deviceType));
     }
     return $this->objects['devices'][$_deviceType];
 }
 /**
  * lazy init of uit
  *
  * @return ActiveSync_Frontend_Json
  *
  * @todo fix ide object class detection for completions
  */
 protected function _getUit()
 {
     return parent::_getUit();
 }