VocabularyTest.php in JSON:API 8
File
tests/src/Functional/VocabularyTest.php
View source
<?php
namespace Drupal\Tests\jsonapi\Functional;
use Drupal\Core\Url;
use Drupal\taxonomy\Entity\Vocabulary;
class VocabularyTest extends ResourceTestBase {
public static $modules = [
'taxonomy',
];
protected static $entityTypeId = 'taxonomy_vocabulary';
protected static $resourceTypeName = 'taxonomy_vocabulary--taxonomy_vocabulary';
protected $entity;
protected function setUpAuthorization($method) {
$this
->grantPermissionsToTestedRole([
'administer taxonomy',
]);
}
protected function createEntity() {
$vocabulary = Vocabulary::create([
'name' => 'Llama',
'vid' => 'llama',
]);
$vocabulary
->save();
return $vocabulary;
}
protected function getExpectedDocument() {
$self_url = Url::fromUri('base:/jsonapi/taxonomy_vocabulary/taxonomy_vocabulary/' . $this->entity
->uuid())
->setAbsolute()
->toString(TRUE)
->getGeneratedUrl();
$expected_document = [
'jsonapi' => [
'meta' => [
'links' => [
'self' => 'http://jsonapi.org/format/1.0/',
],
],
'version' => '1.0',
],
'links' => [
'self' => $self_url,
],
'data' => [
'id' => $this->entity
->uuid(),
'type' => 'taxonomy_vocabulary--taxonomy_vocabulary',
'links' => [
'self' => $self_url,
],
'attributes' => [
'uuid' => $this->entity
->uuid(),
'vid' => 'llama',
'langcode' => 'en',
'status' => TRUE,
'dependencies' => [],
'name' => 'Llama',
'description' => NULL,
'weight' => 0,
],
],
];
if (floatval(\Drupal::VERSION) < 8.699999999999999) {
$expected_document['data']['attributes']['hierarchy'] = 0;
}
return $expected_document;
}
protected function getPostDocument() {
}
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($method === 'GET') {
if (floatval(\Drupal::VERSION) < 8.5) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
return "The following permissions are required: 'access taxonomy overview' OR 'administer taxonomy'.";
}
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
Classes
Name |
Description |
VocabularyTest |
JSON API integration test for the "vocabulary" config entity type. |