BUGFIX ViewableData->castingClass() cuts off last character of a casting definition if it has bracketed arguments (fixes #5536, thanks ajshort)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@104063 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-05-04 20:08:25 +00:00 committed by Sam Minnee
parent b36fc700da
commit 2210783c68
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))'
);
}
/**#@-*/