Merge pull request #2021 from jthomerson/fix_if_link_not_working

FIX: <% if Link %> wasn't working
This commit is contained in:
Ingo Schommer 2013-06-24 06:16:21 -07:00
commit 2f9eaeea41
2 changed files with 23 additions and 2 deletions

View File

@ -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;

View File

@ -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 {