function FormTestBase::getMockForm

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::getMockForm()
  2. 10 core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::getMockForm()
  3. 11.x 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')
        ->willReturn($form_id);
    if ($expected_form) {
        $form->expects($this->exactly($count))
            ->method('buildForm')
            ->willReturn($expected_form);
    }
    return $form;
}

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