PageRenderTime 26ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/GData/Calendar/SendEventNotificationsTest.php

https://github.com/sidealice/zf2
PHP | 126 lines | 80 code | 14 blank | 32 comment | 6 complexity | 0a68c903a68801da5f26d92ad5c9b7e2 MD5 | raw file
  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-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @namespace
  23. */
  24. namespace ZendTest\GData\Calendar;
  25. use Zend\GData\Calendar\Extension;
  26. /**
  27. * @category Zend
  28. * @package Zend_GData_Calendar
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_GData
  33. * @group Zend_GData_Calendar
  34. */
  35. class SendEventNotificationsTest extends \PHPUnit_Framework_TestCase
  36. {
  37. public function setUp() {
  38. $this->sendEventNotificationsText = file_get_contents(
  39. 'Zend/GData/Calendar/_files/SendEventNotificationsElementSample1.xml',
  40. true);
  41. $this->sendEventNotifications = new Extension\SendEventNotifications();
  42. }
  43. public function testEmptySendEventNotificationsShouldHaveNoExtensionElements() {
  44. $this->assertTrue(is_array($this->sendEventNotifications->extensionElements));
  45. $this->assertTrue(count($this->sendEventNotifications->extensionElements) == 0);
  46. }
  47. public function testEmptySendEventNotificationsShouldHaveNoExtensionAttributes() {
  48. $this->assertTrue(is_array($this->sendEventNotifications->extensionAttributes));
  49. $this->assertTrue(count($this->sendEventNotifications->extensionAttributes) == 0);
  50. }
  51. public function testSampleSendEventNotificationsShouldHaveNoExtensionElements() {
  52. $this->sendEventNotifications->transferFromXML($this->sendEventNotificationsText);
  53. $this->assertTrue(is_array($this->sendEventNotifications->extensionElements));
  54. $this->assertTrue(count($this->sendEventNotifications->extensionElements) == 0);
  55. }
  56. public function testSampleSendEventNotificationsShouldHaveNoExtensionAttributes() {
  57. $this->sendEventNotifications->transferFromXML($this->sendEventNotificationsText);
  58. $this->assertTrue(is_array($this->sendEventNotifications->extensionAttributes));
  59. $this->assertTrue(count($this->sendEventNotifications->extensionAttributes) == 0);
  60. }
  61. public function testNormalSendEventNotificationsShouldHaveNoExtensionElements() {
  62. $this->sendEventNotifications->value = true;
  63. $this->assertEquals($this->sendEventNotifications->value, true);
  64. $this->assertEquals(count($this->sendEventNotifications->extensionElements), 0);
  65. $newSendEventNotifications = new Extension\SendEventNotifications();
  66. $newSendEventNotifications->transferFromXML($this->sendEventNotifications->saveXML());
  67. $this->assertEquals(count($newSendEventNotifications->extensionElements), 0);
  68. $newSendEventNotifications->extensionElements = array(
  69. new \Zend\GData\App\Extension\Element('foo', 'atom', null, 'bar'));
  70. $this->assertEquals(count($newSendEventNotifications->extensionElements), 1);
  71. $this->assertEquals($newSendEventNotifications->value, true);
  72. /* try constructing using magic factory */
  73. $cal = new \Zend\GData\Calendar();
  74. $newSendEventNotifications2 = $cal->newSendEventNotifications();
  75. $newSendEventNotifications2->transferFromXML($newSendEventNotifications->saveXML());
  76. $this->assertEquals(count($newSendEventNotifications2->extensionElements), 1);
  77. $this->assertEquals($newSendEventNotifications2->value, true);
  78. }
  79. public function testEmptySendEventNotificationsToAndFromStringShouldMatch() {
  80. $sendEventNotificationsXml = $this->sendEventNotifications->saveXML();
  81. $newSendEventNotifications = new Extension\SendEventNotifications();
  82. $newSendEventNotifications->transferFromXML($sendEventNotificationsXml);
  83. $newSendEventNotificationsXml = $newSendEventNotifications->saveXML();
  84. $this->assertTrue($sendEventNotificationsXml == $newSendEventNotificationsXml);
  85. }
  86. public function testSendEventNotificationsWithValueToAndFromStringShouldMatch() {
  87. $this->sendEventNotifications->value = true;
  88. $sendEventNotificationsXml = $this->sendEventNotifications->saveXML();
  89. $newSendEventNotifications = new Extension\SendEventNotifications();
  90. $newSendEventNotifications->transferFromXML($sendEventNotificationsXml);
  91. $newSendEventNotificationsXml = $newSendEventNotifications->saveXML();
  92. $this->assertTrue($sendEventNotificationsXml == $newSendEventNotificationsXml);
  93. $this->assertEquals(true, $newSendEventNotifications->value);
  94. }
  95. public function testExtensionAttributes() {
  96. $extensionAttributes = $this->sendEventNotifications->extensionAttributes;
  97. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  98. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  99. $this->sendEventNotifications->extensionAttributes = $extensionAttributes;
  100. $this->assertEquals('bar', $this->sendEventNotifications->extensionAttributes['foo1']['value']);
  101. $this->assertEquals('rab', $this->sendEventNotifications->extensionAttributes['foo2']['value']);
  102. $sendEventNotificationsXml = $this->sendEventNotifications->saveXML();
  103. $newSendEventNotifications = new Extension\SendEventNotifications();
  104. $newSendEventNotifications->transferFromXML($sendEventNotificationsXml);
  105. $this->assertEquals('bar', $newSendEventNotifications->extensionAttributes['foo1']['value']);
  106. $this->assertEquals('rab', $newSendEventNotifications->extensionAttributes['foo2']['value']);
  107. }
  108. public function testConvertFullSendEventNotificationsToAndFromString() {
  109. $this->sendEventNotifications->transferFromXML($this->sendEventNotificationsText);
  110. $this->assertEquals($this->sendEventNotifications->value, false);
  111. }
  112. }