Mercurial > hg > rc1
comparison vendor/sabre/vobject/tests/VObject/Splitter/VCardTest.php @ 7:430dbd5346f7
vendor sabre as distributed
author | Charlie Root |
---|---|
date | Sat, 13 Jan 2018 09:06:10 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
6:cec75ba50afc | 7:430dbd5346f7 |
---|---|
1 <?php | |
2 | |
3 namespace Sabre\VObject\Splitter; | |
4 | |
5 use Sabre\VObject; | |
6 | |
7 class VCardTest extends \PHPUnit_Framework_TestCase { | |
8 | |
9 function createStream($data) { | |
10 | |
11 $stream = fopen('php://memory','r+'); | |
12 fwrite($stream, $data); | |
13 rewind($stream); | |
14 return $stream; | |
15 | |
16 } | |
17 | |
18 function testVCardImportValidVCard() { | |
19 $data = <<<EOT | |
20 BEGIN:VCARD | |
21 UID:foo | |
22 END:VCARD | |
23 EOT; | |
24 $tempFile = $this->createStream($data); | |
25 | |
26 $objects = new VCard($tempFile); | |
27 | |
28 $count = 0; | |
29 while($objects->getNext()) { | |
30 $count++; | |
31 } | |
32 $this->assertEquals(1, $count); | |
33 | |
34 } | |
35 | |
36 /** | |
37 * @expectedException Sabre\VObject\ParseException | |
38 */ | |
39 function testVCardImportWrongType() { | |
40 $event[] = <<<EOT | |
41 BEGIN:VEVENT | |
42 UID:foo1 | |
43 DTSTAMP:20140122T233226Z | |
44 DTSTART:20140101T050000Z | |
45 END:VEVENT | |
46 EOT; | |
47 | |
48 $event[] = <<<EOT | |
49 BEGIN:VEVENT | |
50 UID:foo2 | |
51 DTSTAMP:20140122T233226Z | |
52 DTSTART:20140101T060000Z | |
53 END:VEVENT | |
54 EOT; | |
55 | |
56 $data = <<<EOT | |
57 BEGIN:VCALENDAR | |
58 $event[0] | |
59 $event[1] | |
60 END:VCALENDAR | |
61 | |
62 EOT; | |
63 $tempFile = $this->createStream($data); | |
64 | |
65 $splitter = new VCard($tempFile); | |
66 | |
67 while($object=$splitter->getNext()) { | |
68 } | |
69 | |
70 } | |
71 | |
72 function testVCardImportValidVCardsWithCategories() { | |
73 $data = <<<EOT | |
74 BEGIN:VCARD | |
75 UID:card-in-foo1-and-foo2 | |
76 CATEGORIES:foo1,foo2 | |
77 END:VCARD | |
78 BEGIN:VCARD | |
79 UID:card-in-foo1 | |
80 CATEGORIES:foo1 | |
81 END:VCARD | |
82 BEGIN:VCARD | |
83 UID:card-in-foo3 | |
84 CATEGORIES:foo3 | |
85 END:VCARD | |
86 BEGIN:VCARD | |
87 UID:card-in-foo1-and-foo3 | |
88 CATEGORIES:foo1\,foo3 | |
89 END:VCARD | |
90 EOT; | |
91 $tempFile = $this->createStream($data); | |
92 | |
93 $splitter = new VCard($tempFile); | |
94 | |
95 $count = 0; | |
96 while($object=$splitter->getNext()) { | |
97 $count++; | |
98 } | |
99 $this->assertEquals(4, $count); | |
100 | |
101 } | |
102 | |
103 function testVCardImportEndOfData() { | |
104 $data = <<<EOT | |
105 BEGIN:VCARD | |
106 UID:foo | |
107 END:VCARD | |
108 EOT; | |
109 $tempFile = $this->createStream($data); | |
110 | |
111 $objects = new VCard($tempFile); | |
112 $object=$objects->getNext(); | |
113 | |
114 $this->assertNull($objects->getNext()); | |
115 | |
116 | |
117 } | |
118 | |
119 /** | |
120 * @expectedException \Sabre\VObject\ParseException | |
121 */ | |
122 function testVCardImportCheckInvalidArgumentException() { | |
123 $data = <<<EOT | |
124 BEGIN:FOO | |
125 END:FOO | |
126 EOT; | |
127 $tempFile = $this->createStream($data); | |
128 | |
129 $objects = new VCard($tempFile); | |
130 while($objects->getNext()) { } | |
131 | |
132 } | |
133 | |
134 function testVCardImportMultipleValidVCards() { | |
135 $data = <<<EOT | |
136 BEGIN:VCARD | |
137 UID:foo | |
138 END:VCARD | |
139 BEGIN:VCARD | |
140 UID:foo | |
141 END:VCARD | |
142 EOT; | |
143 $tempFile = $this->createStream($data); | |
144 | |
145 $objects = new VCard($tempFile); | |
146 | |
147 $count = 0; | |
148 while($objects->getNext()) { | |
149 $count++; | |
150 } | |
151 $this->assertEquals(2, $count); | |
152 | |
153 } | |
154 | |
155 function testImportMultipleSeparatedWithNewLines() { | |
156 $data = <<<EOT | |
157 BEGIN:VCARD | |
158 UID:foo | |
159 END:VCARD | |
160 | |
161 | |
162 BEGIN:VCARD | |
163 UID:foo | |
164 END:VCARD | |
165 | |
166 | |
167 EOT; | |
168 $tempFile = $this->createStream($data); | |
169 $objects = new VCard($tempFile); | |
170 | |
171 $count = 0; | |
172 while ($objects->getNext()) { | |
173 $count++; | |
174 } | |
175 $this->assertEquals(2, $count); | |
176 } | |
177 | |
178 function testVCardImportVCardWithoutUID() { | |
179 $data = <<<EOT | |
180 BEGIN:VCARD | |
181 END:VCARD | |
182 EOT; | |
183 $tempFile = $this->createStream($data); | |
184 | |
185 $objects = new VCard($tempFile); | |
186 | |
187 $count = 0; | |
188 while($objects->getNext()) { | |
189 $count++; | |
190 } | |
191 | |
192 $this->assertEquals(1, $count); | |
193 } | |
194 | |
195 } |