/**
  * test xml generation for IPhone
  *
  * birthday must have 12 hours added
  */
 public function testAppendXmlData()
 {
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
     $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
     $testDoc->formatOutput = true;
     $testDoc->encoding = 'utf-8';
     $appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
     $email = new Syncroton_Model_FileReference(array('contentType' => 'text/plain', 'data' => 'Lars'));
     $email->appendXML($appData, $this->_testDevice);
     #echo $testDoc->saveXML();
     $xpath = new DomXPath($testDoc);
     $xpath->registerNamespace('AirSync', 'uri:AirSync');
     $xpath->registerNamespace('AirSyncBase', 'uri:AirSyncBase');
     $xpath->registerNamespace('Email', 'uri:Email');
     $xpath->registerNamespace('Email2', 'uri:Email2');
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:ContentType');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('text/plain', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/ItemOperations:Data');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('TGFycw==', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     // try to encode XML until we have wbxml tests
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
 }
Пример #2
0
 /**
  *
  */
 public function testEncode()
 {
     $testDoc = new DOMDocument();
     $testDoc->loadXML($this->_xmlContactBirthdayWithoutTimeAndroid);
     $testDoc->formatOutput = true;
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
     $this->assertEquals(183, ftell($outputStream));
 }
Пример #3
0
 /**
  * test xml generation for IPhone
  *
  * birthday must have 12 hours added
  */
 public function testAppendXmlData()
 {
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
     $testDoc = $imp->createDocument('uri:Provision', 'Provision', $dtd);
     $testDoc->formatOutput = true;
     $testDoc->encoding = 'utf-8';
     $provDoc = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:Provision', 'EASProvisionDoc'));
     $provData = new Syncroton_Model_Policy(array('id' => 'skdjhfkjsfd', 'devicePasswordEnabled' => 1));
     $provData->appendXML($provDoc, $this->_testDevice);
     #echo $testDoc->saveXML();
     $xpath = new DomXPath($testDoc);
     $xpath->registerNamespace('Provision', 'uri:Provision');
     $nodes = $xpath->query('//Provision:Provision/Provision:EASProvisionDoc/Provision:DevicePasswordEnabled');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('1', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     // try to encode XML until we have wbxml tests
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
 }
Пример #4
0
    /**
     * test reponse with synckey 0
     */
    public function testGetFoldersSyncKey0()
    {
        $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, null);
        $folderSync->handle();
        $responseDoc = $folderSync->getResponse();
        //$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); die;
        $xpath = new DomXPath($responseDoc);
        $xpath->registerNamespace('FolderHierarchy', 'uri:FolderHierarchy');
        $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:Status');
        $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
        $this->assertEquals(Syncroton_Command_FolderSync::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
        $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:SyncKey');
        $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
        $this->assertEquals(1, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
        $nodes = $xpath->query('//FolderHierarchy:FolderSync/FolderHierarchy:Changes/FolderHierarchy:Add');
        $this->assertGreaterThanOrEqual(1, $nodes->length, $responseDoc->saveXML());
        $outputStream = fopen("php://temp", 'r+');
        $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
        $encoder->encode($responseDoc);
    }
Пример #5
0
 /**
  * handle post request
  */
 protected function _handlePost()
 {
     $requestParameters = $this->_getRequestParameters($this->_request);
     if ($this->_logger instanceof Syncroton_Log) {
         $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' REQUEST ' . print_r($requestParameters, true));
     }
     $className = 'Syncroton_Command_' . $requestParameters['command'];
     if (!class_exists($className)) {
         if ($this->_logger instanceof Syncroton_Log) {
             $this->_logger->critical(__METHOD__ . '::' . __LINE__ . " command not supported: " . $requestParameters['command']);
         }
         header("HTTP/1.1 501 not implemented");
         return;
     }
     // get user device
     $device = $this->_getUserDevice($this->_userId, $requestParameters);
     if ($requestParameters['contentType'] == 'application/vnd.ms-sync.wbxml' || $requestParameters['contentType'] == 'application/vnd.ms-sync') {
         // decode wbxml request
         try {
             $decoder = new Syncroton_Wbxml_Decoder($this->_body);
             $requestBody = $decoder->decode();
             if ($this->_logger instanceof Syncroton_Log) {
                 $requestBody->formatOutput = true;
                 $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " xml request:\n" . $requestBody->saveXML());
             }
         } catch (Syncroton_Wbxml_Exception_UnexpectedEndOfFile $e) {
             $requestBody = NULL;
         }
     } else {
         $requestBody = $this->_body;
     }
     header("MS-Server-ActiveSync: 14.00.0536.000");
     // avoid sending HTTP header "Content-Type: text/html" for empty sync responses
     ini_set('default_mimetype', 'application/vnd.ms-sync.wbxml');
     try {
         $command = new $className($requestBody, $device, $requestParameters);
         $command->handle();
         $response = $command->getResponse();
     } catch (Syncroton_Exception_ProvisioningNeeded $sepn) {
         if ($this->_logger instanceof Syncroton_Log) {
             $this->_logger->info(__METHOD__ . '::' . __LINE__ . " provisioning needed");
         }
         header("HTTP/1.1 449 Retry after sending a PROVISION command");
         if (version_compare($device->acsversion, '14.0', '>=')) {
             $response = $sepn->domDocument;
         } else {
             // pre 14.0 method
             return;
         }
     } catch (Exception $e) {
         if ($this->_logger instanceof Syncroton_Log) {
             $this->_logger->critical(__METHOD__ . '::' . __LINE__ . " unexpected exception occured: " . get_class($e));
         }
         if ($this->_logger instanceof Syncroton_Log) {
             $this->_logger->critical(__METHOD__ . '::' . __LINE__ . " exception message: " . $e->getMessage());
         }
         if ($this->_logger instanceof Syncroton_Log) {
             $this->_logger->critical(__METHOD__ . '::' . __LINE__ . " " . $e->getTraceAsString());
         }
         header("HTTP/1.1 500 Internal server error");
         return;
     }
     if ($response instanceof DOMDocument) {
         if ($this->_logger instanceof Syncroton_Log) {
             $this->_logDomDocument('debug', $response, __METHOD__, __LINE__);
         }
         if (isset($command) && $command instanceof Syncroton_Command_ICommand) {
             $this->_sendHeaders($command->getHeaders());
         }
         $outputStream = fopen("php://temp", 'r+');
         $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
         try {
             $encoder->encode($response);
         } catch (Syncroton_Wbxml_Exception $swe) {
             if ($this->_logger instanceof Syncroton_Log) {
                 $this->_logger->err(__METHOD__ . '::' . __LINE__ . " Could not encode output: " . $swe);
                 $this->_logDomDocument('error', $response, __METHOD__, __LINE__);
             }
             header("HTTP/1.1 500 Internal server error");
             return;
         }
         if ($requestParameters['acceptMultipart'] == true) {
             $parts = $command->getParts();
             // output multipartheader
             $bodyPartCount = 1 + count($parts);
             // number of parts (4 bytes)
             $header = pack('i', $bodyPartCount);
             $partOffset = 4 + $bodyPartCount * 2 * 4;
             // wbxml body start and length
             $streamStat = fstat($outputStream);
             $header .= pack('ii', $partOffset, $streamStat['size']);
             $partOffset += $streamStat['size'];
             // calculate start and length of parts
             foreach ($parts as $partId => $partStream) {
                 rewind($partStream);
                 $streamStat = fstat($partStream);
                 // part start and length
                 $header .= pack('ii', $partOffset, $streamStat['size']);
                 $partOffset += $streamStat['size'];
             }
             echo $header;
         }
         // output body
         rewind($outputStream);
         fpassthru($outputStream);
         // output multiparts
         if (isset($parts)) {
             foreach ($parts as $partStream) {
                 rewind($partStream);
                 fpassthru($partStream);
             }
         }
     }
 }
Пример #6
0
 /**
  * test xml generation for IPhone
  *
  * birthday must have 12 hours added
  */
 public function testAppendXmlData()
 {
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
     $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
     $testDoc->formatOutput = true;
     $testDoc->encoding = 'utf-8';
     $appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
     $xml = new SimpleXMLElement($this->_testXMLInput);
     $event = new Syncroton_Model_Task($xml->Collections->Collection->Commands->Change->ApplicationData);
     $event->appendXML($appData, $this->_testDevice);
     #echo $testDoc->saveXML();
     $xpath = new DomXPath($testDoc);
     $xpath->registerNamespace('AirSync', 'uri:AirSync');
     $xpath->registerNamespace('Tasks', 'uri:Tasks');
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Tasks:Subject');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('Testaufgabe auf mfe', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Tasks:Complete');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('0', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Tasks:DueDate');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('2010-11-28T23:59:00.000Z', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Tasks:Recurrence/Tasks:Type');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals(Syncroton_Model_TaskRecurrence::TYPE_WEEKLY, $nodes->item(0)->nodeValue, $testDoc->saveXML());
     // try to encode XML until we have wbxml tests
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
 }
Пример #7
0
 /**
  * test xml generation for Android
  */
 public function testAppendXmlDataAS120()
 {
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
     $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
     $testDoc->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:Syncroton', 'uri:Syncroton');
     $testDoc->formatOutput = true;
     $testDoc->encoding = 'utf-8';
     $appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
     $email = new Syncroton_Model_Email(array('accountId' => 'FooBar', 'attachments' => array(new Syncroton_Model_EmailAttachment(array('displayName' => 'example.pdf', 'fileReference' => '12345abcd', 'umAttOrder' => 1))), 'categories' => array('123', '456'), 'cc' => '*****@*****.**', 'dateReceived' => new DateTime('2012-03-21 14:00:00', new DateTimeZone('UTC')), 'flag' => new Syncroton_Model_EmailFlag(array('status' => Syncroton_Model_EmailFlag::STATUS_COMPLETE, 'reminderTime' => new DateTime('2012-04-21 14:00:00', new DateTimeZone('UTC')))), 'from' => '*****@*****.**', 'subject' => 'Test Subject', 'to' => '*****@*****.**', 'read' => 1, 'body' => new Syncroton_Model_EmailBody(array('type' => Syncroton_Model_EmailBody::TYPE_HTML, 'data' => 'Hallo <br>', 'estimatedDataSize' => 1234, 'truncated' => 1)), 'conversationId' => 'abcd'));
     $this->_testDevice->acsversion = '12.0';
     $email->appendXML($appData, $this->_testDevice);
     #echo $testDoc->saveXML();
     $xpath = new DomXPath($testDoc);
     $xpath->registerNamespace('AirSync', 'uri:AirSync');
     $xpath->registerNamespace('AirSyncBase', 'uri:AirSyncBase');
     $xpath->registerNamespace('Email', 'uri:Email');
     $xpath->registerNamespace('Email2', 'uri:Email2');
     $xpath->registerNamespace('Tasks', 'uri:Tasks');
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Email2:AccountId');
     $this->assertEquals(0, $nodes->length, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Email:DateReceived');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('2012-03-21T14:00:00.000Z', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:Attachments/AirSyncBase:Attachment/AirSyncBase:FileReference');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('12345abcd', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:Attachments/AirSyncBase:Attachment/Email2:UmAttOrder');
     $this->assertEquals(0, $nodes->length, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:Body/AirSyncBase:Type');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals(Syncroton_Model_EmailBody::TYPE_HTML, $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Email2:ConversationId');
     $this->assertEquals(0, $nodes->length, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Email:Flag/Tasks:ReminderTime');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('2012-04-21T14:00:00.000Z', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     // try to encode XML until we have wbxml tests
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
 }
Пример #8
0
 /**
  * test xml generation for IPhone
  *
  * birthday must have 12 hours added
  */
 public function testAppendXmlData()
 {
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
     $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
     $testDoc->formatOutput = true;
     $testDoc->encoding = 'utf-8';
     $appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
     $xml = new SimpleXMLElement($this->_testXMLInput);
     $event = new Syncroton_Model_Event($xml->Collections->Collection->Commands->Change->ApplicationData);
     $event->body = new Syncroton_Model_EmailBody(array('data' => 'lars', 'type' => Syncroton_Model_EmailBody::TYPE_PLAINTEXT));
     $event->appendXML($appData, $this->_testDevice);
     #echo $testDoc->saveXML();
     $xpath = new DomXPath($testDoc);
     $xpath->registerNamespace('AirSync', 'uri:AirSync');
     $xpath->registerNamespace('AirSyncBase', 'uri:AirSyncBase');
     $xpath->registerNamespace('Calendar', 'uri:Calendar');
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Calendar:Subject');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('Repeat', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Calendar:Recurrence/Calendar:Until');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('20101128T225959Z', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Calendar:Exceptions/Calendar:Exception/Calendar:ExceptionStartTime');
     $this->assertEquals(2, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('20101125T130000Z', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Calendar:Exceptions/Calendar:Exception/Calendar:AllDayEvent');
     $this->assertEquals(0, $nodes->length, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Calendar:Exceptions/Calendar:Exception/Calendar:BusyStatus');
     $this->assertEquals(0, $nodes->length, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:Body');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     // try to encode XML until we have wbxml tests
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
 }
 /**
  * try to encode XML until we have wbxml tests
  *
  * @param $testDoc
  * @return string returns encoded/decoded xml string
  */
 public static function encodeXml($testDoc)
 {
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
     rewind($outputStream);
     $decoder = new Syncroton_Wbxml_Decoder($outputStream);
     $xml = $decoder->decode();
     return $xml->saveXML();
 }
Пример #10
0
 /**
  * test xml generation for IPhone
  *
  * birthday must have 12 hours added
  */
 public function testAppendXmlIPhone()
 {
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
     $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
     $testDoc->formatOutput = true;
     $testDoc->encoding = 'utf-8';
     $testDoc->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:Contacts', 'uri:Contacts');
     $collections = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'Collections'));
     $collection = $collections->appendChild($testDoc->createElementNS('uri:AirSync', 'Collection'));
     $commands = $collection->appendChild($testDoc->createElementNS('uri:AirSync', 'Commands'));
     $add = $commands->appendChild($testDoc->createElementNS('uri:AirSync', 'Add'));
     $applicationData = $add->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
     try {
         $device = Syncroton_Registry::getDeviceBackend()->getUserDevice('1234', 'iphone-abcd');
         Syncroton_Registry::getDeviceBackend()->delete($device);
     } catch (Syncroton_Exception_NotFound $e) {
         // do nothing => it's ok
     }
     require_once dirname(dirname(__FILE__)) . DS . 'Backend' . DS . 'DeviceTest.php';
     $device = Syncroton_Registry::getDeviceBackend()->create(DeviceTest::getTestDevice(Syncroton_Model_Device::TYPE_IPHONE));
     $dataController = Syncroton_Data_Factory::factory(Syncroton_Data_Factory::CLASS_CONTACTS, $device, new DateTime(null, new DateTimeZone('UTC')));
     $collection = new Syncroton_Model_SyncCollection();
     $collection->collectionId = 'addressbookFolderId';
     $allEntries = $dataController->getServerEntries('addressbookFolderId', null);
     $dataController->getEntry($collection, $allEntries[0])->appendXML($applicationData, $device);
     // no offset and namespace === uri:Contacts
     #$this->assertEquals('1975-01-02T03:00:00.000Z', @$testDoc->getElementsByTagNameNS('uri:Contacts', 'Birthday')->item(0)->nodeValue, $testDoc->saveXML());
     #echo $testDoc->saveXML();
     // try to encode XML until we have wbxml tests
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
     #rewind($outputStream);
     #fpassthru($outputStream);
 }
Пример #11
0
 /**
  * test xml generation for IPhone
  *
  * birthday must have 12 hours added
  */
 public function testAppendXmlData()
 {
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
     $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
     $testDoc->formatOutput = true;
     $testDoc->encoding = 'utf-8';
     $appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
     $xml = new SimpleXMLElement($this->_xmlContactBirthdayWithoutTimeAndroid);
     $contact = new Syncroton_Model_Contact($xml->Collections->Collection->Commands->Add->ApplicationData);
     $contact->picture = fopen(__DIR__ . '/../../files/test_image.jpeg', 'r');
     $contact->appendXML($appData, $this->_testDevice);
     #echo $testDoc->saveXML();
     $xpath = new DomXPath($testDoc);
     $xpath->registerNamespace('AirSync', 'uri:AirSync');
     $xpath->registerNamespace('Contacts', 'uri:Contacts');
     $xpath->registerNamespace('Contacts2', 'uri:Contacts2');
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Contacts:FirstName');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('Fritzchen', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Contacts2:ManagerName');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('The Boss', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/Contacts:Children/Contacts:Child');
     $this->assertEquals(2, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('1234', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:Body/AirSyncBase:Type');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals(Syncroton_Model_EmailBody::TYPE_PLAINTEXT, $nodes->item(0)->nodeValue, $testDoc->saveXML());
     // try to encode XML until we have wbxml tests
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
 }
 /**
  * test create contact
  */
 public function testCreateContact()
 {
     $personalContainer = $this->_getPersonalContainer('Addressbook');
     $this->testSyncOfContacts();
     // lets add one contact
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     $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:Contacts="uri:Contacts" xmlns:AirSyncBase="uri:AirSyncBase"><Collections>
             <Collection>
                 <Class>Contacts</Class><SyncKey>2</SyncKey><CollectionId>' . $personalContainer->getId() . '</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize>
                 <Options><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options>
                 <Commands><Add><ClientId>42</ClientId><ApplicationData><Contacts:FirstName>aaaadde</Contacts:FirstName><Contacts:LastName>aaaaade</Contacts:LastName></ApplicationData></Add></Commands>
             </Collection>
         </Collections></Sync>');
     // decode to wbxml and back again to test the wbxml en-/decoder
     $xmlStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($xmlStream, 'UTF-8', 3);
     $encoder->encode($doc);
     rewind($xmlStream);
     $decoder = new Syncroton_Wbxml_Decoder($xmlStream);
     $doc = $decoder->decode();
     #$doc->formatOutput = true; echo $doc->saveXML();
     $sync = new Syncroton_Command_Sync($doc, $this->_device, $this->_device->policykey);
     $sync->handle();
     $syncDoc = $sync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     $xpath = new DomXPath($syncDoc);
     $xpath->registerNamespace('AirSync', 'uri:AirSync');
     $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:Class');
     $this->assertEquals(1, $nodes->length, 'one contact should be in here: ' . $syncDoc->saveXML());
     $this->assertEquals('Contacts', $nodes->item(0)->nodeValue, $syncDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:SyncKey');
     $this->assertEquals(1, $nodes->length, $syncDoc->saveXML());
     $this->assertEquals(3, $nodes->item(0)->nodeValue, $syncDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:Status');
     $this->assertEquals(1, $nodes->length, $syncDoc->saveXML());
     $this->assertEquals(Syncroton_Command_Sync::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $syncDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:Responses/AirSync:Add/AirSync:ServerId');
     $this->assertEquals(1, $nodes->length, $syncDoc->saveXML());
     $this->assertFalse(empty($nodes->item(0)->nodeValue), $syncDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:Responses/AirSync:Add/AirSync:Status');
     $this->assertEquals(1, $nodes->length, $syncDoc->saveXML());
     $this->assertEquals(Syncroton_Command_Sync::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $syncDoc->saveXML());
 }