diff --git a/model/DataObject.php b/model/DataObject.php index 70749387f..0b6109860 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -2643,8 +2643,8 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity } else if($fieldName == 'ID') { return new PrimaryKey($fieldName, $this); - // General casting information for items in $db or $casting - } else if($helper = $this->castingHelper($fieldName)) { + // General casting information for items in $db + } else if($helper = $this->db($fieldName)) { $obj = Object::create_from_string($helper, $fieldName); $obj->setValue($this->$fieldName, $this->record, false); return $obj; diff --git a/tests/view/SSViewerTest.php b/tests/view/SSViewerTest.php index 92b181b28..15003e9d9 100644 --- a/tests/view/SSViewerTest.php +++ b/tests/view/SSViewerTest.php @@ -165,6 +165,18 @@ SS; 'Permissions template functions result correct result'); } + public function testNonFieldCastingHelpersNotUsedInHasValue() { + // check if Link without $ in front of variable + $result = $this->render( + 'A<% if Link %>$Link<% end_if %>B', new SSViewerTest_Object()); + $this->assertEquals('Asome/url.htmlB', $result, 'casting helper not used for <% if Link %>'); + + // check if Link with $ in front of variable + $result = $this->render( + 'A<% if $Link %>$Link<% end_if %>B', new SSViewerTest_Object()); + $this->assertEquals('Asome/url.htmlB', $result, 'casting helper not used for <% if $Link %>'); + } + public function testLocalFunctionsTakePriorityOverGlobals() { $data = new ArrayData(array( 'Page' => new SSViewerTest_Object() @@ -1274,6 +1286,11 @@ class SSViewerTest_Object extends DataObject { public $number = null; + private static $casting = array( + 'Link' => 'Text', + ); + + public function __construct($number = null) { parent::__construct(); $this->number = $number; @@ -1290,6 +1307,10 @@ class SSViewerTest_Object extends DataObject { public function lotsOfArguments11($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k) { return $a. $b. $c. $d. $e. $f. $g. $h. $i. $j. $k; } + + public function Link() { + return 'some/url.html'; + } } class SSViewerTest_GlobalProvider implements TemplateGlobalProvider, TestOnly {