You are here

function MultiStepNodeFormBasicOptionsTest::testMultiStepNodeFormBasicOptions in Zircon Profile 8

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

Tests changing the default values of basic options to ensure they persist.

File

core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php, line 28
Contains \Drupal\node\Tests\MultiStepNodeFormBasicOptionsTest.

Class

MultiStepNodeFormBasicOptionsTest
Tests the persistence of basic options through multiple steps.

Namespace

Drupal\node\Tests

Code

function testMultiStepNodeFormBasicOptions() {

  // Prepare a user to create the node.
  $web_user = $this
    ->drupalCreateUser(array(
    'administer nodes',
    'create page content',
  ));
  $this
    ->drupalLogin($web_user);

  // Create an unlimited cardinality field.
  $this->fieldName = Unicode::strtolower($this
    ->randomMachineName());
  entity_create('field_storage_config', array(
    'field_name' => $this->fieldName,
    'entity_type' => 'node',
    'type' => 'text',
    'cardinality' => -1,
  ))
    ->save();

  // Attach an instance of the field to the page content type.
  entity_create('field_config', array(
    'field_name' => $this->fieldName,
    'entity_type' => 'node',
    'bundle' => 'page',
    'label' => $this
      ->randomMachineName() . '_label',
  ))
    ->save();
  entity_get_form_display('node', 'page', 'default')
    ->setComponent($this->fieldName, array(
    'type' => 'text_textfield',
  ))
    ->save();
  $edit = array(
    'title[0][value]' => 'a',
    'promote[value]' => FALSE,
    'sticky[value]' => 1,
    "{$this->fieldName}[0][value]" => $this
      ->randomString(32),
  );
  $this
    ->drupalPostForm('node/add/page', $edit, t('Add another item'));
  $this
    ->assertNoFieldChecked('edit-promote-value', 'Promote stayed unchecked');
  $this
    ->assertFieldChecked('edit-sticky-value', 'Sticky stayed checked');
}