ArrayData should only change the type of included objects if they're not ViewableData.

Included regression test

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60473 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-08-12 03:34:19 +00:00
parent 130ecfe5aa
commit a99accbea4
2 changed files with 16 additions and 1 deletions

View File

@ -35,7 +35,7 @@ class ArrayData extends ViewableData {
}
public function getField($f) {
if((is_object($this->array[$f]) && !$this->array[$f] instanceof ArrayData) || (is_array($this->array[$f]) && ArrayLib::is_associative($this->array[$f]))) {
if((is_object($this->array[$f]) && !$this->array[$f] instanceof ViewableData) || (is_array($this->array[$f]) && ArrayLib::is_associative($this->array[$f]))) {
return new ArrayData($this->array[$f]);
} else {
return $this->array[$f];
@ -66,6 +66,7 @@ class ArrayData extends ViewableData {
* This is pretty crude, but it helps diagnose error situations
*/
function forTemplate() {
return "(ArrayData)";
return var_export($this->array, true);
}

14
tests/ArrayDataTest.php Normal file
View File

@ -0,0 +1,14 @@
<?php
class ArrayDataTest extends SapphireTest {
function testViewabledataItemsInsideArraydataArePreserved() {
/* ViewableData objects will be preserved, but other objects will be converted */
$arrayData = new ArrayData(array(
"A" => new Varchar("A"),
"B" => new Object(),
));
$this->assertEquals("Varchar", get_class($arrayData->A));
$this->assertEquals("ArrayData", get_class($arrayData->B));
}
}