public function FormBuilderTest::testUniqueHtmlId in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testUniqueHtmlId()
- 10 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testUniqueHtmlId()
Tests that HTML IDs are unique when rebuilding a form with errors.
File
- core/
tests/ Drupal/ Tests/ Core/ Form/ FormBuilderTest.php, line 465 - Contains \Drupal\Tests\Core\Form\FormBuilderTest.
Class
- FormBuilderTest
- @coversDefaultClass \Drupal\Core\Form\FormBuilder @group Form
Namespace
Drupal\Tests\Core\FormCode
public function testUniqueHtmlId() {
$form_id = 'test_form_id';
$expected_form = $form_id();
$expected_form['test']['#required'] = TRUE;
// Mock a form object that will be built two times.
$form_arg = $this
->createMock('Drupal\\Core\\Form\\FormInterface');
$form_arg
->expects($this
->exactly(2))
->method('getFormId')
->will($this
->returnValue($form_id));
$form_arg
->expects($this
->exactly(2))
->method('buildForm')
->will($this
->returnValue($expected_form));
$form_state = new FormState();
$form = $this
->simulateFormSubmission($form_id, $form_arg, $form_state);
$this
->assertSame('test-form-id', $form['#id']);
$form_state = new FormState();
$form = $this
->simulateFormSubmission($form_id, $form_arg, $form_state);
$this
->assertSame('test-form-id--2', $form['#id']);
}