function ContentTranslationUITestBase::doTestTranslationDeletion

Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestTranslationDeletion()
  2. 8.9.x core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php \Drupal\content_translation\Tests\ContentTranslationUITestBase::doTestTranslationDeletion()
  3. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestTranslationDeletion()
  4. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestTranslationDeletion()

Tests translation deletion.

1 call to ContentTranslationUITestBase::doTestTranslationDeletion()
ContentTranslationUITestBase::testTranslationUI in core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
Tests the basic translation UI.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php, line 371

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function doTestTranslationDeletion() {
    // Confirm and delete a translation.
    $this->drupalLogin($this->translator);
    $langcode = 'fr';
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage($this->entityTypeId);
    $storage->resetCache([
        $this->entityId,
    ]);
    $entity = $storage->load($this->entityId);
    $language = ConfigurableLanguage::load($langcode);
    $url = $entity->toUrl('edit-form', [
        'language' => $language,
    ]);
    $this->drupalGet($url);
    $this->clickLink('Delete translation');
    $this->submitForm([], 'Delete ' . $language->getName() . ' translation');
    $storage->resetCache([
        $this->entityId,
    ]);
    $entity = $storage->load($this->entityId, TRUE);
    $this->assertIsObject($entity);
    $translations = $entity->getTranslationLanguages();
    $this->assertCount(2, $translations);
    $this->assertArrayNotHasKey($langcode, $translations);
    // Check that the translator cannot delete the original translation.
    $args = [
        $this->entityTypeId => $entity->id(),
        'language' => 'en',
    ];
    $this->drupalGet(Url::fromRoute("entity.{$this->entityTypeId}.content_translation_delete", $args));
    $this->assertSession()
        ->statusCodeEquals(403);
}

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