2014-12-24 03:28:26 +01:00
< ? php
2015-03-01 19:56:11 +01:00
2014-12-24 03:28:26 +01:00
namespace PicoFeed\Parser ;
use PHPUnit_Framework_TestCase ;
2015-07-19 17:19:26 +02:00
2014-12-24 03:28:26 +01:00
class Rss20ParserTest extends PHPUnit_Framework_TestCase
{
/**
* @ expectedException PicoFeed\Parser\MalformedXmlException
*/
public function testBadInput ()
{
$parser = new Rss20 ( 'boo' );
$parser -> execute ();
}
2015-07-19 17:19:26 +02:00
public function testGetItemsTree ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertCount ( 4 , $feed -> items );
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_feed.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( array (), $feed -> items );
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindFeedTitle ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( 'литература на русском языке, либо написанная русскими авторами' , $feed -> getTitle ());
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_fallback_on_invalid_feed_values.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/Category:Russian-language_literature' , $feed -> getTitle ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_channel.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> getTitle ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_feed.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> getTitle ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindFeedDescription ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( " Зародилась во второй половине X века, однако до XIX века, \n когда начался её «золотой век», была практически неизвестна \n в мире. " , $feed -> getDescription ());
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_channel.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( '' , $feed -> getDescription ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_feed.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> getDescription ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindFeedLogo ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'https://ru.wikipedia.org/static/images/project-logos/ruwiki.png' , $feed -> getLogo ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_channel.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> getLogo ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_feed.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( '' , $feed -> getLogo ());
}
public function testFindFeedIcon ()
{
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( '' , $feed -> getIcon ());
}
public function testFindFeedUrl ()
{
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
$this -> assertEquals ( '' , $feed -> getFeedUrl ());
}
2015-07-19 17:19:26 +02:00
public function testFindSiteUrl ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/Category:Russian-language_literature' , $feed -> getSiteUrl ());
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_extra.xml' ), '' , 'https://feeds.wikipedia.org/category/Russian-language_literature.xml' ); // relative url
$feed = $parser -> execute ();
$this -> assertEquals ( 'https://feeds.wikipedia.org/wiki/Category:Russian-language_literature' , $feed -> getSiteUrl ());
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_channel.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> getSiteUrl ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_feed.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> getSiteUrl ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindFeedId ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/Category:Russian-language_literature' , $feed -> getId ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindFeedDate ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
// pubDate
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 1433451900 , $feed -> getDate () -> getTimestamp ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
// lastBuildDate
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_extra.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( 1433451900 , $feed -> getDate () -> getTimestamp ());
// prefer most recent date and not a particular date element
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_element_preference.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( 1433455500 , $feed -> getDate () -> getTimestamp ());
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_channel.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( time (), $feed -> getDate () -> getTimestamp (), '' , 1 );
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_feed.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-03-19 23:26:02 +01:00
$this -> assertEquals ( time (), $feed -> getDate () -> getTimestamp (), '' , 1 );
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindFeedLanguage ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'ru' , $feed -> getLanguage ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_channel.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> getTitle ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_feed.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> getTitle ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindItemId ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' )); // <guid>
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '06e53052cd17cdfb264d9c37d495cc3746ac43f79488c7ce67894e718f674bd5' , $feed -> items [ 1 ] -> getId ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' )); // alternate generation
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'eb6f2d388a77e1f7d067a924970622d630031365fd444abe776d974d95b21990' , $feed -> items [ 0 ] -> getId ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_item.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' , $feed -> items [ 0 ] -> getId ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindItemUrl ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/War_and_Peace' , $feed -> items [ 0 ] -> getUrl ()); // <rss:link>
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/Crime_and_Punishment' , $feed -> items [ 1 ] -> getUrl ()); // <atom:link>
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/Doctor_Zhivago_(novel)' , $feed -> items [ 2 ] -> getUrl ()); // <feedburner:origLink>
$this -> assertEquals ( 'https://guid.wikipedia.org/wiki/A_Hero_of_Our_Time' , $feed -> items [ 3 ] -> getUrl ()); // <guid>
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
// relative urls
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_extra.xml' ), '' , 'https://feeds.wikipedia.org/category/Russian-language_literature.xml' );
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'https://feeds.wikipedia.org/wiki/War_and_Peace' , $feed -> items [ 0 ] -> getUrl ()); // <rss:link>
$this -> assertEquals ( 'https://feeds.wikipedia.org/wiki/Crime_and_Punishment' , $feed -> items [ 1 ] -> getUrl ()); // <atom:link>
$this -> assertEquals ( 'https://feeds.wikipedia.org/wiki/Doctor_Zhivago_(novel)' , $feed -> items [ 2 ] -> getUrl ()); // <feedburner:origLink>
2015-07-03 03:03:00 +02:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_element_preference.xml' ));
2015-07-03 03:03:00 +02:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/War_and_Peace' , $feed -> items [ 0 ] -> getUrl ()); // <feedburner:origLink> is preferred over <rss:link>, <atom:link>, <guid>
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/Crime_and_Punishment' , $feed -> items [ 1 ] -> getUrl ()); // <rss:link> is preferred over <atom:link>, <guid>
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/Doctor_Zhivago_(novel)' , $feed -> items [ 2 ] -> getUrl ()); // <atom:link> is preferred over <guid>
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_fallback_on_invalid_item_values.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> items [ 0 ] -> getUrl ()); // <guid> is invalid URI
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_item.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> items [ 0 ] -> getUrl ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindItemTitle ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'Война и мир' , $feed -> items [ 0 ] -> getTitle ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_fallback_on_invalid_item_values.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'https://en.wikipedia.org/wiki/Doctor_Zhivago_(novel)' , $feed -> items [ 2 ] -> getTitle ());
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_item.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( '' , $feed -> items [ 0 ] -> getTitle ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindItemDate ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
$feed = $parser -> execute ();
$this -> assertEquals ( 1433451720 , $feed -> items [ 0 ] -> getDate () -> getTimestamp ()); // item date
$this -> assertEquals ( 1433451900 , $feed -> items [ 1 ] -> getDate () -> getTimestamp ()); // fallback to feed date
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_item.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( time (), $feed -> items [ 0 ] -> getDate () -> getTimestamp (), 1 );
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindItemLanguage ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'bg' , $feed -> items [ 0 ] -> getLanguage ()); // item language
$this -> assertEquals ( 'ru' , $feed -> items [ 1 ] -> getLanguage ()); // fallback to feed language
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_item.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> items [ 0 ] -> getLanguage ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindItemAuthor ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
// items[0] === item author
// items[1] === feed author via empty fallback (channel/managingEditor)
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2015-03-01 19:56:11 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'Лев Николаевич Толсто́й' , $feed -> items [ 0 ] -> getAuthor ());
$this -> assertEquals ( 'Вики педии - свободной энциклопедии' , $feed -> items [ 1 ] -> getAuthor ());
2015-03-01 19:56:11 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_dc.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'Лев Николаевич Толсто́й' , $feed -> items [ 0 ] -> getAuthor ());
$this -> assertEquals ( 'Вики педии - свободной энциклопедии' , $feed -> items [ 1 ] -> getAuthor ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
// <dc:creator> is preferred over <author>
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_element_preference.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'Лев Николаевич Толсто́й' , $feed -> items [ 0 ] -> getAuthor ());
$this -> assertEquals ( 'Вики педии - свободной энциклопедии' , $feed -> items [ 1 ] -> getAuthor ());
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_item.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> items [ 0 ] -> getAuthor ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
public function testFindItemContent ()
2014-12-24 03:28:26 +01:00
{
2015-07-19 17:19:26 +02:00
// items[0] === <description>
// items[1] === <content:encoded>
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
$parser -> disableContentFiltering ();
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertTrue ( strpos ( $feed -> items [ 0 ] -> getContent (), " В наброске предисловия к «Войне и миру» Толстой\n писал, что в 1856 г . " ) === 0 );
$this -> assertTrue ( strpos ( $feed -> items [ 1 ] -> getContent (), " <h1> \n История создания \n </h1> \n <p> \n Осенью \n <a href= \" /wiki/1865_%D0%B3%D0%BE%D0%B4 \" " ) === 0 );
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
// <content:encoding> is preferred over <description>
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_element_preference.xml' ));
$parser -> disableContentFiltering ();
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertTrue ( strpos ( $feed -> items [ 1 ] -> getContent (), " <h1> \n История создания \n </h1> \n <p> \n Осенью \n <a href= \" /wiki/1865_%D0%B3%D0%BE%D0%B4 \" " ) === 0 );
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_fallback_on_invalid_item_values.xml' ));
$parser -> disableContentFiltering ();
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertTrue ( strpos ( $feed -> items [ 1 ] -> getContent (), " Осенью 1865 года, потеряв все свои \n деньги в казино " ) === 0 ); // <content:encoded> => <description>
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_item.xml' ));
$parser -> disableContentFiltering ();
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> items [ 0 ] -> getContent ());
}
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
public function testFindItemEnclosure ()
{
// Test tests covers the preference of <feedburner:origEnclosureLink> over <enclosure> as well
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( 'https://upload.wikimedia.org/wikipedia/commons/4/41/War-and-peace_1873.gif' , $feed -> items [ 0 ] -> getEnclosureUrl ()); // <enclosure>
$this -> assertEquals ( 'image/gif' , $feed -> items [ 0 ] -> getEnclosureType ());
$this -> assertEquals ( 'https://upload.wikimedia.org/wikipedia/commons/7/7b/Crime_and_Punishment-1.png' , $feed -> items [ 1 ] -> getEnclosureUrl ()); // <feedburner:origEnclosureLink>
2014-12-24 03:28:26 +01:00
2015-07-19 17:19:26 +02:00
$parser = new Rss20 ( file_get_contents ( 'tests/fixtures/rss_20_empty_item.xml' ));
2014-12-24 03:28:26 +01:00
$feed = $parser -> execute ();
2015-07-19 17:19:26 +02:00
$this -> assertEquals ( '' , $feed -> items [ 0 ] -> getEnclosureUrl ());
$this -> assertEquals ( '' , $feed -> items [ 0 ] -> getEnclosureType ());
2014-12-24 03:28:26 +01:00
}
2015-07-19 17:19:26 +02:00
}