headers['content-type'] = $mime; $locator = new SimplePie_Locator($data, 0, null, false); $registry = new SimplePie_Registry(); $registry->register('File', 'MockSimplePie_File'); $locator->set_registry($registry); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); $this->assertEquals($feed, $data); } public function testInvalidMIMEType() { $data = new MockSimplePie_File('http://example.com/feed.xml'); $data->headers['content-type'] = 'application/pdf'; $locator = new SimplePie_Locator($data, 0, null, false); $registry = new SimplePie_Registry(); $registry->register('File', 'MockSimplePie_File'); $locator->set_registry($registry); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); $this->assertEquals($feed, null); } public function testDirectNoDOM() { $data = new MockSimplePie_File('http://example.com/feed.xml'); $registry = new SimplePie_Registry(); $locator = new SimplePie_Locator($data, 0, null, false); $locator->dom = null; $locator->set_registry($registry); $this->assertTrue($locator->is_feed($data)); $this->assertEquals($locator->find(SIMPLEPIE_LOCATOR_ALL, $found), $data); } /** * @expectedException SimplePie_Exception */ public function testFailDiscoveryNoDOM() { $data = new MockSimplePie_File('http://example.com/feed.xml'); $data->headers['content-type'] = 'text/html'; $data->body = 'Hi!'; $registry = new SimplePie_Registry(); $locator = new SimplePie_Locator($data, 0, null, false); $locator->dom = null; $locator->set_registry($registry); $this->assertFalse($locator->is_feed($data)); $this->assertFalse($locator->find(SIMPLEPIE_LOCATOR_ALL, $found)); } /** * Tests from Firefox * * Tests are used under the LGPL license, see file for license * information */ public static function firefoxtests() { $data = array( array(new SimplePie_File(dirname(__FILE__) . '/data/fftests.html')) ); foreach ($data as &$row) { $row[0]->headers = array('content-type' => 'text/html'); $row[0]->method = SIMPLEPIE_FILE_SOURCE_REMOTE; $row[0]->url = 'http://example.com/'; } return $data; } /** * @dataProvider firefoxtests */ public function test_from_file($data) { $locator = new SimplePie_Locator($data, 0, null, false); $registry = new SimplePie_Registry(); $registry->register('File', 'MockSimplePie_File'); $locator->set_registry($registry); $expected = array(); $document = new DOMDocument(); $document->loadHTML($data->body); $xpath = new DOMXPath($document); foreach ($xpath->query('//link') as $element) { $expected[] = 'http://example.com' . $element->getAttribute('href'); } //$expected = SimplePie_Misc::get_element('link', $data->body); $feed = $locator->find(SIMPLEPIE_LOCATOR_ALL, $all); $this->assertFalse($locator->is_feed($data), 'HTML document not be a feed itself'); $this->assertInstanceOf('MockSimplePie_File', $feed); $success = array_filter($expected, array(get_class(), 'filter_success')); $found = array_map(array(get_class(), 'map_url_file'), $all); $this->assertEquals($success, $found); } protected static function filter_success($url) { return (stripos($url, 'bogus') === false); } protected static function map_url_file($file) { return $file->url; } } /** * Acts as a fake feed request */ class MockSimplePie_File extends SimplePie_File { public function __construct($url) { $this->url = $url; $this->headers = array( 'content-type' => 'application/atom+xml' ); $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; $this->body = ''; $this->status_code = 200; } }