function EntityFormTest::testGetEntityFromRouteMatchAddStatic

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testGetEntityFromRouteMatchAddStatic()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testGetEntityFromRouteMatchAddStatic()
  3. 11.x 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 184

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetEntityFromRouteMatchAddStatic() : void {
  $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);
}

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