Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / rest / tests / src / Functional / EntityResource / Editor / EditorResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\EntityResource\Editor;
4
5 use Drupal\editor\Entity\Editor;
6 use Drupal\filter\Entity\FilterFormat;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8
9 /**
10  * ResourceTestBase for Editor entity.
11  */
12 abstract class EditorResourceTestBase extends EntityResourceTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['ckeditor', 'editor'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected static $entityTypeId = 'editor';
23
24   /**
25    * The Editor entity.
26    *
27    * @var \Drupal\editor\EditorInterface
28    */
29   protected $entity;
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUpAuthorization($method) {
35     $this->grantPermissionsToTestedRole(['administer filters']);
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   protected function createEntity() {
42     // Create a "Llama" filter format.
43     $llama_format = FilterFormat::create([
44       'name' => 'Llama',
45       'format' => 'llama',
46       'langcode' => 'es',
47       'filters' => [
48         'filter_html' => [
49           'status' => TRUE,
50           'settings' => [
51             'allowed_html' => '<p> <a> <b> <lo>',
52           ],
53         ],
54       ],
55     ]);
56
57     $llama_format->save();
58
59     // Create a "Camelids" editor.
60     $camelids = Editor::create([
61       'format' => 'llama',
62       'editor' => 'ckeditor',
63     ]);
64     $camelids
65       ->setImageUploadSettings([
66         'status' => FALSE,
67         'scheme' => file_default_scheme(),
68         'directory' => 'inline-images',
69         'max_size' => '',
70         'max_dimensions' => [
71           'width' => '',
72           'height' => '',
73         ],
74       ])
75       ->save();
76
77     return $camelids;
78   }
79
80   /**
81    * {@inheritdoc}
82    */
83   protected function getExpectedNormalizedEntity() {
84     return [
85       'dependencies' => [
86         'config' => [
87           'filter.format.llama',
88         ],
89         'module' => [
90           'ckeditor',
91         ],
92       ],
93       'editor' => 'ckeditor',
94       'format' => 'llama',
95       'image_upload' => [
96         'status' => FALSE,
97         'scheme' => 'public',
98         'directory' => 'inline-images',
99         'max_size' => '',
100         'max_dimensions' => [
101           'width' => NULL,
102           'height' => NULL,
103         ],
104       ],
105       'langcode' => 'en',
106       'settings' => [
107         'toolbar' => [
108           'rows' => [
109             [
110               [
111                 'name' => 'Formatting',
112                 'items' => [
113                   'Bold',
114                   'Italic',
115                 ],
116               ],
117               [
118                 'name' => 'Links',
119                 'items' => [
120                   'DrupalLink',
121                   'DrupalUnlink',
122                 ],
123               ],
124               [
125                 'name' => 'Lists',
126                 'items' => [
127                   'BulletedList',
128                   'NumberedList',
129                 ],
130               ],
131               [
132                 'name' => 'Media',
133                 'items' => [
134                   'Blockquote',
135                   'DrupalImage',
136                 ],
137               ],
138               [
139                 'name' => 'Tools',
140                 'items' => [
141                   'Source',
142                 ],
143               ],
144             ],
145           ],
146         ],
147         'plugins' => [
148           'language' => [
149             'language_list' => 'un',
150           ],
151         ],
152       ],
153       'status' => TRUE,
154       'uuid' => $this->entity->uuid(),
155     ];
156   }
157
158   /**
159    * {@inheritdoc}
160    */
161   protected function getNormalizedPostEntity() {
162     // @todo Update in https://www.drupal.org/node/2300677.
163   }
164
165   /**
166    * {@inheritdoc}
167    */
168   protected function getExpectedCacheContexts() {
169     // @see ::createEntity()
170     return ['user.permissions'];
171   }
172
173   /**
174    * {@inheritdoc}
175    */
176   protected function getExpectedUnauthorizedAccessMessage($method) {
177     if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
178       return parent::getExpectedUnauthorizedAccessMessage($method);
179     }
180
181     return "The 'administer filters' permission is required.";
182   }
183
184 }