public function EntityUrlTest::testUriRelationships in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testUriRelationships()
- 10 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testUriRelationships()
Tests the uriRelationships() method.
@covers ::uriRelationships
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php, line 387
Class
- EntityUrlTest
- Tests URL handling of the \Drupal\Core\Entity\EntityBase class.
Namespace
Drupal\Tests\Core\EntityCode
public function testUriRelationships() {
$entity = $this
->getEntity(EntityBase::class, [
'id' => $this->entityId,
]);
$container_builder = new ContainerBuilder();
$url_generator = $this
->createMock(UrlGeneratorInterface::class);
$container_builder
->set('url_generator', $url_generator);
\Drupal::setContainer($container_builder);
// Test route with no mandatory parameters.
$this
->registerLinkTemplate('canonical');
$route_name_0 = 'entity.' . $this->entityTypeId . '.canonical';
$url_generator
->expects($this
->any())
->method('generateFromRoute')
->with($route_name_0)
->willReturn((new GeneratedUrl())
->setGeneratedUrl('/entity_test'));
$this
->assertEquals([
'canonical',
], $entity
->uriRelationships());
// Test route with non-default mandatory parameters.
$this
->registerLinkTemplate('{non_default_parameter}');
$route_name_1 = 'entity.' . $this->entityTypeId . '.{non_default_parameter}';
$url_generator
->expects($this
->any())
->method('generateFromRoute')
->with($route_name_1)
->willThrowException(new MissingMandatoryParametersException());
$this
->assertEquals([], $entity
->uriRelationships());
}