Skip to content

Commit

Permalink
Merge pull request #2515 from guttmann/html-text-absolutelink-placeho…
Browse files Browse the repository at this point in the history
…lders

HTMLText AbsoluteLink parse placeholders
  • Loading branch information
Sean Harvey committed Sep 25, 2014
2 parents 1d219aa + cd4ebb2 commit 409aebf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
12 changes: 10 additions & 2 deletions model/fieldtypes/HTMLText.php
Expand Up @@ -173,8 +173,16 @@ public function FirstSentence() {
/* 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);
Expand Down
45 changes: 42 additions & 3 deletions tests/api/RSSFeedTest.php
Expand Up @@ -16,7 +16,6 @@ public function testRSSFeed() {
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
$content = $rssFeed->outputToBrowser();

//Debug::message($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-c.html</link>', $content);
Expand Down Expand Up @@ -44,6 +43,23 @@ public function testRSSFeed() {
$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() {
$rssFeed = new RSSFeed(new ArrayList(), "", "", "");
$rssFeed->setTemplate('RSSFeedTest');
Expand All @@ -61,6 +77,10 @@ public function setUp() {
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() {
Expand All @@ -77,7 +97,7 @@ class RSSFeedTest_ItemA extends ViewableData {
'Content' => 'Text',
'AltContent' => 'Text',
);

public function getTitle() {
return "ItemA";
}
Expand All @@ -89,7 +109,7 @@ public function getContent() {
public function getAltContent() {
return "ItemA AltContent";
}

public function Link($action = null) {
return Controller::join_links("item-a/", $action);
}
Expand Down Expand Up @@ -134,3 +154,22 @@ public function AbsoluteLink() {
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';
}
}

0 comments on commit 409aebf

Please sign in to comment.