RecurrenceExceptionTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com);
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'Zend/Gdata/Extension/RecurrenceException.php';
  22. require_once 'Zend/Gdata.php';
  23. /**
  24. * @package Zend_Gdata
  25. * @subpackage UnitTests
  26. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Gdata_RecurrenceExceptionTest extends PHPUnit_Framework_TestCase
  30. {
  31. public function setUp() {
  32. $this->recurrenceExceptionText = file_get_contents(
  33. 'Zend/Gdata/_files/RecurrenceExceptionElementSample1.xml',
  34. true);
  35. $this->recurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  36. }
  37. public function testEmptyRecurrenceExceptionShouldHaveNoExtensionElements() {
  38. $this->assertTrue(is_array($this->recurrenceException->extensionElements));
  39. $this->assertTrue(count($this->recurrenceException->extensionElements) == 0);
  40. }
  41. public function testEmptyRecurrenceExceptionShouldHaveNoExtensionAttributes() {
  42. $this->assertTrue(is_array($this->recurrenceException->extensionAttributes));
  43. $this->assertTrue(count($this->recurrenceException->extensionAttributes) == 0);
  44. }
  45. public function testSampleRecurrenceExceptionShouldHaveNoExtensionElements() {
  46. $this->recurrenceException->transferFromXML($this->recurrenceExceptionText);
  47. $this->assertTrue(is_array($this->recurrenceException->extensionElements));
  48. $this->assertTrue(count($this->recurrenceException->extensionElements) == 0);
  49. }
  50. public function testSampleRecurrenceExceptionShouldHaveNoExtensionAttributes() {
  51. $this->recurrenceException->transferFromXML($this->recurrenceExceptionText);
  52. $this->assertTrue(is_array($this->recurrenceException->extensionAttributes));
  53. $this->assertTrue(count($this->recurrenceException->extensionAttributes) == 0);
  54. }
  55. public function testNormalRecurrenceExceptionShouldHaveNoExtensionElements() {
  56. $this->recurrenceException->specialized = "false";
  57. $this->assertEquals("false", $this->recurrenceException->specialized);
  58. $this->assertEquals(0, count($this->recurrenceException->extensionElements));
  59. $newRecurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  60. $newRecurrenceException->transferFromXML($this->recurrenceException->saveXML());
  61. $this->assertEquals(0, count($newRecurrenceException->extensionElements));
  62. $newRecurrenceException->extensionElements = array(
  63. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  64. $this->assertEquals(1, count($newRecurrenceException->extensionElements));
  65. $this->assertEquals("false", $newRecurrenceException->specialized);
  66. /* try constructing using magic factory */
  67. $gdata = new Zend_Gdata();
  68. $newRecurrenceException2 = $gdata->newRecurrenceException();
  69. $newRecurrenceException2->transferFromXML($newRecurrenceException->saveXML());
  70. $this->assertEquals(1, count($newRecurrenceException2->extensionElements));
  71. $this->assertEquals("false", $newRecurrenceException2->specialized);
  72. }
  73. public function testEmptyRecurrenceExceptionToAndFromStringShouldMatch() {
  74. $recurrenceExceptionXml = $this->recurrenceException->saveXML();
  75. $newRecurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  76. $newRecurrenceException->transferFromXML($recurrenceExceptionXml);
  77. $newRecurrenceExceptionXml = $newRecurrenceException->saveXML();
  78. $this->assertTrue($recurrenceExceptionXml == $newRecurrenceExceptionXml);
  79. }
  80. public function testRecurrenceExceptionWithValueToAndFromStringShouldMatch() {
  81. $this->recurrenceException->specialized = "false";
  82. $recurrenceExceptionXml = $this->recurrenceException->saveXML();
  83. $newRecurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  84. $newRecurrenceException->transferFromXML($recurrenceExceptionXml);
  85. $newRecurrenceExceptionXml = $newRecurrenceException->saveXML();
  86. $this->assertTrue($recurrenceExceptionXml == $newRecurrenceExceptionXml);
  87. $this->assertEquals("false", $this->recurrenceException->specialized);
  88. }
  89. public function testExtensionAttributes() {
  90. $extensionAttributes = $this->recurrenceException->extensionAttributes;
  91. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  92. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  93. $this->recurrenceException->extensionAttributes = $extensionAttributes;
  94. $this->assertEquals('bar', $this->recurrenceException->extensionAttributes['foo1']['value']);
  95. $this->assertEquals('rab', $this->recurrenceException->extensionAttributes['foo2']['value']);
  96. $recurrenceExceptionXml = $this->recurrenceException->saveXML();
  97. $newRecurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  98. $newRecurrenceException->transferFromXML($recurrenceExceptionXml);
  99. $this->assertEquals('bar', $newRecurrenceException->extensionAttributes['foo1']['value']);
  100. $this->assertEquals('rab', $newRecurrenceException->extensionAttributes['foo2']['value']);
  101. }
  102. public function testConvertFullRecurrenceExceptionToAndFromString() {
  103. $this->recurrenceException->transferFromXML($this->recurrenceExceptionText);
  104. $this->assertEquals("true", $this->recurrenceException->specialized);
  105. $this->assertTrue($this->recurrenceException->entryLink instanceof Zend_Gdata_Extension_EntryLink);
  106. $this->assertEquals("http://www.google.com/calendar/feeds/default/private/full/hj4geu9lpkh3ebk6rvm4k8mhik", $this->recurrenceException->entryLink->href);
  107. $this->assertTrue($this->recurrenceException->originalEvent instanceof Zend_Gdata_Extension_OriginalEvent);
  108. $this->assertEquals("hj4geu9lpkh3ebk6rvm4k8mhik", $this->recurrenceException->originalEvent->id);
  109. }
  110. }