You are here

public function TestObjectItemTest::testTestObjectItem in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/TestObjectItemTest.php \Drupal\Tests\field\Kernel\TestObjectItemTest::testTestObjectItem()
  2. 9 core/modules/field/tests/src/Kernel/TestObjectItemTest.php \Drupal\Tests\field\Kernel\TestObjectItemTest::testTestObjectItem()

Tests the serialization of a field type that has an object.

File

core/modules/field/tests/src/Kernel/TestObjectItemTest.php, line 45

Class

TestObjectItemTest
Tests the serialization of an object.

Namespace

Drupal\Tests\field\Kernel

Code

public function testTestObjectItem() {
  $object = new \stdClass();
  $object->foo = 'bar';
  $entity = EntityTest::create();
  $entity->field_test->value = $object;
  $entity
    ->save();

  // Verify that the entity has been created properly.
  $id = $entity
    ->id();
  $entity = EntityTest::load($id);
  $this
    ->assertInstanceOf(\stdClass::class, $entity->field_test->value);
  $this
    ->assertEquals($object, $entity->field_test->value);
}