mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fixed handing of false values in GridState_Data
API Added ability to unset values
This commit is contained in:
parent
6df276c843
commit
cd213ab488
@ -153,7 +153,7 @@ class GridState_Data {
|
||||
* @return mixed The value associated with this key, or the value specified by $default if not set
|
||||
*/
|
||||
public function getData($name, $default = null) {
|
||||
if(empty($this->data[$name])) {
|
||||
if(!isset($this->data[$name])) {
|
||||
$this->data[$name] = $default;
|
||||
} else if(is_array($this->data[$name])) {
|
||||
$this->data[$name] = new GridState_Data($this->data[$name]);
|
||||
@ -170,6 +170,10 @@ class GridState_Data {
|
||||
return isset($this->data[$name]);
|
||||
}
|
||||
|
||||
public function __unset($name) {
|
||||
unset($this->data[$name]);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
if(!$this->data) {
|
||||
return "";
|
||||
|
@ -124,21 +124,21 @@ class GridFieldTest extends SapphireTest {
|
||||
$this->assertEquals(10, $obj->State->NoValue);
|
||||
$this->assertEquals(10, $obj->State->NoValue(20));
|
||||
|
||||
//Show that values returned by the assignment function don't
|
||||
// actually return the value stored
|
||||
// Test that values can be set, unset, and inspected
|
||||
$this->assertFalse(isset($obj->State->NotSet));
|
||||
$obj->State->NotSet = false;
|
||||
$this->assertTrue(isset($obj->State->NotSet));
|
||||
unset($obj->State->NotSet);
|
||||
$this->assertFalse(isset($obj->State->NotSet));
|
||||
|
||||
// Test that false evaluating values are storable
|
||||
$this->assertEquals(0, $obj->State->Falsey0(0)); // expect 0 back
|
||||
$this->assertEquals(0, $obj->State->Falsey0(10)); // expect 0 back
|
||||
$this->assertEquals(0, $obj->State->Falsey0); //expect 0 back
|
||||
$obj->State->Falsey0 = 0; //manually assign 0
|
||||
$this->assertEquals(0, $obj->State->Falsey0); //expect 0 back
|
||||
|
||||
//repeat for other falsey values
|
||||
$this->assertEquals(array(), $obj->State->Falsey1(array()));
|
||||
$this->assertEquals(array(), $obj->State->Falsey1(array('test')));
|
||||
$this->assertEquals(array(), $obj->State->Falsey1);
|
||||
$obj->State->Falsey1 = array(); //manually assign 0
|
||||
$this->assertEquals(array(), $obj->State->Falsey1); //expect 0 back
|
||||
|
||||
// Test that false is storable
|
||||
$this->assertFalse($obj->State->Falsey2(false));
|
||||
$this->assertFalse($obj->State->Falsey2(true));
|
||||
$this->assertFalse($obj->State->Falsey2);
|
||||
|
Loading…
Reference in New Issue
Block a user