You are here

protected function ContentTranslationUITestBase::doTestOutdatedStatus in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php \Drupal\content_translation\Tests\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 233
Contains \Drupal\content_translation\Tests\ContentTranslationUITestBase.

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\content_translation\Tests

Code

protected function doTestOutdatedStatus() {
  $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
  $langcode = 'fr';
  $languages = \Drupal::languageManager()
    ->getLanguages();

  // Mark translations as outdated.
  $edit = array(
    'content_translation[retranslate]' => TRUE,
  );
  $edit_path = $entity
    ->urlInfo('edit-form', array(
    'language' => $languages[$langcode],
  ));
  $this
    ->drupalPostForm($edit_path, $edit, $this
    ->getFormSubmitAction($entity, $langcode));
  $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);

  // 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
      ->urlInfo('edit-form', array(
      '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 = array(
        '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.');
      $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
      $this
        ->assertFalse($this->manager
        ->getTranslationMetadata($entity
        ->getTranslation($added_langcode))
        ->isOutdated(), 'The "outdated" status has been correctly stored.');
    }
  }
}