fbdb200cc56dc88b0e6a5ce770289179f71dcdc5
[yaffs-website] / web / core / modules / node / tests / src / Functional / MultiStepNodeFormBasicOptionsTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional;
4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
8
9 /**
10  * Tests the persistence of basic options through multiple steps.
11  *
12  * @group node
13  */
14 class MultiStepNodeFormBasicOptionsTest extends NodeTestBase {
15
16   /**
17    * The field name to create.
18    *
19    * @var string
20    */
21   protected $fieldName;
22
23   /**
24    * Tests changing the default values of basic options to ensure they persist.
25    */
26   public function testMultiStepNodeFormBasicOptions() {
27     // Prepare a user to create the node.
28     $web_user = $this->drupalCreateUser(['administer nodes', 'create page content']);
29     $this->drupalLogin($web_user);
30
31     // Create an unlimited cardinality field.
32     $this->fieldName = Unicode::strtolower($this->randomMachineName());
33     FieldStorageConfig::create([
34       'field_name' => $this->fieldName,
35       'entity_type' => 'node',
36       'type' => 'text',
37       'cardinality' => -1,
38     ])->save();
39
40     // Attach an instance of the field to the page content type.
41     FieldConfig::create([
42       'field_name' => $this->fieldName,
43       'entity_type' => 'node',
44       'bundle' => 'page',
45       'label' => $this->randomMachineName() . '_label',
46     ])->save();
47     entity_get_form_display('node', 'page', 'default')
48       ->setComponent($this->fieldName, [
49         'type' => 'text_textfield',
50       ])
51       ->save();
52
53     $edit = [
54       'title[0][value]' => 'a',
55       'promote[value]' => FALSE,
56       'sticky[value]' => 1,
57       "{$this->fieldName}[0][value]" => $this->randomString(32),
58     ];
59     $this->drupalPostForm('node/add/page', $edit, t('Add another item'));
60     $this->assertNoFieldChecked('edit-promote-value', 'Promote stayed unchecked');
61     $this->assertFieldChecked('edit-sticky-value', 'Sticky stayed checked');
62   }
63
64 }