2008-03-21 06:58:50 +01:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2016-11-13 08:35:43 +01:00
|
|
|
namespace SilverStripe\Control\Tests\RSS;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Director;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Control\RSS\RSSFeed;
|
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\View\Parsers\ShortcodeParser;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class RSSFeedTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
|
|
|
protected static $original_host;
|
|
|
|
|
|
|
|
public function testRSSFeed()
|
|
|
|
{
|
|
|
|
$list = new ArrayList();
|
|
|
|
$list->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();
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<link>http://www.example.org/item-a/</link>', $content);
|
|
|
|
$this->assertStringContainsString('<link>http://www.example.com/item-b.html</link>', $content);
|
|
|
|
$this->assertStringContainsString('<link>http://www.example.com/item-c.html</link>', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<title>ItemA</title>', $content);
|
|
|
|
$this->assertStringContainsString('<title>ItemB</title>', $content);
|
|
|
|
$this->assertStringContainsString('<title>ItemC</title>', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<description>ItemA Content</description>', $content);
|
|
|
|
$this->assertStringContainsString('<description>ItemB Content</description>', $content);
|
|
|
|
$this->assertStringContainsString('<description>ItemC Content</description>', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
// 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->outputToBrowser();
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<title>ItemA Content</title>', $content);
|
|
|
|
$this->assertStringContainsString('<title>ItemB Content</title>', $content);
|
|
|
|
$this->assertStringContainsString('<title>ItemC Content</title>', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<description>ItemA AltContent</description>', $content);
|
|
|
|
$this->assertStringContainsString('<description>ItemB AltContent</description>', $content);
|
|
|
|
$this->assertStringContainsString('<description>ItemC AltContent</description>', $content);
|
2016-12-16 05:34:21 +01: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();
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<link>http://www.example.com/?param1=true&param2=true', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<link>http://www.example.org/item-d.html</link>', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<title>ItemD</title>', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString(
|
2016-12-16 05:34:21 +01:00
|
|
|
'<description><![CDATA[<p>ItemD Content test shortcode output</p>]]></description>',
|
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-03 02:21:27 +02:00
|
|
|
/**
|
|
|
|
* @skipUpgrade
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testRenderWithTemplate()
|
|
|
|
{
|
|
|
|
$rssFeed = new RSSFeed(new ArrayList(), "", "", "");
|
|
|
|
$rssFeed->setTemplate('RSSFeedTest');
|
|
|
|
|
|
|
|
$content = $rssFeed->outputToBrowser();
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringContainsString('<title>Test Custom Template</title>', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$rssFeed->setTemplate(null);
|
|
|
|
$content = $rssFeed->outputToBrowser();
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertStringNotContainsString('<title>Test Custom Template</title>', $content);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
protected function setUp(): void
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2017-07-03 02:21:27 +02:00
|
|
|
Config::modify()->set(Director::class, 'alternate_base_url', '/');
|
2016-12-16 05:34:21 +01:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
protected function tearDown(): void
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
$_SERVER['HTTP_HOST'] = self::$original_host;
|
|
|
|
}
|
2008-03-21 06:58:50 +01:00
|
|
|
}
|