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