Permalink
Browse files

FIX: <% if Link %> wasn't working

Since ViewableData was returning a casting helper for Link, but DataObject was
only using $this->$fieldname to set values on that casting helper, you could
not use <% if Link %> (or <% if $Link %>) in your templates because Link is not
a field, and thus had no value to be set on the casting helper, causing
hasValue to think that there was no value.  Since DataObject->dbObject says that
"it only matches fields and not methods", it seems safe to have it call db(..)
to get the field spec, and not call ViewableData->castingHelper at all.
  • Loading branch information...
1 parent a9bf7df commit 964b3f2d48e15348c9ae3891017b8428019a10d3 @jthomerson jthomerson committed Jun 15, 2013
Showing with 23 additions and 2 deletions.
  1. +2 −2 model/DataObject.php
  2. +21 −0 tests/view/SSViewerTest.php
View
@@ -2643,8 +2643,8 @@ public function dbObject($fieldName) {
} 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;
@@ -165,6 +165,18 @@ public function testCoreGlobalVariableCalls() {
'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 @@ public function absoluteBaseURL() {
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 {

0 comments on commit 964b3f2

Please sign in to comment.