From 00eb220e916ce274b99ce923b434b4fc1e2ef69a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 15 Oct 2009 21:48:24 +0000 Subject: [PATCH] BUGFIX Don't return empty value from ViewableData->XML_val() if the actual value is an uncasted 0 integeter (or anything else evaluating to untyped boolean false) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89161 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/ViewableData.php | 5 ++--- tests/ViewableDataTest.php | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/ViewableData.php b/core/ViewableData.php index 6d335cc69..dc61482d9 100755 --- a/core/ViewableData.php +++ b/core/ViewableData.php @@ -454,9 +454,8 @@ class ViewableData extends Object implements IteratorAggregate { * template. */ public function XML_val($field, $arguments = null, $cache = false) { - if($result = $this->obj($field, $arguments, false, $cache)) { - return is_object($result) ? $result->forTemplate() : $result; - } + $result = $this->obj($field, $arguments, false, $cache); + return is_object($result) ? $result->forTemplate() : $result; } /** diff --git a/tests/ViewableDataTest.php b/tests/ViewableDataTest.php index 3ceb9a604..b2448a9b0 100755 --- a/tests/ViewableDataTest.php +++ b/tests/ViewableDataTest.php @@ -26,6 +26,11 @@ class ViewableDataTest extends SapphireTest { $this->assertEquals('<foo>', $caster->XML_val('castedUnsafeXML')); } + public function testUncastedXMLVal() { + $caster = new ViewableDataTest_Castable(); + $this->assertEquals($caster->XML_val('uncastedZeroValue'), 0); + } + public function testArrayCustomise() { $viewableData = new ViewableDataTest_Castable(); $newViewableData = $viewableData->customise(array ( @@ -67,6 +72,8 @@ class ViewableDataTest_Castable extends ViewableData { public $test = 'test'; + public $uncastedZeroValue = 0; + public function alwaysCasted() { return 'alwaysCasted'; }