3 namespace Drupal\Tests\field\Kernel;
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
10 * Tests the serialization of an object.
14 class TestObjectItemTest extends FieldKernelTestBase {
21 public static $modules = ['field_test'];
26 protected function setUp() {
29 // Create a 'test_field' field and storage for validation.
30 FieldStorageConfig::create([
31 'field_name' => 'field_test',
32 'entity_type' => 'entity_test',
33 'type' => 'test_object_field',
36 'entity_type' => 'entity_test',
37 'field_name' => 'field_test',
38 'bundle' => 'entity_test',
43 * Tests the serialization of a field type that has an object.
45 public function testTestObjectItem() {
46 $object = new \stdClass();
48 $entity = EntityTest::create();
49 $entity->field_test->value = $object;
52 // Verify that the entity has been created properly.
54 $entity = EntityTest::load($id);
55 $this->assertTrue($entity->field_test->value instanceof \stdClass);
56 $this->assertEquals($object, $entity->field_test->value);