Pull merge.
[yaffs-website] / web / core / modules / system / tests / src / Functional / Form / RebuildTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Form;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests functionality of \Drupal\Core\Form\FormBuilderInterface::rebuildForm().
9  *
10  * @group Form
11  */
12 class RebuildTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['node', 'form_test'];
20
21   /**
22    * A user for testing.
23    *
24    * @var \Drupal\user\UserInterface
25    */
26   protected $webUser;
27
28   protected function setUp() {
29     parent::setUp();
30
31     $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
32
33     $this->webUser = $this->drupalCreateUser(['access content']);
34     $this->drupalLogin($this->webUser);
35   }
36
37   /**
38    * Tests preservation of values.
39    */
40   public function testRebuildPreservesValues() {
41     $edit = [
42       'checkbox_1_default_off' => TRUE,
43       'checkbox_1_default_on' => FALSE,
44       'text_1' => 'foo',
45     ];
46     $this->drupalPostForm('form-test/form-rebuild-preserve-values', $edit, 'Add more');
47
48     $assert_session = $this->assertSession();
49
50     // Verify that initial elements retained their submitted values.
51     $assert_session->checkboxChecked('edit-checkbox-1-default-off');
52     $assert_session->checkboxNotChecked('edit-checkbox-1-default-on');
53     $assert_session->fieldValueEquals('edit-text-1', 'foo');
54
55     // Verify that newly added elements were initialized with their default values.
56     $assert_session->checkboxChecked('edit-checkbox-2-default-on');
57     $assert_session->checkboxNotChecked('edit-checkbox-2-default-off');
58     $assert_session->fieldValueEquals('edit-text-2', 'DEFAULT 2');
59   }
60
61 }