annotate vendor/sabre/vobject/tests/VObject/ComponentTest.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 Sabre\VObject\Component\VCalendar,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 Sabre\VObject\Component\VCard;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 class ComponentTest extends \PHPUnit_Framework_TestCase {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 function testIterate() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 $sub = $comp->createComponent('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 $sub = $comp->createComponent('VTODO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 $count = 0;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 foreach($comp->children() as $key=>$subcomponent) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 $count++;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 $this->assertInstanceOf('Sabre\\VObject\\Component',$subcomponent);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 $this->assertEquals(2,$count);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 $this->assertEquals(1,$key);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 function testMagicGet() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 $sub = $comp->createComponent('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 $sub = $comp->createComponent('VTODO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 $event = $comp->vevent;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 $this->assertInstanceOf('Sabre\\VObject\\Component', $event);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 $this->assertEquals('VEVENT', $event->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 $this->assertInternalType('null', $comp->vjournal);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 function testMagicGetGroups() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 $comp = new VCard();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 $sub = $comp->createProperty('GROUP1.EMAIL','1@1.com');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 $sub = $comp->createProperty('GROUP2.EMAIL','2@2.com');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 $sub = $comp->createProperty('EMAIL','3@3.com');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 $emails = $comp->email;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 $this->assertEquals(3, count($emails));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 $email1 = $comp->{"group1.email"};
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 $this->assertEquals('EMAIL', $email1[0]->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 $this->assertEquals('GROUP1', $email1[0]->group);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 $email3 = $comp->{".email"};
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 $this->assertEquals('EMAIL', $email3[0]->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 $this->assertEquals(null, $email3[0]->group);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 function testMagicIsset() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 $sub = $comp->createComponent('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 $sub = $comp->createComponent('VTODO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 $comp->add($sub);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 $this->assertTrue(isset($comp->vevent));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 $this->assertTrue(isset($comp->vtodo));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 $this->assertFalse(isset($comp->vjournal));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 function testMagicSetScalar() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 $comp->myProp = 'myValue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 $this->assertInstanceOf('Sabre\\VObject\\Property',$comp->MYPROP);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 $this->assertEquals('myValue',(string)$comp->MYPROP);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 function testMagicSetScalarTwice() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 $comp->myProp = 'myValue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 $comp->myProp = 'myValue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 $this->assertEquals(1,count($comp->children()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 $this->assertInstanceOf('Sabre\\VObject\\Property',$comp->MYPROP);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112 $this->assertEquals('myValue',(string)$comp->MYPROP);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 function testMagicSetArray() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 $comp->ORG = array('Acme Inc', 'Section 9');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 $this->assertInstanceOf('Sabre\\VObject\\Property',$comp->ORG);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 $this->assertEquals(array('Acme Inc', 'Section 9'),$comp->ORG->getParts());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 function testMagicSetComponent() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 // Note that 'myProp' is ignored here.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 $comp->myProp = $comp->createComponent('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 $this->assertEquals(1, count($comp));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 $this->assertEquals('VEVENT',$comp->VEVENT->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139 function testMagicSetTwice() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 $comp->VEVENT = $comp->createComponent('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 $comp->VEVENT = $comp->createComponent('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 $this->assertEquals(1, count($comp->children()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 $this->assertEquals('VEVENT',$comp->VEVENT->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 function testArrayAccessGet() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 $event = $comp->createComponent('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157 $event->summary = 'Event 1';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 $comp->add($event);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 $event2 = clone $event;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 $event2->summary = 'Event 2';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 $comp->add($event2);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 $this->assertEquals(2,count($comp->children()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 $this->assertTrue($comp->vevent[1] instanceof Component);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 $this->assertEquals('Event 2', (string)$comp->vevent[1]->summary);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 function testArrayAccessExists() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 $event = $comp->createComponent('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 $event->summary = 'Event 1';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 $comp->add($event);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 $event2 = clone $event;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182 $event2->summary = 'Event 2';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 $comp->add($event2);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186 $this->assertTrue(isset($comp->vevent[0]));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 $this->assertTrue(isset($comp->vevent[1]));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 * @expectedException LogicException
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 function testArrayAccessSet() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 $comp['hey'] = 'hi there';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 * @expectedException LogicException
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203 function testArrayAccessUnset() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 unset($comp[0]);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 function testAddScalar() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 $comp->add('myprop','value');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 $this->assertEquals(1, count($comp->children()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 $bla = $comp->children[0];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 $this->assertTrue($bla instanceof Property);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 $this->assertEquals('MYPROP',$bla->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 $this->assertEquals('value',(string)$bla);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 function testAddScalarParams() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 $comp->add('myprop','value',array('param1'=>'value1'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 $this->assertEquals(1, count($comp->children()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 $bla = $comp->children[0];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 $this->assertInstanceOf('Sabre\\VObject\\Property', $bla);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 $this->assertEquals('MYPROP',$bla->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 $this->assertEquals('value', (string)$bla);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 $this->assertEquals(1, count($bla->parameters()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 $this->assertEquals('PARAM1',$bla->parameters['PARAM1']->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 $this->assertEquals('value1',$bla->parameters['PARAM1']->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 function testAddComponent() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 $comp->add($comp->createComponent('VEVENT'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 $this->assertEquals(1, count($comp->children()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 $this->assertEquals('VEVENT',$comp->VEVENT->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 function testAddComponentTwice() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 $comp->add($comp->createComponent('VEVENT'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 $comp->add($comp->createComponent('VEVENT'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 $this->assertEquals(2, count($comp->children()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 $this->assertEquals('VEVENT',$comp->VEVENT->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274 * @expectedException InvalidArgumentException
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 function testAddArgFail() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 $comp->add($comp->createComponent('VEVENT'),'hello');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284 * @expectedException InvalidArgumentException
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286 function testAddArgFail2() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289 $comp->add(array());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
290
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
291 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
292
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
293 function testMagicUnset() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296 $comp->add($comp->createComponent('VEVENT'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
297
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
298 unset($comp->vevent);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
299
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
300 $this->assertEquals(0, count($comp->children()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
301
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
303
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
304
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
305 function testCount() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308 $this->assertEquals(1,$comp->count());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312 function testChildren() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316 // Note that 'myProp' is ignored here.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 $comp->add($comp->createComponent('VEVENT'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318 $comp->add($comp->createComponent('VTODO'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320 $r = $comp->children();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321 $this->assertInternalType('array', $r);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322 $this->assertEquals(2,count($r));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325 function testGetComponents() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329 $comp->add($comp->createProperty('FOO','BAR'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330 $comp->add($comp->createComponent('VTODO'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 $r = $comp->getComponents();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333 $this->assertInternalType('array', $r);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
334 $this->assertEquals(1, count($r));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
335 $this->assertEquals('VTODO', $r[0]->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
336 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
337
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
338 function testSerialize() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
339
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
340 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
341 $this->assertEquals("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", $comp->serialize());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
342
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
343 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
344
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
345 function testSerializeChildren() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
346
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
347 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
348 $event = $comp->add($comp->createComponent('VEVENT'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
349 unset($event->DTSTAMP, $event->UID);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
350 $comp->add($comp->createComponent('VTODO'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
351
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
352 $str = $comp->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
353
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
354 $this->assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n", $str);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
355
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
356 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
357
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
358 function testSerializeOrderCompAndProp() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
359
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
360 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
361 $comp->add($event = $comp->createComponent('VEVENT'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
362 $comp->add('PROP1','BLABLA');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
363 $comp->add('VERSION','2.0');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
364 $comp->add($comp->createComponent('VTIMEZONE'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
365
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
366 unset($event->DTSTAMP, $event->UID);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
367 $str = $comp->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
368
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
369 $this->assertEquals("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPROP1:BLABLA\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $str);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
370
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
371 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
372
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
373 function testAnotherSerializeOrderProp() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
374
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
375 $prop4s=array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
376
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
377 $comp = new VCard(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
378
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
379 $comp->__set('SOMEPROP','FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
380 $comp->__set('ANOTHERPROP','FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
381 $comp->__set('THIRDPROP','FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
382 foreach ($prop4s as $prop4) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
383 $comp->add('PROP4', 'FOO '.$prop4);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
384 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
385 $comp->__set('PROPNUMBERFIVE', 'FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
386 $comp->__set('PROPNUMBERSIX', 'FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
387 $comp->__set('PROPNUMBERSEVEN', 'FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
388 $comp->__set('PROPNUMBEREIGHT', 'FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
389 $comp->__set('PROPNUMBERNINE', 'FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
390 $comp->__set('PROPNUMBERTEN', 'FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
391 $comp->__set('VERSION','2.0');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
392 $comp->__set('UID', 'FOO');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
393
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
394 $str = $comp->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
395
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
396 $this->assertEquals("BEGIN:VCARD\r\nVERSION:2.0\r\nSOMEPROP:FOO\r\nANOTHERPROP:FOO\r\nTHIRDPROP:FOO\r\nPROP4:FOO 1\r\nPROP4:FOO 2\r\nPROP4:FOO 3\r\nPROP4:FOO 4\r\nPROP4:FOO 5\r\nPROP4:FOO 6\r\nPROP4:FOO 7\r\nPROP4:FOO 8\r\nPROP4:FOO 9\r\nPROP4:FOO 10\r\nPROPNUMBERFIVE:FOO\r\nPROPNUMBERSIX:FOO\r\nPROPNUMBERSEVEN:FOO\r\nPROPNUMBEREIGHT:FOO\r\nPROPNUMBERNINE:FOO\r\nPROPNUMBERTEN:FOO\r\nUID:FOO\r\nEND:VCARD\r\n", $str);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
397
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
398 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
399
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
400 function testInstantiateWithChildren() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
401
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
402 $comp = new VCard(array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
403 'ORG' => array('Acme Inc.', 'Section 9'),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
404 'FN' => 'Finn The Human',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
405 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
406
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
407 $this->assertEquals(array('Acme Inc.', 'Section 9'), $comp->ORG->getParts());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
408 $this->assertEquals('Finn The Human', $comp->FN->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
409
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
410 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
411
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
412 function testInstantiateSubComponent() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
413
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
414 $comp = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
415 $event = $comp->createComponent('VEVENT', array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
416 $comp->createProperty('UID', '12345'),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
417 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
418 $comp->add($event);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
419
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
420 $this->assertEquals('12345', $comp->VEVENT->UID->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
421
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
422 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
423
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
424 function testRemoveByName() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
425
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
426 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
427 $comp->add('prop1','val1');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
428 $comp->add('prop2','val2');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
429 $comp->add('prop2','val2');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
430
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
431 $comp->remove('prop2');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
432 $this->assertFalse(isset($comp->prop2));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
433 $this->assertTrue(isset($comp->prop1));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
434
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
435 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
436
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
437 function testRemoveByObj() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
438
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
439 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
440 $comp->add('prop1','val1');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
441 $prop = $comp->add('prop2','val2');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
442
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
443 $comp->remove($prop);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
444 $this->assertFalse(isset($comp->prop2));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
445 $this->assertTrue(isset($comp->prop1));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
446
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
447 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
448
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
449 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
450 * @expectedException InvalidArgumentException
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
451 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
452 function testRemoveNotFound() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
453
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
454 $comp = new VCalendar(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
455 $prop = $comp->createProperty('A','B');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
456 $comp->remove($prop);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
457
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
458 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
459
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
460 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
461 * @dataProvider ruleData
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
462 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
463 function testValidateRules($componentList, $errorCount) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
464
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
465 $vcard = new Component\VCard();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
466
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
467 $component = new FakeComponent($vcard,'Hi', array(), $defaults = false );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
468 foreach($componentList as $v) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
469 $component->add($v,'Hello.');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
470 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
471
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
472 $this->assertEquals($errorCount, count($component->validate()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
473
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
474 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
475
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
476 function testValidateRepair() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
477
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
478 $vcard = new Component\VCard();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
479
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
480 $component = new FakeComponent($vcard,'Hi', array(), $defaults = false );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
481 $component->validate(Component::REPAIR);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
482 $this->assertEquals('yow', $component->BAR->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
483
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
484 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
485
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
486 function ruleData() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
487
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
488 return array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
489
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
490 array(array(), 2),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
491 array(array('FOO'), 3),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
492 array(array('BAR'), 1),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
493 array(array('BAZ'), 1),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
494 array(array('BAR','BAZ'), 0),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
495 array(array('BAR','BAZ','ZIM',), 0),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
496 array(array('BAR','BAZ','ZIM','GIR'), 0),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
497 array(array('BAR','BAZ','ZIM','GIR','GIR'), 1),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
498
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
499 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
500
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
501 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
502
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
503 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
504
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
505 class FakeComponent extends Component {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
506
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
507 public function getValidationRules() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
508
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
509 return array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
510 'FOO' => '0',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
511 'BAR' => '1',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
512 'BAZ' => '+',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
513 'ZIM' => '*',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
514 'GIR' => '?',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
515 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
516
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
517 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
518
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
519 public function getDefaults() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
520
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
521 return array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
522 'BAR' => 'yow',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
523 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
524
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
525 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
526
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
527 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
528