function EntityFormTest::doTestMultilingualFormCRUD

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/EntityFormTest.php \Drupal\Tests\system\Functional\Entity\EntityFormTest::doTestMultilingualFormCRUD()
  2. 8.9.x core/modules/system/tests/src/Functional/Entity/EntityFormTest.php \Drupal\Tests\system\Functional\Entity\EntityFormTest::doTestMultilingualFormCRUD()
  3. 11.x 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 173

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->drupalGet($entity_type_id . '/add');
    $this->submitForm($edit, 'Save');
    $entity = $this->loadEntityByName($entity_type_id, $name1);
    $this->assertNotNull($entity, "{$entity_type_id}: Entity found in the database.");
    // 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->assertEquals($name1_ro, $translated_entity->name->value, "{$entity_type_id}: The translation has been added.");
    $edit['name[0][value]'] = $name2_ro;
    $this->drupalGet('ro/' . $entity_type_id . '/manage/' . $entity->id() . '/edit');
    $this->submitForm($edit, 'Save');
    $translated_entity = $this->loadEntityByName($entity_type_id, $name1)
        ->getTranslation('ro');
    $this->assertNotNull($translated_entity, "{$entity_type_id}: Modified translation found in the database.");
    $this->assertEquals($name2_ro, $translated_entity->name->value, "{$entity_type_id}: The name of the translation has been modified.");
    $this->drupalGet('ro/' . $entity_type_id . '/manage/' . $entity->id() . '/edit');
    $this->clickLink('Delete');
    $this->submitForm([], 'Delete Romanian translation');
    $entity = $this->loadEntityByName($entity_type_id, $name1);
    $this->assertNotNull($entity, "{$entity_type_id}: The original entity still exists.");
    $this->assertFalse($entity->hasTranslation('ro'), "{$entity_type_id}: Entity translation does not exist anymore.");
}

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