/** * Tests EntityForm::getEntityFromRouteMatch() with a config entity bundle. * * @covers ::getEntityFromRouteMatch */ 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); }