function test_missingElement() { $file = '<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <title>sample blog</title> <link>http://www.example.com/</link> <description>sample rss2 feed</description> <language>en</language> <copyright>Copyright 2006</copyright> <lastBuildDate>Tue, 25 Jul 2006 11:53:38 -0500</lastBuildDate> <generator>http://www.sixapart.com/movabletype/?v=3.31</generator> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <item> <title>A sample entry</title> <description>Sample content</description> <link>http://www.example.com/archives/2006/07</link> <guid>http://www.example.com/archives/2006/07</guid> <category>Examples</category> <pubDate>Tue, 25 Jul 2006 11:53:38 -0500</pubDate> </item> </channel></rss>'; $feed = new XML_Feed_Parser($file, false, true); $entry = $feed->getEntryByOffset(0); $this->assertFalse($entry->enclosure()); }
function test_handlesMultipleEnclosuresInAtom() { $xml = file_get_contents($this->sample_dir . "/bug12844-atom.xml"); $feed = new XML_Feed_Parser($xml); $entry = $feed->getEntryByOffset(0); $first = $entry->enclosure(0); $second = $entry->enclosure(1); $this->assertEquals('http://example.org/audio/ph34r_my_podcast.mp3', $first['url']); $this->assertEquals('http://example.org/audio/ph34r_my_podcast2.mp3', $second['url']); }
/** * Try to work with this ill-formed feed. If the tidy extension is not installed, * it expects parsing to fail. If tidy is installed and parsing fails, the test * fails. If tidy is installed and it parses, then the test passes. */ function test_Tidy() { if (!extension_loaded('tidy')) { $this->markTestSkipped("You need the tidy extension installed to run this test"); } $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); $file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "illformed_atom10.xml"); $feed = new XML_Feed_Parser($file, false, true, true); $entry = $feed->getEntryByOffset(0); $this->assertEquals($entry->author, 'Example author'); }
function test_Base() { $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); $file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "xmlbase.xml"); try { $feed = new XML_Feed_Parser($file, false, true, true); } catch (XML_Feed_Parser_Exception $e) { $this->assertTrue(false); } $entry = $feed->getEntryByOffset(0); $this->assertEquals($entry->link, 'http://www.tbray.org/ongoing/When/200x/2006/02/17/FSS'); }
/** * Try to work with this ill-formed feed. If the tidy extension is not installed, * it expects parsing to fail. If tidy is installed and parsing fails, the test * fails. If tidy is installed and it parses, then the test passes. */ function test_Tidy() { $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); $file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "illformed_atom10.xml"); try { $feed = new XML_Feed_Parser($file, false, true, true); } catch (XML_Feed_Parser_Exception $e) { if (extension_loaded('tidy')) { $this->assertTrue(false); } else { $this->assertTrue(true); } return; } $entry = $feed->getEntryByOffset(0); $this->assertEquals($entry->author, 'Example author'); }
function hookLeftColumn($params) { // Conf $title = strval(Configuration::get('RSS_FEED_TITLE')); $url = strval(Configuration::get('RSS_FEED_URL')); $nb = (int) Configuration::get('RSS_FEED_NBR'); $cacheId = $this->getCacheId($this->name . '-' . date("YmdH")); if (!$this->isCached('blockrss.tpl', $cacheId)) { // Getting data $rss_links = array(); if ($url && ($contents = Tools::file_get_contents($url))) { try { if (@($src = new XML_Feed_Parser($contents))) { for ($i = 0; $i < ($nb ? $nb : 5); $i++) { if (@($item = $src->getEntryByOffset($i))) { $xmlValues = array(); foreach (self::$xmlFields as $xmlField) { $xmlValues[$xmlField] = $item->__get($xmlField); } $xmlValues['enclosure'] = $item->getEnclosure(); // First image if (isset($xmlValues['content']) && $xmlValues['content']) { preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/', $xmlValues['content'], $image); if (array_key_exists(1, $image) && $image[1]) { // Try if distant image exist : timeout 0.3s $context = stream_context_create(array('http' => array('timeout' => 0.3))); if (file_get_contents($image[1], false, $context, -1, 1) !== false) { $xmlValues['image'] = $image[1]; } } } // Compatibility $xmlValues['url'] = $xmlValues['link']; $rss_links[] = $xmlValues; } } } } catch (XML_Feed_Parser_Exception $e) { Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false); } } // Display smarty $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links)); } return $this->display(__FILE__, 'blockrss.tpl', $cacheId); }
function hookLeftColumn($params) { // Conf $title = strval(Configuration::get('RSS_FEED_TITLE')); $url = strval(Configuration::get('RSS_FEED_URL')); $nb = (int) Configuration::get('RSS_FEED_NBR'); // Getting data $rss_links = array(); if ($url && ($contents = @file_get_contents($url))) { try { if (@($src = new XML_Feed_Parser($contents))) { for ($i = 0; $i < ($nb ? $nb : 5); $i++) { if (@($item = $src->getEntryByOffset($i))) { $rss_links[] = array('title' => $item->title, 'url' => $item->link); } } } } catch (XML_Feed_Parser_Exception $e) { Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false); } } // Display smarty $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links)); return $this->display(__FILE__, 'blockrss.tpl'); }
function test_item_xhtml_body_type_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/rss/item_xhtml_body_type.xml'); $feed = new XML_Feed_Parser($content); $this->assertEquals('application/xhtml+xml', $feed->getEntryByOffset(0)->content(0, 'type')); }
function test_entry_title_text_plain_brackets_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/atom/entry_title_text_plain_brackets.xml'); $feed = new XML_Feed_Parser($content); $this->assertEquals('History of the <blink> tag', $feed->getEntryByOffset(0)->title); }
function test_item_xhtml_body_xml_lang_inherit_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/lang/item_xhtml_body_xml_lang_inherit.xml'); $feed = new XML_Feed_Parser($content); $this->assertEquals('en', $feed->getEntryByOffset(0)->content(0, 'language')); }
function testEntryLink() { foreach ($this->files as $file) { $contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file); $feed = new XML_Feed_Parser($contents); $entry = $feed->getEntryByOffset(0); $this->assertEquals($entry->link, $entry->link()); } }
function test_getsLinkWithoutRel() { $source = '<?xml version="1.0" ?> <entry xmlns="http://www.w3.org/2005/Atom"> <link href="http://example.org/2005/04/02/atom" /> </entry> '; $feed = new XML_Feed_Parser($source); $entry = $feed->getEntryByOffset(0); // Output $this->assertEquals("http://example.org/2005/04/02/atom", $entry->link(0, 'href', array('rel' => 'alternate'))); }
function test_rss090_item_title_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/rdf/rss090_item_title.xml'); $feed = new XML_Feed_Parser($content); $this->assertEquals('Item title', $feed->getEntryByOffset(0)->title); }
function test_amp64_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/amp/amp64.xml'); $feed = new XML_Feed_Parser($content); $this->assertEquals('<div><strong>&</strong></div>', $feed->getEntryByOffset(0)->title); }
function test_item_pubDate_rfc2822_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/date/item_pubDate_rfc2822.xml'); $feed = new XML_Feed_Parser($content); $this->assertEquals(array(2004, 1, 1, 19, 48, 21, 3, 1, 0), $feed->getEntryByOffset(0)->date_parsed); }
function test_itunes_link_enclosure_maps_id_2_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/itunes/itunes_link_enclosure_maps_id_2.xml'); $feed = new XML_Feed_Parser($content, false, true); $this->assertEquals('http://example.com/id', $feed->getEntryByOffset(0)->id); }
function test_http_text_xml_charset_overrides_encoding_2_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/encoding/http_text_xml_charset_overrides_encoding_2.xml'); $feed = new XML_Feed_Parser($content, false, true); $this->assertEquals('This is a \\xa3\\u201ctest.\\u201d', $feed->getEntryByOffset(0)->description); }
function hookLeftColumn($params) { // Conf $title = strval(Configuration::get('RSS_FEED_TITLE')); $url = strval(Configuration::get('RSS_FEED_URL')); $nb = (int) Configuration::get('RSS_FEED_NBR'); $cacheId = $this->getCacheId($this->name . '-' . date("YmdH")); if (!$this->isCached('blockrss.tpl', $cacheId)) { // Getting data $rss_links = array(); if ($url && ($contents = Tools::file_get_contents($url))) { try { if (@($src = new XML_Feed_Parser($contents))) { for ($i = 0; $i < ($nb ? $nb : 5); $i++) { if (@($item = $src->getEntryByOffset($i))) { $xmlValues = array(); foreach (self::$xmlFields as $xmlField) { $xmlValues[$xmlField] = $item->__get($xmlField); } $xmlValues['enclosure'] = $item->getEnclosure(); # Compatibility $xmlValues['url'] = $xmlValues['link']; $rss_links[] = $xmlValues; } } } } catch (XML_Feed_Parser_Exception $e) { Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false); } } // Display smarty $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links)); } return $this->display(__FILE__, 'blockrss.tpl', $cacheId); }
function hookLeftColumn($params) { global $smarty; // Conf $title = strval(Configuration::get('RSS_FEED_TITLE')); $url = strval(Configuration::get('RSS_FEED_URL')); $nb = intval(Configuration::get('RSS_FEED_NBR')); // Getting data if ($contents = @file_get_contents($url)) { if ($url) { @($src = new XML_Feed_Parser($contents)); } $content = ''; for ($i = 0; isset($src) and $i < ($nb ? $nb : 5); ++$i) { @($item = $src->getEntryByOffset($i)); $content .= '<li><a href="' . @$item->link . '">' . Tools::htmlentitiesUTF8(@$item->title) . '</a></li>'; } } // Display smarty $smarty->assign('title', $title ? $title : $this->l('RSS feed')); $smarty->assign('content', isset($content) ? $content : ''); return $this->display(__FILE__, 'blockrss.tpl'); }
function hookLeftColumn($params) { global $smarty; // Conf $title = strval(Configuration::get('RSS_FEED_TITLE')); $url = strval(Configuration::get('RSS_FEED_URL')); $nb = (int) Configuration::get('RSS_FEED_NBR'); // Getting data $rss_links = array(); if ($url && ($contents = @file_get_contents($url))) { if (@($src = new XML_Feed_Parser($contents))) { for ($i = 0; $i < ($nb ? $nb : 5); $i++) { if (@($item = $src->getEntryByOffset($i))) { $rss_links[] = array('title' => $item->title, 'url' => $item->link); } } } } // Display smarty $smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links)); return $this->display(__FILE__, 'blockrss.tpl'); }
function test_rss2_0NSwithModulesNoDefNSLocalNameClash_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/namespace/rss2.0NSwithModulesNoDefNSLocalNameClash.xml'); try { $feed = new XML_Feed_Parser($content); } catch (XML_Feed_Parser_Exception $e) { $this->assertTrue(false); return; } $this->assertEquals('correct description', $feed->getEntryByOffset(0)->description); }
function test_rss090_item_title_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/rdf/rss090_item_title.xml'); try { $feed = new XML_Feed_Parser($content); } catch (XML_Feed_Parser_Exception $e) { $this->assertTrue(false); return; } $this->assertEquals('Item title', $feed->getEntryByOffset(0)->title); }
function test_item_xhtml_body_style_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/sanitize/item_xhtml_body_style.xml'); try { $feed = new XML_Feed_Parser($content); } catch (XML_Feed_Parser_Exception $e) { $this->assertTrue(false); return; } $this->assertEquals('<a href="http://www.ragingplatypus.com/">never trust your upstream platypus</a>', $feed->getEntryByOffset(0)->description); }
function test_getAlternativeLinkForItem() { $source = '<?xml version="1.0" ?> <entry xmlns="http://www.w3.org/2005/Atom"> <link rel="replies" href="http://example.org/2005/04/02/atom/comments" /> <link rel="edit" href="http://example.org/2005/04/02/atom/edit"/> <link rel="self" href="http://example.org/2005/04/02/atom/self"/> <link rel="alternate" href="http://example.org/2005/04/02/atom" /> </entry> '; $feed = new XML_Feed_Parser($source); $entry = $feed->getEntryByOffset(0); // Output $this->assertEquals("http://example.org/2005/04/02/atom", $entry->link(0, 'href', array())); }
function test_entry_title_type_text_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/atom10/entry_title_type_text.xml'); $feed = new XML_Feed_Parser($content); $this->assertEquals('text/plain', $feed->getEntryByOffset(0)->title(0, 'type')); }
function test_relative_xml_base_2_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/base/relative_xml_base_2.xml'); try { $feed = new XML_Feed_Parser($content); } catch (XML_Feed_Parser_Exception $e) { $this->assertTrue(false); return; } $this->assertEquals('http://example.com/test/', $feed->getEntryByOffset(0)->title(0, 'base')); }
function test_relative_xml_base_2_1() { $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/base/relative_xml_base_2.xml'); $feed = new XML_Feed_Parser($content, true, true); $this->assertEquals('http://example.com/test/', $feed->getEntryByOffset(0)->title(0, 'base')); }
function testEntryLink() { foreach ($this->files as $file) { $contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file); $feed = new XML_Feed_Parser($contents); $entry = $feed->getEntryByOffset(0); $this->assertTrue($this->checkString('link', $entry), "Failed for {$file}"); } }