Merge pull request #2515 from guttmann/html-text-absolutelink-placeholders

HTMLText AbsoluteLink parse placeholders
This commit is contained in:
Sean Harvey 2014-09-25 16:07:41 +12:00
commit 409aebf0af
2 changed files with 52 additions and 5 deletions

View File

@ -173,8 +173,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 /* 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 */ * Summary will limit the result this time */
return $this->Summary(); 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() { public function forTemplate() {
if ($this->processShortcodes) { if ($this->processShortcodes) {
return ShortcodeParser::get_active()->parse($this->value); return ShortcodeParser::get_active()->parse($this->value);

View File

@ -16,7 +16,6 @@ class RSSFeedTest extends SapphireTest {
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description"); $rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
$content = $rssFeed->outputToBrowser(); $content = $rssFeed->outputToBrowser();
//Debug::message($content);
$this->assertContains('<link>http://www.example.org/item-a/</link>', $content); $this->assertContains('<link>http://www.example.org/item-a/</link>', $content);
$this->assertContains('<link>http://www.example.com/item-b.html</link>', $content); $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('<link>http://www.example.com/item-c.html</link>', $content);
@ -44,6 +43,23 @@ class RSSFeedTest extends SapphireTest {
$this->assertContains('<description>ItemC AltContent</description>', $content); $this->assertContains('<description>ItemC AltContent</description>', $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('<link>http://www.example.org/item-d.html</link>', $content);
$this->assertContains('<title>ItemD</title>', $content);
$this->assertContains(
'<description>&lt;p&gt;ItemD Content test shortcode output&lt;/p&gt;</description>',
$content
);
}
public function testRenderWithTemplate() { public function testRenderWithTemplate() {
$rssFeed = new RSSFeed(new ArrayList(), "", "", ""); $rssFeed = new RSSFeed(new ArrayList(), "", "", "");
$rssFeed->setTemplate('RSSFeedTest'); $rssFeed->setTemplate('RSSFeedTest');
@ -61,6 +77,10 @@ class RSSFeedTest extends SapphireTest {
Config::inst()->update('Director', 'alternate_base_url', '/'); Config::inst()->update('Director', 'alternate_base_url', '/');
if(!self::$original_host) self::$original_host = $_SERVER['HTTP_HOST']; if(!self::$original_host) self::$original_host = $_SERVER['HTTP_HOST'];
$_SERVER['HTTP_HOST'] = 'www.example.org'; $_SERVER['HTTP_HOST'] = 'www.example.org';
ShortcodeParser::get('default')->register('test_shortcode', function() {
return 'test shortcode output';
});
} }
public function tearDown() { public function tearDown() {
@ -77,7 +97,7 @@ class RSSFeedTest_ItemA extends ViewableData {
'Content' => 'Text', 'Content' => 'Text',
'AltContent' => 'Text', 'AltContent' => 'Text',
); );
public function getTitle() { public function getTitle() {
return "ItemA"; return "ItemA";
} }
@ -89,7 +109,7 @@ class RSSFeedTest_ItemA extends ViewableData {
public function getAltContent() { public function getAltContent() {
return "ItemA AltContent"; return "ItemA AltContent";
} }
public function Link($action = null) { public function Link($action = null) {
return Controller::join_links("item-a/", $action); return Controller::join_links("item-a/", $action);
} }
@ -134,3 +154,22 @@ class RSSFeedTest_ItemC extends ViewableData {
return "http://www.example.com/item-c.html"; 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 = '<p>ItemD Content [test_shortcode]</p>';
public function Link() {
return 'item-d.html';
}
public function AbsoluteLink() {
return 'http://www.example.org/item-d.html';
}
}