function FormBuilderTest::testGetFormIdWithBaseForm

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testGetFormIdWithBaseForm()
  2. 10 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testGetFormIdWithBaseForm()
  3. 11.x 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 125

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')
        ->willReturn($expected_form_id);
    $form_arg->expects($this->once())
        ->method('getBaseFormId')
        ->willReturn($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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.