* @license BSD */ namespace Domframework\Tests; use Domframework\Rss; /** * Test the RSS */ class RssTest extends \PHPUnit_Framework_TestCase { public function testEmpty0() { // Empty $this->expectException("Exception", "No title is provided for this RSS"); $rss = new Rss(); $res = $rss->asXML(); } public function testFunctional1() { // Functionnal 1 $rss = new Rss(); $rss->title("Global Title") ->link("http://localhost") ->language("fr-fr") ->description("The Super Global Description"); $rss->addItem()->title("Item1 Title") ->link("http://Item1Link") ->description("Item1 Description"); $rss->addItem()->title("Item2 Title") ->pubDate("2017-04-13 12:25:30") ->link("http://Item2Link") ->description("Item2 Description"); $res = $rss->asXML(); $this->assertSame($res, " Global Title http://localhost The Super Global Description fr-fr Item1 Title http://Item1Link Item1 Description Item2 Title http://Item2Link Item2 Description Thu, 13 Apr 2017 12:25:30 +0200 "); } public function testError1() { // Missing global description $this->expectException( "Exception", "No description is provided for this RSS" ); $rss = new Rss(); $rss->title("Global Title") ->link("http://localhost") ->language("fr-fr"); $res = $rss->asXML(); } public function testError2() { // Missing global link $this->expectException("Exception", "No link is provided for this RSS"); $rss = new Rss(); $rss->title("Global Title") ->language("fr-fr") ->description("The Super Global Description"); $res = $rss->asXML(); } public function testError3() { // Missing global title $this->expectException("Exception", "No title is provided for this RSS"); $rss = new Rss(); $rss->link("http://localhost") ->language("fr-fr") ->description("The Super Global Description"); $res = $rss->asXML(); } public function testError4() { // Invalid date provided $this->expectException( "Exception", "lastBuildDate provided to RSS is not a valid date" ); $rss = new Rss(); $rss->title("Global Title") ->link("http://localhost") ->lastBuildDate("2017-04-33") ->language("fr-fr") ->description("The Super Global Description"); $res = $rss->asXML(); } public function testItemError1() { // Empty Item provided $this->expectException( "Exception", "No title nor description defined in the RSS item" ); $rss = new Rss(); $rss->title("Global Title") ->link("http://localhost") ->lastBuildDate("2017-04-30 12:35:32") ->language("fr-fr") ->description("The Super Global Description"); $rss->addItem(); $res = $rss->asXML(); } public function testItemError2() { // Item without Title and Description $this->expectException( "Exception", "No title nor description defined in the RSS item" ); $rss = new Rss(); $rss->title("Global Title") ->link("http://localhost") ->lastBuildDate("2017-04-30 12:35:32") ->language("fr-fr") ->description("The Super Global Description"); $rss->addItem()->link("http://localhost/link"); $res = $rss->asXML(); } public function testItemError3() { // Item with invalid date $this->expectException( "Exception", "pubDate provided to RSS Item is not a valid date" ); $rss = new Rss(); $rss->title("Global Title") ->link("http://localhost") ->lastBuildDate("2017-10-30 12:35:32") ->language("fr-fr") ->description("The Super Global Description"); $rss->addItem()->title("Item title") ->pubDate("2017-14-33 12:32:32"); $res = $rss->asXML(); } }