View source
<?php
namespace Drupal\Tests\system\Functional\Form;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
class ArbitraryRebuildTest extends BrowserTestBase {
protected static $modules = [
'text',
'form_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
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();
}
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');
}
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');
}
}