You are here

protected function EntitySerializationTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 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',
  ]);
}