public function testStore() { $driver = new Horde_Kolab_Storage_Stub_Driver('user'); $driver->setMessage('INBOX', 1, file_get_contents(__DIR__ . '/../../../../fixtures/note.eml')); $factory = new Horde_Kolab_Format_Factory(); $writer = new Horde_Kolab_Storage_Object_Writer_Format($factory); $object = new Horde_Kolab_Storage_Object(); $object->setDriver($driver); $folder = $this->getMock('Horde_Kolab_Storage_Folder'); $folder->expects($this->once())->method('getPath')->will($this->returnValue('INBOX')); $folder->expects($this->once())->method('getType')->will($this->returnValue('note')); $structure = $driver->fetchComplete('INBOX', 1); $object->load(1, $folder, $writer, $structure[1]); $object->setData(array('summary' => 'NEW', 'description' => 'test', 'uid' => 'ABC1234')); $object->save($writer); $result = $driver->messages['INBOX'][2]; $result = preg_replace(array('/=20/', '/Date: .*/', '/boundary=".*"/', '/--=_.*/', '/<creation-date>[^<]*/', '/<last-modification-date>[^<]*/', '/\\r\\n/', '/=\\n/'), array(' ', 'Date: ', 'boundary=""', '--=_', '<creation-date>', '<last-modification-date>', "\n", ''), $result); $this->assertEquals('From: user To: user Date: Subject: ABC1234 User-Agent: Horde::Kolab::Storage v@version@ MIME-Version: 1.0 X-Kolab-Type: application/x-vnd.kolab.note Content-Type: multipart/mixed; boundary=""; name="Kolab Groupware Data" Content-Disposition: attachment; filename="Kolab Groupware Data" This message is in MIME format. --=_ Content-Type: text/plain; charset=utf-8; name="Kolab Groupware Information" Content-Disposition: inline; filename="Kolab Groupware Information" This is a Kolab Groupware object. To view this object you will need an email client that understands the Kolab Groupware format. For a list of such email clients please visit http://www.kolab.org/content/kolab-clients --=_ Content-Type: application/x-vnd.kolab.note; name=kolab.xml Content-Disposition: inline; x-kolab-type=xml; filename=kolab.xml <?xml version="1.0" encoding="UTF-8"?> <note version="1.0"> <uid>ABC1234</uid> <body/> <categories/> <creation-date></creation-date> <last-modification-date></last-modification-date> <sensitivity>public</sensitivity> <product-id>Horde_Kolab_Format_Xml-@version@ (api version: 2)</product-id> <summary>NEW</summary> <x-test>other client</x-test> <background-color>#000000</background-color> <foreground-color>#ffff00</foreground-color> </note> --=_ ', $result); }
public function testStore() { if (version_compare(PHP_VERSION, '5.5.0', '>=') && version_compare(PHP_VERSION, '5.5.3', '<=')) { $this->markTestSkipped('PHP version with broken quoted-printable-encode'); } setlocale(LC_MESSAGES, 'C'); $factory = new Horde_Kolab_Format_Factory(); $writer = new Horde_Kolab_Storage_Object_Writer_Format($factory); $folder = $this->getMock('Horde_Kolab_Storage_Folder'); $folder->expects($this->once())->method('getPath')->will($this->returnValue('INBOX')); $driver = new Horde_Kolab_Storage_Stub_Driver('user'); $object = new Horde_Kolab_Storage_Object(); $object->setDriver($driver); $object->setData(array('summary' => 'TEST', 'description' => 'test', 'uid' => 'ABC1234')); $object->create($folder, $writer, 'note'); $result = $driver->messages['INBOX'][0]; $result = preg_replace(array('/=20/', '/Date: .*/', '/boundary=".*"/', '/--=_.*/', '/<creation-date>[^<]*/', '/<last-modification-date>[^<]*/', '/\\r\\n/', '/=\\n/'), array(' ', 'Date: ', 'boundary=""', '--=_', '<creation-date>', '<last-modification-date>', "\n", ''), $result); $this->assertEquals('From: user To: user Date: Subject: ABC1234 User-Agent: Horde_Kolab_Storage @version@ MIME-Version: 1.0 X-Kolab-Type: application/x-vnd.kolab.note Content-Type: multipart/mixed; name="Kolab Groupware Data"; boundary="" Content-Disposition: attachment; filename="Kolab Groupware Data" This message is in MIME format. --=_ Content-Type: text/plain; name="Kolab Groupware Information"; charset=utf-8 Content-Disposition: inline; filename="Kolab Groupware Information" This is a Kolab Groupware object. To view this object you will need an email client that understands the Kolab Groupware format. For a list of such email clients please visit http://www.kolab.org/content/kolab-clients --=_ Content-Type: application/x-vnd.kolab.note; name=kolab.xml Content-Disposition: inline; x-kolab-type=xml; filename=kolab.xml Content-Transfer-Encoding: quoted-printable <?xml version=3D"1.0" encoding=3D"UTF-8"?> <note version=3D"1.0"> <uid>ABC1234</uid> <body></body> <categories></categories> <creation-date></creation-date> <last-modification-date></last-modification-date> <sensitivity>public</sensitivity> <product-id>Horde_Kolab_Format_Xml-@version@ (api version: 2)</product-id> <summary>TEST</summary> <background-color>#000000</background-color> <foreground-color>#ffff00</foreground-color> </note> --=_ ', $result); }
/** * Return the object data in a form that it can be stored in the backend. * * @param Horde_Kolab_Storage_Object $object The object that should receive the parsed data. * * @return string The encoded object data, ready to be written into the * backend. */ public function save(Horde_Kolab_Storage_Object $object) { try { return $this->_getParser($object->getType())->save($object->getData(), array('previous' => $object->getCurrentContent())); } catch (Horde_Kolab_Format_Exception $e) { throw new Horde_Kolab_Storage_Object_Exception(sprintf('Failed writing the Kolab object: %s', $e->getMessage())); } }
public function testAutomaticUid() { $object = new Horde_Kolab_Storage_Object(); $object->setData(array()); $this->assertEquals(array('uid'), array_keys($object->getData())); }
/** * Retrieves the objects for the given UIDs. * * @param array $uids The message UIDs. * @param boolean $raw True if the raw format should be returned rather than * the parsed data. * * @return array An array of objects. * @throws new Horde_Kolab_Storage_Exception */ public function fetch($uids, $raw = false) { if (empty($uids)) { return array(); } if ($raw === false) { $writer = new Horde_Kolab_Storage_Object_Writer_Format(new Horde_Kolab_Format_Factory(), array('version' => $this->_version)); } else { $writer = new Horde_Kolab_Storage_Object_Writer_Raw(); } $objects = array(); $structures = $this->_driver->fetchStructure($this->_folder->getPath(), $uids); foreach ($structures as $uid => $structure) { if (!isset($structure['structure'])) { throw new Horde_Kolab_Storage_Exception('Backend returned a structure without the expected "structure" element.'); } $object = new Horde_Kolab_Storage_Object(); $object->setDriver($this->_driver); $object->load($uid, $this->_folder, $writer, $structure['structure']); $objects[$uid] = $object; } return $objects; }
/** * Return the object data in a form that it can be stored in the backend. * * @param Horde_Kolab_Storage_Object $object The object that should receive the parsed data. * * @return resource The encoded object data, ready to be written into the * backend. */ public function save(Horde_Kolab_Storage_Object $object) { return $object->getContent(); }