You are here

protected function ContentTranslationUITestBase::doTestPublishedStatus in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestPublishedStatus()
  2. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestPublishedStatus()

Tests the translation publishing status.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php, line 290

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\Tests\content_translation\Functional

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
        ->drupalGet($url);
      $this
        ->submitForm($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
    ->assertSession()
    ->fieldDisabled('content_translation[status]');
  $this
    ->assertSession()
    ->fieldValueEquals('content_translation[status]', TRUE);
}