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

 $formBuilder
 
 $formValidator
 
 $formSubmitter
 
 $urlGenerator
 
 $moduleHandler
 
 $formCache
 
 $cache
 
 $account
 
 $controllerResolver
 
 $csrfToken
 
 $request
 
 $requestStack
 
 $classResolver
 
 $elementInfo
 
 $eventDispatcher
 
 $translationManager
 
 $kernel
 
 $logger
 
 $themeManager
 
- Protected Attributes inherited from UnitTestCase
 $randomGenerator
 
 $root
 

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 
)
protected

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

Parameters
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.

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

Provides a mocked form object.

Parameters
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.
Returns
| 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 ( )
protected

{}

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 
)
protected

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.

Parameters
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.
Returns
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 ( )
protected

{}

References Html\resetSeenIds().

Here is the call graph for this function:


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