-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(DataChangeRecord): Workaround nested array limitation with DataDi…
…fferencer (#26) * fix(DataChangeRecord): Workaround nested array limitation with DataDifferencer by only json_decode'ing 1 level down. This resolve bugs when you're storing JSON data in a 'Text' DB field via MultiValueField. * fix(DataChangeTest): Fix tests and logic surrounding getting the class from the table name * feat(DataChangeCMSTest): Add test for json_decode() / DataDifferencer bug, Update DataChangeAdmin to use class name identifier (::class)
- Loading branch information
1 parent
98b6a8f
commit 35d7d8c
Showing
14 changed files
with
377 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,17 @@ | |
namespace Symbiote\DataChange\Admin; | ||
|
||
use SilverStripe\Admin\ModelAdmin; | ||
use Symbiote\DataChange\Model\DataChangeRecord; | ||
|
||
/** | ||
* @author [email protected] | ||
* @license BSD License http://silverstripe.org/bsd-license/ | ||
*/ | ||
class DataChangeAdmin extends ModelAdmin | ||
{ | ||
private static $managed_models = array( | ||
'Symbiote\DataChange\Model\DataChangeRecord', | ||
); | ||
private static $managed_models = [ | ||
DataChangeRecord::class, | ||
]; | ||
|
||
private static $url_segment = 'datachanges'; | ||
private static $menu_title = 'Data Changes'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Symbiote\DataChange\Tests; | ||
|
||
use SilverStripe\Dev\FunctionalTest; | ||
use SilverStripe\Control\Controller; | ||
use Symbiote\DataChange\Admin\DataChangeAdmin; | ||
|
||
class DataChangeCMSTest extends FunctionalTest | ||
{ | ||
protected $usesDatabase = true; | ||
|
||
protected static $extra_dataobjects = [ | ||
TestTextJSONFieldObject::class, | ||
]; | ||
|
||
public function testCMSFieldsWithJSONData() | ||
{ | ||
// Create test data | ||
$record = new TestTextJSONFieldObject(); | ||
$record->TextFieldWithJSON = json_encode([ | ||
'The Pixies' => [ | ||
'Bossanova' => [ | ||
'The Happening' => [ | ||
'My head was feeling scared', | ||
'but my heart was feeling free', | ||
] | ||
], | ||
] | ||
]); | ||
$record->write(); | ||
$record->TextFieldWithJSON = json_encode([ | ||
'Radiohead' => [ | ||
'A Moonshaped Pool' => [ | ||
'Present Tense' => [ | ||
'Keep it light and', | ||
'Keep it moving', | ||
'I am doing', | ||
'No harm', | ||
] | ||
], | ||
] | ||
]); | ||
$record->write(); | ||
|
||
// Get the data change tracker record that was written in 'TestTextJSONFieldObject's onAfterWrite() | ||
$dataChangeTrackRecordIds = $record->getDataChangesList()->column('ID'); | ||
$this->assertEquals(2, count($dataChangeTrackRecordIds)); | ||
|
||
// View in the CMS. | ||
$this->logInWithPermission('ADMIN'); | ||
$dataChangeTrackEditID = $dataChangeTrackRecordIds[0]; | ||
$editLink = 'admin/datachanges/Symbiote-DataChange-Model-DataChangeRecord/EditForm/field/Symbiote-DataChange-Model-DataChangeRecord/item/'.$dataChangeTrackEditID.'/edit'; | ||
|
||
// NOTE(Jake): 2018-06-25 | ||
// | ||
// If the test fails, you will get something like: | ||
// - nl2br() expects parameter 1 to be string, array given | ||
// | ||
// This is because the DataDifferencer can't work wtih a 'Text' field that returns an array. | ||
// ie. `TestTextJSONFieldObject` custom getter "getTextFieldWithJSON" | ||
// | ||
$response = $this->get($editLink); | ||
$this->assertEquals(200, $response->getStatusCode()); | ||
|
||
$body = $response->getBody(); | ||
$this->assertTrue( | ||
true, | ||
strpos($body, 'Get Vars') !== false, | ||
'Cannot find \'Get Vars\' field to prove that we\'re actually on the editing DataChangeRecord page.' | ||
); | ||
$this->assertTrue( | ||
true, | ||
strpos($body, 'Post Vars') !== false, | ||
'Cannot find \'Post Vars\' field to prove that we\'re actually on the editing DataChangeRecord page.' | ||
); | ||
} | ||
} |
Oops, something went wrong.