You are here

public function DefaultHtmlRouteProviderTest::providerTestGetCanonicalRoute in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php \Drupal\Tests\Core\Entity\Routing\DefaultHtmlRouteProviderTest::providerTestGetCanonicalRoute()

File

core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php, line 214
Contains \Drupal\Tests\Core\Entity\Routing\DefaultHtmlRouteProviderTest.

Class

DefaultHtmlRouteProviderTest
@coversDefaultClass \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider @group Entity

Namespace

Drupal\Tests\Core\Entity\Routing

Code

public function providerTestGetCanonicalRoute() {
  $data = [];
  $entity_type1 = $this
    ->getEntityType();
  $entity_type1
    ->hasLinkTemplate('canonical')
    ->willReturn(FALSE);
  $data['no_canonical_link_template'] = [
    NULL,
    $entity_type1
      ->reveal(),
  ];
  $entity_type2 = $this
    ->getEntityType();
  $entity_type2
    ->hasLinkTemplate('canonical')
    ->willReturn(TRUE);
  $entity_type2
    ->hasViewBuilderClass()
    ->willReturn(FALSE);
  $data['no_view_builder'] = [
    NULL,
    $entity_type2
      ->reveal(),
  ];
  $entity_type3 = $this
    ->getEntityType($entity_type2);
  $entity_type3
    ->hasViewBuilderClass()
    ->willReturn(TRUE);
  $entity_type3
    ->id()
    ->willReturn('the_entity_type_id');
  $entity_type3
    ->getLinkTemplate('canonical')
    ->willReturn('/the/canonical/link/template');
  $entity_type3
    ->entityClassImplements(FieldableEntityInterface::class)
    ->willReturn(FALSE);
  $route = (new Route('/the/canonical/link/template'))
    ->setDefaults([
    '_entity_view' => 'the_entity_type_id.full',
    '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::title',
  ])
    ->setRequirements([
    '_entity_access' => 'the_entity_type_id.view',
  ])
    ->setOptions([
    'parameters' => [
      'the_entity_type_id' => [
        'type' => 'entity:the_entity_type_id',
      ],
    ],
  ]);
  $data['id_key_type_null'] = [
    clone $route,
    $entity_type3
      ->reveal(),
  ];
  $entity_type4 = $this
    ->getEntityType($entity_type3);
  $entity_type4
    ->entityClassImplements(FieldableEntityInterface::class)
    ->willReturn(TRUE);
  $entity_type4
    ->getKey('id')
    ->willReturn('id');
  $route
    ->setRequirement('the_entity_type_id', '\\d+');
  $field_storage_definition = $this
    ->prophesize(FieldStorageDefinitionInterface::class);
  $field_storage_definition
    ->getType()
    ->willReturn('integer');
  $data['id_key_type_integer'] = [
    clone $route,
    $entity_type4
      ->reveal(),
    $field_storage_definition
      ->reveal(),
  ];
  return $data;
}