SmartdocRoutingTest.php in Apigee API Catalog 8.2
File
tests/src/Functional/SmartdocRoutingTest.php
View source
<?php
namespace Drupal\Tests\apigee_api_catalog\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class SmartdocRoutingTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'node',
'path_alias',
'apigee_api_catalog',
];
protected $apidoc;
protected function setUp() {
parent::setUp();
$this->apidoc = $this->container
->get('entity_type.manager')
->getStorage('node')
->create([
'type' => 'apidoc',
'title' => 'API 1',
'body' => [
'value' => 'Test API 1',
'format' => 'basic_html',
],
'field_apidoc_spec' => NULL,
]);
$this->apidoc
->save();
$user = $this
->drupalCreateUser([
'access content',
]);
$this
->drupalLogin($user);
}
public function testNotFoundSubscriber() {
$this
->assertEqual($this->apidoc
->id(), 1);
$this->apidoc
->toUrl()
->toString();
$alias = \Drupal::service('path_alias.manager')
->getAliasByPath('/node/1', $this->apidoc
->language()
->getId());
$this
->assertEqual($alias, '/api/1');
$assert = $this
->assertSession();
$url = Url::fromRoute('entity.node.canonical', [
'node' => $this->apidoc
->id(),
]);
$this
->drupalGet($url);
$assert
->statusCodeEquals(200);
static::assertEmpty($this
->getSession()
->getResponseHeader('location'));
$this
->assertEqual(parse_url($this
->getSession()
->getCurrentUrl(), PHP_URL_PATH), '/api/1');
$this
->drupalGet('/api/1');
$assert
->statusCodeEquals(200);
static::assertEmpty($this
->getSession()
->getResponseHeader('location'));
$url = Url::fromUserInput('/api/1/1/overview')
->setAbsolute();
$response = $this
->getHttpClient()
->request('GET', $url
->toString(), [
'allow_redirects' => FALSE,
]);
$this
->assertEqual($response
->getStatusCode(), 302);
$this
->assertEqual($response
->getHeader('location')[0], '/api/1');
}
}