You are here

public function EntityFormTest::testGetEntityFromRouteMatchAddStatic in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testGetEntityFromRouteMatchAddStatic()
  2. 9 core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testGetEntityFromRouteMatchAddStatic()

Tests EntityForm::getEntityFromRouteMatch() with a static bundle.

@covers ::getEntityFromRouteMatch

File

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

Class

EntityFormTest
@coversDefaultClass \Drupal\Core\Entity\EntityForm @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetEntityFromRouteMatchAddStatic() {
  $entity = $this
    ->prophesize(EntityInterface::class)
    ->reveal();
  $bundle_key = 'bundle';
  $bundle = 'test_bundle';
  $this->entityType
    ->set('entity_keys', [
    'bundle' => $bundle_key,
  ]);
  $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 a static bundle parameter.
  $storage
    ->create([
    $bundle_key => 'test_bundle',
  ])
    ->willReturn($entity);
  $route_match = new RouteMatch('test_route', new Route('/entity-test/add/{' . $bundle_key . '}'), [
    $bundle_key => $bundle,
  ], [
    $bundle_key => $bundle,
  ]);
  $actual = $this->entityForm
    ->getEntityFromRouteMatch($route_match, $this->entityType
    ->id());
  $this
    ->assertEquals($entity, $actual);
}