RebuildTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/Form/RebuildTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Form;
use Drupal\Tests\BrowserTestBase;
class RebuildTest extends BrowserTestBase {
protected static $modules = [
'node',
'form_test',
];
protected $defaultTheme = 'stark';
protected $webUser;
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$this->webUser = $this
->drupalCreateUser([
'access content',
]);
$this
->drupalLogin($this->webUser);
}
public function testRebuildPreservesValues() {
$edit = [
'checkbox_1_default_off' => TRUE,
'checkbox_1_default_on' => FALSE,
'text_1' => 'foo',
];
$this
->drupalGet('form-test/form-rebuild-preserve-values');
$this
->submitForm($edit, 'Add more');
$assert_session = $this
->assertSession();
$assert_session
->checkboxChecked('edit-checkbox-1-default-off');
$assert_session
->checkboxNotChecked('edit-checkbox-1-default-on');
$assert_session
->fieldValueEquals('edit-text-1', 'foo');
$assert_session
->checkboxChecked('edit-checkbox-2-default-on');
$assert_session
->checkboxNotChecked('edit-checkbox-2-default-off');
$assert_session
->fieldValueEquals('edit-text-2', 'DEFAULT 2');
}
}