You are here

protected function BlockContentTranslationUITest::doTestBasicTranslation in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php \Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::doTestBasicTranslation()
  2. 10 core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php \Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::doTestBasicTranslation()

Tests the basic translation workflow.

Overrides ContentTranslationUITestBase::doTestBasicTranslation

File

core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php, line 107

Class

BlockContentTranslationUITest
Tests the block content translation UI.

Namespace

Drupal\Tests\block_content\Functional

Code

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

  // Ensure that a block translation can be created using the same description
  // as in the original language.
  $default_langcode = $this->langcodes[0];
  $values = $this
    ->getNewEntityValues($default_langcode);
  $storage = \Drupal::entityTypeManager()
    ->getStorage($this->entityTypeId);

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $storage
    ->create([
    'type' => 'basic',
  ] + $values);
  $entity
    ->save();
  $entity
    ->addTranslation('it', $values);
  try {
    $entity
      ->save();
  } catch (\Exception $e) {
    $this
      ->fail('Blocks can have translations with the same "info" value.');
  }

  // Check that the translate operation link is shown.
  $this
    ->drupalGet('admin/structure/block/block-content');
  $this
    ->assertSession()
    ->linkByHrefExists('block/' . $entity
    ->id() . '/translations');
}