2008-03-21 06:58:50 +01:00
|
|
|
<?php
|
2008-06-15 15:33:53 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-06-15 15:33:53 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2008-03-21 06:58:50 +01:00
|
|
|
class RSSFeedTest extends SapphireTest {
|
2010-12-05 09:35:33 +01:00
|
|
|
|
|
|
|
protected static $original_host;
|
|
|
|
|
2008-03-21 06:58:50 +01:00
|
|
|
function testRSSFeed() {
|
2011-05-05 12:40:24 +02:00
|
|
|
$list = new ArrayList();
|
2008-03-21 06:58:50 +01:00
|
|
|
$list->push(new RSSFeedTest_ItemA());
|
|
|
|
$list->push(new RSSFeedTest_ItemB());
|
|
|
|
$list->push(new RSSFeedTest_ItemC());
|
2008-05-22 01:51:17 +02:00
|
|
|
|
2008-03-21 06:58:50 +01:00
|
|
|
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
|
|
|
|
$content = $rssFeed->feedContent();
|
|
|
|
|
2008-09-27 18:04:01 +02:00
|
|
|
//Debug::message($content);
|
2008-05-22 01:51:17 +02:00
|
|
|
$this->assertContains('<link>http://www.example.org/item-a/</link>', $content);
|
2008-03-21 06:58:50 +01:00
|
|
|
$this->assertContains('<link>http://www.example.com/item-b.html</link>', $content);
|
|
|
|
$this->assertContains('<link>http://www.example.com/item-c.html</link>', $content);
|
|
|
|
|
|
|
|
$this->assertContains('<title>ItemA</title>', $content);
|
|
|
|
$this->assertContains('<title>ItemB</title>', $content);
|
|
|
|
$this->assertContains('<title>ItemC</title>', $content);
|
|
|
|
|
|
|
|
$this->assertContains('<description>ItemA Content</description>', $content);
|
|
|
|
$this->assertContains('<description>ItemB Content</description>', $content);
|
|
|
|
$this->assertContains('<description>ItemC Content</description>', $content);
|
|
|
|
|
|
|
|
|
|
|
|
// Feed #2 - put Content() into <title> and AltContent() into <description>
|
|
|
|
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description", "Content", "AltContent");
|
|
|
|
$content = $rssFeed->feedContent();
|
|
|
|
|
|
|
|
$this->assertContains('<title>ItemA Content</title>', $content);
|
|
|
|
$this->assertContains('<title>ItemB Content</title>', $content);
|
|
|
|
$this->assertContains('<title>ItemC Content</title>', $content);
|
|
|
|
|
|
|
|
$this->assertContains('<description>ItemA AltContent</description>', $content);
|
|
|
|
$this->assertContains('<description>ItemB AltContent</description>', $content);
|
|
|
|
$this->assertContains('<description>ItemC AltContent</description>', $content);
|
2010-12-05 09:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
Director::setBaseURL('/');
|
|
|
|
if(!self::$original_host) self::$original_host = $_SERVER['HTTP_HOST'];
|
|
|
|
$_SERVER['HTTP_HOST'] = 'www.example.org';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2010-04-13 01:15:04 +02:00
|
|
|
Director::setBaseURL(null);
|
2010-12-05 09:35:33 +01:00
|
|
|
$_SERVER['HTTP_HOST'] = self::$original_host;
|
2008-03-21 06:58:50 +01:00
|
|
|
}
|
2010-12-05 09:35:33 +01:00
|
|
|
|
2008-03-21 06:58:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class RSSFeedTest_ItemA extends ViewableData {
|
|
|
|
// RSS-feed items must have $casting/$db information.
|
|
|
|
static $casting = array(
|
|
|
|
'Title' => 'Varchar',
|
|
|
|
'Content' => 'Text',
|
|
|
|
'AltContent' => 'Text',
|
|
|
|
);
|
|
|
|
|
2010-05-25 05:49:55 +02:00
|
|
|
function getTitle() {
|
2008-03-21 06:58:50 +01:00
|
|
|
return "ItemA";
|
|
|
|
}
|
2010-05-25 05:49:55 +02:00
|
|
|
function getContent() {
|
2008-03-21 06:58:50 +01:00
|
|
|
return "ItemA Content";
|
|
|
|
}
|
2010-05-25 05:49:55 +02:00
|
|
|
function getAltContent() {
|
2008-03-21 06:58:50 +01:00
|
|
|
return "ItemA AltContent";
|
|
|
|
}
|
|
|
|
|
2009-10-11 02:07:16 +02:00
|
|
|
function Link($action = null) {
|
|
|
|
return Controller::join_links("item-a/", $action);
|
2008-03-21 06:58:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class RSSFeedTest_ItemB extends ViewableData {
|
|
|
|
// ItemB tests without $casting
|
|
|
|
|
|
|
|
function Title() {
|
|
|
|
return "ItemB";
|
|
|
|
}
|
|
|
|
function AbsoluteLink() {
|
|
|
|
return "http://www.example.com/item-b.html";
|
|
|
|
}
|
|
|
|
function Content() {
|
|
|
|
return "ItemB Content";
|
|
|
|
}
|
|
|
|
function AltContent() {
|
|
|
|
return "ItemB AltContent";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class RSSFeedTest_ItemC extends ViewableData {
|
|
|
|
// ItemC tests fields - Title has casting, Content doesn't.
|
|
|
|
static $casting = array(
|
|
|
|
'Title' => 'Varchar',
|
|
|
|
'AltContent' => 'Text',
|
|
|
|
);
|
|
|
|
|
|
|
|
public $Title = "ItemC";
|
|
|
|
public $Content = "ItemC Content";
|
|
|
|
public $AltContent = "ItemC AltContent";
|
|
|
|
|
|
|
|
function Link() {
|
|
|
|
return "item-c.html";
|
|
|
|
}
|
|
|
|
function AbsoluteLink() {
|
|
|
|
return "http://www.example.com/item-c.html";
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|