function FieldItemSerializationTest::setUp

Same name in this branch
  1. 9 core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php \Drupal\Tests\serialization\Kernel\FieldItemSerializationTest::setUp()
Same name and namespace in other branches
  1. 8.9.x core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php \Drupal\Tests\serialization\Kernel\FieldItemSerializationTest::setUp()
  2. 10 core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php \Drupal\Tests\serialization\Kernel\FieldItemSerializationTest::setUp()
  3. 11.x core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php \Drupal\Tests\serialization\Kernel\FieldItemSerializationTest::setUp()

Overrides NormalizerTestBase::setUp

File

core/modules/hal/tests/src/Kernel/serialization/FieldItemSerializationTest.php, line 63

Class

FieldItemSerializationTest
Test field level normalization process.

Namespace

Drupal\Tests\hal\Kernel\serialization

Code

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',
    ]);
}

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