function TestObjectItemTest::testTestObjectItem

Same name in other branches
  1. 9 core/modules/field/tests/src/Kernel/TestObjectItemTest.php \Drupal\Tests\field\Kernel\TestObjectItemTest::testTestObjectItem()
  2. 10 core/modules/field/tests/src/Kernel/TestObjectItemTest.php \Drupal\Tests\field\Kernel\TestObjectItemTest::testTestObjectItem()
  3. 11.x 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.