WebContentTest.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/WebContent.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_WebContentTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->webContentText = file_get_contents(
  37. 'Zend/Gdata/Calendar/_files/WebContentElementSample1.xml',
  38. true);
  39. $this->webContent = new Zend_Gdata_Calendar_Extension_WebContent();
  40. }
  41. public function testEmptyWebContentShouldHaveNoExtensionElements() {
  42. $this->assertTrue(is_array($this->webContent->extensionElements));
  43. $this->assertTrue(count($this->webContent->extensionElements) == 0);
  44. }
  45. public function testEmptyWebContentShouldHaveNoExtensionAttributes() {
  46. $this->assertTrue(is_array($this->webContent->extensionAttributes));
  47. $this->assertTrue(count($this->webContent->extensionAttributes) == 0);
  48. }
  49. public function testSampleWebContentShouldHaveNoExtensionElements() {
  50. $this->webContent->transferFromXML($this->webContentText);
  51. $this->assertTrue(is_array($this->webContent->extensionElements));
  52. $this->assertTrue(count($this->webContent->extensionElements) == 0);
  53. }
  54. public function testSampleWebContentShouldHaveNoExtensionAttributes() {
  55. $this->webContent->transferFromXML($this->webContentText);
  56. $this->assertTrue(is_array($this->webContent->extensionAttributes));
  57. $this->assertTrue(count($this->webContent->extensionAttributes) == 0);
  58. }
  59. public function testNormalWebContentShouldHaveNoExtensionElements() {
  60. $this->webContent->url = "http://nowhere.invalid/";
  61. $this->webContent->height = "100";
  62. $this->webContent->width = "200";
  63. $this->assertEquals($this->webContent->url, "http://nowhere.invalid/");
  64. $this->assertEquals($this->webContent->height, "100");
  65. $this->assertEquals($this->webContent->width, "200");
  66. $this->assertEquals(count($this->webContent->extensionElements), 0);
  67. $newWebContent = new Zend_Gdata_Calendar_Extension_WebContent();
  68. $newWebContent->transferFromXML($this->webContent->saveXML());
  69. $this->assertEquals(count($newWebContent->extensionElements), 0);
  70. $newWebContent->extensionElements = array(
  71. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  72. $this->assertEquals(count($newWebContent->extensionElements), 1);
  73. $this->assertEquals($newWebContent->url, "http://nowhere.invalid/");
  74. $this->assertEquals($newWebContent->height, "100");
  75. $this->assertEquals($newWebContent->width, "200");
  76. /* try constructing using magic factory */
  77. $cal = new Zend_Gdata_Calendar();
  78. $newWebContent2 = $cal->newWebContent();
  79. $newWebContent2->transferFromXML($newWebContent->saveXML());
  80. $this->assertEquals(count($newWebContent2->extensionElements), 1);
  81. $this->assertEquals($newWebContent2->url, "http://nowhere.invalid/");
  82. $this->assertEquals($newWebContent2->height, "100");
  83. $this->assertEquals($newWebContent2->width, "200");
  84. }
  85. public function testEmptyWebContentToAndFromStringShouldMatch() {
  86. $webContentXml = $this->webContent->saveXML();
  87. $newWebContent = new Zend_Gdata_Calendar_Extension_WebContent();
  88. $newWebContent->transferFromXML($webContentXml);
  89. $newWebContentXml = $newWebContent->saveXML();
  90. $this->assertTrue($webContentXml == $newWebContentXml);
  91. }
  92. public function testWebContentWithValueToAndFromStringShouldMatch() {
  93. $this->webContent->url = "http://nowhere.invalid/";
  94. $this->webContent->height = "100";
  95. $this->webContent->width = "200";
  96. $webContentXml = $this->webContent->saveXML();
  97. $newWebContent = new Zend_Gdata_Calendar_Extension_WebContent();
  98. $newWebContent->transferFromXML($webContentXml);
  99. $newWebContentXml = $newWebContent->saveXML();
  100. $this->assertTrue($webContentXml == $newWebContentXml);
  101. $this->assertEquals($this->webContent->url, "http://nowhere.invalid/");
  102. $this->assertEquals($this->webContent->height, "100");
  103. $this->assertEquals($this->webContent->width, "200");
  104. }
  105. public function testExtensionAttributes() {
  106. $extensionAttributes = $this->webContent->extensionAttributes;
  107. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  108. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  109. $this->webContent->extensionAttributes = $extensionAttributes;
  110. $this->assertEquals('bar', $this->webContent->extensionAttributes['foo1']['value']);
  111. $this->assertEquals('rab', $this->webContent->extensionAttributes['foo2']['value']);
  112. $webContentXml = $this->webContent->saveXML();
  113. $newWebContent = new Zend_Gdata_Calendar_Extension_WebContent();
  114. $newWebContent->transferFromXML($webContentXml);
  115. $this->assertEquals('bar', $newWebContent->extensionAttributes['foo1']['value']);
  116. $this->assertEquals('rab', $newWebContent->extensionAttributes['foo2']['value']);
  117. }
  118. public function testConvertFullWebContentToAndFromString() {
  119. $this->webContent->transferFromXML($this->webContentText);
  120. $this->assertEquals($this->webContent->url, "http://www.google.com/logos/july4th06.gif");
  121. $this->assertEquals($this->webContent->height, "120");
  122. $this->assertEquals($this->webContent->width, "276");
  123. }
  124. }