Test that original fields also still exist and aren't broken

This commit is contained in:
Antony Videtta 2020-01-23 12:24:09 +13:00
parent f208f3e527
commit ee220f79b6
1 changed files with 20 additions and 13 deletions

View File

@ -5,16 +5,14 @@ namespace SilverStripe\RestfulServer\Tests;
use SilverStripe\RestfulServer\RestfulServer;
use SilverStripe\ORM\DataObject;
use SilverStripe\RestfulServer\Tests\Stubs\JSONDataFormatterTypeTestObject;
use SilverStripe\RestfulServer\Tests\Stubs\JSONDataFormatterOriginalFunctionality;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\RestfulServer\DataFormatter\JSONDataFormatter;
/**
*
* @todo Test Relation getters
* @todo Test filter and limit through GET params
* @todo Test DELETE verb
*
* Tests improvements made to JsonTypes,
* calls method which appends more fields
*/
class JSONDataFormatterTest extends SapphireTest
{
@ -28,6 +26,7 @@ class JSONDataFormatterTest extends SapphireTest
public function testJSONTypes()
{
// Needed as private static $api_access = true; doesn't seem to work on the stub file
Config::inst()->update(JSONDataFormatterTypeTestObject::class, 'api_access', true);
@ -39,16 +38,24 @@ class JSONDataFormatterTest extends SapphireTest
// Returns valid array and isn't null
$this->assertNotEmpty($json, 'Array is empty');
$timestamp = date('Y-m-d H:i:s', time() - 1);
// Test that original fields still exist, ie id, href, and className
$standard_id = $json->Children[0]->id;
$standard_className = $json->Children[0]->className;
$standard_href = $json->Children[0]->href;
$this->assertEquals(8, $standard_id, "Standard id field not equal");
$this->assertEquals('SilverStripe\RestfulServer\Tests\Stubs\JSONDataFormatterTypeTestObject', $standard_className, "Standard className does not equal");
$this->assertEquals('http://localhost/api/v1/SilverStripe-RestfulServer-Tests-Stubs-JSONDataFormatterTypeTestObject/8.json', $standard_href, "Standard href field not equal");
// Test method improvements, more fields rather than just id, href, className
$this->assertEquals(9, $json->ID, "ID not equal");
$this->assertEquals("SilverStripe\\RestfulServer\\Tests\\Stubs\\JSONDataFormatterTypeTestObject", $json->ClassName, "Class not equal");
$this->assertEquals($timestamp, $json->LastEdited, "Last edited does not equal");
$this->assertEquals($timestamp, $json->Created, "Created at does not equal");
$this->assertEquals("Test Object", $json->Name);
$this->assertEquals(false, $json->Active);
$this->assertEquals(0, $json->Sort);
$this->assertEquals(0, $json->Average);
$this->assertEquals(0, $json->ParentID);
$this->assertEquals(date('Y-m-d H:i:s', time() - 1), $json->LastEdited, "Last edited does not equal");
$this->assertEquals(date('Y-m-d H:i:s', time() - 1), $json->Created, "Created at does not equal");
$this->assertEquals("Test Object", $json->Name, "Name not equal");
$this->assertEquals(false, $json->Active, "Active not equal to false");
$this->assertEquals(0, $json->Sort, "Sort not equal to 0");
$this->assertEquals(0, $json->Average, "Average not equal to 0");
$this->assertEquals(0, $json->ParentID, "ParentID not equal to 0");
}
}