2008-03-21 05:58:50 +00:00
|
|
|
<?php
|
2016-06-15 16:03:16 +12:00
|
|
|
|
2016-11-13 20:35:43 +13:00
|
|
|
namespace SilverStripe\Control\Tests\RSS;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Director;
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\Control\RSS\RSSFeed;
|
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2016-06-15 16:03:16 +12:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\View\Parsers\ShortcodeParser;
|
|
|
|
|
2008-03-21 05:58:50 +00:00
|
|
|
class RSSFeedTest extends SapphireTest {
|
2010-12-05 08:35:33 +00:00
|
|
|
|
|
|
|
protected static $original_host;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testRSSFeed() {
|
2011-05-05 20:40:24 +10:00
|
|
|
$list = new ArrayList();
|
2016-11-13 20:35:43 +13:00
|
|
|
$list->push(new RSSFeedTest\ItemA());
|
|
|
|
$list->push(new RSSFeedTest\ItemB());
|
|
|
|
$list->push(new RSSFeedTest\ItemC());
|
2008-05-21 23:51:17 +00:00
|
|
|
|
2008-03-21 05:58:50 +00:00
|
|
|
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
|
2012-07-31 20:38:12 +12:00
|
|
|
$content = $rssFeed->outputToBrowser();
|
2008-03-21 05:58:50 +00:00
|
|
|
|
2008-05-21 23:51:17 +00:00
|
|
|
$this->assertContains('<link>http://www.example.org/item-a/</link>', $content);
|
2008-03-21 05:58:50 +00: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>
|
2012-09-27 09:34:00 +12:00
|
|
|
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description",
|
|
|
|
"Content", "AltContent");
|
2012-07-31 20:38:12 +12:00
|
|
|
$content = $rssFeed->outputToBrowser();
|
2008-03-21 05:58:50 +00:00
|
|
|
|
|
|
|
$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 08:35:33 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 11:33:04 +13:00
|
|
|
public function testLinkEncoding() {
|
|
|
|
$list = new ArrayList();
|
|
|
|
$rssFeed = new RSSFeed($list, "http://www.example.com/?param1=true¶m2=true", "Test RSS Feed");
|
|
|
|
$content = $rssFeed->outputToBrowser();
|
|
|
|
$this->assertContains('<link>http://www.example.com/?param1=true&param2=true', $content);
|
|
|
|
}
|
|
|
|
|
2013-10-10 08:04:03 +00:00
|
|
|
public function testRSSFeedWithShortcode() {
|
|
|
|
$list = new ArrayList();
|
2016-11-13 20:35:43 +13:00
|
|
|
$list->push(new RSSFeedTest\ItemD());
|
2013-10-10 08:04:03 +00:00
|
|
|
|
|
|
|
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
|
|
|
|
$content = $rssFeed->outputToBrowser();
|
|
|
|
|
|
|
|
$this->assertContains('<link>http://www.example.org/item-d.html</link>', $content);
|
|
|
|
|
|
|
|
$this->assertContains('<title>ItemD</title>', $content);
|
|
|
|
|
|
|
|
$this->assertContains(
|
2016-06-03 20:51:02 +12:00
|
|
|
'<description><![CDATA[<p>ItemD Content test shortcode output</p>]]></description>',
|
2013-10-10 08:04:03 +00:00
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-07-01 21:25:57 +12:00
|
|
|
public function testRenderWithTemplate() {
|
|
|
|
$rssFeed = new RSSFeed(new ArrayList(), "", "", "");
|
|
|
|
$rssFeed->setTemplate('RSSFeedTest');
|
|
|
|
|
2012-07-31 20:38:12 +12:00
|
|
|
$content = $rssFeed->outputToBrowser();
|
2012-07-01 21:25:57 +12:00
|
|
|
$this->assertContains('<title>Test Custom Template</title>', $content);
|
|
|
|
|
2016-08-23 14:32:26 +12:00
|
|
|
$rssFeed->setTemplate(null);
|
2012-07-31 20:38:12 +12:00
|
|
|
$content = $rssFeed->outputToBrowser();
|
2012-07-01 21:25:57 +12:00
|
|
|
$this->assertNotContains('<title>Test Custom Template</title>', $content);
|
|
|
|
}
|
|
|
|
|
2010-12-05 08:35:33 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2016-11-13 20:35:43 +13:00
|
|
|
Config::inst()->update(Director::class, 'alternate_base_url', '/');
|
|
|
|
if(!self::$original_host) {
|
|
|
|
self::$original_host = $_SERVER['HTTP_HOST'];
|
|
|
|
}
|
2010-12-05 08:35:33 +00:00
|
|
|
$_SERVER['HTTP_HOST'] = 'www.example.org';
|
2013-10-10 08:04:03 +00:00
|
|
|
|
|
|
|
ShortcodeParser::get('default')->register('test_shortcode', function() {
|
|
|
|
return 'test shortcode output';
|
|
|
|
});
|
2010-12-05 08:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
$_SERVER['HTTP_HOST'] = self::$original_host;
|
2008-03-21 05:58:50 +00:00
|
|
|
}
|
|
|
|
}
|