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