MultiStepNodeFormBasicOptionsTest.php in Drupal 8
File
core/modules/node/tests/src/Functional/MultiStepNodeFormBasicOptionsTest.php
View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
class MultiStepNodeFormBasicOptionsTest extends NodeTestBase {
protected $defaultTheme = 'stark';
protected $fieldName;
public function testMultiStepNodeFormBasicOptions() {
$web_user = $this
->drupalCreateUser([
'administer nodes',
'create page content',
]);
$this
->drupalLogin($web_user);
$this->fieldName = mb_strtolower($this
->randomMachineName());
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'text',
'cardinality' => -1,
])
->save();
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');
}
}