annotate vendor/sabre/vobject/tests/VObject/PropertyTest.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
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 class PropertyTest extends \PHPUnit_Framework_TestCase {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 public function testToString() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 $this->assertEquals('PROPNAME', $property->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 $this->assertEquals('propvalue', $property->__toString());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 $this->assertEquals('propvalue', (string)$property);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 $this->assertEquals('propvalue', $property->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 public function testCreate() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 $params = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 'param1' => 'value1',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 'param2' => 'value2',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 $property = $cal->createProperty('propname','propvalue', $params);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 $this->assertEquals('value1', $property['param1']->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 $this->assertEquals('value2', $property['param2']->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 public function testSetValue() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 $property->setValue('value2');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 $this->assertEquals('PROPNAME', $property->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 $this->assertEquals('value2', $property->__toString());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47
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 public function testParameterExists() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 $property['paramname'] = 'paramvalue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 $this->assertTrue(isset($property['PARAMNAME']));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 $this->assertTrue(isset($property['paramname']));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 $this->assertFalse(isset($property['foo']));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 public function testParameterGet() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 $property['paramname'] = 'paramvalue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 $this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 public function testParameterNotExists() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 $property['paramname'] = 'paramvalue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 $this->assertInternalType('null',$property['foo']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 public function testParameterMultiple() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 $property['paramname'] = 'paramvalue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 $property->add('paramname', 'paramvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 $this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 $this->assertEquals(2,count($property['paramname']->getParts()));
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
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 public function testSetParameterAsString() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 $property['paramname'] = 'paramvalue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 $this->assertEquals(1,count($property->parameters()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 $this->assertInstanceOf('Sabre\\VObject\\Parameter', $property->parameters['PARAMNAME']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 $this->assertEquals('PARAMNAME',$property->parameters['PARAMNAME']->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 $this->assertEquals('paramvalue',$property->parameters['PARAMNAME']->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 public function testUnsetParameter() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 $property['paramname'] = 'paramvalue';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113 unset($property['PARAMNAME']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 $this->assertEquals(0,count($property->parameters()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 public function testSerialize() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 $this->assertEquals("PROPNAME:propvalue\r\n",$property->serialize());
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
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 public function testSerializeParam() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 $property = $cal->createProperty('propname','propvalue', array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 'paramname' => 'paramvalue',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132 'paramname2' => 'paramvalue2',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 $this->assertEquals("PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propvalue\r\n",$property->serialize());
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 public function testSerializeNewLine() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 $property = $cal->createProperty('SUMMARY',"line1\nline2");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 $this->assertEquals("SUMMARY:line1\\nline2\r\n",$property->serialize());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 public function testSerializeLongLine() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 $value = str_repeat('!',200);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 $property = $cal->createProperty('propname',$value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 $expected = "PROPNAME:" . str_repeat('!',66) . "\r\n " . str_repeat('!',74) . "\r\n " . str_repeat('!',60) . "\r\n";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 $this->assertEquals($expected,$property->serialize());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 public function testSerializeUTF8LineFold() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163 $value = str_repeat('!',65) . "\xc3\xa4bla"; // inserted umlaut-a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 $property = $cal->createProperty('propname', $value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165 $expected = "PROPNAME:" . str_repeat('!',65) . "\r\n \xc3\xa4bla\r\n";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 $this->assertEquals($expected, $property->serialize());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 public function testGetIterator() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 $it = new ElementList(array());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 $property->setIterator($it);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 $this->assertEquals($it,$property->getIterator());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 public function testGetIteratorDefault() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 $property = $cal->createProperty('propname','propvalue');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185 $it = $property->getIterator();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186 $this->assertTrue($it instanceof ElementList);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 $this->assertEquals(1,count($it));
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 function testAddScalar() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 $property = $cal->createProperty('EMAIL');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 $property->add('myparam','value');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 $this->assertEquals(1, count($property->parameters()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 $this->assertTrue($property->parameters['MYPARAM'] instanceof Parameter);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 $this->assertEquals('MYPARAM',$property->parameters['MYPARAM']->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 $this->assertEquals('value',$property->parameters['MYPARAM']->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 function testAddParameter() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 $prop = $cal->createProperty('EMAIL');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 $prop->add('MYPARAM','value');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 $this->assertEquals(1, count($prop->parameters()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 $this->assertEquals('MYPARAM',$prop['myparam']->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 function testAddParameterTwice() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 $prop = $cal->createProperty('EMAIL');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 $prop->add('MYPARAM', 'value1');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 $prop->add('MYPARAM', 'value2');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 $this->assertEquals(1, count($prop->parameters));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227 $this->assertEquals(2, count($prop->parameters['MYPARAM']->getParts()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 $this->assertEquals('MYPARAM',$prop['MYPARAM']->name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 function testClone() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 $property = $cal->createProperty('EMAIL','value');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 $property['FOO'] = 'BAR';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 $property2 = clone $property;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 $property['FOO'] = 'BAZ';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 $this->assertEquals('BAR', (string)$property2['FOO']);
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 function testCreateParams() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 $cal = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 $property = $cal->createProperty('X-PROP','value', array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 'param1' => 'value1',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 'param2' => array('value2', 'value3')
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 ));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 $this->assertEquals(1, count($property['PARAM1']->getParts()));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 $this->assertEquals(2, count($property['PARAM2']->getParts()));
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 testValidateNonUTF8() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 $calendar = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263 $property = $calendar->createProperty('X-PROP', "Bla\x00");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 $result = $property->validate(Property::REPAIR);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266 $this->assertEquals('Property contained a control character (0x00)', $result[0]['message']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 $this->assertEquals('Bla', $property->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 function testValidateControlChars() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 $s = "chars[";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274 foreach (array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 0x7F, 0x5E, 0x5C, 0x3B, 0x3A, 0x2C, 0x22, 0x20,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280 ) as $c) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 $s .= sprintf('%02X(%c)', $c, $c);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 $s .= "]end";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 $calendar = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286 $property = $calendar->createProperty('X-PROP', $s);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287 $result = $property->validate(Property::REPAIR);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289 $this->assertEquals('Property contained a control character (0x7f)', $result[0]['message']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
290 $this->assertEquals("chars[7F()5E(^)5C(\\\\)3B(\\;)3A(:)2C(\\,)22(\")20( )1F()1E()1D()1C()1B()1A()19()18()17()16()15()14()13()12()11()10()0F()0E()0D()0C()0B()0A(\\n)09( )08()07()06()05()04()03()02()01()00()]end", $property->getRawMimeDirValue());
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
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 function testValidateBadPropertyName() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
297 $calendar = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
298 $property = $calendar->createProperty("X_*&PROP*", "Bla");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
299 $result = $property->validate(Property::REPAIR);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
300
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
301 $this->assertEquals($result[0]['message'], 'The propertyname: X_*&PROP* contains invalid characters. Only A-Z, 0-9 and - are allowed');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 $this->assertEquals('X-PROP', $property->name);
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
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306 function testGetValue() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308 $calendar = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309 $property = $calendar->createProperty("SUMMARY", null);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310 $this->assertEquals(array(), $property->getParts());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311 $this->assertNull($property->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313 $property->setValue(array());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314 $this->assertEquals(array(), $property->getParts());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315 $this->assertNull($property->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 $property->setValue(array(1));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318 $this->assertEquals(array(1), $property->getParts());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319 $this->assertEquals(1, $property->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321 $property->setValue(array(1,2));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322 $this->assertEquals(array(1,2), $property->getParts());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323 $this->assertEquals('1,2', $property->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325 $property->setValue('str');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326 $this->assertEquals(array('str'), $property->getParts());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327 $this->assertEquals('str', $property->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331 * ElementList should reject this.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333 * @expectedException \LogicException
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
334 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
335 public function testArrayAccessSetInt() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
336
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
337 $calendar = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
338 $property = $calendar->createProperty("X-PROP", null);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
339
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
340 $calendar->add($property);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
341 $calendar->{'X-PROP'}[0] = 'Something!';
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 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
346 * ElementList should reject this.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
347 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
348 * @expectedException \LogicException
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
349 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
350 public function testArrayAccessUnsetInt() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
351
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
352 $calendar = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
353 $property = $calendar->createProperty("X-PROP", null);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
354
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
355 $calendar->add($property);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
356 unset($calendar->{'X-PROP'}[0]);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
357
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
358 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
359
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
360 }