Drupal 8  8.0.2
FormTestBase Class Reference
Inheritance diagram for FormTestBase:

Public Member Functions

 getInfo ($type)
- Public Member Functions inherited from UnitTestCase
 randomMachineName ($length=8)
 getConfigFactoryStub (array $configs=array())
 getConfigStorageStub (array $configs)
 getStringTranslationStub ()

Protected Member Functions

 setUp ()
 tearDown ()
 getMockForm ($form_id, $expected_form=NULL, $count=1)
 simulateFormSubmission ($form_id, FormInterface $form_arg, FormStateInterface $form_state, $programmed=TRUE)
 assertFormElement (array $expected_form, array $actual_form, $form_key=NULL)
- Protected Member Functions inherited from UnitTestCase
 setUp ()
 getRandomGenerator ()
 assertArrayEquals (array $expected, array $actual, $message=NULL)
 getBlockMockWithMachineName ($machine_name)
 getContainerWithCacheTagsInvalidator (CacheTagsInvalidatorInterface $cache_tags_validator)
 getClassResolverStub ()

Protected Attributes

- Protected Attributes inherited from UnitTestCase

Detailed Description

Provides a base class for testing form functionality.

See Also

Member Function Documentation

assertFormElement ( array  $expected_form,
array  $actual_form,
  $form_key = NULL 

Asserts that the expected form structure is found in a form for a given key.

array$expected_formThe expected form structure.
array$actual_formThe actual form.
string | null$form_key(optional) The form key to look in. Otherwise the entire form will be compared.

Referenced by FormBuilderTest\testBuildFormWithClassString(), FormBuilderTest\testBuildFormWithObject(), FormBuilderTest\testBuildFormWithString(), FormBuilderTest\testGetFormWithClassString(), FormBuilderTest\testGetFormWithObject(), and FormBuilderTest\testGetFormWithString().

Here is the caller graph for this function:

getInfo (   $type)

A stub method returning properties for the defined element type.

string$typeThe machine name of an element type plugin.
array An array with dummy values to be used in tests. Defaults to an empty array.
getMockForm (   $form_id,
  $expected_form = NULL,
  $count = 1 

Provides a mocked form object.

string$form_idThe form ID to be used.
mixed$expected_form(optional) If provided, the expected form response for buildForm() to return. Defaults to NULL.
int$count(optional) The number of times the form is expected to be built. Defaults to 1.
| The mocked form object.

Referenced by FormBuilderTest\testBuildFormWithObject(), FormBuilderTest\testBuildFormWithTriggeringElement(), FormBuilderTest\testExceededFileSize(), FormBuilderTest\testFormCacheDeletionCached(), FormBuilderTest\testFormCacheDeletionUncached(), FormBuilderTest\testGetFormIdWithObject(), FormBuilderTest\testGetFormWithObject(), FormBuilderTest\testHandleFormStateResponse(), FormBuilderTest\testHandleRedirectWithResponse(), and FormBuilderTest\testInvalidToken().

Here is the caller graph for this function:

setUp ( )


References Drupal\cache(), Drupal\csrfToken(), Drupal\formBuilder(), UnitTestCase\getClassResolverStub(), UnitTestCase\getStringTranslationStub(), Drupal\logger(), Drupal\moduleHandler(), Drupal\request(), Drupal\requestStack(), Drupal\root(), and Drupal\urlGenerator().

Here is the call graph for this function:

simulateFormSubmission (   $form_id,
FormInterface  $form_arg,
FormStateInterface  $form_state,
  $programmed = TRUE 

Simulates a form submission within a request, bypassing submitForm().

Calling submitForm() will reset the form builder, if two forms were on the same page, they will be submitted simultaneously.

string$form_idThe unique string identifying the form.
\Drupal\Core\Form\FormInterface$form_argThe form object.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
bool$programmedWhether $form_state->setProgrammed() should be passed TRUE or not. If it is not set to TRUE, you must provide additional data in $form_state for the submission to take place.
array The built form.

References Drupal\formBuilder(), FormStateInterface\getUserInput(), and FormStateInterface\setUserInput().

Referenced by FormBuilderTest\testFormCacheDeletionCached(), FormBuilderTest\testFormCacheDeletionUncached(), FormBuilderTest\testHandleFormStateResponse(), FormBuilderTest\testHandleRedirectWithResponse(), FormBuilderTest\testInvalidToken(), and FormBuilderTest\testUniqueHtmlId().

Here is the call graph for this function:

Here is the caller graph for this function:

tearDown ( )


References Html\resetSeenIds().

Here is the call graph for this function:

The documentation for this class was generated from the following file: