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->assertStringContainsString('http://www.example.org/item-a/', $content); $this->assertStringContainsString('http://www.example.com/item-b.html', $content); $this->assertStringContainsString('http://www.example.com/item-c.html', $content); $this->assertStringContainsString('ItemA', $content); $this->assertStringContainsString('ItemB', $content); $this->assertStringContainsString('ItemC', $content); $this->assertStringContainsString('ItemA Content', $content); $this->assertStringContainsString('ItemB Content', $content); $this->assertStringContainsString('ItemC Content', $content); // Feed #2 - put Content() into and AltContent() into <description> $rssFeed = new RSSFeed( $list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description", "Content", "AltContent" ); $content = $rssFeed->outputToBrowser(); $this->assertStringContainsString('<title>ItemA Content', $content); $this->assertStringContainsString('ItemB Content', $content); $this->assertStringContainsString('ItemC Content', $content); $this->assertStringContainsString('ItemA AltContent', $content); $this->assertStringContainsString('ItemB AltContent', $content); $this->assertStringContainsString('ItemC AltContent', $content); } 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->assertStringContainsString('http://www.example.com/?param1=true&param2=true', $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->assertStringContainsString('http://www.example.org/item-d.html', $content); $this->assertStringContainsString('ItemD', $content); $this->assertStringContainsString( 'ItemD Content test shortcode output

]]>
', $content ); } /** * @skipUpgrade */ public function testRenderWithTemplate() { $rssFeed = new RSSFeed(new ArrayList(), "", "", ""); $rssFeed->setTemplate('RSSFeedTest'); $content = $rssFeed->outputToBrowser(); $this->assertStringContainsString('Test Custom Template', $content); $rssFeed->setTemplate(null); $content = $rssFeed->outputToBrowser(); $this->assertStringNotContainsString('Test Custom Template', $content); } protected function setUp(): void { parent::setUp(); Config::modify()->set(Director::class, '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'; } ); } protected function tearDown(): void { parent::tearDown(); $_SERVER['HTTP_HOST'] = self::$original_host; } }