You are here

protected function FormTestBase::getMockForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::getMockForm()
  2. 9 core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::getMockForm()

Provides a mocked form object.

Parameters

string $form_id: The 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.

Return value

\PHPUnit\Framework\MockObject\MockObject|\Drupal\Core\Form\FormInterface The mocked form object.

10 calls to FormTestBase::getMockForm()
FormBuilderTest::testBuildFormWithObject in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
Tests the buildForm() method with a form object.
FormBuilderTest::testBuildFormWithTriggeringElement in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
Tests whether the triggering element is properly identified.
FormBuilderTest::testExceededFileSize in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
@covers ::buildForm
FormBuilderTest::testFormCacheDeletionCached in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
Tests that a cached form is deleted after submit.
FormBuilderTest::testFormCacheDeletionUncached in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
Tests that an uncached form does not trigger cache set or delete.

... See full list

File

core/tests/Drupal/Tests/Core/Form/FormTestBase.php, line 216

Class

FormTestBase
Provides a base class for testing form functionality.

Namespace

Drupal\Tests\Core\Form

Code

protected function getMockForm($form_id, $expected_form = NULL, $count = 1) {
  $form = $this
    ->createMock('Drupal\\Core\\Form\\FormInterface');
  $form
    ->expects($this
    ->once())
    ->method('getFormId')
    ->will($this
    ->returnValue($form_id));
  if ($expected_form) {
    $form
      ->expects($this
      ->exactly($count))
      ->method('buildForm')
      ->will($this
      ->returnValue($expected_form));
  }
  return $form;
}