/framework/Kolab_Format/test/Horde/Kolab/Format/Integration/XmlTest.php

https://github.com/ewandor/horde · PHP · 140 lines · 101 code · 9 blank · 30 comment · 0 complexity · 644d399ebe5f8ac7394298881317b1a5 MD5 · raw file

  1. <?php
  2. /**
  3. * Test the XML format implementation.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Kolab
  8. * @package Kolab_Format
  9. * @subpackage UnitTests
  10. * @author Gunnar Wrobel <wrobel@pardus.de>
  11. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  12. * @link http://www.horde.org/libraries/Horde_Kolab_Format
  13. */
  14. /**
  15. * Prepare the test setup.
  16. */
  17. require_once dirname(__FILE__) . '/../Autoload.php';
  18. /**
  19. * Test the XML format.
  20. *
  21. * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
  22. *
  23. * See the enclosed file COPYING for license information (LGPL). If you
  24. * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  25. *
  26. * @category Kolab
  27. * @package Kolab_Format
  28. * @subpackage UnitTests
  29. * @author Gunnar Wrobel <wrobel@pardus.de>
  30. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  31. * @link http://www.horde.org/libraries/Horde_Kolab_Format
  32. */
  33. class Horde_Kolab_Format_Integration_XmlTest
  34. extends Horde_Kolab_Format_TestCase
  35. {
  36. public function testBasic()
  37. {
  38. $this->assertContains(
  39. '<?xml version="1.0" encoding="UTF-8"?>
  40. <kolab version="1.0">
  41. <body></body>
  42. <categories></categories>',
  43. $this->_getPlain()->save(array(), array('relaxed' => true))
  44. );
  45. }
  46. public function testReadable()
  47. {
  48. $xml = $this->_getPlain();
  49. $first = $xml->save(array(), array('relaxed' => true));
  50. $object = $xml->load($first, array('relaxed' => true));
  51. $this->assertEquals('1.0', $object['_format-version']);
  52. }
  53. public function testRoundtrip()
  54. {
  55. $xml = $this->_getPlain();
  56. $first = $xml->save(array(), array('relaxed' => true));
  57. $second = $xml->save(
  58. $xml->load($first, array('relaxed' => true)),
  59. array('relaxed' => true)
  60. );
  61. $this->assertEquals(
  62. $this->removeLastModification($first),
  63. $this->removeLastModification($second)
  64. );
  65. }
  66. public function testRoundtripWithPrevious()
  67. {
  68. $xml = $this->_getPlain();
  69. $first = $xml->save(array(), array('relaxed' => true));
  70. $second = $xml->save(
  71. $xml->load($first, array('relaxed' => true)),
  72. array('relaxed' => true, 'previous' => $first)
  73. );
  74. $this->assertEquals(
  75. $this->removeLastModification($first),
  76. $this->removeLastModification($second)
  77. );
  78. }
  79. public function testRoundtripWithPreviousOnApiV1()
  80. {
  81. $xml = new Horde_Kolab_Format_Xml(
  82. new Horde_Kolab_Format_Xml_Parser(
  83. new DOMDocument('1.0', 'UTF-8')
  84. ),
  85. new Horde_Kolab_Format_Factory(),
  86. array('version' => 1)
  87. );
  88. $first = $xml->save(array('uid' => 1));
  89. $second = $xml->save($xml->load($first));
  90. $this->assertEquals(
  91. $this->removeLastModification($first),
  92. $this->removeLastModification($second)
  93. );
  94. }
  95. public function testReload()
  96. {
  97. $xml = $this->_getPlain();
  98. $cdate = new DateTime('1970-01-01T00:00:00Z');
  99. $cdate->setTimezone(new DateTimeZone('UTC'));
  100. $result = $xml->save(
  101. array(
  102. 'uid'=>'test',
  103. 'body' => 'body',
  104. 'dummy' => 'hello',
  105. 'creation-date' => $cdate
  106. )
  107. );
  108. $object = $xml->load($result);
  109. $this->assertEquals('body', $object['body']);
  110. $this->assertTrue(!isset($object['dummy']));
  111. $this->assertEquals('public', $object['sensitivity']);
  112. $this->assertEquals($cdate, $object['creation-date']);
  113. $now = new DateTime('now', new DateTimeZone('UTC'));
  114. $this->assertTrue(
  115. $object['last-modification-date']->format('U') <= $now->format('U')
  116. );
  117. $this->assertEquals(
  118. 'Horde_Kolab_Format_Xml-@version@ (api version: 2)',
  119. $object['product-id']
  120. );
  121. }
  122. private function _getPlain()
  123. {
  124. return new Horde_Kolab_Format_Xml(
  125. new Horde_Kolab_Format_Xml_Parser(
  126. new DOMDocument('1.0', 'UTF-8')
  127. ),
  128. new Horde_Kolab_Format_Factory()
  129. );
  130. }
  131. }