mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
a1dc52719c
commit
f7c3c35a13
@ -236,7 +236,7 @@ class ViewableData extends Object implements IteratorAggregate {
|
|||||||
user_error("castingHelperPair() Deprecated, use castingHelper() instead", E_USER_NOTICE);
|
user_error("castingHelperPair() Deprecated, use castingHelper() instead", E_USER_NOTICE);
|
||||||
return $this->castingHelper($field);
|
return $this->castingHelper($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field
|
* Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field
|
||||||
* on this object.
|
* on this object.
|
||||||
@ -248,9 +248,11 @@ class ViewableData extends Object implements IteratorAggregate {
|
|||||||
if($this->hasMethod('db') && $fieldSpec = $this->db($field)) {
|
if($this->hasMethod('db') && $fieldSpec = $this->db($field)) {
|
||||||
return $fieldSpec;
|
return $fieldSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
$specs = Object::combined_static(get_class($this), 'casting');
|
$specs = Object::combined_static(get_class($this), 'casting');
|
||||||
if(isset($specs[$field])) return $specs[$field];
|
if(isset($specs[$field])) return $specs[$field];
|
||||||
|
|
||||||
|
if($this->failover) return $this->failover->castingHelper($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,7 +14,22 @@ class ViewableDataTest extends SapphireTest {
|
|||||||
$this->assertTrue($caster->obj('alwaysCasted', null, false) instanceof ViewableDataTest_RequiresCasting);
|
$this->assertTrue($caster->obj('alwaysCasted', null, false) instanceof ViewableDataTest_RequiresCasting);
|
||||||
$this->assertFalse($caster->obj('noCastingInformation', null, false) instanceof ViewableData_Caster);
|
$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() {
|
public function testCastingXMLVal() {
|
||||||
$caster = new ViewableDataTest_Castable();
|
$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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**#@-*/
|
/**#@-*/
|
Loading…
x
Reference in New Issue
Block a user