class ArbitraryRebuildTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Form/ArbitraryRebuildTest.php \Drupal\Tests\system\Functional\Form\ArbitraryRebuildTest
- 10 core/modules/system/tests/src/Functional/Form/ArbitraryRebuildTest.php \Drupal\Tests\system\Functional\Form\ArbitraryRebuildTest
- 8.9.x core/modules/system/tests/src/Functional/Form/ArbitraryRebuildTest.php \Drupal\Tests\system\Functional\Form\ArbitraryRebuildTest
Tests altering forms to be rebuilt so there are multiple steps.
@group Form
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Form\ArbitraryRebuildTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ArbitraryRebuildTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Form/ ArbitraryRebuildTest.php, line 14
Namespace
Drupal\Tests\system\Functional\FormView source
class ArbitraryRebuildTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'text',
'form_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Auto-create a field for testing.
FieldStorageConfig::create([
'entity_type' => 'user',
'field_name' => 'test_multiple',
'type' => 'text',
'cardinality' => -1,
'translatable' => FALSE,
])->save();
FieldConfig::create([
'entity_type' => 'user',
'field_name' => 'test_multiple',
'bundle' => 'user',
'label' => 'Test a multiple valued field',
])->save();
\Drupal::service('entity_display.repository')->getFormDisplay('user', 'user', 'register')
->setComponent('test_multiple', [
'type' => 'text_textfield',
'weight' => 0,
])
->save();
}
/**
* Tests a basic rebuild with the user registration form.
*/
public function testUserRegistrationRebuild() {
$edit = [
'name' => 'foo',
'mail' => 'bar@example.com',
];
$this->drupalGet('user/register');
$this->submitForm($edit, 'Rebuild');
$this->assertSession()
->pageTextContains('Form rebuilt.');
$this->assertSession()
->fieldValueEquals('name', 'foo');
$this->assertSession()
->fieldValueEquals('mail', 'bar@example.com');
}
/**
* Tests a rebuild caused by a multiple value field.
*/
public function testUserRegistrationMultipleField() {
$edit = [
'name' => 'foo',
'mail' => 'bar@example.com',
];
$this->drupalGet('user/register');
$this->submitForm($edit, 'Add another item');
$this->assertSession()
->pageTextContains('Test a multiple valued field');
$this->assertSession()
->fieldValueEquals('name', 'foo');
$this->assertSession()
->fieldValueEquals('mail', 'bar@example.com');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.