Add RSS support
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3523 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
148
Tests/rssTest.php
Normal file
148
Tests/rssTest.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
require_once ("rss.php");
|
||||
|
||||
/** Test the RSS */
|
||||
class test_rss 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 ();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user