]> git.mxchange.org Git - friendica.git/blob - simplepie/test/functions.php
Add simplepie
[friendica.git] / simplepie / test / functions.php
1 <?php
2
3 require_once 'unit_test/unit_test2.php';
4
5 class SimplePie_Unit_Test2_Group extends Unit_Test2_Group
6 {
7         function pre()
8         {
9                 ob_start();
10         }
11         
12         function post()
13         {
14                 $output = ob_get_contents();
15                 
16                 if ($output !== false)
17                 {
18                         ob_end_clean();
19                 }
20                 
21                 $passed_percentage = floor($this->passes() / $this->total() * 100);
22                 $failed_percentage = ceil($this->fails() / $this->total() * 100);
23                 
24                 echo '<h2 class=' . (($passed_percentage == 100) ? 'pass' : 'fail') . '>' . htmlspecialchars($this->name(), ENT_COMPAT, 'UTF-8') . ': ' . $passed_percentage . "% passed!</h2>\n";
25                 echo "<p>\n$output\n</p>\n";
26                 echo '<p>We ran ' . $this->total() . ' tests in ' . round($this->time(), 3) . ' seconds of which ' . $this->passes() . ' passed, and ' . $this->fails() . ' failed.</p>';
27                 flush();
28         }
29 }
30
31 class SimplePie_Unit_Test2 extends Unit_Test2
32 {
33         function SimplePie_Unit_Test2()
34         {
35                 parent::Unit_Test2();
36                 if (strpos($this->name, 'SimplePie') === 0)
37                 {
38                         $this->name = trim(substr_replace($this->name, '', 0, 9));
39                 }
40         }
41         
42         function output($title, $class, $content)
43         {
44                 printf("<span title='%s' class='%s'>%s</span>\n", $title, $class, $content);
45         }
46         
47         function pass()
48         {
49                 $this->output(htmlspecialchars($this->name(), ENT_COMPAT, 'UTF-8'), 'pass', '&#x2714;');
50                 parent::pass();
51         }
52         
53         function fail()
54         {
55                 $this->output(htmlspecialchars($this->name(), ENT_COMPAT, 'UTF-8'), 'fail', '&#x2718;');
56                 parent::fail();
57         }
58         
59         function result()
60         {
61                 if ($this->result === $this->expected)
62                 {
63                         $this->pass();
64                 }
65                 else
66                 {
67                         $this->fail();
68                 }
69         }
70 }
71
72 class SimplePie_Feed_Test extends SimplePie_Unit_Test2
73 {
74         function feed()
75         {
76                 $feed = new SimplePie();
77                 $feed->set_raw_data($this->data);
78                 $feed->enable_cache(false);
79                 $feed->init();
80                 return $feed;
81         }
82 }
83
84 class SimplePie_Feed_Author_Test extends SimplePie_Feed_Test
85 {
86         function author()
87         {
88                 $feed = $this->feed();
89                 if ($author = $item->get_author())
90                 {
91                         return $author;
92                 }
93                 else
94                 {
95                         return false;
96                 }
97         }
98 }
99
100 class SimplePie_Feed_Category_Test extends SimplePie_Feed_Test
101 {
102         function category()
103         {
104                 $feed = $this->feed();
105                 if ($category = $feed->get_category())
106                 {
107                         return $category;
108                 }
109                 else
110                 {
111                         return false;
112                 }
113         }
114 }
115
116 class SimplePie_First_Item_Test extends SimplePie_Feed_Test
117 {
118         function first_item()
119         {
120                 $feed = $this->feed();
121                 if ($item = $feed->get_item(0))
122                 {
123                         return $item;
124                 }
125                 else
126                 {
127                         return false;
128                 }
129         }
130 }
131
132 class SimplePie_First_Item_Author_Test extends SimplePie_First_Item_Test
133 {
134         function author()
135         {
136                 if ($item = $this->first_item())
137                 {
138                         if ($author = $item->get_author())
139                         {
140                                 return $author;
141                         }
142                 }
143                 return false;
144         }
145 }
146
147 class SimplePie_First_Item_Category_Test extends SimplePie_First_Item_Test
148 {
149         function category()
150         {
151                 if ($item = $this->first_item())
152                 {
153                         if ($category = $item->get_category())
154                         {
155                                 return $category;
156                         }
157                 }
158                 return false;
159         }
160 }
161
162 class SimplePie_First_Item_Contributor_Test extends SimplePie_First_Item_Test
163 {
164         function contributor()
165         {
166                 if ($item = $this->first_item())
167                 {
168                         if ($contributor = $item->get_contributor())
169                         {
170                                 return $contributor;
171                         }
172                 }
173                 return false;
174         }
175 }
176
177 class SimplePie_Absolutize_Test extends SimplePie_Unit_Test2
178 {
179         function test()
180         {
181                 $this->result = SimplePie_Misc::absolutize_url($this->data['relative'], $this->data['base']);
182         }
183 }
184
185 class SimplePie_Date_Test extends SimplePie_Unit_Test2
186 {
187         function test()
188         {
189                 $this->result = SimplePie_Misc::parse_date($this->data);
190         }
191 }
192
193 class SimplePie_Feed_Category_Label_Test extends SimplePie_Feed_Category_Test
194 {
195         function test()
196         {
197                 if ($category = $this->category())
198                 {
199                         $this->result = $category->get_label();
200                 }
201         }
202 }
203
204 class SimplePie_Feed_Copyright_Test extends SimplePie_Feed_Test
205 {
206         function test()
207         {
208                 $feed = $this->feed();
209                 $this->result = $feed->get_copyright();
210         }
211 }
212
213 class SimplePie_Feed_Description_Test extends SimplePie_Feed_Test
214 {
215         function test()
216         {
217                 $feed = $this->feed();
218                 $this->result = $feed->get_description();
219         }
220 }
221
222 class SimplePie_Feed_Image_Height_Test extends SimplePie_Feed_Test
223 {
224         function test()
225         {
226                 $feed = $this->feed();
227                 $this->result = $feed->get_image_height();
228         }
229 }
230
231 class SimplePie_Feed_Image_Link_Test extends SimplePie_Feed_Test
232 {
233         function test()
234         {
235                 $feed = $this->feed();
236                 $this->result = $feed->get_image_link();
237         }
238 }
239
240 class SimplePie_Feed_Image_Title_Test extends SimplePie_Feed_Test
241 {
242         function test()
243         {
244                 $feed = $this->feed();
245                 $this->result = $feed->get_image_title();
246         }
247 }
248
249 class SimplePie_Feed_Image_URL_Test extends SimplePie_Feed_Test
250 {
251         function test()
252         {
253                 $feed = $this->feed();
254                 $this->result = $feed->get_image_url();
255         }
256 }
257
258 class SimplePie_Feed_Image_Width_Test extends SimplePie_Feed_Test
259 {
260         function test()
261         {
262                 $feed = $this->feed();
263                 $this->result = $feed->get_image_width();
264         }
265 }
266
267 class SimplePie_Feed_Language_Test extends SimplePie_Feed_Test
268 {
269         function test()
270         {
271                 $feed = $this->feed();
272                 $this->result = $feed->get_language();
273         }
274 }
275
276 class SimplePie_Feed_Link_Test extends SimplePie_Feed_Test
277 {
278         function test()
279         {
280                 $feed = $this->feed();
281                 $this->result = $feed->get_link();
282         }
283 }
284
285 class SimplePie_Feed_Title_Test extends SimplePie_Feed_Test
286 {
287         function test()
288         {
289                 $feed = $this->feed();
290                 $this->result = $feed->get_title();
291         }
292 }
293
294 class SimplePie_First_Item_Author_Name_Test extends SimplePie_First_Item_Author_Test
295 {
296         function test()
297         {
298                 if ($author = $this->author())
299                 {
300                         $this->result = $author->get_name();
301                 }
302         }
303 }
304
305 class SimplePie_First_Item_Category_Label_Test extends SimplePie_First_Item_Category_Test
306 {
307         function test()
308         {
309                 if ($category = $this->category())
310                 {
311                         $this->result = $category->get_label();
312                 }
313         }
314 }
315
316 class SimplePie_First_Item_Content_Test extends SimplePie_First_Item_Test
317 {
318         function test()
319         {
320                 if ($item = $this->first_item())
321                 {
322                         $this->result = $item->get_content();
323                 }
324         }
325 }
326
327 class SimplePie_First_Item_Contributor_Name_Test extends SimplePie_First_Item_Contributor_Test
328 {
329         function test()
330         {
331                 if ($contributor = $this->contributor())
332                 {
333                         $this->result = $contributor->get_name();
334                 }
335         }
336 }
337
338 class SimplePie_First_Item_Date_Test extends SimplePie_First_Item_Test
339 {
340         function test()
341         {
342                 if ($item = $this->first_item())
343                 {
344                         $this->result = $item->get_date('U');
345                 }
346         }
347 }
348
349 class SimplePie_First_Item_Description_Test extends SimplePie_First_Item_Test
350 {
351         function test()
352         {
353                 if ($item = $this->first_item())
354                 {
355                         $this->result = $item->get_description();
356                 }
357         }
358 }
359
360 class SimplePie_First_Item_ID_Test extends SimplePie_First_Item_Test
361 {
362         function test()
363         {
364                 if ($item = $this->first_item())
365                 {
366                         $this->result = $item->get_id();
367                 }
368         }
369 }
370
371 class SimplePie_First_Item_Latitude_Test extends SimplePie_First_Item_Test
372 {
373         function test()
374         {
375                 if ($item = $this->first_item())
376                 {
377                         $this->result = $item->get_latitude();
378                 }
379         }
380 }
381
382 class SimplePie_First_Item_Longitude_Test extends SimplePie_First_Item_Test
383 {
384         function test()
385         {
386                 if ($item = $this->first_item())
387                 {
388                         $this->result = $item->get_longitude();
389                 }
390         }
391 }
392
393 class SimplePie_First_Item_Permalink_Test extends SimplePie_First_Item_Test
394 {
395         function test()
396         {
397                 if ($item = $this->first_item())
398                 {
399                         $this->result = $item->get_permalink();
400                 }
401         }
402 }
403
404 class SimplePie_First_Item_Title_Test extends SimplePie_First_Item_Test
405 {
406         function test()
407         {
408                 if ($item = $this->first_item())
409                 {
410                         $this->result = $item->get_title();
411                 }
412         }
413 }
414
415 class SimplePie_iTunesRSS_Channel_Block_Test extends SimplePie_First_Item_Test
416 {
417         function test()
418         {
419                 if ($item = $this->first_item())
420                 {
421                         if ($enclosure = $item->get_enclosure())
422                         {
423                                 if ($restriction = $enclosure->get_restriction())
424                                 {
425                                         return $restriction->get_relationship();
426                                 }
427                         }
428                 }
429                 return false;
430         }
431 }
432
433 class diveintomark_Atom_Autodiscovery extends SimplePie_Unit_Test2
434 {
435         var $data = array('url' => 'http://diveintomark.org/tests/client/autodiscovery/');
436         
437         function data()
438         {
439                 $this->data['file'] =& new SimplePie_File($this->data['url'], 10, 5, null, SIMPLEPIE_USERAGENT);
440                 $this->name = $this->data['url'];
441                 $this->data['url'] = false;
442         }
443         
444         function expected()
445         {
446                 $this->expected = $this->data['file']->url;
447         }
448         
449         function test()
450         {
451                 $feed = new SimplePie();
452                 $feed->set_file($this->data['file']);
453                 $feed->enable_cache(false);
454                 $feed->init();
455                 $this->result = $feed->get_link();
456         }
457         
458         function result()
459         {
460                 if ($this->data['file']->url != 'http://diveintomark.org/tests/client/autodiscovery/')
461                 {
462                         parent::result();
463                 }
464                 static $done = array();
465                 $links = SimplePie_Misc::get_element('link', $this->data['file']->body);
466                 foreach ($links as $link)
467                 {
468                         if (!empty($link['attribs']['href']['data']) && !empty($link['attribs']['rel']['data']))
469                         {
470                                 $rel = array_unique(SimplePie_Misc::space_seperated_tokens(strtolower($link['attribs']['rel']['data'])));
471                                 $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->data['file']->url);
472                                 if (!in_array($href, $done) && in_array('next', $rel))
473                                 {
474                                         $done[] = $this->data['url'] = $href;
475                                         break;
476                                 }
477                         }
478                 }
479                 if ($this->data['url'])
480                 {
481                         $this->run();
482                 }
483         }
484 }
485
486 ?>