You are here

public function NodeTranslationUITest::testPublishedStatusNoFields in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeTranslationUITest.php \Drupal\node\Tests\NodeTranslationUITest::testPublishedStatusNoFields()

Tests changing the published status on a node without fields.

File

core/modules/node/src/Tests/NodeTranslationUITest.php, line 77
Contains \Drupal\node\Tests\NodeTranslationUITest.

Class

NodeTranslationUITest
Tests the Node Translation UI.

Namespace

Drupal\node\Tests

Code

public function testPublishedStatusNoFields() {

  // 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
    ->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete', array(), t('Delete'));
  $this
    ->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags/delete', array(), t('Delete'));
  $this
    ->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/delete', array(), t('Delete'));

  // Add a node.
  $default_langcode = $this->langcodes[0];
  $values[$default_langcode] = array(
    'title' => array(
      array(
        'value' => $this
          ->randomMachineName(),
      ),
    ),
  );
  $entity_id = $this
    ->createEntity($values[$default_langcode], $default_langcode);
  $entity = entity_load($this->entityTypeId, $entity_id, TRUE);

  // Add a content translation.
  $langcode = 'fr';
  $language = ConfigurableLanguage::load($langcode);
  $values[$langcode] = array(
    'title' => array(
      array(
        '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,
  ], array(
    'language' => $language,
  ));
  $this
    ->drupalPostForm($add_url, $this
    ->getEditValues($values, $langcode), t('Save and unpublish (this translation)'));
  $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
  $translation = $entity
    ->getTranslation($langcode);

  // Make sure we unpublished the node correctly.
  $this
    ->assertFalse($this->manager
    ->getTranslationMetadata($translation)
    ->isPublished(), 'The translation has been correctly unpublished.');
}