function BlockContentTranslationUITest::doTestBasicTranslation

Same name in other branches
  1. 9 core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php \Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::doTestBasicTranslation()
  2. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php \Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::doTestBasicTranslation()
  3. 10 core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php \Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::doTestBasicTranslation()

Overrides ContentTranslationUITestBase::doTestBasicTranslation

File

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

Class

BlockContentTranslationUITest
Tests the block content translation UI.

Namespace

Drupal\Tests\block_content\Functional

Code

protected function doTestBasicTranslation() : void {
    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) {
        $this->fail('Blocks can have translations with the same "info" value.');
    }
    // Check that the translate operation link is shown.
    $this->drupalGet('admin/content/block');
    $this->assertSession()
        ->linkByHrefExists('admin/content/block/' . $entity->id() . '/translations');
}

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