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:
Ingo Schommer 2010-10-14 23:56:11 +00:00
parent bf9a3d43f6
commit 2bab8c8729
2 changed files with 27 additions and 1 deletions

View File

@ -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);
}
/**

View File

@ -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))'
);
}
/**#@-*/