From 135b65ee04377996beab63cdba34d553fe1f56c8 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 13 Oct 2010 00:42:17 +0000 Subject: [PATCH] BUGFIX Fixed SiteTree->Content link shortcode parsing introduced in r101093 (#5227) (from r101302) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@111992 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/ViewableData.php | 3 ++- tests/control/ContentControllerTest.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/ViewableData.php b/core/ViewableData.php index 30b4f1f5a..e30e1d1d5 100755 --- a/core/ViewableData.php +++ b/core/ViewableData.php @@ -245,7 +245,7 @@ class ViewableData extends Object implements IteratorAggregate { * @return string */ public function castingHelper($field) { - if($this instanceof DataObject && ($fieldSpec = $this->db($field))) { + if($this->hasMethod('db') && $fieldSpec = $this->db($field)) { return $fieldSpec; } @@ -441,6 +441,7 @@ class ViewableData extends Object implements IteratorAggregate { */ public function XML_val($field, $arguments = null, $cache = false) { $result = $this->obj($field, $arguments, false, $cache); + return is_object($result) ? $result->forTemplate() : $result; } diff --git a/tests/control/ContentControllerTest.php b/tests/control/ContentControllerTest.php index 51cd77bcd..287e96b59 100755 --- a/tests/control/ContentControllerTest.php +++ b/tests/control/ContentControllerTest.php @@ -103,6 +103,25 @@ class ContentControllerTest extends FunctionalTest { } + + public function testLinkShortcodes() { + $linkedPage = new SiteTree(); + $linkedPage->URLSegment = 'linked-page'; + $linkedPage->write(); + $linkedPage->publish('Stage', 'Live'); + + $page = new SiteTree(); + $page->URLSegment = 'linking-page'; + $page->Content = sprintf('Testlink', $linkedPage->ID); + $page->write(); + $page->publish('Stage', 'Live'); + + $this->assertContains( + sprintf('Testlink', $linkedPage->Link()), + $this->get($page->RelativeLink())->getBody(), + '"sitetree_link" shortcodes get parsed properly' + ); + } }