BUGFIX: r101093 broke casting of values from the failover object. Add lookup to the failover for casting info, and add test

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@103240 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Hamish Friedlander 2010-04-21 03:56:37 +00:00 committed by Sam Minnee
parent a1dc52719c
commit f7c3c35a13
2 changed files with 28 additions and 3 deletions

View File

@ -251,6 +251,8 @@ class ViewableData extends Object implements IteratorAggregate {
$specs = Object::combined_static(get_class($this), 'casting');
if(isset($specs[$field])) return $specs[$field];
if($this->failover) return $this->failover->castingHelper($field);
}
/**

View File

@ -15,6 +15,21 @@ class ViewableDataTest extends SapphireTest {
$this->assertFalse($caster->obj('noCastingInformation', null, false) instanceof ViewableData_Caster);
}
public function testFailoverRequiresCasting() {
$caster = new ViewableDataTest_Castable();
$container = new ViewableDataTest_Container($caster);
$this->assertTrue($container->obj('alwaysCasted') instanceof ViewableDataTest_RequiresCasting);
$this->assertTrue($caster->obj('alwaysCasted', null, false) instanceof ViewableDataTest_RequiresCasting);
/* @todo - This currently fails, because the default_cast static variable is always taken from the topmost object,
* not the failover object the field actually came from. Should we fix this, or declare current behaviour as correct?
$this->assertTrue($container->obj('noCastingInformation') instanceof ViewableData_Caster);
$this->assertFalse($caster->obj('noCastingInformation', null, false) instanceof ViewableData_Caster);
*/
}
public function testCastingXMLVal() {
$caster = new ViewableDataTest_Castable();
@ -151,4 +166,12 @@ class ViewableData_Caster extends ViewableData {
}
class ViewableDataTest_Container extends ViewableData {
public function __construct($failover) {
$this->failover = $failover;
parent::__construct();
}
}
/**#@-*/