protected function FieldItemSerializationTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php \Drupal\Tests\serialization\Kernel\FieldItemSerializationTest::setUp()
- 9 core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php \Drupal\Tests\serialization\Kernel\FieldItemSerializationTest::setUp()
File
- core/
modules/ serialization/ tests/ src/ Kernel/ FieldItemSerializationTest.php, line 62
Class
- FieldItemSerializationTest
- Test field level normalization process.
Namespace
Drupal\Tests\serialization\KernelCode
protected function setUp() : void {
parent::setUp();
// Auto-create a field for testing default field values.
FieldStorageConfig::create([
'entity_type' => 'entity_test_mulrev',
'field_name' => 'field_test_text_default',
'type' => 'text',
'cardinality' => 1,
'translatable' => FALSE,
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test_mulrev',
'field_name' => 'field_test_text_default',
'bundle' => 'entity_test_mulrev',
'label' => 'Test text-field with default',
'default_value' => [
[
'value' => 'This is the default',
'format' => 'full_html',
],
],
'widget' => [
'type' => 'text_textfield',
'weight' => 0,
],
])
->save();
FieldStorageConfig::create([
'entity_type' => 'entity_test_mulrev',
'field_name' => 'field_test_boolean',
'type' => 'boolean',
'cardinality' => 1,
'translatable' => FALSE,
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test_mulrev',
'field_name' => 'field_test_boolean',
'bundle' => 'entity_test_mulrev',
'label' => 'Test boolean',
])
->save();
// Create a test entity to serialize.
$this->values = [
'name' => $this
->randomMachineName(),
'field_test_text' => [
'value' => $this
->randomMachineName(),
'format' => 'full_html',
],
'field_test_boolean' => [
'value' => FALSE,
],
];
$this->entity = EntityTestMulRev::create($this->values);
$this->entity
->save();
$this->serializer = $this->container
->get('serializer');
$this
->installConfig([
'field',
]);
}