function MultiStepNodeFormBasicOptionsTest::testMultiStepNodeFormBasicOptions

Same name and namespace in other branches
  1. 7.x modules/node/node.test \MultiStepNodeFormBasicOptionsTest::testMultiStepNodeFormBasicOptions()
  2. 9 core/modules/node/tests/src/Functional/MultiStepNodeFormBasicOptionsTest.php \Drupal\Tests\node\Functional\MultiStepNodeFormBasicOptionsTest::testMultiStepNodeFormBasicOptions()
  3. 10 core/modules/node/tests/src/Functional/MultiStepNodeFormBasicOptionsTest.php \Drupal\Tests\node\Functional\MultiStepNodeFormBasicOptionsTest::testMultiStepNodeFormBasicOptions()
  4. 11.x core/modules/node/tests/src/Functional/MultiStepNodeFormBasicOptionsTest.php \Drupal\Tests\node\Functional\MultiStepNodeFormBasicOptionsTest::testMultiStepNodeFormBasicOptions()

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

File

core/modules/node/tests/src/Functional/MultiStepNodeFormBasicOptionsTest.php, line 30

Class

MultiStepNodeFormBasicOptionsTest
Tests the persistence of basic options through multiple steps.

Namespace

Drupal\Tests\node\Functional

Code

public function testMultiStepNodeFormBasicOptions() {
    // Prepare a user to create the node.
    $web_user = $this->drupalCreateUser([
        'administer nodes',
        'create page content',
    ]);
    $this->drupalLogin($web_user);
    // Create an unlimited cardinality field.
    $this->fieldName = mb_strtolower($this->randomMachineName());
    FieldStorageConfig::create([
        'field_name' => $this->fieldName,
        'entity_type' => 'node',
        'type' => 'text',
        'cardinality' => -1,
    ])
        ->save();
    // Attach an instance of the field to the page content type.
    FieldConfig::create([
        'field_name' => $this->fieldName,
        'entity_type' => 'node',
        'bundle' => 'page',
        'label' => $this->randomMachineName() . '_label',
    ])
        ->save();
    \Drupal::service('entity_display.repository')->getFormDisplay('node', 'page')
        ->setComponent($this->fieldName, [
        'type' => 'text_textfield',
    ])
        ->save();
    $edit = [
        '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');
}

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