mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Make sure GridState always outputs a JSON Object string
This commit is contained in:
parent
70ffb3297a
commit
a43414dedb
@ -106,11 +106,8 @@ class GridState extends HiddenField
|
||||
*/
|
||||
public function Value()
|
||||
{
|
||||
if (!$this->data) {
|
||||
return json_encode([]);
|
||||
}
|
||||
|
||||
return json_encode($this->data->getChangesArray());
|
||||
$data = $this->data ? $this->data->getChangesArray() : [];
|
||||
return json_encode($data, JSON_FORCE_OBJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
33
tests/php/Forms/GridField/GridStateTest.php
Normal file
33
tests/php/Forms/GridField/GridStateTest.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\Tests\GridField;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridState;
|
||||
|
||||
class GridStateTest extends SapphireTest
|
||||
{
|
||||
|
||||
public function testValue()
|
||||
{
|
||||
$gridfield = new GridField('Test');
|
||||
|
||||
$state = new GridState($gridfield);
|
||||
$this->assertEquals('{}', $state->Value(), 'GridState without any data has empty JSON object for Value');
|
||||
|
||||
$data = $state->getData();
|
||||
$data->initDefaults(['Foo' => 'Bar']);
|
||||
|
||||
$this->assertEquals('{}', $state->Value(), 'GridState without change has empty JSON object for Value');
|
||||
|
||||
$data->Foo = 'Barrr';
|
||||
|
||||
$this->assertEquals(
|
||||
'{"Foo":"Barrr"}',
|
||||
$state->Value(),
|
||||
'GridState with changes returns has a JSON object string for Value.'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user