PropertyTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_Gapps
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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/Gapps/Extension/Property.php';
  23. require_once 'Zend/Gdata.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_Gapps
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2012 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_Gapps
  32. */
  33. class Zend_Gdata_Gapps_PropertyTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->thePropertyText = file_get_contents(
  37. 'Zend/Gdata/Gapps/_files/PropertyElementSample1.xml',
  38. true);
  39. $this->theProperty = new Zend_Gdata_Gapps_Extension_Property();
  40. }
  41. public function testEmptyPropertyShouldHaveNoExtensionElements() {
  42. $this->assertTrue(is_array($this->theProperty->extensionElements));
  43. $this->assertTrue(count($this->theProperty->extensionElements) == 0);
  44. }
  45. public function testEmptyPropertyShouldHaveNoExtensionAttributes() {
  46. $this->assertTrue(is_array($this->theProperty->extensionAttributes));
  47. $this->assertTrue(count($this->theProperty->extensionAttributes) == 0);
  48. }
  49. public function testSamplePropertyShouldHaveNoExtensionElements() {
  50. $this->theProperty->transferFromXML($this->thePropertyText);
  51. $this->assertTrue(is_array($this->theProperty->extensionElements));
  52. $this->assertTrue(count($this->theProperty->extensionElements) == 0);
  53. }
  54. public function testSamplePropertyShouldHaveNoExtensionAttributes() {
  55. $this->theProperty->transferFromXML($this->thePropertyText);
  56. $this->assertTrue(is_array($this->theProperty->extensionAttributes));
  57. $this->assertTrue(count($this->theProperty->extensionAttributes) == 0);
  58. }
  59. public function testNormalPropertyShouldHaveNoExtensionElements() {
  60. $this->theProperty->name = "foo";
  61. $this->theProperty->value = "bar";
  62. $this->assertEquals("foo", $this->theProperty->name);
  63. $this->assertEquals("bar", $this->theProperty->value);
  64. $this->assertEquals(0, count($this->theProperty->extensionElements));
  65. $newProperty = new Zend_Gdata_Gapps_Extension_Property();
  66. $newProperty->transferFromXML($this->theProperty->saveXML());
  67. $this->assertEquals(0, count($newProperty->extensionElements));
  68. $newProperty->extensionElements = array(
  69. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  70. $this->assertEquals(1, count($newProperty->extensionElements));
  71. $this->assertEquals("foo", $newProperty->name);
  72. $this->assertEquals("bar", $newProperty->value);
  73. /* try constructing using magic factory */
  74. $gdata = new Zend_Gdata_Gapps();
  75. $newProperty2 = $gdata->newProperty();
  76. $newProperty2->transferFromXML($newProperty->saveXML());
  77. $this->assertEquals(1, count($newProperty2->extensionElements));
  78. $this->assertEquals("foo", $newProperty2->name);
  79. $this->assertEquals("bar", $newProperty2->value);
  80. }
  81. public function testEmptyPropertyToAndFromStringShouldMatch() {
  82. $propertyXml = $this->theProperty->saveXML();
  83. $newProperty = new Zend_Gdata_Gapps_Extension_Property();
  84. $newProperty->transferFromXML($propertyXml);
  85. $newPropertyXml = $newProperty->saveXML();
  86. $this->assertTrue($propertyXml == $newPropertyXml);
  87. }
  88. public function testPropertyWithValueToAndFromStringShouldMatch() {
  89. $this->theProperty->name = "foo2";
  90. $this->theProperty->value = "bar2";
  91. $propertyXml = $this->theProperty->saveXML();
  92. $newProperty = new Zend_Gdata_Gapps_Extension_Property();
  93. $newProperty->transferFromXML($propertyXml);
  94. $newPropertyXml = $newProperty->saveXML();
  95. $this->assertTrue($propertyXml == $newPropertyXml);
  96. $this->assertEquals("foo2", $this->theProperty->name);
  97. $this->assertEquals("bar2", $this->theProperty->value);
  98. }
  99. public function testExtensionAttributes() {
  100. $extensionAttributes = $this->theProperty->extensionAttributes;
  101. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  102. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  103. $this->theProperty->extensionAttributes = $extensionAttributes;
  104. $this->assertEquals('bar', $this->theProperty->extensionAttributes['foo1']['value']);
  105. $this->assertEquals('rab', $this->theProperty->extensionAttributes['foo2']['value']);
  106. $propertyXml = $this->theProperty->saveXML();
  107. $newProperty = new Zend_Gdata_Gapps_Extension_Property();
  108. $newProperty->transferFromXML($propertyXml);
  109. $this->assertEquals('bar', $newProperty->extensionAttributes['foo1']['value']);
  110. $this->assertEquals('rab', $newProperty->extensionAttributes['foo2']['value']);
  111. }
  112. public function testConvertFullNameToAndFromString() {
  113. $this->theProperty->transferFromXML($this->thePropertyText);
  114. $this->assertEquals("Some Name", $this->theProperty->name);
  115. $this->assertEquals("Some Value", $this->theProperty->value);
  116. }
  117. }