mirror of
https://github.com/silverstripe/silverstripe-restfulserver
synced 2024-10-22 14:05:58 +02:00
reinstate old test
This commit is contained in:
parent
2c4803bd42
commit
07ddd20399
@ -31,8 +31,29 @@ class JSONDataFormatterTest extends SapphireTest
|
|||||||
|
|
||||||
// Grab test object
|
// Grab test object
|
||||||
$formatter = new JSONDataFormatter();
|
$formatter = new JSONDataFormatter();
|
||||||
$parent = $this->objFromFixture(JSONDataFormatterTypeTestObject::class, 'original');
|
|
||||||
$json = json_decode($formatter->convertDataObject($parent));
|
$parent = $this->objFromFixture(JSONDataFormatterTypeTestObject::class, 'parent');
|
||||||
|
$json = $formatter->convertDataObject($parent);
|
||||||
|
|
||||||
|
$this->assertRegexp('/"ID":\d+/', $json, 'PK casted to integer');
|
||||||
|
$this->assertRegexp('/"Created":"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}"/', $json, 'Datetime casted to string');
|
||||||
|
$this->assertContains('"Name":"Parent"', $json, 'String casted to string');
|
||||||
|
$this->assertContains('"Active":true', $json, 'Boolean casted to boolean');
|
||||||
|
$this->assertContains('"Sort":17', $json, 'Integer casted to integer');
|
||||||
|
$this->assertContains('"Average":1.2345', $json, 'Float casted to float');
|
||||||
|
$this->assertContains('"ParentID":0', $json, 'Empty FK is 0');
|
||||||
|
|
||||||
|
$child3 = $this->objFromFixture(JSONDataFormatterTypeTestObject::class, 'child3');
|
||||||
|
$json = $formatter->convertDataObject($child3);
|
||||||
|
|
||||||
|
$this->assertContains('"Name":null', $json, 'Empty string is null');
|
||||||
|
$this->assertContains('"Active":false', $json, 'Empty boolean is false');
|
||||||
|
$this->assertContains('"Sort":0', $json, 'Empty integer is 0');
|
||||||
|
$this->assertContains('"Average":0', $json, 'Empty float is 0');
|
||||||
|
$this->assertRegexp('/"ParentID":\d+/', $json, 'FK casted to integer');
|
||||||
|
|
||||||
|
$original = $this->objFromFixture(JSONDataFormatterTypeTestObject::class, 'original');
|
||||||
|
$json = json_decode($formatter->convertDataObject($original));
|
||||||
|
|
||||||
// Returns valid array and isn't null
|
// Returns valid array and isn't null
|
||||||
$this->assertNotEmpty($json, 'Array is empty');
|
$this->assertNotEmpty($json, 'Array is empty');
|
||||||
|
Loading…
Reference in New Issue
Block a user