SmartdocRoutingTest.php in Apigee API Catalog 8
File
tests/src/Kernel/SmartdocRoutingTest.php
View source
<?php
namespace Drupal\Tests\apigee_api_catalog\Kernel;
use Drupal\apigee_api_catalog\Entity\ApiDoc;
use Drupal\Core\Url;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Symfony\Component\HttpFoundation\Request;
class SmartdocRoutingTest extends KernelTestBase {
use UserCreationTrait;
protected static $modules = [
'user',
'system',
'apigee_edge',
'key',
'apigee_api_catalog',
'options',
'text',
'file',
'file_link',
'filter',
];
private $apidoc;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('apidoc');
$this->apidoc = ApiDoc::create([
'name' => 'API 1',
'description' => 'Test API 1',
'spec' => NULL,
'api_product' => NULL,
]);
$this->apidoc
->save();
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
]);
$this
->installSchema('user', [
'users_data',
]);
$this
->installConfig([
'filter',
]);
$user = $this
->createUser([
'view published apidoc entities',
]);
$this
->setCurrentUser($user);
}
public function testNotFoundSubscriber() {
$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'));
$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'));
}
}