You are here

protected function ContentTranslationUITestBase::doTestPublishedStatus in Drupal 8

Same name in this branch
  1. 8 core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php \Drupal\content_translation\Tests\ContentTranslationUITestBase::doTestPublishedStatus()
  2. 8 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestPublishedStatus()

Tests the translation publishing status.

1 call to ContentTranslationUITestBase::doTestPublishedStatus()
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 288

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\content_translation\Tests

Code

protected function doTestPublishedStatus() {
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityTypeId);
  $storage
    ->resetCache([
    $this->entityId,
  ]);
  $entity = $storage
    ->load($this->entityId);

  // Unpublish translations.
  foreach ($this->langcodes as $index => $langcode) {
    if ($index > 0) {
      $url = $entity
        ->toUrl('edit-form', [
        'language' => ConfigurableLanguage::load($langcode),
      ]);
      $edit = [
        'content_translation[status]' => FALSE,
      ];
      $this
        ->drupalPostForm($url, $edit, $this
        ->getFormSubmitAction($entity, $langcode));
      $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($langcode))
        ->isPublished(), 'The translation has been correctly unpublished.');
    }
  }

  // Check that the last published translation cannot be unpublished.
  $this
    ->drupalGet($entity
    ->toUrl('edit-form'));
  $this
    ->assertFieldByXPath('//input[@name="content_translation[status]" and @disabled="disabled"]', TRUE, 'The last translation is published and cannot be unpublished.');
}