Source of file DataChangeCMSTest.php
Size: 2,785 Bytes - Last Modified: 2021-12-23T10:20:14+00:00
/var/www/docs.ssmods.com/process/src/tests/DataChangeCMSTest.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 | <?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.' ); } } |