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/OriginalEvent.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_OriginalEventTest
extends PHPUnit_Framework_TestCase
37 public function setUp() {
38 $this->originalEventText
= file_get_contents(
39 'Zend/Gdata/_files/OriginalEventElementSample1.xml',
41 $this->originalEvent
= new Zend_Gdata_Extension_OriginalEvent();
44 public function testEmptyOriginalEventShouldHaveNoExtensionElements() {
45 $this->assertTrue(is_array($this->originalEvent
->extensionElements
));
46 $this->assertTrue(count($this->originalEvent
->extensionElements
) == 0);
49 public function testEmptyOriginalEventShouldHaveNoExtensionAttributes() {
50 $this->assertTrue(is_array($this->originalEvent
->extensionAttributes
));
51 $this->assertTrue(count($this->originalEvent
->extensionAttributes
) == 0);
54 public function testSampleOriginalEventShouldHaveNoExtensionElements() {
55 $this->originalEvent
->transferFromXML($this->originalEventText
);
56 $this->assertTrue(is_array($this->originalEvent
->extensionElements
));
57 $this->assertTrue(count($this->originalEvent
->extensionElements
) == 0);
60 public function testSampleOriginalEventShouldHaveNoExtensionAttributes() {
61 $this->originalEvent
->transferFromXML($this->originalEventText
);
62 $this->assertTrue(is_array($this->originalEvent
->extensionAttributes
));
63 $this->assertTrue(count($this->originalEvent
->extensionAttributes
) == 0);
66 public function testNormalOriginalEventShouldHaveNoExtensionElements() {
67 $this->originalEvent
->href
= "http://www.google.com/calendar/feeds/nobody@gmail.com/private/composite";
68 $this->originalEvent
->id
= "abcdef123456789";
70 $this->assertEquals("http://www.google.com/calendar/feeds/nobody@gmail.com/private/composite", $this->originalEvent
->href
);
71 $this->assertEquals("abcdef123456789", $this->originalEvent
->id
);
73 $this->assertEquals(0, count($this->originalEvent
->extensionElements
));
74 $newOriginalEvent = new Zend_Gdata_Extension_OriginalEvent();
75 $newOriginalEvent->transferFromXML($this->originalEvent
->saveXML());
76 $this->assertEquals(0, count($newOriginalEvent->extensionElements
));
77 $newOriginalEvent->extensionElements
= array(
78 new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
79 $this->assertEquals(1, count($newOriginalEvent->extensionElements
));
80 $this->assertEquals("http://www.google.com/calendar/feeds/nobody@gmail.com/private/composite", $newOriginalEvent->href
);
81 $this->assertEquals("abcdef123456789", $newOriginalEvent->id
);
83 /* try constructing using magic factory */
84 $gdata = new Zend_Gdata();
85 $newOriginalEvent2 = $gdata->newOriginalEvent();
86 $newOriginalEvent2->transferFromXML($newOriginalEvent->saveXML());
87 $this->assertEquals(1, count($newOriginalEvent2->extensionElements
));
88 $this->assertEquals("http://www.google.com/calendar/feeds/nobody@gmail.com/private/composite", $newOriginalEvent2->href
);
89 $this->assertEquals("abcdef123456789", $newOriginalEvent2->id
);
92 public function testEmptyOriginalEventToAndFromStringShouldMatch() {
93 $originalEventXml = $this->originalEvent
->saveXML();
94 $newOriginalEvent = new Zend_Gdata_Extension_OriginalEvent();
95 $newOriginalEvent->transferFromXML($originalEventXml);
96 $newOriginalEventXml = $newOriginalEvent->saveXML();
97 $this->assertTrue($originalEventXml == $newOriginalEventXml);
100 public function testOriginalEventWithValueToAndFromStringShouldMatch() {
101 $this->originalEvent
->href
= "http://www.google.com/calendar/feeds/nobody@gmail.com/private/composite";
102 $this->originalEvent
->id
= "abcdef123456789";
103 $originalEventXml = $this->originalEvent
->saveXML();
104 $newOriginalEvent = new Zend_Gdata_Extension_OriginalEvent();
105 $newOriginalEvent->transferFromXML($originalEventXml);
106 $newOriginalEventXml = $newOriginalEvent->saveXML();
107 $this->assertTrue($originalEventXml == $newOriginalEventXml);
108 $this->assertEquals("http://www.google.com/calendar/feeds/nobody@gmail.com/private/composite", $this->originalEvent
->href
);
109 $this->assertEquals("abcdef123456789", $this->originalEvent
->id
);
112 public function testExtensionAttributes() {
113 $extensionAttributes = $this->originalEvent
->extensionAttributes
;
114 $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
115 $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
116 $this->originalEvent
->extensionAttributes
= $extensionAttributes;
117 $this->assertEquals('bar', $this->originalEvent
->extensionAttributes
['foo1']['value']);
118 $this->assertEquals('rab', $this->originalEvent
->extensionAttributes
['foo2']['value']);
119 $originalEventXml = $this->originalEvent
->saveXML();
120 $newOriginalEvent = new Zend_Gdata_Extension_OriginalEvent();
121 $newOriginalEvent->transferFromXML($originalEventXml);
122 $this->assertEquals('bar', $newOriginalEvent->extensionAttributes
['foo1']['value']);
123 $this->assertEquals('rab', $newOriginalEvent->extensionAttributes
['foo2']['value']);
126 public function testConvertFullOriginalEventToAndFromString() {
127 $this->originalEvent
->transferFromXML($this->originalEventText
);
128 $this->assertEquals("http://www.google.com/calendar/feeds/userID/private/full/123456789", $this->originalEvent
->href
);
129 $this->assertEquals("i8fl1nrv2bl57c1qgr3f0onmgg", $this->originalEvent
->id
);
130 $this->assertTrue($this->originalEvent
->when
instanceof Zend_Gdata_Extension_When
);
131 $this->assertEquals("2006-03-17T22:00:00.000Z", $this->originalEvent
->when
->startTime
);