You are here

protected function EntityFormTest::doTestMultilingualFormCRUD in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityFormTest.php \Drupal\system\Tests\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/src/Tests/Entity/EntityFormTest.php
Tests basic multilingual form CRUD functionality.

File

core/modules/system/src/Tests/Entity/EntityFormTest.php, line 107
Contains \Drupal\system\Tests\Entity\EntityFormTest.

Class

EntityFormTest
Tests the entity form.

Namespace

Drupal\system\Tests\Entity

Code

protected function doTestMultilingualFormCRUD($entity_type_id) {
  $name1 = $this
    ->randomMachineName(8);
  $name1_ro = $this
    ->randomMachineName(9);
  $name2_ro = $this
    ->randomMachineName(11);
  $edit = array(
    '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
    ->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array(
    '%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, format_string('%entity_type: The translation has been added.', array(
    '%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
    ->assertTrue($translated_entity, format_string('%entity_type: Modified translation found in the database.', array(
    '%entity_type' => $entity_type_id,
  )));
  $this
    ->assertEqual($translated_entity->name->value, $name2_ro, format_string('%entity_type: The name of the translation has been modified.', array(
    '%entity_type' => $entity_type_id,
  )));
  $this
    ->drupalGet('ro/' . $entity_type_id . '/manage/' . $entity
    ->id() . '/edit');
  $this
    ->clickLink(t('Delete'));
  $this
    ->drupalPostForm(NULL, array(), t('Delete Romanian translation'));
  $entity = $this
    ->loadEntityByName($entity_type_id, $name1);
  $this
    ->assertNotNull($entity, format_string('%entity_type: The original entity still exists.', array(
    '%entity_type' => $entity_type_id,
  )));
  $this
    ->assertFalse($entity
    ->hasTranslation('ro'), format_string('%entity_type: Entity translation does not exist anymore.', array(
    '%entity_type' => $entity_type_id,
  )));
}