mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #2818 from tractorcow/pulls/gridstate_data-error-test
BUG GridState_Data doesn't hold falsey values - Fixes #2813
This commit is contained in:
commit
b145e96d27
@ -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,6 +124,27 @@ class GridFieldTest extends SapphireTest {
|
||||
$this->assertEquals(10, $obj->State->NoValue);
|
||||
$this->assertEquals(10, $obj->State->NoValue(20));
|
||||
|
||||
// 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
|
||||
|
||||
// Test that false is storable
|
||||
$this->assertFalse($obj->State->Falsey2(false));
|
||||
$this->assertFalse($obj->State->Falsey2(true));
|
||||
$this->assertFalse($obj->State->Falsey2);
|
||||
$obj->State->Falsey2 = false;
|
||||
$this->assertFalse($obj->State->Falsey2);
|
||||
|
||||
// Check nested values
|
||||
$this->assertInstanceOf('GridState_Data', $obj->State->Nested);
|
||||
$this->assertInstanceOf('GridState_Data', $obj->State->Nested->DeeperNested());
|
||||
|
Loading…
Reference in New Issue
Block a user