comparison core/modules/jsonapi/tests/src/Functional/SearchPageTest.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
1 <?php
2
3 namespace Drupal\Tests\jsonapi\Functional;
4
5 use Drupal\Core\Url;
6 use Drupal\search\Entity\SearchPage;
7
8 /**
9 * JSON:API integration test for the "SearchPage" config entity type.
10 *
11 * @group jsonapi
12 */
13 class SearchPageTest extends ResourceTestBase {
14
15 /**
16 * {@inheritdoc}
17 */
18 public static $modules = ['node', 'search'];
19
20 /**
21 * {@inheritdoc}
22 */
23 protected static $entityTypeId = 'search_page';
24
25 /**
26 * {@inheritdoc}
27 */
28 protected static $resourceTypeName = 'search_page--search_page';
29
30 /**
31 * {@inheritdoc}
32 *
33 * @var \Drupal\search\SearchPageInterface
34 */
35 protected $entity;
36
37 /**
38 * {@inheritdoc}
39 */
40 protected function setUpAuthorization($method) {
41 switch ($method) {
42 case 'GET':
43 $this->grantPermissionsToTestedRole(['access content']);
44 break;
45
46 case 'POST':
47 case 'PATCH':
48 case 'DELETE':
49 $this->grantPermissionsToTestedRole(['administer search']);
50 break;
51 }
52 }
53
54 /**
55 * {@inheritdoc}
56 */
57 protected function createEntity() {
58 $search_page = SearchPage::create([
59 'id' => 'hinode_search',
60 'plugin' => 'node_search',
61 'label' => 'Search of magnetic activity of the Sun',
62 'path' => 'sun',
63 ]);
64 $search_page->save();
65 return $search_page;
66 }
67
68 /**
69 * {@inheritdoc}
70 */
71 protected function getExpectedDocument() {
72 $self_url = Url::fromUri('base:/jsonapi/search_page/search_page/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
73 return [
74 'jsonapi' => [
75 'meta' => [
76 'links' => [
77 'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
78 ],
79 ],
80 'version' => '1.0',
81 ],
82 'links' => [
83 'self' => ['href' => $self_url],
84 ],
85 'data' => [
86 'id' => $this->entity->uuid(),
87 'type' => 'search_page--search_page',
88 'links' => [
89 'self' => ['href' => $self_url],
90 ],
91 'attributes' => [
92 'configuration' => [
93 'rankings' => [],
94 ],
95 'dependencies' => [
96 'module' => [
97 'node',
98 ],
99 ],
100 'label' => 'Search of magnetic activity of the Sun',
101 'langcode' => 'en',
102 'path' => 'sun',
103 'plugin' => 'node_search',
104 'status' => TRUE,
105 'weight' => 0,
106 'drupal_internal__id' => 'hinode_search',
107 ],
108 ],
109 ];
110 }
111
112 /**
113 * {@inheritdoc}
114 */
115 protected function getPostDocument() {
116 // @todo Update in https://www.drupal.org/node/2300677.
117 }
118
119 /**
120 * {@inheritdoc}
121 */
122 protected function getExpectedUnauthorizedAccessMessage($method) {
123 switch ($method) {
124 case 'GET':
125 return "The 'access content' permission is required.";
126
127 default:
128 return parent::getExpectedUnauthorizedAccessMessage($method);
129 }
130 }
131
132 /**
133 * {@inheritdoc}
134 */
135 protected function getExpectedUnauthorizedAccessCacheability() {
136 // @see \Drupal\search\SearchPageAccessControlHandler::checkAccess()
137 return parent::getExpectedUnauthorizedAccessCacheability()
138 ->addCacheTags(['config:search.page.hinode_search']);
139 }
140
141 }