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.
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 require_once 'Zend/Gdata/Extension/ExtendedProperty.php';
24 require_once 'Zend/Gdata.php';
29 * @subpackage UnitTests
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
34 class Zend_Gdata_ExtendedPropertyTest
extends PHPUnit_Framework_TestCase
37 public function setUp() {
38 $this->extendedPropertyText
= file_get_contents(
39 'Zend/Gdata/_files/ExtendedPropertyElementSample1.xml',
41 $this->extendedProperty
= new Zend_Gdata_Extension_ExtendedProperty();
44 public function testEmptyExtendedPropertyShouldHaveNoExtensionElements() {
45 $this->assertTrue(is_array($this->extendedProperty
->extensionElements
));
46 $this->assertTrue(count($this->extendedProperty
->extensionElements
) == 0);
49 public function testEmptyExtendedPropertyShouldHaveNoExtensionAttributes() {
50 $this->assertTrue(is_array($this->extendedProperty
->extensionAttributes
));
51 $this->assertTrue(count($this->extendedProperty
->extensionAttributes
) == 0);
54 public function testSampleExtendedPropertyShouldHaveNoExtensionElements() {
55 $this->extendedProperty
->transferFromXML($this->extendedPropertyText
);
56 $this->assertTrue(is_array($this->extendedProperty
->extensionElements
));
57 $this->assertTrue(count($this->extendedProperty
->extensionElements
) == 0);
60 public function testSampleExtendedPropertyShouldHaveNoExtensionAttributes() {
61 $this->extendedProperty
->transferFromXML($this->extendedPropertyText
);
62 $this->assertTrue(is_array($this->extendedProperty
->extensionAttributes
));
63 $this->assertTrue(count($this->extendedProperty
->extensionAttributes
) == 0);
66 public function testNormalExtendedPropertyShouldHaveNoExtensionElements() {
67 $this->extendedProperty
->name
= "http://www.example.com/schemas/2007#mycal.foo";
68 $this->extendedProperty
->value
= "5678";
70 $this->assertEquals("http://www.example.com/schemas/2007#mycal.foo", $this->extendedProperty
->name
);
71 $this->assertEquals("5678", $this->extendedProperty
->value
);
73 $this->assertEquals(0, count($this->extendedProperty
->extensionElements
));
74 $newExtendedProperty = new Zend_Gdata_Extension_ExtendedProperty();
75 $newExtendedProperty->transferFromXML($this->extendedProperty
->saveXML());
76 $this->assertEquals(0, count($newExtendedProperty->extensionElements
));
77 $newExtendedProperty->extensionElements
= array(
78 new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
79 $this->assertEquals(1, count($newExtendedProperty->extensionElements
));
80 $this->assertEquals("http://www.example.com/schemas/2007#mycal.foo", $newExtendedProperty->name
);
81 $this->assertEquals("5678", $newExtendedProperty->value
);
83 /* try constructing using magic factory */
84 $gdata = new Zend_Gdata();
85 $newExtendedProperty2 = $gdata->newExtendedProperty();
86 $newExtendedProperty2->transferFromXML($newExtendedProperty->saveXML());
87 $this->assertEquals(1, count($newExtendedProperty2->extensionElements
));
88 $this->assertEquals("http://www.example.com/schemas/2007#mycal.foo", $newExtendedProperty2->name
);
89 $this->assertEquals("5678", $newExtendedProperty2->value
);
92 public function testEmptyExtendedPropertyToAndFromStringShouldMatch() {
93 $extendedPropertyXml = $this->extendedProperty
->saveXML();
94 $newExtendedProperty = new Zend_Gdata_Extension_ExtendedProperty();
95 $newExtendedProperty->transferFromXML($extendedPropertyXml);
96 $newExtendedPropertyXml = $newExtendedProperty->saveXML();
97 $this->assertTrue($extendedPropertyXml == $newExtendedPropertyXml);
100 public function testExtendedPropertyWithValueToAndFromStringShouldMatch() {
101 $this->extendedProperty
->name
= "http://www.example.com/schemas/2007#mycal.foo";
102 $this->extendedProperty
->value
= "5678";
103 $extendedPropertyXml = $this->extendedProperty
->saveXML();
104 $newExtendedProperty = new Zend_Gdata_Extension_ExtendedProperty();
105 $newExtendedProperty->transferFromXML($extendedPropertyXml);
106 $newExtendedPropertyXml = $newExtendedProperty->saveXML();
107 $this->assertTrue($extendedPropertyXml == $newExtendedPropertyXml);
108 $this->assertEquals("http://www.example.com/schemas/2007#mycal.foo", $this->extendedProperty
->name
);
109 $this->assertEquals("5678", $this->extendedProperty
->value
);
112 public function testExtensionAttributes() {
113 $extensionAttributes = $this->extendedProperty
->extensionAttributes
;
114 $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
115 $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
116 $this->extendedProperty
->extensionAttributes
= $extensionAttributes;
117 $this->assertEquals('bar', $this->extendedProperty
->extensionAttributes
['foo1']['value']);
118 $this->assertEquals('rab', $this->extendedProperty
->extensionAttributes
['foo2']['value']);
119 $extendedPropertyXml = $this->extendedProperty
->saveXML();
120 $newExtendedProperty = new Zend_Gdata_Extension_ExtendedProperty();
121 $newExtendedProperty->transferFromXML($extendedPropertyXml);
122 $this->assertEquals('bar', $newExtendedProperty->extensionAttributes
['foo1']['value']);
123 $this->assertEquals('rab', $newExtendedProperty->extensionAttributes
['foo2']['value']);
126 public function testConvertFullExtendedPropertyToAndFromString() {
127 $this->extendedProperty
->transferFromXML($this->extendedPropertyText
);
128 $this->assertEquals("http://www.example.com/schemas/2007#mycal.id", $this->extendedProperty
->name
);
129 $this->assertEquals("1234", $this->extendedProperty
->value
);