function FormBuilderTest::testGetFormIdWithBaseForm

Same name and namespace in other branches
  1. 11.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. 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

Class

FormBuilderTest
@coversDefaultClass \Drupal\Core\Form\FormBuilder[[api-linebreak]] @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']);
}

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