EntryPointTest.php in JSON:API 8
File
tests/src/Kernel/Controller/EntryPointTest.php
View source
<?php
namespace Drupal\Tests\jsonapi\Kernel\Controller;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\jsonapi\Controller\EntryPoint;
use Drupal\Tests\jsonapi\Kernel\JsonapiKernelTestBase;
class EntryPointTest extends JsonapiKernelTestBase {
public static $modules = [
'node',
'jsonapi',
'serialization',
'system',
'user',
];
public function testIndex() {
$controller = new EntryPoint(\Drupal::service('jsonapi.resource_type.repository'), \Drupal::service('renderer'), new CacheableJsonResponse());
$processed_response = $controller
->index();
$this
->assertEquals([
'url.site',
], $processed_response
->getCacheableMetadata()
->getCacheContexts());
$data = json_decode($processed_response
->getContent(), TRUE);
$links = $data['links'];
$this
->assertRegExp('/.*\\/jsonapi/', $links['self']);
$this
->assertRegExp('/.*\\/jsonapi\\/user\\/user/', $links['user--user']);
$this
->assertRegExp('/.*\\/jsonapi\\/node_type\\/node_type/', $links['node_type--node_type']);
}
}