TestForm example

$form = $this->formBuilder->getForm($form_arg);
    $this->assertFormElement($expected_form$form, 'test');
    $this->assertArrayHasKey('#id', $form);
  }

  /** * Tests the getForm() method with a class name based form ID. */
  public function testGetFormWithClassString() {
    $form_id = '\Drupal\Tests\Core\Form\TestForm';
    $object = new TestForm();
    $form = [];
    $form_state = new FormState();
    $expected_form = $object->buildForm($form$form_state);

    $form = $this->formBuilder->getForm($form_id);
    $this->assertFormElement($expected_form$form, 'test');
    $this->assertSame('test-form', $form['#id']);
  }

  /** * Tests the buildForm() method with a string based form ID. */
Home | Imprint | This part of the site doesn't use cookies.