Loading CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ JSON Field 8.x-1.x-dev, xxxx-xx-xx #3213899 by paulocs, DamienMcKenna, guilhermevp: Fix test coverage for D9. #3281633 by DamienMcKenna: Fail tests sooner if database is not supported. #3281648 by DamienMcKenna: Move JsonEditorWidget into a submodule. #3252426 by geek-merlin, mfb, DamienMcKenna, mbovan: Support sqlite; set sqlite_type to native JSON field. JSON Field 8.x-1.0-rc4, 2021-05-13 Loading src/Plugin/Field/FieldType/NativeJSONItem.php +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ class NativeJSONItem extends FieldItemBase { 'type' => 'json', 'pgsql_type' => 'json', 'mysql_type' => 'json', 'sqlite_type' => 'text', 'not null' => FALSE, ], ], Loading tests/src/Kernel/JsonItemTest.php +13 −2 Original line number Diff line number Diff line Loading @@ -17,9 +17,11 @@ class JsonItemTest extends KernelTestBase { /** * Tests that field values are saved a retrievable. * * @dataProvider providerTestFieldCreate */ public function testFieldCreate() { $this->createTestField(); public function testFieldCreate($type) { $this->createTestField([], [], $type); $entity = EntityTest::create([ 'test_json_field' => json_encode([]), Loading @@ -29,6 +31,15 @@ class JsonItemTest extends KernelTestBase { $this->assertEquals(json_encode([]), $entity->test_json_field->value); } /** * Data provider. * * @see testFieldCreate() */ public function providerTestFieldCreate() { return [['json'], ['json_native']]; } /** * Tests that default values are used when no value is added. */ Loading tests/src/Kernel/KernelTestBase.php +4 −3 Original line number Diff line number Diff line Loading @@ -42,19 +42,20 @@ abstract class KernelTestBase extends DrupalKernelTestBase { * * @param array $field_storage_properties * @param array $field_properties * @param string $type */ protected function createTestField($field_storage_properties = [], $field_properties = []) { protected function createTestField($field_storage_properties = [], $field_properties = [], $type = 'json') { $field_storage = FieldStorageConfig::create([ 'field_name' => 'test_json_field', 'entity_type' => 'entity_test', 'type' => 'json', 'type' => $type, ] + $field_storage_properties); $field_storage->save(); $field = FieldConfig::create([ 'field_name' => 'test_json_field', 'entity_type' => 'entity_test', 'type' => 'json', 'type' => $type, 'bundle' => 'entity_test', ] + $field_properties); $field->save(); Loading Loading
CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ JSON Field 8.x-1.x-dev, xxxx-xx-xx #3213899 by paulocs, DamienMcKenna, guilhermevp: Fix test coverage for D9. #3281633 by DamienMcKenna: Fail tests sooner if database is not supported. #3281648 by DamienMcKenna: Move JsonEditorWidget into a submodule. #3252426 by geek-merlin, mfb, DamienMcKenna, mbovan: Support sqlite; set sqlite_type to native JSON field. JSON Field 8.x-1.0-rc4, 2021-05-13 Loading
src/Plugin/Field/FieldType/NativeJSONItem.php +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ class NativeJSONItem extends FieldItemBase { 'type' => 'json', 'pgsql_type' => 'json', 'mysql_type' => 'json', 'sqlite_type' => 'text', 'not null' => FALSE, ], ], Loading
tests/src/Kernel/JsonItemTest.php +13 −2 Original line number Diff line number Diff line Loading @@ -17,9 +17,11 @@ class JsonItemTest extends KernelTestBase { /** * Tests that field values are saved a retrievable. * * @dataProvider providerTestFieldCreate */ public function testFieldCreate() { $this->createTestField(); public function testFieldCreate($type) { $this->createTestField([], [], $type); $entity = EntityTest::create([ 'test_json_field' => json_encode([]), Loading @@ -29,6 +31,15 @@ class JsonItemTest extends KernelTestBase { $this->assertEquals(json_encode([]), $entity->test_json_field->value); } /** * Data provider. * * @see testFieldCreate() */ public function providerTestFieldCreate() { return [['json'], ['json_native']]; } /** * Tests that default values are used when no value is added. */ Loading
tests/src/Kernel/KernelTestBase.php +4 −3 Original line number Diff line number Diff line Loading @@ -42,19 +42,20 @@ abstract class KernelTestBase extends DrupalKernelTestBase { * * @param array $field_storage_properties * @param array $field_properties * @param string $type */ protected function createTestField($field_storage_properties = [], $field_properties = []) { protected function createTestField($field_storage_properties = [], $field_properties = [], $type = 'json') { $field_storage = FieldStorageConfig::create([ 'field_name' => 'test_json_field', 'entity_type' => 'entity_test', 'type' => 'json', 'type' => $type, ] + $field_storage_properties); $field_storage->save(); $field = FieldConfig::create([ 'field_name' => 'test_json_field', 'entity_type' => 'entity_test', 'type' => 'json', 'type' => $type, 'bundle' => 'entity_test', ] + $field_properties); $field->save(); Loading