You are here

protected function ContentTranslationUITestBase::doTestOutdatedStatus in Drupal 8

Same name in this branch
  1. 8 core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php \Drupal\content_translation\Tests\ContentTranslationUITestBase::doTestOutdatedStatus()
  2. 8 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/src/Tests/ContentTranslationUITestBase.php
Tests the basic translation UI.

File

core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php, line 245

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\content_translation\Tests

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
    ->drupalPostForm($edit_path, $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) {
      $this
        ->assertFieldByXPath('//input[@name="content_translation[retranslate]"]', FALSE, 'The retranslate flag is not checked by default.');
      $this
        ->assertFalse($this
        ->xpath('//details[@id="edit-content-translation" and @open="open"]'), 'The translation tab should be collapsed by default.');
    }
    else {
      $this
        ->assertFieldByXPath('//input[@name="content_translation[outdated]"]', TRUE, 'The translate flag is checked by default.');
      $this
        ->assertTrue($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
        ->drupalPostForm($url, $edit, $this
        ->getFormSubmitAction($entity, $added_langcode));
      $this
        ->drupalGet($url);
      $this
        ->assertFieldByXPath('//input[@name="content_translation[retranslate]"]', FALSE, 'The retranslate flag is now shown.');
      $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.');
    }
  }
}