TransparencyTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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) 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/Extension/Transparency.php';
  22. require_once 'Zend/Gdata.php';
  23. /**
  24. * @package Zend_Gdata
  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_TransparencyTest extends PHPUnit_Framework_TestCase
  30. {
  31. public function setUp() {
  32. $this->transparencyText = file_get_contents(
  33. 'Zend/Gdata/_files/TransparencyElementSample1.xml',
  34. true);
  35. $this->transparency = new Zend_Gdata_Extension_Transparency();
  36. }
  37. public function testEmptyTransparencyShouldHaveNoExtensionElements() {
  38. $this->assertTrue(is_array($this->transparency->extensionElements));
  39. $this->assertTrue(count($this->transparency->extensionElements) == 0);
  40. }
  41. public function testEmptyTransparencyShouldHaveNoExtensionAttributes() {
  42. $this->assertTrue(is_array($this->transparency->extensionAttributes));
  43. $this->assertTrue(count($this->transparency->extensionAttributes) == 0);
  44. }
  45. public function testSampleTransparencyShouldHaveNoExtensionElements() {
  46. $this->transparency->transferFromXML($this->transparencyText);
  47. $this->assertTrue(is_array($this->transparency->extensionElements));
  48. $this->assertTrue(count($this->transparency->extensionElements) == 0);
  49. }
  50. public function testSampleTransparencyShouldHaveNoExtensionAttributes() {
  51. $this->transparency->transferFromXML($this->transparencyText);
  52. $this->assertTrue(is_array($this->transparency->extensionAttributes));
  53. $this->assertTrue(count($this->transparency->extensionAttributes) == 0);
  54. }
  55. public function testNormalTransparencyShouldHaveNoExtensionElements() {
  56. $this->transparency->value = "http://schemas.google.com/g/2005#event.opaque";
  57. $this->assertEquals("http://schemas.google.com/g/2005#event.opaque", $this->transparency->value);
  58. $this->assertEquals(0, count($this->transparency->extensionElements));
  59. $newTransparency = new Zend_Gdata_Extension_Transparency();
  60. $newTransparency->transferFromXML($this->transparency->saveXML());
  61. $this->assertEquals(0, count($newTransparency->extensionElements));
  62. $newTransparency->extensionElements = array(
  63. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  64. $this->assertEquals(1, count($newTransparency->extensionElements));
  65. $this->assertEquals("http://schemas.google.com/g/2005#event.opaque", $newTransparency->value);
  66. /* try constructing using magic factory */
  67. $gdata = new Zend_Gdata();
  68. $newTransparency2 = $gdata->newTransparency();
  69. $newTransparency2->transferFromXML($newTransparency->saveXML());
  70. $this->assertEquals(1, count($newTransparency2->extensionElements));
  71. $this->assertEquals("http://schemas.google.com/g/2005#event.opaque", $newTransparency2->value);
  72. }
  73. public function testEmptyTransparencyToAndFromStringShouldMatch() {
  74. $transparencyXml = $this->transparency->saveXML();
  75. $newTransparency = new Zend_Gdata_Extension_Transparency();
  76. $newTransparency->transferFromXML($transparencyXml);
  77. $newTransparencyXml = $newTransparency->saveXML();
  78. $this->assertTrue($transparencyXml == $newTransparencyXml);
  79. }
  80. public function testTransparencyWithValueToAndFromStringShouldMatch() {
  81. $this->transparency->value = "http://schemas.google.com/g/2005#event.opaque";
  82. $transparencyXml = $this->transparency->saveXML();
  83. $newTransparency = new Zend_Gdata_Extension_Transparency();
  84. $newTransparency->transferFromXML($transparencyXml);
  85. $newTransparencyXml = $newTransparency->saveXML();
  86. $this->assertTrue($transparencyXml == $newTransparencyXml);
  87. $this->assertEquals("http://schemas.google.com/g/2005#event.opaque", $this->transparency->value);
  88. }
  89. public function testExtensionAttributes() {
  90. $extensionAttributes = $this->transparency->extensionAttributes;
  91. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  92. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  93. $this->transparency->extensionAttributes = $extensionAttributes;
  94. $this->assertEquals('bar', $this->transparency->extensionAttributes['foo1']['value']);
  95. $this->assertEquals('rab', $this->transparency->extensionAttributes['foo2']['value']);
  96. $transparencyXml = $this->transparency->saveXML();
  97. $newTransparency = new Zend_Gdata_Extension_Transparency();
  98. $newTransparency->transferFromXML($transparencyXml);
  99. $this->assertEquals('bar', $newTransparency->extensionAttributes['foo1']['value']);
  100. $this->assertEquals('rab', $newTransparency->extensionAttributes['foo2']['value']);
  101. }
  102. public function testConvertFullTransparencyToAndFromString() {
  103. $this->transparency->transferFromXML($this->transparencyText);
  104. $this->assertEquals("http://schemas.google.com/g/2005#event.transparent", $this->transparency->value);
  105. }
  106. }