More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / modules / rest / tests / src / Functional / EntityResource / Feed / FeedResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
4
5 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
6 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
7 use Drupal\aggregator\Entity\Feed;
8
9 abstract class FeedResourceTestBase extends EntityResourceTestBase {
10
11   use BcTimestampNormalizerUnixTestTrait;
12
13   /**
14    * {@inheritdoc}
15    */
16   public static $modules = ['aggregator'];
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $entityTypeId = 'aggregator_feed';
22
23   /**
24    * {@inheritdoc}
25    */
26   protected static $patchProtectedFieldNames = [];
27
28   /**
29    * {@inheritdoc}
30    */
31   protected static $uniqueFieldNames = ['url'];
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function setUpAuthorization($method) {
37     switch ($method) {
38       case 'GET':
39         $this->grantPermissionsToTestedRole(['access news feeds']);
40         break;
41       case 'POST':
42       case 'PATCH':
43       case 'DELETE':
44         $this->grantPermissionsToTestedRole(['administer news feeds']);
45         break;
46     }
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function createEntity() {
53     $feed = Feed::create();
54     $feed->set('fid', 1)
55       ->set('uuid', 'abcdefg')
56       ->setTitle('Feed')
57       ->setUrl('http://example.com/rss.xml')
58       ->setDescription('Feed Resource Test 1')
59       ->setRefreshRate(900)
60       ->setLastCheckedTime(123456789)
61       ->setQueuedTime(123456789)
62       ->setWebsiteUrl('http://example.com')
63       ->setImage('http://example.com/feed_logo')
64       ->setHash('abcdefg')
65       ->setEtag('hijklmn')
66       ->setLastModified(123456789)
67       ->save();
68
69     return $feed;
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   protected function getExpectedNormalizedEntity() {
76     return [
77       'uuid' => [
78         [
79           'value' => 'abcdefg'
80         ]
81       ],
82       'fid' => [
83         [
84           'value' => 1
85         ]
86       ],
87       'langcode' => [
88         [
89           'value' => 'en'
90         ]
91       ],
92       'url' => [
93         [
94           'value' => 'http://example.com/rss.xml'
95         ]
96       ],
97       'title' => [
98         [
99           'value' => 'Feed'
100         ]
101       ],
102       'refresh' => [
103         [
104           'value' => 900
105         ]
106       ],
107       'checked' => [
108         $this->formatExpectedTimestampItemValues(123456789),
109       ],
110       'queued' => [
111         $this->formatExpectedTimestampItemValues(123456789),
112       ],
113       'link' => [
114         [
115           'value' => 'http://example.com'
116         ]
117       ],
118       'description' => [
119         [
120           'value' => 'Feed Resource Test 1'
121         ]
122       ],
123       'image' => [
124         [
125           'value' => 'http://example.com/feed_logo'
126         ]
127       ],
128       'hash' => [
129         [
130           'value' => 'abcdefg'
131         ]
132       ],
133       'etag' => [
134         [
135           'value' => 'hijklmn'
136         ]
137       ],
138       'modified' => [
139         $this->formatExpectedTimestampItemValues(123456789),
140       ],
141     ];
142   }
143
144   /**
145    * {@inheritdoc}
146    */
147   protected function getNormalizedPostEntity() {
148     return [
149       'title' => [
150         [
151           'value' => 'Feed Resource Post Test'
152         ]
153       ],
154       'url' => [
155         [
156           'value' => 'http://example.com/feed'
157         ]
158       ],
159       'refresh' => [
160         [
161           'value' => 900
162         ]
163       ],
164       'description' => [
165         [
166           'value' => 'Feed Resource Post Test Description'
167         ]
168       ],
169     ];
170   }
171
172   /**
173    * {@inheritdoc}
174    */
175   protected function getExpectedUnauthorizedAccessMessage($method) {
176     if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
177       return parent::getExpectedUnauthorizedAccessMessage($method);
178     }
179
180     switch ($method) {
181       case 'GET':
182         return "The 'access news feeds' permission is required.";
183       case 'POST':
184       case 'PATCH':
185       case 'DELETE':
186         return "The 'administer news feeds' permission is required.";
187       default:
188         return parent::getExpectedUnauthorizedAccessMessage($method);
189     }
190   }
191
192 }