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/Reminder.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_ReminderTest
extends PHPUnit_Framework_TestCase
37 public function setUp() {
38 $this->reminderText
= file_get_contents(
39 'Zend/Gdata/_files/ReminderElementSample1.xml',
41 $this->reminder
= new Zend_Gdata_Extension_Reminder();
44 public function testEmptyReminderShouldHaveNoExtensionElements() {
45 $this->assertTrue(is_array($this->reminder
->extensionElements
));
46 $this->assertTrue(count($this->reminder
->extensionElements
) == 0);
49 public function testEmptyReminderShouldHaveNoExtensionAttributes() {
50 $this->assertTrue(is_array($this->reminder
->extensionAttributes
));
51 $this->assertTrue(count($this->reminder
->extensionAttributes
) == 0);
54 public function testSampleReminderShouldHaveNoExtensionElements() {
55 $this->reminder
->transferFromXML($this->reminderText
);
56 $this->assertTrue(is_array($this->reminder
->extensionElements
));
57 $this->assertTrue(count($this->reminder
->extensionElements
) == 0);
60 public function testSampleReminderShouldHaveNoExtensionAttributes() {
61 $this->reminder
->transferFromXML($this->reminderText
);
62 $this->assertTrue(is_array($this->reminder
->extensionAttributes
));
63 $this->assertTrue(count($this->reminder
->extensionAttributes
) == 0);
66 public function testNormalReminderShouldHaveNoExtensionElements() {
67 $this->reminder
->days
= "12";
68 $this->reminder
->minutes
= "64";
69 $this->reminder
->absoluteTime
= "2007-06-19T12:42:19-06:00";
70 $this->reminder
->method
= "email";
71 $this->reminder
->hours
= "80";
73 $this->assertEquals("12", $this->reminder
->days
);
74 $this->assertEquals("64", $this->reminder
->minutes
);
75 $this->assertEquals("2007-06-19T12:42:19-06:00", $this->reminder
->absoluteTime
);
76 $this->assertEquals("email", $this->reminder
->method
);
77 $this->assertEquals("80", $this->reminder
->hours
);
79 $this->assertEquals(0, count($this->reminder
->extensionElements
));
80 $newReminder = new Zend_Gdata_Extension_Reminder();
81 $newReminder->transferFromXML($this->reminder
->saveXML());
82 $this->assertEquals(0, count($newReminder->extensionElements
));
83 $newReminder->extensionElements
= array(
84 new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
85 $this->assertEquals(1, count($newReminder->extensionElements
));
86 $this->assertEquals("12", $newReminder->days
);
87 $this->assertEquals("64", $newReminder->minutes
);
88 $this->assertEquals("2007-06-19T12:42:19-06:00", $newReminder->absoluteTime
);
89 $this->assertEquals("email", $newReminder->method
);
90 $this->assertEquals("80", $newReminder->hours
);
92 /* try constructing using magic factory */
93 $gdata = new Zend_Gdata();
94 $newReminder2 = $gdata->newReminder();
95 $newReminder2->transferFromXML($newReminder->saveXML());
96 $this->assertEquals(1, count($newReminder2->extensionElements
));
97 $this->assertEquals("12", $newReminder2->days
);
98 $this->assertEquals("64", $newReminder2->minutes
);
99 $this->assertEquals("2007-06-19T12:42:19-06:00", $newReminder2->absoluteTime
);
100 $this->assertEquals("email", $newReminder2->method
);
101 $this->assertEquals("80", $newReminder2->hours
);
104 public function testEmptyReminderToAndFromStringShouldMatch() {
105 $reminderXml = $this->reminder
->saveXML();
106 $newReminder = new Zend_Gdata_Extension_Reminder();
107 $newReminder->transferFromXML($reminderXml);
108 $newReminderXml = $newReminder->saveXML();
109 $this->assertTrue($reminderXml == $newReminderXml);
112 public function testReminderWithValueToAndFromStringShouldMatch() {
113 $this->reminder
->days
= "12";
114 $this->reminder
->minutes
= "64";
115 $this->reminder
->absoluteTime
= "2007-06-19T12:42:19-06:00";
116 $this->reminder
->method
= "email";
117 $this->reminder
->hours
= "80";
118 $reminderXml = $this->reminder
->saveXML();
119 $newReminder = new Zend_Gdata_Extension_Reminder();
120 $newReminder->transferFromXML($reminderXml);
121 $newReminderXml = $newReminder->saveXML();
122 $this->assertTrue($reminderXml == $newReminderXml);
123 $this->assertEquals("12", $this->reminder
->days
);
124 $this->assertEquals("64", $this->reminder
->minutes
);
125 $this->assertEquals("2007-06-19T12:42:19-06:00", $this->reminder
->absoluteTime
);
126 $this->assertEquals("email", $this->reminder
->method
);
127 $this->assertEquals("80", $this->reminder
->hours
);
130 public function testExtensionAttributes() {
131 $extensionAttributes = $this->reminder
->extensionAttributes
;
132 $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
133 $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
134 $this->reminder
->extensionAttributes
= $extensionAttributes;
135 $this->assertEquals('bar', $this->reminder
->extensionAttributes
['foo1']['value']);
136 $this->assertEquals('rab', $this->reminder
->extensionAttributes
['foo2']['value']);
137 $reminderXml = $this->reminder
->saveXML();
138 $newReminder = new Zend_Gdata_Extension_Reminder();
139 $newReminder->transferFromXML($reminderXml);
140 $this->assertEquals('bar', $newReminder->extensionAttributes
['foo1']['value']);
141 $this->assertEquals('rab', $newReminder->extensionAttributes
['foo2']['value']);
144 public function testConvertFullReminderToAndFromString() {
145 $this->reminder
->transferFromXML($this->reminderText
);
146 $this->assertEquals("42", $this->reminder
->days
);
147 $this->assertEquals("50", $this->reminder
->minutes
);
148 $this->assertEquals("2005-06-06T16:55:00-08:00", $this->reminder
->absoluteTime
);
149 $this->assertEquals("sms", $this->reminder
->method
);
150 $this->assertEquals("20", $this->reminder
->hours
);