comparison core/modules/jsonapi/tests/src/Functional/VocabularyTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php
2
3 namespace Drupal\Tests\jsonapi\Functional;
4
5 use Drupal\Core\Url;
6 use Drupal\taxonomy\Entity\Vocabulary;
7
8 /**
9 * JSON:API integration test for the "vocabulary" config entity type.
10 *
11 * @group jsonapi
12 */
13 class VocabularyTest extends ResourceTestBase {
14
15 /**
16 * {@inheritdoc}
17 */
18 public static $modules = ['taxonomy'];
19
20 /**
21 * {@inheritdoc}
22 */
23 protected static $entityTypeId = 'taxonomy_vocabulary';
24
25 /**
26 * {@inheritdoc}
27 */
28 protected static $resourceTypeName = 'taxonomy_vocabulary--taxonomy_vocabulary';
29
30 /**
31 * {@inheritdoc}
32 *
33 * @var \Drupal\taxonomy\VocabularyInterface
34 */
35 protected $entity;
36
37 /**
38 * {@inheritdoc}
39 */
40 protected function setUpAuthorization($method) {
41 $this->grantPermissionsToTestedRole(['administer taxonomy']);
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 protected function createEntity() {
48 $vocabulary = Vocabulary::create([
49 'name' => 'Llama',
50 'vid' => 'llama',
51 ]);
52 $vocabulary->save();
53
54 return $vocabulary;
55 }
56
57 /**
58 * {@inheritdoc}
59 */
60 protected function getExpectedDocument() {
61 $self_url = Url::fromUri('base:/jsonapi/taxonomy_vocabulary/taxonomy_vocabulary/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
62 return [
63 'jsonapi' => [
64 'meta' => [
65 'links' => [
66 'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
67 ],
68 ],
69 'version' => '1.0',
70 ],
71 'links' => [
72 'self' => ['href' => $self_url],
73 ],
74 'data' => [
75 'id' => $this->entity->uuid(),
76 'type' => 'taxonomy_vocabulary--taxonomy_vocabulary',
77 'links' => [
78 'self' => ['href' => $self_url],
79 ],
80 'attributes' => [
81 'langcode' => 'en',
82 'status' => TRUE,
83 'dependencies' => [],
84 'name' => 'Llama',
85 'description' => NULL,
86 'weight' => 0,
87 'drupal_internal__vid' => 'llama',
88 ],
89 ],
90 ];
91 }
92
93 /**
94 * {@inheritdoc}
95 */
96 protected function getPostDocument() {
97 // @todo Update in https://www.drupal.org/node/2300677.
98 }
99
100 /**
101 * {@inheritdoc}
102 */
103 protected function getExpectedUnauthorizedAccessMessage($method) {
104 if ($method === 'GET') {
105 return "The following permissions are required: 'access taxonomy overview' OR 'administer taxonomy'.";
106 }
107 return parent::getExpectedUnauthorizedAccessMessage($method);
108 }
109
110 }