push(new RSSFeedTest_ItemA());
$list->push(new RSSFeedTest_ItemB());
$list->push(new RSSFeedTest_ItemC());
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
$content = $rssFeed->outputToBrowser();
$this->assertContains('http://www.example.org/item-a/', $content);
$this->assertContains('http://www.example.com/item-b.html', $content);
$this->assertContains('http://www.example.com/item-c.html', $content);
$this->assertContains('
ItemA', $content);
$this->assertContains('ItemB', $content);
$this->assertContains('ItemC', $content);
$this->assertContains('ItemA Content', $content);
$this->assertContains('ItemB Content', $content);
$this->assertContains('ItemC Content', $content);
// Feed #2 - put Content() into and AltContent() into
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description",
"Content", "AltContent");
$content = $rssFeed->outputToBrowser();
$this->assertContains('ItemA Content', $content);
$this->assertContains('ItemB Content', $content);
$this->assertContains('ItemC Content', $content);
$this->assertContains('ItemA AltContent', $content);
$this->assertContains('ItemB AltContent', $content);
$this->assertContains('ItemC AltContent', $content);
}
public function testRSSFeedWithShortcode() {
$list = new ArrayList();
$list->push(new RSSFeedTest_ItemD());
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
$content = $rssFeed->outputToBrowser();
$this->assertContains('http://www.example.org/item-d.html', $content);
$this->assertContains('ItemD', $content);
$this->assertContains(
'<p>ItemD Content test shortcode output</p>',
$content
);
}
public function testRenderWithTemplate() {
$rssFeed = new RSSFeed(new ArrayList(), "", "", "");
$rssFeed->setTemplate('RSSFeedTest');
$content = $rssFeed->outputToBrowser();
$this->assertContains('Test Custom Template', $content);
$rssFeed->setTemplate('RSSFeed');
$content = $rssFeed->outputToBrowser();
$this->assertNotContains('Test Custom Template', $content);
}
public function setUp() {
parent::setUp();
Config::inst()->update('Director', 'alternate_base_url', '/');
if(!self::$original_host) self::$original_host = $_SERVER['HTTP_HOST'];
$_SERVER['HTTP_HOST'] = 'www.example.org';
ShortcodeParser::get('default')->register('test_shortcode', function() {
return 'test shortcode output';
});
}
public function tearDown() {
parent::tearDown();
Config::inst()->update('Director', 'alternate_base_url', null);
$_SERVER['HTTP_HOST'] = self::$original_host;
}
}
class RSSFeedTest_ItemA extends ViewableData {
// RSS-feed items must have $casting/$db information.
private static $casting = array(
'Title' => 'Varchar',
'Content' => 'Text',
'AltContent' => 'Text',
);
public function getTitle() {
return "ItemA";
}
public function getContent() {
return "ItemA Content";
}
public function getAltContent() {
return "ItemA AltContent";
}
public function Link($action = null) {
return Controller::join_links("item-a/", $action);
}
}
class RSSFeedTest_ItemB extends ViewableData {
// ItemB tests without $casting
public function Title() {
return "ItemB";
}
public function AbsoluteLink() {
return "http://www.example.com/item-b.html";
}
public function Content() {
return "ItemB Content";
}
public function AltContent() {
return "ItemB AltContent";
}
}
class RSSFeedTest_ItemC extends ViewableData {
// ItemC tests fields - Title has casting, Content doesn't.
private static $casting = array(
'Title' => 'Varchar',
'AltContent' => 'Text',
);
public $Title = "ItemC";
public $Content = "ItemC Content";
public $AltContent = "ItemC AltContent";
public function Link() {
return "item-c.html";
}
public function AbsoluteLink() {
return "http://www.example.com/item-c.html";
}
}
class RSSFeedTest_ItemD extends ViewableData {
// ItemD test fields - all fields use casting but Content & AltContent cast as HTMLText
private static $casting = array(
'Title' => 'Varchar',
'Content' => 'HTMLText'
);
public $Title = 'ItemD';
public $Content = 'ItemD Content [test_shortcode]
';
public function Link() {
return 'item-d.html';
}
public function AbsoluteLink() {
return 'http://www.example.org/item-d.html';
}
}