function ContentTranslationUITestBase::doTestOutdatedStatus

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

Tests up-to-date status tracking.

1 call to ContentTranslationUITestBase::doTestOutdatedStatus()
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 242

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function doTestOutdatedStatus() {
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage($this->entityTypeId);
    $storage->resetCache([
        $this->entityId,
    ]);
    $entity = $storage->load($this->entityId);
    $langcode = 'fr';
    $languages = \Drupal::languageManager()->getLanguages();
    // Mark translations as outdated.
    $edit = [
        'content_translation[retranslate]' => TRUE,
    ];
    $edit_path = $entity->toUrl('edit-form', [
        'language' => $languages[$langcode],
    ]);
    $this->drupalGet($edit_path);
    $this->submitForm($edit, $this->getFormSubmitAction($entity, $langcode));
    $storage->resetCache([
        $this->entityId,
    ]);
    $entity = $storage->load($this->entityId);
    // Check that every translation has the correct "outdated" status, and that
    // the Translation fieldset is open if the translation is "outdated".
    foreach ($this->langcodes as $added_langcode) {
        $url = $entity->toUrl('edit-form', [
            'language' => ConfigurableLanguage::load($added_langcode),
        ]);
        $this->drupalGet($url);
        if ($added_langcode == $langcode) {
            // Verify that the retranslate flag is not checked by default.
            $this->assertSession()
                ->fieldValueEquals('content_translation[retranslate]', FALSE);
            $this->assertSession()
                ->elementNotExists('xpath', '//details[@id="edit-content-translation" and @open="open"]');
        }
        else {
            // Verify that the translate flag is checked by default.
            $this->assertSession()
                ->fieldValueEquals('content_translation[outdated]', TRUE);
            $this->assertSession()
                ->elementExists('xpath', '//details[@id="edit-content-translation" and @open="open"]');
            $edit = [
                'content_translation[outdated]' => FALSE,
            ];
            $this->drupalGet($url);
            $this->submitForm($edit, $this->getFormSubmitAction($entity, $added_langcode));
            $this->drupalGet($url);
            // Verify that retranslate flag is now shown.
            $this->assertSession()
                ->fieldValueEquals('content_translation[retranslate]', FALSE);
            $storage = $this->container
                ->get('entity_type.manager')
                ->getStorage($this->entityTypeId);
            $storage->resetCache([
                $this->entityId,
            ]);
            $entity = $storage->load($this->entityId);
            $this->assertFalse($this->manager
                ->getTranslationMetadata($entity->getTranslation($added_langcode))
                ->isOutdated(), 'The "outdated" status has been correctly stored.');
        }
    }
}

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