WebContentTest.php 6.4 KB

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