You are here

protected function EntityFormTest::doTestMultilingualFormCRUD in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/EntityFormTest.php \Drupal\Tests\system\Functional\Entity\EntityFormTest::doTestMultilingualFormCRUD()

Executes the multilingual form CRUD tests for the given entity type ID.

Parameters

string $entity_type_id: The ID of entity type to run the tests with.

1 call to EntityFormTest::doTestMultilingualFormCRUD()
EntityFormTest::testMultilingualFormCRUD in core/modules/system/tests/src/Functional/Entity/EntityFormTest.php
Tests basic multilingual form CRUD functionality.

File

core/modules/system/tests/src/Functional/Entity/EntityFormTest.php, line 111

Class

EntityFormTest
Tests the entity form.

Namespace

Drupal\Tests\system\Functional\Entity

Code

protected function doTestMultilingualFormCRUD($entity_type_id) {
  $name1 = $this
    ->randomMachineName(8);
  $name1_ro = $this
    ->randomMachineName(9);
  $name2_ro = $this
    ->randomMachineName(11);
  $edit = [
    'name[0][value]' => $name1,
    'field_test_text[0][value]' => $this
      ->randomMachineName(16),
  ];
  $this
    ->drupalPostForm($entity_type_id . '/add', $edit, t('Save'));
  $entity = $this
    ->loadEntityByName($entity_type_id, $name1);
  $this
    ->assertNotNull($entity, new FormattableMarkup('%entity_type: Entity found in the database.', [
    '%entity_type' => $entity_type_id,
  ]));

  // Add a translation to the newly created entity without using the Content
  // translation module.
  $entity
    ->addTranslation('ro', [
    'name' => $name1_ro,
  ])
    ->save();
  $translated_entity = $this
    ->loadEntityByName($entity_type_id, $name1)
    ->getTranslation('ro');
  $this
    ->assertEqual($translated_entity->name->value, $name1_ro, new FormattableMarkup('%entity_type: The translation has been added.', [
    '%entity_type' => $entity_type_id,
  ]));
  $edit['name[0][value]'] = $name2_ro;
  $this
    ->drupalPostForm('ro/' . $entity_type_id . '/manage/' . $entity
    ->id() . '/edit', $edit, t('Save'));
  $translated_entity = $this
    ->loadEntityByName($entity_type_id, $name1)
    ->getTranslation('ro');
  $this
    ->assertNotNull($translated_entity, new FormattableMarkup('%entity_type: Modified translation found in the database.', [
    '%entity_type' => $entity_type_id,
  ]));
  $this
    ->assertEqual($translated_entity->name->value, $name2_ro, new FormattableMarkup('%entity_type: The name of the translation has been modified.', [
    '%entity_type' => $entity_type_id,
  ]));
  $this
    ->drupalGet('ro/' . $entity_type_id . '/manage/' . $entity
    ->id() . '/edit');
  $this
    ->clickLink(t('Delete'));
  $this
    ->drupalPostForm(NULL, [], t('Delete Romanian translation'));
  $entity = $this
    ->loadEntityByName($entity_type_id, $name1);
  $this
    ->assertNotNull($entity, new FormattableMarkup('%entity_type: The original entity still exists.', [
    '%entity_type' => $entity_type_id,
  ]));
  $this
    ->assertFalse($entity
    ->hasTranslation('ro'), new FormattableMarkup('%entity_type: Entity translation does not exist anymore.', [
    '%entity_type' => $entity_type_id,
  ]));
}