function EntityFormTest::testGetEntityFromRouteMatchAddEntity

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

Tests EntityForm::getEntityFromRouteMatch() with a config entity bundle.

@covers ::getEntityFromRouteMatch

File

core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php, line 214

Class

EntityFormTest
@coversDefaultClass \Drupal\Core\Entity\EntityForm[[api-linebreak]] @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetEntityFromRouteMatchAddEntity() : void {
  $entity = $this->prophesize(EntityInterface::class)
    ->reveal();
  $bundle_entity_type_id = 'entity_test_bundle';
  $bundle = 'test_entity_bundle';
  $this->entityType
    ->set('bundle_entity_type', $bundle_entity_type_id);
  $storage = $this->setUpStorage();
  // Test without a bundle parameter in the route.
  $storage->create([])
    ->willReturn($entity);
  $route_match = new RouteMatch('test_route', new Route('/entity-test/add'));
  $actual = $this->entityForm
    ->getEntityFromRouteMatch($route_match, $this->entityType
    ->id());
  $this->assertEquals($entity, $actual);
  // Test with an entity bundle parameter.
  $storage->create([
    'bundle' => $bundle,
  ])
    ->willReturn($entity);
  $bundle_entity = $this->prophesize(EntityInterface::class);
  $bundle_entity->id()
    ->willReturn('test_entity_bundle');
  $route_match = new RouteMatch('test_route', new Route('/entity-test/add/{entity_test_bundle}'), [
    $bundle_entity_type_id => $bundle_entity->reveal(),
  ], [
    $bundle_entity_type_id => $bundle,
  ]);
  $actual = $this->entityForm
    ->getEntityFromRouteMatch($route_match, $this->entityType
    ->id());
  $this->assertEquals($entity, $actual);
}

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