class TestObjectItemTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/field/tests/src/Kernel/TestObjectItemTest.php \Drupal\Tests\field\Kernel\TestObjectItemTest
- 9 core/modules/field/tests/src/Kernel/TestObjectItemTest.php \Drupal\Tests\field\Kernel\TestObjectItemTest
Tests the serialization of an object.
@group field
Hierarchy
- class \Drupal\Tests\field\Kernel\TestObjectItemTest extends \Drupal\Tests\field\Kernel\FieldKernelTestBase
Expanded class hierarchy of TestObjectItemTest
File
- core/
modules/ field/ tests/ src/ Kernel/ TestObjectItemTest.php, line 14
Namespace
Drupal\Tests\field\KernelView source
class TestObjectItemTest extends FieldKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'field_test',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create a 'test_field' field and storage for validation.
FieldStorageConfig::create([
'field_name' => 'field_test',
'entity_type' => 'entity_test',
'type' => 'test_object_field',
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'bundle' => 'entity_test',
])
->save();
}
/**
* Tests the serialization of a field type that has an object.
*/
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);
}
}