function ContentTranslationUITestBase::doTestPublishedStatus

Same name in this branch
  1. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestPublishedStatus()
Same name and namespace in other branches
  1. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestPublishedStatus()
  2. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestPublishedStatus()
  3. 11.x 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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.