ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VCardTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\VObject\Splitter;
4 
6 
7 class VCardTest extends 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 
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 
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 
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 
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 
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 
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 
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 
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 }
$stream
PHP stream implementation.
The VCard component.
Definition: VCard.php:18
$data
Definition: bench.php:6