function EntityTypeManagerTest::testGetFormObject

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php \Drupal\Tests\Core\Entity\EntityTypeManagerTest::testGetFormObject()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php \Drupal\Tests\Core\Entity\EntityTypeManagerTest::testGetFormObject()
  3. 10 core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php \Drupal\Tests\Core\Entity\EntityTypeManagerTest::testGetFormObject()

Tests the getFormObject() method.

@covers ::getFormObject

File

core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php, line 229

Class

EntityTypeManagerTest
@coversDefaultClass \Drupal\Core\Entity\EntityTypeManager @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetFormObject() : void {
    $apple = $this->prophesize(EntityTypeInterface::class);
    $apple->getFormClass('default')
        ->willReturn(TestEntityForm::class);
    $banana = $this->prophesize(EntityTypeInterface::class);
    $banana->getFormClass('default')
        ->willReturn(TestEntityFormInjected::class);
    $this->setUpEntityTypeDefinitions([
        'apple' => $apple,
        'banana' => $banana,
    ]);
    $apple_form = $this->entityTypeManager
        ->getFormObject('apple', 'default');
    $this->assertInstanceOf(TestEntityForm::class, $apple_form);
    $this->assertInstanceOf(ModuleHandlerInterface::class, $apple_form->moduleHandler);
    $this->assertInstanceOf(TranslationInterface::class, $apple_form->stringTranslation);
    $banana_form = $this->entityTypeManager
        ->getFormObject('banana', 'default');
    $this->assertInstanceOf(TestEntityFormInjected::class, $banana_form);
    $this->assertEquals('yellow', $banana_form->color);
}

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