function RoutesTest::testRoutesIndividual

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php \Drupal\Tests\jsonapi\Unit\Routing\RoutesTest::testRoutesIndividual()
  2. 10 core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php \Drupal\Tests\jsonapi\Unit\Routing\RoutesTest::testRoutesIndividual()
  3. 11.x core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php \Drupal\Tests\jsonapi\Unit\Routing\RoutesTest::testRoutesIndividual()

@covers ::routes

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Unit\Routing

Code

public function testRoutesIndividual() {
    // Get the route collection and start making assertions.
    $iterator = $this->routes['ok']
        ->routes()
        ->getIterator();
    // Check the individual route.
    
    /** @var \Symfony\Component\Routing\Route $route */
    $route = $iterator->offsetGet('jsonapi.entity_type_1--bundle_1_1.individual');
    $this->assertSame('/jsonapi/entity_type_1/bundle_1_1/{entity}', $route->getPath());
    $this->assertSame('entity_type_1--bundle_1_1', $route->getDefault(Routes::RESOURCE_TYPE_KEY));
    $this->assertEquals([
        'GET',
    ], $route->getMethods());
    $this->assertSame(Routes::CONTROLLER_SERVICE_NAME . ':getIndividual', $route->getDefault(RouteObjectInterface::CONTROLLER_NAME));
    $this->assertSame([
        'lorem',
        'ipsum',
    ], $route->getOption('_auth'));
    $this->assertEquals([
        'entity' => [
            'type' => 'entity:entity_type_1',
        ],
        'resource_type' => [
            'type' => 'jsonapi_resource_type',
        ],
    ], $route->getOption('parameters'));
    $route = $iterator->offsetGet('jsonapi.entity_type_1--bundle_1_1.individual.patch');
    $this->assertSame('/jsonapi/entity_type_1/bundle_1_1/{entity}', $route->getPath());
    $this->assertSame('entity_type_1--bundle_1_1', $route->getDefault(Routes::RESOURCE_TYPE_KEY));
    $this->assertEquals([
        'PATCH',
    ], $route->getMethods());
    $this->assertSame(Routes::CONTROLLER_SERVICE_NAME . ':patchIndividual', $route->getDefault(RouteObjectInterface::CONTROLLER_NAME));
    $this->assertSame([
        'lorem',
        'ipsum',
    ], $route->getOption('_auth'));
    $this->assertEquals([
        'entity' => [
            'type' => 'entity:entity_type_1',
        ],
        'resource_type' => [
            'type' => 'jsonapi_resource_type',
        ],
    ], $route->getOption('parameters'));
    $route = $iterator->offsetGet('jsonapi.entity_type_1--bundle_1_1.individual.delete');
    $this->assertSame('/jsonapi/entity_type_1/bundle_1_1/{entity}', $route->getPath());
    $this->assertSame('entity_type_1--bundle_1_1', $route->getDefault(Routes::RESOURCE_TYPE_KEY));
    $this->assertEquals([
        'DELETE',
    ], $route->getMethods());
    $this->assertSame(Routes::CONTROLLER_SERVICE_NAME . ':deleteIndividual', $route->getDefault(RouteObjectInterface::CONTROLLER_NAME));
    $this->assertSame([
        'lorem',
        'ipsum',
    ], $route->getOption('_auth'));
    $this->assertEquals([
        'entity' => [
            'type' => 'entity:entity_type_1',
        ],
        'resource_type' => [
            'type' => 'jsonapi_resource_type',
        ],
    ], $route->getOption('parameters'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.