From cd4ebb25ca59b15e216ce2e546b7c5cf2e6b5e51 Mon Sep 17 00:00:00 2001 From: James Goodman Date: Thu, 10 Oct 2013 08:04:03 +0000 Subject: [PATCH] Fix HTMLText AbsoluteLinks not parsing placeholder Add an AbsoluteLinks method to HTMLText that parses placeholders instead of returning the raw value. --- model/fieldtypes/HTMLText.php | 12 ++++++++-- tests/api/RSSFeedTest.php | 45 ++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/model/fieldtypes/HTMLText.php b/model/fieldtypes/HTMLText.php index 46d462aa8..b2c8b1885 100644 --- a/model/fieldtypes/HTMLText.php +++ b/model/fieldtypes/HTMLText.php @@ -172,8 +172,16 @@ class HTMLText extends Text { /* If we didn't find a sentence ending, use the summary. We re-call rather than using paragraph so that * Summary will limit the result this time */ return $this->Summary(); - } - + } + + /** + * Return the value of the field with relative links converted to absolute urls (with placeholders parsed). + * @return string + */ + public function AbsoluteLinks() { + return HTTP::absoluteURLs($this->forTemplate()); + } + public function forTemplate() { if ($this->processShortcodes) { return ShortcodeParser::get_active()->parse($this->value); diff --git a/tests/api/RSSFeedTest.php b/tests/api/RSSFeedTest.php index 57032965a..0402bd30a 100644 --- a/tests/api/RSSFeedTest.php +++ b/tests/api/RSSFeedTest.php @@ -16,7 +16,6 @@ class RSSFeedTest extends SapphireTest { $rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description"); $content = $rssFeed->outputToBrowser(); - //Debug::message($content); $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); @@ -44,6 +43,23 @@ class RSSFeedTest extends SapphireTest { $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'); @@ -61,6 +77,10 @@ class RSSFeedTest extends SapphireTest { 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() { @@ -77,7 +97,7 @@ class RSSFeedTest_ItemA extends ViewableData { 'Content' => 'Text', 'AltContent' => 'Text', ); - + public function getTitle() { return "ItemA"; } @@ -89,7 +109,7 @@ class RSSFeedTest_ItemA extends ViewableData { public function getAltContent() { return "ItemA AltContent"; } - + public function Link($action = null) { return Controller::join_links("item-a/", $action); } @@ -134,3 +154,22 @@ class RSSFeedTest_ItemC extends ViewableData { 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'; + } +}