You are here

protected function ContentEntityNormalizerTest::setUp in Replication 8

Overrides NormalizerTestBase::setUp

File

tests/src/Kernel/Normalizer/ContentEntityNormalizerTest.php, line 18

Class

ContentEntityNormalizerTest
Tests the content serialization format.

Namespace

Drupal\Tests\replication\Kernel\Normalizer

Code

protected function setUp() {
  parent::setUp();

  // Create a test entity to serialize.
  $this->values = [
    'name' => $this
      ->randomMachineName(),
    'user_id' => 1,
    'field_test_text' => [
      'value' => $this
        ->randomMachineName(),
      'format' => 'full_html',
    ],
  ];
  ConfigurableLanguage::createFromLangcode('ro')
    ->save();
  $entity = EntityTestMulRev::create($this->values);
  $entity
    ->save();

  // Save again.
  $entity
    ->save();

  // Add Romanian translation.
  $romanian = $entity
    ->addTranslation('ro');
  $romanian->name->value = $entity->name->value . '_ro';
  $romanian->field_test_text->value = $this->values['field_test_text']['value'] . '_ro';
  $romanian->field_test_text->format = 'full_html';
  $romanian
    ->save();

  // Save again the original entity.
  $entity = EntityTestMulRev::load($entity
    ->id());
  $entity
    ->save();

  // Load again romanian translation and save a new revision.
  $romanian = $entity
    ->getTranslation('ro');
  $romanian
    ->save();
  $this->entity = EntityTestMulRev::load($entity
    ->id());
  $this->romanian = $entity
    ->getTranslation('ro');
}