RecurrenceExceptionTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. require_once 'Zend/Gdata/Extension/RecurrenceException.php';
  23. require_once 'Zend/Gdata.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Gdata
  31. */
  32. class Zend_Gdata_RecurrenceExceptionTest extends PHPUnit_Framework_TestCase
  33. {
  34. public function setUp() {
  35. $this->recurrenceExceptionText = file_get_contents(
  36. 'Zend/Gdata/_files/RecurrenceExceptionElementSample1.xml',
  37. true);
  38. $this->recurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  39. }
  40. public function testEmptyRecurrenceExceptionShouldHaveNoExtensionElements() {
  41. $this->assertTrue(is_array($this->recurrenceException->extensionElements));
  42. $this->assertTrue(count($this->recurrenceException->extensionElements) == 0);
  43. }
  44. public function testEmptyRecurrenceExceptionShouldHaveNoExtensionAttributes() {
  45. $this->assertTrue(is_array($this->recurrenceException->extensionAttributes));
  46. $this->assertTrue(count($this->recurrenceException->extensionAttributes) == 0);
  47. }
  48. public function testSampleRecurrenceExceptionShouldHaveNoExtensionElements() {
  49. $this->recurrenceException->transferFromXML($this->recurrenceExceptionText);
  50. $this->assertTrue(is_array($this->recurrenceException->extensionElements));
  51. $this->assertTrue(count($this->recurrenceException->extensionElements) == 0);
  52. }
  53. public function testSampleRecurrenceExceptionShouldHaveNoExtensionAttributes() {
  54. $this->recurrenceException->transferFromXML($this->recurrenceExceptionText);
  55. $this->assertTrue(is_array($this->recurrenceException->extensionAttributes));
  56. $this->assertTrue(count($this->recurrenceException->extensionAttributes) == 0);
  57. }
  58. public function testNormalRecurrenceExceptionShouldHaveNoExtensionElements() {
  59. $this->recurrenceException->specialized = false;
  60. $this->assertEquals(false, $this->recurrenceException->specialized);
  61. $this->assertEquals(0, count($this->recurrenceException->extensionElements));
  62. $newRecurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  63. $newRecurrenceException->transferFromXML($this->recurrenceException->saveXML());
  64. $this->assertEquals(0, count($newRecurrenceException->extensionElements));
  65. $newRecurrenceException->extensionElements = array(
  66. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  67. $this->assertEquals(1, count($newRecurrenceException->extensionElements));
  68. $this->assertEquals(false, $newRecurrenceException->specialized);
  69. /* try constructing using magic factory */
  70. $gdata = new Zend_Gdata();
  71. $newRecurrenceException2 = $gdata->newRecurrenceException();
  72. $newRecurrenceException2->transferFromXML($newRecurrenceException->saveXML());
  73. $this->assertEquals(1, count($newRecurrenceException2->extensionElements));
  74. $this->assertEquals(false, $newRecurrenceException2->specialized);
  75. }
  76. public function testEmptyRecurrenceExceptionToAndFromStringShouldMatch() {
  77. $recurrenceExceptionXml = $this->recurrenceException->saveXML();
  78. $newRecurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  79. $newRecurrenceException->transferFromXML($recurrenceExceptionXml);
  80. $newRecurrenceExceptionXml = $newRecurrenceException->saveXML();
  81. $this->assertTrue($recurrenceExceptionXml == $newRecurrenceExceptionXml);
  82. }
  83. public function testRecurrenceExceptionWithValueToAndFromStringShouldMatch() {
  84. $this->recurrenceException->specialized = false;
  85. $recurrenceExceptionXml = $this->recurrenceException->saveXML();
  86. $newRecurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  87. $newRecurrenceException->transferFromXML($recurrenceExceptionXml);
  88. $newRecurrenceExceptionXml = $newRecurrenceException->saveXML();
  89. $this->assertTrue($recurrenceExceptionXml == $newRecurrenceExceptionXml);
  90. $this->assertEquals(false, $this->recurrenceException->specialized);
  91. }
  92. public function testExtensionAttributes() {
  93. $extensionAttributes = $this->recurrenceException->extensionAttributes;
  94. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  95. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  96. $this->recurrenceException->extensionAttributes = $extensionAttributes;
  97. $this->assertEquals('bar', $this->recurrenceException->extensionAttributes['foo1']['value']);
  98. $this->assertEquals('rab', $this->recurrenceException->extensionAttributes['foo2']['value']);
  99. $recurrenceExceptionXml = $this->recurrenceException->saveXML();
  100. $newRecurrenceException = new Zend_Gdata_Extension_RecurrenceException();
  101. $newRecurrenceException->transferFromXML($recurrenceExceptionXml);
  102. $this->assertEquals('bar', $newRecurrenceException->extensionAttributes['foo1']['value']);
  103. $this->assertEquals('rab', $newRecurrenceException->extensionAttributes['foo2']['value']);
  104. }
  105. public function testConvertFullRecurrenceExceptionToAndFromString() {
  106. $this->recurrenceException->transferFromXML($this->recurrenceExceptionText);
  107. $this->assertEquals(true, $this->recurrenceException->specialized);
  108. $this->assertTrue($this->recurrenceException->entryLink instanceof Zend_Gdata_Extension_EntryLink);
  109. $this->assertEquals("http://www.google.com/calendar/feeds/default/private/full/hj4geu9lpkh3ebk6rvm4k8mhik", $this->recurrenceException->entryLink->href);
  110. $this->assertTrue($this->recurrenceException->originalEvent instanceof Zend_Gdata_Extension_OriginalEvent);
  111. $this->assertEquals("hj4geu9lpkh3ebk6rvm4k8mhik", $this->recurrenceException->originalEvent->id);
  112. }
  113. }