3 require_once 'unit_test/unit_test2.php';
5 class SimplePie_Unit_Test2_Group extends Unit_Test2_Group
14 $output = ob_get_contents();
16 if ($output !== false)
21 $passed_percentage = floor($this->passes() / $this->total() * 100);
22 $failed_percentage = ceil($this->fails() / $this->total() * 100);
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>';
31 class SimplePie_Unit_Test2 extends Unit_Test2
33 function SimplePie_Unit_Test2()
36 if (strpos($this->name, 'SimplePie') === 0)
38 $this->name = trim(substr_replace($this->name, '', 0, 9));
42 function output($title, $class, $content)
44 printf("<span title='%s' class='%s'>%s</span>\n", $title, $class, $content);
49 $this->output(htmlspecialchars($this->name(), ENT_COMPAT, 'UTF-8'), 'pass', '✔');
55 $this->output(htmlspecialchars($this->name(), ENT_COMPAT, 'UTF-8'), 'fail', '✘');
61 if ($this->result === $this->expected)
72 class SimplePie_Feed_Test extends SimplePie_Unit_Test2
76 $feed = new SimplePie();
77 $feed->set_raw_data($this->data);
78 $feed->enable_cache(false);
84 class SimplePie_Feed_Author_Test extends SimplePie_Feed_Test
88 $feed = $this->feed();
89 if ($author = $item->get_author())
100 class SimplePie_Feed_Category_Test extends SimplePie_Feed_Test
104 $feed = $this->feed();
105 if ($category = $feed->get_category())
116 class SimplePie_First_Item_Test extends SimplePie_Feed_Test
118 function first_item()
120 $feed = $this->feed();
121 if ($item = $feed->get_item(0))
132 class SimplePie_First_Item_Author_Test extends SimplePie_First_Item_Test
136 if ($item = $this->first_item())
138 if ($author = $item->get_author())
147 class SimplePie_First_Item_Category_Test extends SimplePie_First_Item_Test
151 if ($item = $this->first_item())
153 if ($category = $item->get_category())
162 class SimplePie_First_Item_Contributor_Test extends SimplePie_First_Item_Test
164 function contributor()
166 if ($item = $this->first_item())
168 if ($contributor = $item->get_contributor())
177 class SimplePie_Absolutize_Test extends SimplePie_Unit_Test2
181 $this->result = SimplePie_Misc::absolutize_url($this->data['relative'], $this->data['base']);
185 class SimplePie_Date_Test extends SimplePie_Unit_Test2
189 $this->result = SimplePie_Misc::parse_date($this->data);
193 class SimplePie_Feed_Category_Label_Test extends SimplePie_Feed_Category_Test
197 if ($category = $this->category())
199 $this->result = $category->get_label();
204 class SimplePie_Feed_Copyright_Test extends SimplePie_Feed_Test
208 $feed = $this->feed();
209 $this->result = $feed->get_copyright();
213 class SimplePie_Feed_Description_Test extends SimplePie_Feed_Test
217 $feed = $this->feed();
218 $this->result = $feed->get_description();
222 class SimplePie_Feed_Image_Height_Test extends SimplePie_Feed_Test
226 $feed = $this->feed();
227 $this->result = $feed->get_image_height();
231 class SimplePie_Feed_Image_Link_Test extends SimplePie_Feed_Test
235 $feed = $this->feed();
236 $this->result = $feed->get_image_link();
240 class SimplePie_Feed_Image_Title_Test extends SimplePie_Feed_Test
244 $feed = $this->feed();
245 $this->result = $feed->get_image_title();
249 class SimplePie_Feed_Image_URL_Test extends SimplePie_Feed_Test
253 $feed = $this->feed();
254 $this->result = $feed->get_image_url();
258 class SimplePie_Feed_Image_Width_Test extends SimplePie_Feed_Test
262 $feed = $this->feed();
263 $this->result = $feed->get_image_width();
267 class SimplePie_Feed_Language_Test extends SimplePie_Feed_Test
271 $feed = $this->feed();
272 $this->result = $feed->get_language();
276 class SimplePie_Feed_Link_Test extends SimplePie_Feed_Test
280 $feed = $this->feed();
281 $this->result = $feed->get_link();
285 class SimplePie_Feed_Title_Test extends SimplePie_Feed_Test
289 $feed = $this->feed();
290 $this->result = $feed->get_title();
294 class SimplePie_First_Item_Author_Name_Test extends SimplePie_First_Item_Author_Test
298 if ($author = $this->author())
300 $this->result = $author->get_name();
305 class SimplePie_First_Item_Category_Label_Test extends SimplePie_First_Item_Category_Test
309 if ($category = $this->category())
311 $this->result = $category->get_label();
316 class SimplePie_First_Item_Content_Test extends SimplePie_First_Item_Test
320 if ($item = $this->first_item())
322 $this->result = $item->get_content();
327 class SimplePie_First_Item_Contributor_Name_Test extends SimplePie_First_Item_Contributor_Test
331 if ($contributor = $this->contributor())
333 $this->result = $contributor->get_name();
338 class SimplePie_First_Item_Date_Test extends SimplePie_First_Item_Test
342 if ($item = $this->first_item())
344 $this->result = $item->get_date('U');
349 class SimplePie_First_Item_Description_Test extends SimplePie_First_Item_Test
353 if ($item = $this->first_item())
355 $this->result = $item->get_description();
360 class SimplePie_First_Item_ID_Test extends SimplePie_First_Item_Test
364 if ($item = $this->first_item())
366 $this->result = $item->get_id();
371 class SimplePie_First_Item_Latitude_Test extends SimplePie_First_Item_Test
375 if ($item = $this->first_item())
377 $this->result = $item->get_latitude();
382 class SimplePie_First_Item_Longitude_Test extends SimplePie_First_Item_Test
386 if ($item = $this->first_item())
388 $this->result = $item->get_longitude();
393 class SimplePie_First_Item_Permalink_Test extends SimplePie_First_Item_Test
397 if ($item = $this->first_item())
399 $this->result = $item->get_permalink();
404 class SimplePie_First_Item_Title_Test extends SimplePie_First_Item_Test
408 if ($item = $this->first_item())
410 $this->result = $item->get_title();
415 class SimplePie_iTunesRSS_Channel_Block_Test extends SimplePie_First_Item_Test
419 if ($item = $this->first_item())
421 if ($enclosure = $item->get_enclosure())
423 if ($restriction = $enclosure->get_restriction())
425 return $restriction->get_relationship();
433 class diveintomark_Atom_Autodiscovery extends SimplePie_Unit_Test2
435 var $data = array('url' => 'http://diveintomark.org/tests/client/autodiscovery/');
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;
446 $this->expected = $this->data['file']->url;
451 $feed = new SimplePie();
452 $feed->set_file($this->data['file']);
453 $feed->enable_cache(false);
455 $this->result = $feed->get_link();
460 if ($this->data['file']->url != 'http://diveintomark.org/tests/client/autodiscovery/')
464 static $done = array();
465 $links = SimplePie_Misc::get_element('link', $this->data['file']->body);
466 foreach ($links as $link)
468 if (!empty($link['attribs']['href']['data']) && !empty($link['attribs']['rel']['data']))
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))
474 $done[] = $this->data['url'] = $href;
479 if ($this->data['url'])