mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX ViewableData->castingClass() cuts off last character of a casting definition if it has bracketed arguments (fixes #5536, thanks ajshort) (from r104063)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112331 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
bf9a3d43f6
commit
2bab8c8729
@ -267,7 +267,7 @@ class ViewableData extends Object implements IteratorAggregate {
|
||||
|
||||
$bPos = strpos($spec,'(');
|
||||
if($bPos === false) return $spec;
|
||||
else return substr($spec, 0, $bPos-1);
|
||||
else return substr($spec, 0, $bPos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,6 +94,24 @@ class ViewableDataTest extends SapphireTest {
|
||||
$this->assertEquals($data->ATT_val('test'), '"this is a test"');
|
||||
}
|
||||
|
||||
public function testCastingClass() {
|
||||
$expected = array(
|
||||
'NonExistant' => null,
|
||||
'Field' => 'CastingType',
|
||||
'Argument' => 'ArgumentType',
|
||||
'ArrayArgument' => 'ArrayArgumentType'
|
||||
);
|
||||
$obj = new ViewableDataTest_CastingClass();
|
||||
|
||||
foreach($expected as $field => $class) {
|
||||
$this->assertEquals(
|
||||
$class,
|
||||
$obj->castingClass($field),
|
||||
"castingClass() returns correct results for ::\$$field"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**#@+
|
||||
@ -174,4 +192,12 @@ class ViewableDataTest_Container extends ViewableData {
|
||||
}
|
||||
}
|
||||
|
||||
class ViewableDataTest_CastingClass extends ViewableData {
|
||||
public static $casting = array(
|
||||
'Field' => 'CastingType',
|
||||
'Argument' => 'ArgumentType(Argument)',
|
||||
'ArrayArgument' => 'ArrayArgumentType(array(foo, bar))'
|
||||
);
|
||||
}
|
||||
|
||||
/**#@-*/
|
Loading…
Reference in New Issue
Block a user