function NodeTranslationUITest::testPublishedStatusNoFields

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testPublishedStatusNoFields()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testPublishedStatusNoFields()
  3. 11.x core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testPublishedStatusNoFields()

Tests changing the published status on a node without fields.

File

core/modules/node/tests/src/Functional/NodeTranslationUITest.php, line 90

Class

NodeTranslationUITest
Tests the Node Translation UI.

Namespace

Drupal\Tests\node\Functional

Code

public function testPublishedStatusNoFields() : void {
    // Test changing the published status of an article without fields.
    $this->drupalLogin($this->administrator);
    // Delete all fields.
    $this->drupalGet('admin/structure/types/manage/article/fields');
    $this->drupalGet('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete');
    $this->submitForm([], 'Delete');
    // Add a node.
    $default_langcode = $this->langcodes[0];
    $values[$default_langcode] = [
        'title' => [
            [
                'value' => $this->randomMachineName(),
            ],
        ],
    ];
    $this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage($this->entityTypeId);
    $storage->resetCache([
        $this->entityId,
    ]);
    $entity = $storage->load($this->entityId);
    // Add a content translation.
    $langcode = 'fr';
    $language = ConfigurableLanguage::load($langcode);
    $values[$langcode] = [
        'title' => [
            [
                'value' => $this->randomMachineName(),
            ],
        ],
    ];
    $entity_type_id = $entity->getEntityTypeId();
    $add_url = Url::fromRoute("entity.{$entity_type_id}.content_translation_add", [
        $entity->getEntityTypeId() => $entity->id(),
        'source' => $default_langcode,
        'target' => $langcode,
    ], [
        'language' => $language,
    ]);
    $edit = $this->getEditValues($values, $langcode);
    $edit['status[value]'] = FALSE;
    $this->drupalGet($add_url);
    $this->submitForm($edit, 'Save (this translation)');
    $storage->resetCache([
        $this->entityId,
    ]);
    $entity = $storage->load($this->entityId);
    $translation = $entity->getTranslation($langcode);
    // Make sure we unpublished the node correctly.
    $this->assertFalse($this->manager
        ->getTranslationMetadata($translation)
        ->isPublished(), 'The translation has been correctly unpublished.');
}

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