function EntityFormBuilderTest::testGetForm

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityFormBuilderTest.php \Drupal\Tests\Core\Entity\EntityFormBuilderTest::testGetForm()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityFormBuilderTest.php \Drupal\Tests\Core\Entity\EntityFormBuilderTest::testGetForm()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/EntityFormBuilderTest.php \Drupal\Tests\Core\Entity\EntityFormBuilderTest::testGetForm()

Tests the getForm() method.

@covers ::getForm

File

core/tests/Drupal/Tests/Core/Entity/EntityFormBuilderTest.php, line 51

Class

EntityFormBuilderTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityFormBuilder.php/class/EntityFormBuilder/9" title="Builds entity forms." class="local">\Drupal\Core\Entity\EntityFormBuilder</a> @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetForm() {
    $form_controller = $this->createMock('Drupal\\Core\\Entity\\EntityFormInterface');
    $form_controller->expects($this->any())
        ->method('getFormId')
        ->willReturn('the_form_id');
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getFormObject')
        ->with('the_entity_type', 'default')
        ->willReturn($form_controller);
    $this->formBuilder
        ->expects($this->once())
        ->method('buildForm')
        ->with($form_controller, $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'))
        ->willReturn('the form contents');
    $entity = $this->createMock('Drupal\\Core\\Entity\\EntityInterface');
    $entity->expects($this->once())
        ->method('getEntityTypeId')
        ->willReturn('the_entity_type');
    $this->assertSame('the form contents', $this->entityFormBuilder
        ->getForm($entity));
}

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