assertEquals( $expected, $types ); } public function testCreateFeedSupportedRss1() { $feed = new ezcFeed( 'rss1' ); $this->assertEquals( 'ezcFeed', get_class( $feed ) ); $this->assertEquals( 'rss1', $feed->getFeedType() ); $this->assertEquals( 'application/rss+xml', $feed->getContentType() ); } public function testCreateFeedSupportedRss2() { $feed = new ezcFeed( 'rss2' ); $this->assertEquals( 'ezcFeed', get_class( $feed ) ); $this->assertEquals( 'rss2', $feed->getFeedType() ); $this->assertEquals( 'application/rss+xml', $feed->getContentType() ); } public function testCreateFeedSupportedAtom() { $feed = new ezcFeed( 'atom' ); $this->assertEquals( 'ezcFeed', get_class( $feed ) ); $this->assertEquals( 'atom', $feed->getFeedType() ); $this->assertEquals( 'application/atom+xml', $feed->getContentType() ); } public function testCreateModuleContent() { $feed = new ezcFeed( 'atom' ); $item = $feed->add( 'item' ); $module = $item->addModule( 'Content' ); $this->assertEquals( 'Content', $module->getModuleName() ); $this->assertEquals( 'http://purl.org/rss/1.0/modules/content/', $module->getNamespace() ); $this->assertEquals( 'content', $module->getNamespacePrefix() ); } public function testCreateModuleCreativeCommons() { $feed = new ezcFeed( 'atom' ); $item = $feed->add( 'item' ); $module = $item->addModule( 'CreativeCommons' ); $this->assertEquals( 'CreativeCommons', $module->getModuleName() ); $this->assertEquals( 'http://backend.userland.com/creativeCommonsRssModule', $module->getNamespace() ); $this->assertEquals( 'creativeCommons', $module->getNamespacePrefix() ); } public function testCreateModuleDublinCore() { $feed = new ezcFeed( 'atom' ); $item = $feed->add( 'item' ); $module = $item->addModule( 'DublinCore' ); $this->assertEquals( 'DublinCore', $module->getModuleName() ); $this->assertEquals( 'http://purl.org/dc/elements/1.1/', $module->getNamespace() ); $this->assertEquals( 'dc', $module->getNamespacePrefix() ); } public function testCreateModuleITunes() { $feed = new ezcFeed( 'atom' ); $item = $feed->add( 'item' ); $module = $item->addModule( 'iTunes' ); $this->assertEquals( 'iTunes', $module->getModuleName() ); $this->assertEquals( 'http://www.itunes.com/dtds/podcast-1.0.dtd', $module->getNamespace() ); $this->assertEquals( 'itunes', $module->getNamespacePrefix() ); } public function testCreateFeedNotSupported() { try { $feed = new ezcFeed( 'molecule' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedUnsupportedTypeException $e ) { $this->assertEquals( "The feed type 'molecule' is not supported.", $e->getMessage() ); } } public function testFeedNonExistentLocal() { try { $feed = ezcFeed::parse( 'not-here.xml' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcBaseFileNotFoundException $e ) { $this->assertEquals( "The file 'not-here.xml' could not be found.", $e->getMessage() ); } } public function testFeedNonExistentRemote() { try { $feed = ezcFeed::parse( 'http://ez.no/not-here.xml' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcBaseFileNotFoundException $e ) { $this->assertEquals( "The file 'http://ez.no/not-here.xml' could not be found.", $e->getMessage() ); } } public function testFeedExistsRemote() { $feed = ezcFeed::parse( 'http://ez.no/rss/feed/communitynews' ); } public function testParseBroken() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}rss2{$dot}regression{$dot}parse{$dot}incomplete{$dot}broken.in"; try { $feed = ezcFeed::parse( $file ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedCanNotParseException $e ) { $this->assertEquals( "The feed '{$file}' could not be parsed: {$file} is not a valid XML file.", $e->getMessage() ); } } public function testParseContentBroken() { try { $feed = ezcFeed::parseContent( 'bad XML document' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedParseErrorException $e ) { $this->assertEquals( "Parse error while parsing feed: Content is no valid XML.", $e->getMessage() ); } } public function testParseContentNotRecognized() { try { $feed = ezcFeed::parseContent( 'Content' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedCanNotParseException $e ) { $expected = "' could not be parsed: Feed type not recognized."; $result = substr( $e->getMessage(), strlen( $e->getMessage() ) - 48 ); $this->assertEquals( $expected, $result ); } } public function testParseRss2NoVersion() { try { $feed = ezcFeed::parseContent( 'RSS no versionItem no version' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedCanNotParseException $e ) { $expected = "' could not be parsed: Feed type not recognized."; $result = substr( $e->getMessage(), strlen( $e->getMessage() ) - 48 ); $this->assertEquals( $expected, $result ); } } public function testParseRss2UnsupportedVersion() { try { $feed = ezcFeed::parseContent( 'RSS unsupported versionItem unsupported version' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedCanNotParseException $e ) { $expected = "' could not be parsed: Feed type not recognized."; $result = substr( $e->getMessage(), strlen( $e->getMessage() ) - 48 ); $this->assertEquals( $expected, $result ); } } public function testParseModuleNotRecognized() { $feed = ezcFeed::parseContent( 'Content' ); $this->assertEquals( 'ezcFeed', get_class( $feed ) ); $this->assertEquals( 'atom', $feed->getFeedType() ); $this->assertEquals( 'application/atom+xml', $feed->getContentType() ); } public function testParseContentModuleElementNotRecognized() { $feed = ezcFeed::parseContent( 'Content' ); $this->assertEquals( 'ezcFeed', get_class( $feed ) ); $this->assertEquals( 'atom', $feed->getFeedType() ); $this->assertEquals( 'application/atom+xml', $feed->getContentType() ); } public function testParseDCModuleElementNotRecognized() { $feed = ezcFeed::parseContent( 'Content' ); $this->assertEquals( 'ezcFeed', get_class( $feed ) ); $this->assertEquals( 'atom', $feed->getFeedType() ); $this->assertEquals( 'application/atom+xml', $feed->getContentType() ); } public function testParseAtomUnsupportedModule() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}atom{$dot}data{$dot}atom_example_from_specs.xml"; $feed = ezcFeed::parse( $file ); try { $module = $feed->unsupported_module; $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedUnsupportedModuleException $e ) { $this->assertEquals( "The module 'unsupported_module' is not supported.", $e->getMessage() ); } } public function testParseAtomUndefinedModule() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}atom{$dot}data{$dot}atom_example_from_specs.xml"; $feed = ezcFeed::parse( $file ); try { $module = $feed->iTunes; $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedUndefinedModuleException $e ) { $this->assertEquals( "The module 'iTunes' is not defined yet.", $e->getMessage() ); } } public function testParseAtom1() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}atom{$dot}data{$dot}atom_example_from_specs.xml"; $feed = ezcFeed::parse( $file ); $this->assertEquals( 'atom', $feed->getFeedType() ); $this->assertEquals( 'application/atom+xml', $feed->getContentType() ); $this->assertEquals( false, isset( $feed->skipDays ) ); $this->assertEquals( false, isset( $feed->unsupportedModule ) ); } public function testParseAtom2() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}atom{$dot}data{$dot}atom_multiple_entries.xml"; $feed = ezcFeed::parse( $file ); $this->assertEquals( 'atom', $feed->getFeedType() ); $items = $feed->items; $expectedTitles = array( 'Atom-Powered Robots Run Amok 1', 'Atom-Powered Robots Run Amok 2', ); $titles = array(); foreach ( $items as $item ) { $titles[] = $item->title->__toString(); } $this->assertEquals( $expectedTitles, $titles ); } public function testParseRss1() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}rss1{$dot}data{$dot}rss1_example_from_specs.xml"; $feed = ezcFeed::parse( $file ); $this->assertEquals( 'rss1', $feed->getFeedType() ); $this->assertEquals( 'application/rss+xml', $feed->getContentType() ); } public function testParseRss2() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}rss2{$dot}data{$dot}rss2_example_from_specs.xml"; $feed = ezcFeed::parse( $file ); $this->assertEquals( 'rss2', $feed->getFeedType() ); $this->assertEquals( 'application/rss+xml', $feed->getContentType() ); } public function testParseRss2Podcast1() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}rss2{$dot}data{$dot}librivox_podcast.xml"; $feed = ezcFeed::parse( $file ); $this->assertEquals( 'rss2', $feed->getFeedType() ); $this->assertEquals( 'LibriVox Audiobooks', $feed->title->__toString() ); $modules = $feed->getModules(); $this->assertEquals( true, isset( $modules['iTunes'] ) ); } public function testParseRss2Podcast2() { $dot = DIRECTORY_SEPARATOR; $file = dirname( __FILE__ ) . "{$dot}rss2{$dot}data{$dot}woodsongs_old_time_radio_hour.xml"; $feed = ezcFeed::parse( $file ); $this->assertEquals( 'rss2', $feed->getFeedType() ); $this->assertEquals( 'The Woodsongs Old Time Radio Hour Podcast', $feed->title->__toString() ); } public function testParseRss2Version091() { $feed = ezcFeed::parseContent( 'RSS 0.91Item 0.91' ); $this->assertEquals( 'rss2', $feed->getFeedType() ); $this->assertEquals( 'RSS 0.91', $feed->title->__toString() ); $this->assertEquals( 'Item 0.91', $feed->items[0]->title->__toString() ); } public function testParseRss2Version092() { $feed = ezcFeed::parseContent( 'RSS 0.92Item 0.92' ); $this->assertEquals( 'rss2', $feed->getFeedType() ); $this->assertEquals( 'RSS 0.92', $feed->title->__toString() ); $this->assertEquals( 'Item 0.92', $feed->items[0]->title->__toString() ); } public function testParseRss2Version093() { $feed = ezcFeed::parseContent( 'RSS 0.93Item 0.93' ); $this->assertEquals( 'rss2', $feed->getFeedType() ); $this->assertEquals( 'RSS 0.93', $feed->title->__toString() ); $this->assertEquals( 'Item 0.93', $feed->items[0]->title->__toString() ); } public function testParseRss2Version094() { $feed = ezcFeed::parseContent( 'RSS 0.94Item 0.94' ); $this->assertEquals( 'rss2', $feed->getFeedType() ); $this->assertEquals( 'RSS 0.94', $feed->title->__toString() ); $this->assertEquals( 'Item 0.94', $feed->items[0]->title->__toString() ); } public function testCreateModuleNotSupported() { try { $module = ezcFeedModule::create( 'unsupported_module' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedUnsupportedModuleException $e ) { $this->assertEquals( "The module 'unsupported_module' is not supported.", $e->getMessage() ); } } public function testAddElementNotSupported() { $feed = new ezcFeed( 'rss2' ); $item = $feed->add( 'item' ); try { $item->add( 'unsupported_element' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedUnsupportedElementException $e ) { $this->assertEquals( "The feed element 'unsupported_element' is not supported.", $e->getMessage() ); } } public function testAddElementNotSupportedInModule() { $feed = new ezcFeed( 'rss2' ); $item = $feed->add( 'item' ); $module = $item->addModule( 'Content' ); try { $module->add( 'unsupported_element' ); $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedUnsupportedElementException $e ) { $this->assertEquals( "The feed element 'unsupported_element' is not supported.", $e->getMessage() ); } } public function testGetItemModules() { $feed = new ezcFeed( 'rss2' ); $item = $feed->add( 'item' ); $module = $item->addModule( 'Content' ); $modules = $item->getModules(); $this->assertEquals( 'ezcFeedContentModule', get_class( $modules['Content'] ) ); } public function testGetItemModuleNotDefinedYet() { $feed = new ezcFeed( 'rss2' ); $item = $feed->add( 'item' ); try { $module = $item->Content; $this->fail( 'Expected exception not thrown' ); } catch ( ezcFeedUndefinedModuleException $e ) { $this->assertEquals( "The module 'Content' is not defined yet.", $e->getMessage() ); } } } ?>