mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT: allow adding a new a field to ArrayData (from r107434)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112595 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
cfe9b518a5
commit
f097b678d8
@ -43,6 +43,16 @@ class ArrayData extends ViewableData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or set a field on this object.
|
||||
*
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setField($field, $value) {
|
||||
$this->array[$field] = $value;
|
||||
}
|
||||
|
||||
public function hasField($f) {
|
||||
return isset($this->array[$f]);
|
||||
}
|
||||
|
@ -75,6 +75,15 @@ class ArrayDataTest extends SapphireTest {
|
||||
$this->assertEquals("Apple", $array['a']);
|
||||
$this->assertEquals("Banana", $array['b']);
|
||||
}
|
||||
|
||||
function testSetField() {
|
||||
$arrayData = new ArrayData(array());
|
||||
|
||||
$arrayData->setField('d', 'Delta');
|
||||
|
||||
$this->assertTrue($arrayData->hasField('d'));
|
||||
$this->assertEquals('Delta', $arrayData->getField('d'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user