167 lines
4.7 KiB
PHP
167 lines
4.7 KiB
PHP
<?php
|
|
|
|
/** DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Rss;
|
|
|
|
/** Test the RSS */
|
|
class RssTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function test_empty0()
|
|
{
|
|
// Empty
|
|
$this->expectException("Exception", "No title is provided for this RSS");
|
|
$rss = new Rss();
|
|
$res = $rss->asXML();
|
|
}
|
|
|
|
public function test_functional1()
|
|
{
|
|
// 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, "<?xml version=\"1.0\"?>
|
|
<rss version=\"2.0\">
|
|
<channel>
|
|
<title>Global Title</title>
|
|
<link>http://localhost</link>
|
|
<description>The Super Global Description</description>
|
|
<language>fr-fr</language>
|
|
<item>
|
|
<title>Item1 Title</title>
|
|
<link>http://Item1Link</link>
|
|
<description>Item1 Description</description>
|
|
</item>
|
|
<item>
|
|
<title>Item2 Title</title>
|
|
<link>http://Item2Link</link>
|
|
<description>Item2 Description</description>
|
|
<pubDate>Thu, 13 Apr 2017 12:25:30 +0200</pubDate>
|
|
</item>
|
|
</channel>
|
|
</rss>
|
|
");
|
|
}
|
|
|
|
public function test_error1()
|
|
{
|
|
// 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 test_error2()
|
|
{
|
|
// 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 test_error3()
|
|
{
|
|
// 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 test_error4()
|
|
{
|
|
// 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 test_itemError1()
|
|
{
|
|
// 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 test_itemError2()
|
|
{
|
|
// 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 test_itemError3()
|
|
{
|
|
// 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();
|
|
}
|
|
}
|