You are here

public function FormBuilderTest::testGetFormIdWithBaseForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testGetFormIdWithBaseForm()
  2. 9 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testGetFormIdWithBaseForm()

Tests the getFormId() method with a base form object.

File

core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php, line 112
Contains \Drupal\Tests\Core\Form\FormBuilderTest.

Class

FormBuilderTest
@coversDefaultClass \Drupal\Core\Form\FormBuilder @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testGetFormIdWithBaseForm() {
  $expected_form_id = 'my_module_form_id';
  $base_form_id = 'my_module';
  $form_arg = $this
    ->createMock('Drupal\\Core\\Form\\BaseFormIdInterface');
  $form_arg
    ->expects($this
    ->once())
    ->method('getFormId')
    ->will($this
    ->returnValue($expected_form_id));
  $form_arg
    ->expects($this
    ->once())
    ->method('getBaseFormId')
    ->will($this
    ->returnValue($base_form_id));
  $form_state = new FormState();
  $form_id = $this->formBuilder
    ->getFormId($form_arg, $form_state);
  $this
    ->assertSame($expected_form_id, $form_id);
  $this
    ->assertSame($form_arg, $form_state
    ->getFormObject());
  $this
    ->assertSame($base_form_id, $form_state
    ->getBuildInfo()['base_form_id']);
}