You are here

public function EntityTypeManagerTest::testGetFormObject in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 219
Contains \Drupal\Tests\Core\Entity\EntityTypeManagerTest.

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetFormObject() {
  $entity_manager = $this
    ->prophesize(EntityManagerInterface::class);
  $container = $this
    ->prophesize(ContainerInterface::class);
  $container
    ->get('entity.manager')
    ->willReturn($entity_manager
    ->reveal());
  \Drupal::setContainer($container
    ->reveal());
  $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
    ->assertAttributeInstanceOf(ModuleHandlerInterface::class, 'moduleHandler', $apple_form);
  $this
    ->assertAttributeInstanceOf(TranslationInterface::class, 'stringTranslation', $apple_form);
  $banana_form = $this->entityTypeManager
    ->getFormObject('banana', 'default');
  $this
    ->assertInstanceOf(TestEntityFormInjected::class, $banana_form);
  $this
    ->assertAttributeEquals('yellow', 'color', $banana_form);
}