You are here

protected function ContentTranslationUITestBase::doTestOutdatedStatus in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestOutdatedStatus()
  2. 10 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
        ->assertEmpty($this
        ->xpath('//details[@id="edit-content-translation" and @open="open"]'), 'The translation tab should be collapsed by default.');
    }
    else {

      // Verify that the translate flag is checked by default.
      $this
        ->assertSession()
        ->fieldValueEquals('content_translation[outdated]', TRUE);
      $this
        ->assertNotEmpty($this
        ->xpath('//details[@id="edit-content-translation" and @open="open"]'), 'The translation tab is correctly expanded when the translation is outdated.');
      $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.');
    }
  }
}