function EntitySerializationTest::setUp

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

Overrides NormalizerTestBase::setUp

File

core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php, line 71

Class

EntitySerializationTest
Tests that entities can be serialized to supported core formats.

Namespace

Drupal\Tests\serialization\Kernel

Code

protected function setUp() {
    parent::setUp();
    // User create needs sequence table.
    $this->installSchema('system', [
        'sequences',
    ]);
    FilterFormat::create([
        'format' => 'my_text_format',
        'name' => 'My Text Format',
        'filters' => [
            'filter_html' => [
                'module' => 'filter',
                'status' => TRUE,
                'weight' => 10,
                'settings' => [
                    'allowed_html' => '<p>',
                ],
            ],
            'filter_autop' => [
                'module' => 'filter',
                'status' => TRUE,
                'weight' => 10,
                'settings' => [],
            ],
        ],
    ])->save();
    // Create a test user to use as the entity owner.
    $this->user = \Drupal::entityTypeManager()->getStorage('user')
        ->create([
        'name' => 'serialization_test_user',
        'mail' => 'foo@example.com',
        'pass' => '123456',
    ]);
    $this->user
        ->save();
    // Create a test entity to serialize.
    $test_text_value = $this->randomMachineName();
    $this->values = [
        'name' => $this->randomMachineName(),
        'user_id' => $this->user
            ->id(),
        'field_test_text' => [
            'value' => $test_text_value,
            'format' => 'my_text_format',
        ],
    ];
    $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.