SendEventNotificationsTest.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_Calendar
  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/Calendar/Extension/SendEventNotifications.php';
  23. require_once 'Zend/Gdata/Calendar.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_Calendar
  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. * @group Zend_Gdata_Calendar
  32. */
  33. class Zend_Gdata_Calendar_SendEventNotificationsTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->sendEventNotificationsText = file_get_contents(
  37. 'Zend/Gdata/Calendar/_files/SendEventNotificationsElementSample1.xml',
  38. true);
  39. $this->sendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications();
  40. }
  41. public function testEmptySendEventNotificationsShouldHaveNoExtensionElements() {
  42. $this->assertTrue(is_array($this->sendEventNotifications->extensionElements));
  43. $this->assertTrue(count($this->sendEventNotifications->extensionElements) == 0);
  44. }
  45. public function testEmptySendEventNotificationsShouldHaveNoExtensionAttributes() {
  46. $this->assertTrue(is_array($this->sendEventNotifications->extensionAttributes));
  47. $this->assertTrue(count($this->sendEventNotifications->extensionAttributes) == 0);
  48. }
  49. public function testSampleSendEventNotificationsShouldHaveNoExtensionElements() {
  50. $this->sendEventNotifications->transferFromXML($this->sendEventNotificationsText);
  51. $this->assertTrue(is_array($this->sendEventNotifications->extensionElements));
  52. $this->assertTrue(count($this->sendEventNotifications->extensionElements) == 0);
  53. }
  54. public function testSampleSendEventNotificationsShouldHaveNoExtensionAttributes() {
  55. $this->sendEventNotifications->transferFromXML($this->sendEventNotificationsText);
  56. $this->assertTrue(is_array($this->sendEventNotifications->extensionAttributes));
  57. $this->assertTrue(count($this->sendEventNotifications->extensionAttributes) == 0);
  58. }
  59. public function testNormalSendEventNotificationsShouldHaveNoExtensionElements() {
  60. $this->sendEventNotifications->value = true;
  61. $this->assertEquals($this->sendEventNotifications->value, true);
  62. $this->assertEquals(count($this->sendEventNotifications->extensionElements), 0);
  63. $newSendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications();
  64. $newSendEventNotifications->transferFromXML($this->sendEventNotifications->saveXML());
  65. $this->assertEquals(count($newSendEventNotifications->extensionElements), 0);
  66. $newSendEventNotifications->extensionElements = array(
  67. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  68. $this->assertEquals(count($newSendEventNotifications->extensionElements), 1);
  69. $this->assertEquals($newSendEventNotifications->value, true);
  70. /* try constructing using magic factory */
  71. $cal = new Zend_Gdata_Calendar();
  72. $newSendEventNotifications2 = $cal->newSendEventNotifications();
  73. $newSendEventNotifications2->transferFromXML($newSendEventNotifications->saveXML());
  74. $this->assertEquals(count($newSendEventNotifications2->extensionElements), 1);
  75. $this->assertEquals($newSendEventNotifications2->value, true);
  76. }
  77. public function testEmptySendEventNotificationsToAndFromStringShouldMatch() {
  78. $sendEventNotificationsXml = $this->sendEventNotifications->saveXML();
  79. $newSendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications();
  80. $newSendEventNotifications->transferFromXML($sendEventNotificationsXml);
  81. $newSendEventNotificationsXml = $newSendEventNotifications->saveXML();
  82. $this->assertTrue($sendEventNotificationsXml == $newSendEventNotificationsXml);
  83. }
  84. public function testSendEventNotificationsWithValueToAndFromStringShouldMatch() {
  85. $this->sendEventNotifications->value = true;
  86. $sendEventNotificationsXml = $this->sendEventNotifications->saveXML();
  87. $newSendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications();
  88. $newSendEventNotifications->transferFromXML($sendEventNotificationsXml);
  89. $newSendEventNotificationsXml = $newSendEventNotifications->saveXML();
  90. $this->assertTrue($sendEventNotificationsXml == $newSendEventNotificationsXml);
  91. $this->assertEquals(true, $newSendEventNotifications->value);
  92. }
  93. public function testExtensionAttributes() {
  94. $extensionAttributes = $this->sendEventNotifications->extensionAttributes;
  95. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  96. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  97. $this->sendEventNotifications->extensionAttributes = $extensionAttributes;
  98. $this->assertEquals('bar', $this->sendEventNotifications->extensionAttributes['foo1']['value']);
  99. $this->assertEquals('rab', $this->sendEventNotifications->extensionAttributes['foo2']['value']);
  100. $sendEventNotificationsXml = $this->sendEventNotifications->saveXML();
  101. $newSendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications();
  102. $newSendEventNotifications->transferFromXML($sendEventNotificationsXml);
  103. $this->assertEquals('bar', $newSendEventNotifications->extensionAttributes['foo1']['value']);
  104. $this->assertEquals('rab', $newSendEventNotifications->extensionAttributes['foo2']['value']);
  105. }
  106. public function testConvertFullSendEventNotificationsToAndFromString() {
  107. $this->sendEventNotifications->transferFromXML($this->sendEventNotificationsText);
  108. $this->assertEquals($this->sendEventNotifications->value, false);
  109. }
  110. }