View source
<?php
namespace Drupal\Tests\jsonapi\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use GuzzleHttp\RequestOptions;
class ConfigurableLanguageTest extends ResourceTestBase {
public static $modules = [
'language',
];
protected static $entityTypeId = 'configurable_language';
protected static $resourceTypeName = 'configurable_language--configurable_language';
protected $entity;
protected function setUpAuthorization($method) {
$this
->grantPermissionsToTestedRole([
'administer languages',
]);
}
protected function createEntity() {
$configurable_language = ConfigurableLanguage::create([
'id' => 'll',
'label' => 'Llama Language',
]);
$configurable_language
->save();
return $configurable_language;
}
protected function getExpectedDocument() {
$self_url = Url::fromUri('base:/jsonapi/configurable_language/configurable_language/' . $this->entity
->uuid())
->setAbsolute()
->toString(TRUE)
->getGeneratedUrl();
return [
'jsonapi' => [
'meta' => [
'links' => [
'self' => [
'href' => 'http://jsonapi.org/format/1.0/',
],
],
],
'version' => '1.0',
],
'links' => [
'self' => [
'href' => $self_url,
],
],
'data' => [
'id' => $this->entity
->uuid(),
'type' => 'configurable_language--configurable_language',
'links' => [
'self' => [
'href' => $self_url,
],
],
'attributes' => [
'dependencies' => [],
'direction' => 'ltr',
'label' => 'Llama Language',
'langcode' => 'en',
'locked' => FALSE,
'status' => TRUE,
'weight' => 0,
'drupal_internal__id' => 'll',
],
],
];
}
protected function getPostDocument() {
}
protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) {
return Cache::mergeContexts(parent::getExpectedCacheContexts(), [
'languages:language_interface',
]);
}
public function testGetIndividualDefaultConfig() {
$url = Url::fromRoute('jsonapi.configurable_language--configurable_language.individual', [
'entity' => ConfigurableLanguage::load('en')
->uuid(),
]);
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$request_options = NestedArray::mergeDeep($request_options, $this
->getAuthenticationRequestOptions());
$this
->setUpAuthorization('GET');
$response = $this
->request('GET', $url, $request_options);
$normalization = Json::decode((string) $response
->getBody());
$this
->assertArrayNotHasKey('_core', $normalization['data']['attributes']);
}
}