You are here

protected function RoutesTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php \Drupal\Tests\jsonapi\Unit\Routing\RoutesTest::setUp()
  2. 9 core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php \Drupal\Tests\jsonapi\Unit\Routing\RoutesTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php, line 32

Class

RoutesTest
@coversDefaultClass \Drupal\jsonapi\Routing\Routes @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\Routing

Code

protected function setUp() : void {
  parent::setUp();
  $relationship_fields = [
    'external' => new ResourceTypeRelationship('external'),
    'internal' => new ResourceTypeRelationship('internal'),
    'both' => new ResourceTypeRelationship('both'),
  ];
  $type_1 = new ResourceType('entity_type_1', 'bundle_1_1', EntityInterface::class, FALSE, TRUE, TRUE, FALSE, $relationship_fields);
  $type_2 = new ResourceType('entity_type_2', 'bundle_2_1', EntityInterface::class, TRUE, TRUE, TRUE, FALSE, $relationship_fields);
  $relatable_resource_types = [
    'external' => [
      $type_1,
    ],
    'internal' => [
      $type_2,
    ],
    'both' => [
      $type_1,
      $type_2,
    ],
  ];
  $type_1
    ->setRelatableResourceTypes($relatable_resource_types);
  $type_2
    ->setRelatableResourceTypes($relatable_resource_types);

  // This type ensures that we can create routes for bundle IDs which might be
  // cast from strings to integers.  It should not affect related resource
  // routing.
  $type_3 = new ResourceType('entity_type_3', '123', EntityInterface::class, TRUE);
  $type_3
    ->setRelatableResourceTypes([]);
  $resource_type_repository = $this
    ->prophesize(ResourceTypeRepository::class);
  $resource_type_repository
    ->all()
    ->willReturn([
    $type_1,
    $type_2,
    $type_3,
  ]);
  $container = $this
    ->prophesize(ContainerInterface::class);
  $container
    ->get('jsonapi.resource_type.repository')
    ->willReturn($resource_type_repository
    ->reveal());
  $container
    ->getParameter('jsonapi.base_path')
    ->willReturn('/jsonapi');
  $container
    ->getParameter('authentication_providers')
    ->willReturn([
    'lorem' => [],
    'ipsum' => [],
  ]);
  $this->routes['ok'] = Routes::create($container
    ->reveal());
}