public function EntityFormTest::testGetEntityFromRouteMatchAddEntity in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testGetEntityFromRouteMatchAddEntity()
- 10 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 202
Class
- EntityFormTest
- @coversDefaultClass \Drupal\Core\Entity\EntityForm @group Entity
Namespace
Drupal\Tests\Core\EntityCode
public function testGetEntityFromRouteMatchAddEntity() {
$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);
}