Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/jsonapi/tests/src/Functional/FeedTest.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\aggregator\Entity\Feed; | |
6 use Drupal\Core\Url; | |
7 use Drupal\Tests\jsonapi\Traits\CommonCollectionFilterAccessTestPatternsTrait; | |
8 | |
9 /** | |
10 * JSON:API integration test for the "Feed" content entity type. | |
11 * | |
12 * @group jsonapi | |
13 */ | |
14 class FeedTest extends ResourceTestBase { | |
15 | |
16 use CommonCollectionFilterAccessTestPatternsTrait; | |
17 | |
18 /** | |
19 * {@inheritdoc} | |
20 */ | |
21 public static $modules = ['aggregator']; | |
22 | |
23 /** | |
24 * {@inheritdoc} | |
25 */ | |
26 protected static $entityTypeId = 'aggregator_feed'; | |
27 | |
28 /** | |
29 * {@inheritdoc} | |
30 */ | |
31 protected static $resourceTypeName = 'aggregator_feed--aggregator_feed'; | |
32 | |
33 /** | |
34 * {@inheritdoc} | |
35 * | |
36 * @var \Drupal\config_test\ConfigTestInterface | |
37 */ | |
38 protected $entity; | |
39 | |
40 /** | |
41 * {@inheritdoc} | |
42 */ | |
43 protected static $patchProtectedFieldNames = []; | |
44 | |
45 /** | |
46 * {@inheritdoc} | |
47 */ | |
48 protected static $uniqueFieldNames = ['url']; | |
49 | |
50 /** | |
51 * {@inheritdoc} | |
52 */ | |
53 protected function setUpAuthorization($method) { | |
54 switch ($method) { | |
55 case 'GET': | |
56 $this->grantPermissionsToTestedRole(['access news feeds']); | |
57 break; | |
58 | |
59 case 'POST': | |
60 case 'PATCH': | |
61 case 'DELETE': | |
62 $this->grantPermissionsToTestedRole(['administer news feeds']); | |
63 break; | |
64 } | |
65 } | |
66 | |
67 /** | |
68 * {@inheritdoc} | |
69 */ | |
70 public function createEntity() { | |
71 $feed = Feed::create(); | |
72 $feed->set('fid', 1) | |
73 ->setTitle('Feed') | |
74 ->setUrl('http://example.com/rss.xml') | |
75 ->setDescription('Feed Resource Test 1') | |
76 ->setRefreshRate(900) | |
77 ->setLastCheckedTime(123456789) | |
78 ->setQueuedTime(123456789) | |
79 ->setWebsiteUrl('http://example.com') | |
80 ->setImage('http://example.com/feed_logo') | |
81 ->setHash('abcdefg') | |
82 ->setEtag('hijklmn') | |
83 ->setLastModified(123456789) | |
84 ->save(); | |
85 | |
86 return $feed; | |
87 } | |
88 | |
89 /** | |
90 * {@inheritdoc} | |
91 */ | |
92 protected function createAnotherEntity($key) { | |
93 /* @var \Drupal\aggregator\FeedInterface $duplicate */ | |
94 $duplicate = $this->getEntityDuplicate($this->entity, $key); | |
95 $duplicate->set('field_rest_test', 'Duplicate feed entity'); | |
96 $duplicate->setUrl("http://example.com/$key.xml"); | |
97 $duplicate->save(); | |
98 return $duplicate; | |
99 } | |
100 | |
101 /** | |
102 * {@inheritdoc} | |
103 */ | |
104 protected function getExpectedDocument() { | |
105 $self_url = Url::fromUri('base:/jsonapi/aggregator_feed/aggregator_feed/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); | |
106 return [ | |
107 'jsonapi' => [ | |
108 'meta' => [ | |
109 'links' => [ | |
110 'self' => ['href' => 'http://jsonapi.org/format/1.0/'], | |
111 ], | |
112 ], | |
113 'version' => '1.0', | |
114 ], | |
115 'links' => [ | |
116 'self' => ['href' => $self_url], | |
117 ], | |
118 'data' => [ | |
119 'id' => $this->entity->uuid(), | |
120 'type' => 'aggregator_feed--aggregator_feed', | |
121 'links' => [ | |
122 'self' => ['href' => $self_url], | |
123 ], | |
124 'attributes' => [ | |
125 'url' => 'http://example.com/rss.xml', | |
126 'title' => 'Feed', | |
127 'refresh' => 900, | |
128 'checked' => '1973-11-29T21:33:09+00:00', | |
129 'queued' => '1973-11-29T21:33:09+00:00', | |
130 'link' => 'http://example.com', | |
131 'description' => 'Feed Resource Test 1', | |
132 'image' => 'http://example.com/feed_logo', | |
133 'hash' => 'abcdefg', | |
134 'etag' => 'hijklmn', | |
135 'modified' => '1973-11-29T21:33:09+00:00', | |
136 'langcode' => 'en', | |
137 'drupal_internal__fid' => 1, | |
138 ], | |
139 ], | |
140 ]; | |
141 } | |
142 | |
143 /** | |
144 * {@inheritdoc} | |
145 */ | |
146 protected function getPostDocument() { | |
147 return [ | |
148 'data' => [ | |
149 'type' => 'aggregator_feed--aggregator_feed', | |
150 'attributes' => [ | |
151 'title' => 'Feed Resource Post Test', | |
152 'url' => 'http://example.com/feed', | |
153 'refresh' => 900, | |
154 'description' => 'Feed Resource Post Test Description', | |
155 ], | |
156 ], | |
157 ]; | |
158 } | |
159 | |
160 /** | |
161 * {@inheritdoc} | |
162 */ | |
163 protected function getExpectedUnauthorizedAccessMessage($method) { | |
164 switch ($method) { | |
165 case 'GET': | |
166 return "The 'access news feeds' permission is required."; | |
167 | |
168 case 'POST': | |
169 case 'PATCH': | |
170 case 'DELETE': | |
171 return "The 'administer news feeds' permission is required."; | |
172 } | |
173 } | |
174 | |
175 /** | |
176 * {@inheritdoc} | |
177 */ | |
178 public function testCollectionFilterAccess() { | |
179 $this->doTestCollectionFilterAccessBasedOnPermissions('title', 'access news feeds'); | |
180 } | |
181 | |
182 } |