You are here

public function SmartdocRoutingTest::testNotFoundSubscriber in Apigee API Catalog 8

Tests the route subscriber will redirect from smartdoc routes.

File

tests/src/Kernel/SmartdocRoutingTest.php, line 92

Class

SmartdocRoutingTest
Tests smartdoc routing compatibility.

Namespace

Drupal\Tests\apigee_api_catalog\Kernel

Code

public function testNotFoundSubscriber() {

  // Tests the normal response.
  $request = Request::create(Url::fromRoute('entity.apidoc.canonical', [
    'apidoc' => $this->apidoc
      ->id(),
  ])
    ->toString());
  $response = $this->container
    ->get('http_kernel')
    ->handle($request);
  static::assertSame(200, $response
    ->getStatusCode());
  static::assertEmpty($response->headers
    ->get('location'));

  // Test that the smartdoc routes redirect to the canonical route.
  $request = Request::create('/api/1/1/overview');
  $response = $this->container
    ->get('http_kernel')
    ->handle($request);
  static::assertSame(302, $response
    ->getStatusCode());
  static::assertSame('/api/1', $response->headers
    ->get('location'));
}