Mercurial > hg > isophonics-drupal-site
comparison core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\quickedit\FunctionalJavascript; | |
4 | |
5 use Drupal\block_content\Entity\BlockContent; | |
6 use Drupal\block_content\Entity\BlockContentType; | |
7 use Drupal\Core\Field\FieldStorageDefinitionInterface; | |
8 use Drupal\editor\Entity\Editor; | |
9 use Drupal\filter\Entity\FilterFormat; | |
10 use Drupal\taxonomy\Entity\Term; | |
11 use Drupal\taxonomy\Entity\Vocabulary; | |
12 use Drupal\Tests\field\Traits\EntityReferenceTestTrait; | |
13 | |
14 /** | |
15 * @group quickedit | |
16 */ | |
17 class QuickEditIntegrationTest extends QuickEditJavascriptTestBase { | |
18 | |
19 use EntityReferenceTestTrait; | |
20 | |
21 /** | |
22 * {@inheritdoc} | |
23 */ | |
24 public static $modules = [ | |
25 'node', | |
26 'editor', | |
27 'ckeditor', | |
28 'taxonomy', | |
29 'block', | |
30 'block_content', | |
31 'hold_test', | |
32 ]; | |
33 | |
34 /** | |
35 * A user with permissions to edit Articles and use Quick Edit. | |
36 * | |
37 * @var \Drupal\user\UserInterface | |
38 */ | |
39 protected $contentAuthorUser; | |
40 | |
41 /** | |
42 * {@inheritdoc} | |
43 */ | |
44 protected function setUp() { | |
45 parent::setUp(); | |
46 // Create text format, associate CKEditor. | |
47 FilterFormat::create([ | |
48 'format' => 'some_format', | |
49 'name' => 'Some format', | |
50 'weight' => 0, | |
51 'filters' => [ | |
52 'filter_html' => [ | |
53 'status' => 1, | |
54 'settings' => [ | |
55 'allowed_html' => '<h2 id> <h3> <h4> <h5> <h6> <p> <br> <strong> <a href hreflang>', | |
56 ], | |
57 ], | |
58 ], | |
59 ])->save(); | |
60 Editor::create([ | |
61 'format' => 'some_format', | |
62 'editor' => 'ckeditor', | |
63 ])->save(); | |
64 | |
65 // Create the Article node type. | |
66 $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); | |
67 | |
68 // Add "tags" vocabulary + field to the Article node type. | |
69 $vocabulary = Vocabulary::create([ | |
70 'name' => 'Tags', | |
71 'vid' => 'tags', | |
72 ]); | |
73 $vocabulary->save(); | |
74 $field_name = 'field_' . $vocabulary->id(); | |
75 $handler_settings = [ | |
76 'target_bundles' => [ | |
77 $vocabulary->id() => $vocabulary->id(), | |
78 ], | |
79 'auto_create' => TRUE, | |
80 ]; | |
81 $this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); | |
82 | |
83 // Add formatter & widget for "tags" field. | |
84 \Drupal::entityTypeManager() | |
85 ->getStorage('entity_form_display') | |
86 ->load('node.article.default') | |
87 ->setComponent($field_name, ['type' => 'entity_reference_autocomplete_tags']) | |
88 ->save(); | |
89 \Drupal::entityTypeManager() | |
90 ->getStorage('entity_view_display') | |
91 ->load('node.article.default') | |
92 ->setComponent($field_name, ['type' => 'entity_reference_label']) | |
93 ->save(); | |
94 | |
95 $this->drupalPlaceBlock('page_title_block'); | |
96 $this->drupalPlaceBlock('system_main_block'); | |
97 | |
98 // Log in as a content author who can use Quick Edit and edit Articles. | |
99 $this->contentAuthorUser = $this->drupalCreateUser([ | |
100 'access contextual links', | |
101 'access toolbar', | |
102 'access in-place editing', | |
103 'access content', | |
104 'create article content', | |
105 'edit any article content', | |
106 'use text format some_format', | |
107 'edit terms in tags', | |
108 'administer blocks', | |
109 ]); | |
110 $this->drupalLogin($this->contentAuthorUser); | |
111 } | |
112 | |
113 /** | |
114 * Tests if an article node can be in-place edited with Quick Edit. | |
115 */ | |
116 public function testArticleNode() { | |
117 $term = Term::create([ | |
118 'name' => 'foo', | |
119 'vid' => 'tags', | |
120 ]); | |
121 $term->save(); | |
122 | |
123 $node = $this->drupalCreateNode([ | |
124 'type' => 'article', | |
125 'title' => t('My Test Node'), | |
126 'body' => [ | |
127 'value' => '<p>Hello world!</p><p>I do not know what to say…</p><p>I wish I were eloquent.</p>', | |
128 'format' => 'some_format', | |
129 ], | |
130 'field_tags' => [ | |
131 ['target_id' => $term->id()], | |
132 ], | |
133 ]); | |
134 | |
135 $this->drupalGet('node/' . $node->id()); | |
136 | |
137 // Initial state. | |
138 $this->awaitQuickEditForEntity('node', 1); | |
139 $this->assertEntityInstanceStates([ | |
140 'node/1[0]' => 'closed', | |
141 ]); | |
142 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
143 'node/1/title/en/full' => 'inactive', | |
144 'node/1/uid/en/full' => 'inactive', | |
145 'node/1/created/en/full' => 'inactive', | |
146 'node/1/body/en/full' => 'inactive', | |
147 'node/1/field_tags/en/full' => 'inactive', | |
148 ]); | |
149 | |
150 // Start in-place editing of the article node. | |
151 $this->startQuickEditViaToolbar('node', 1, 0); | |
152 $this->assertEntityInstanceStates([ | |
153 'node/1[0]' => 'opened', | |
154 ]); | |
155 $this->assertQuickEditEntityToolbar((string) $node->label(), NULL); | |
156 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
157 'node/1/title/en/full' => 'candidate', | |
158 'node/1/uid/en/full' => 'candidate', | |
159 'node/1/created/en/full' => 'candidate', | |
160 'node/1/body/en/full' => 'candidate', | |
161 'node/1/field_tags/en/full' => 'candidate', | |
162 ]); | |
163 | |
164 $assert_session = $this->assertSession(); | |
165 | |
166 // Click the title field. | |
167 $this->click('[data-quickedit-field-id="node/1/title/en/full"].quickedit-candidate'); | |
168 $assert_session->waitForElement('css', '.quickedit-toolbar-field div[id*="title"]'); | |
169 $this->assertQuickEditEntityToolbar((string) $node->label(), 'Title'); | |
170 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
171 'node/1/title/en/full' => 'active', | |
172 'node/1/uid/en/full' => 'candidate', | |
173 'node/1/created/en/full' => 'candidate', | |
174 'node/1/body/en/full' => 'candidate', | |
175 'node/1/field_tags/en/full' => 'candidate', | |
176 ]); | |
177 $this->assertEntityInstanceFieldMarkup('node', 1, 0, [ | |
178 'node/1/title/en/full' => '[contenteditable="true"]', | |
179 ]); | |
180 | |
181 // Append something to the title. | |
182 $this->typeInPlainTextEditor('[data-quickedit-field-id="node/1/title/en/full"].quickedit-candidate', ' Llamas are awesome!'); | |
183 $this->awaitEntityInstanceFieldState('node', 1, 0, 'title', 'en', 'changed'); | |
184 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
185 'node/1/title/en/full' => 'changed', | |
186 'node/1/uid/en/full' => 'candidate', | |
187 'node/1/created/en/full' => 'candidate', | |
188 'node/1/body/en/full' => 'candidate', | |
189 'node/1/field_tags/en/full' => 'candidate', | |
190 ]); | |
191 | |
192 // Click the body field. | |
193 hold_test_response(TRUE); | |
194 $this->click('[data-quickedit-entity-id="node/1"] .field--name-body'); | |
195 $assert_session->waitForElement('css', '.quickedit-toolbar-field div[id*="body"]'); | |
196 $this->assertQuickEditEntityToolbar((string) $node->label(), 'Body'); | |
197 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
198 'node/1/title/en/full' => 'saving', | |
199 'node/1/uid/en/full' => 'candidate', | |
200 'node/1/created/en/full' => 'candidate', | |
201 'node/1/body/en/full' => 'active', | |
202 'node/1/field_tags/en/full' => 'candidate', | |
203 ]); | |
204 hold_test_response(FALSE); | |
205 | |
206 // Wait for CKEditor to load, then verify it has. | |
207 $this->assertJsCondition('CKEDITOR.status === "loaded"'); | |
208 $this->assertEntityInstanceFieldMarkup('node', 1, 0, [ | |
209 'node/1/body/en/full' => '.cke_editable_inline', | |
210 'node/1/field_tags/en/full' => ':not(.quickedit-editor-is-popup)', | |
211 ]); | |
212 $this->assertSession()->elementExists('css', '#quickedit-entity-toolbar .quickedit-toolgroup.wysiwyg-main > .cke_chrome .cke_top[role="presentation"] .cke_toolbar[role="toolbar"] .cke_toolgroup[role="presentation"] > .cke_button[title~="Bold"][role="button"]'); | |
213 | |
214 // Wait for the validating & saving of the title to complete. | |
215 $this->awaitEntityInstanceFieldState('node', 1, 0, 'title', 'en', 'candidate'); | |
216 | |
217 // Click the tags field. | |
218 hold_test_response(TRUE); | |
219 $this->click('[data-quickedit-field-id="node/1/field_tags/en/full"]'); | |
220 $assert_session->waitForElement('css', '.quickedit-toolbar-field div[id*="tags"]'); | |
221 $this->assertQuickEditEntityToolbar((string) $node->label(), 'Tags'); | |
222 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
223 'node/1/uid/en/full' => 'candidate', | |
224 'node/1/created/en/full' => 'candidate', | |
225 'node/1/body/en/full' => 'candidate', | |
226 'node/1/field_tags/en/full' => 'activating', | |
227 'node/1/title/en/full' => 'candidate', | |
228 ]); | |
229 $this->assertEntityInstanceFieldMarkup('node', 1, 0, [ | |
230 'node/1/title/en/full' => '.quickedit-changed', | |
231 'node/1/field_tags/en/full' => '.quickedit-editor-is-popup', | |
232 ]); | |
233 // Assert the "Loading…" popup appears. | |
234 $this->assertSession()->elementExists('css', '.quickedit-form-container > .quickedit-form[role="dialog"] > .placeholder'); | |
235 hold_test_response(FALSE); | |
236 // Wait for the form to load. | |
237 $this->assertJsCondition('document.querySelector(\'.quickedit-form-container > .quickedit-form[role="dialog"] > .placeholder\') === null'); | |
238 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
239 'node/1/uid/en/full' => 'candidate', | |
240 'node/1/created/en/full' => 'candidate', | |
241 'node/1/body/en/full' => 'candidate', | |
242 'node/1/field_tags/en/full' => 'active', | |
243 'node/1/title/en/full' => 'candidate', | |
244 ]); | |
245 | |
246 // Enter an additional tag. | |
247 $this->typeInFormEditorTextInputField('field_tags[target_id]', 'foo, bar'); | |
248 $this->awaitEntityInstanceFieldState('node', 1, 0, 'field_tags', 'en', 'changed'); | |
249 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
250 'node/1/uid/en/full' => 'candidate', | |
251 'node/1/created/en/full' => 'candidate', | |
252 'node/1/body/en/full' => 'candidate', | |
253 'node/1/field_tags/en/full' => 'changed', | |
254 'node/1/title/en/full' => 'candidate', | |
255 ]); | |
256 | |
257 // Click 'Save'. | |
258 hold_test_response(TRUE); | |
259 $this->saveQuickEdit(); | |
260 $this->assertEntityInstanceStates([ | |
261 'node/1[0]' => 'committing', | |
262 ]); | |
263 $this->assertEntityInstanceFieldStates('node', 1, 0, [ | |
264 'node/1/uid/en/full' => 'candidate', | |
265 'node/1/created/en/full' => 'candidate', | |
266 'node/1/body/en/full' => 'candidate', | |
267 'node/1/field_tags/en/full' => 'saving', | |
268 'node/1/title/en/full' => 'candidate', | |
269 ]); | |
270 hold_test_response(FALSE); | |
271 $this->assertEntityInstanceFieldMarkup('node', 1, 0, [ | |
272 'node/1/title/en/full' => '.quickedit-changed', | |
273 'node/1/field_tags/en/full' => '.quickedit-changed', | |
274 ]); | |
275 | |
276 // Wait for the saving of the tags field to complete. | |
277 $this->assertJsCondition("Drupal.quickedit.collections.entities.get('node/1[0]').get('state') === 'closed'"); | |
278 $this->assertEntityInstanceStates([ | |
279 'node/1[0]' => 'closed', | |
280 ]); | |
281 } | |
282 | |
283 /** | |
284 * Tests if a custom can be in-place edited with Quick Edit. | |
285 */ | |
286 public function testCustomBlock() { | |
287 $block_content_type = BlockContentType::create([ | |
288 'id' => 'basic', | |
289 'label' => 'basic', | |
290 'revision' => FALSE, | |
291 ]); | |
292 $block_content_type->save(); | |
293 block_content_add_body_field($block_content_type->id()); | |
294 | |
295 $block_content = BlockContent::create([ | |
296 'info' => 'Llama', | |
297 'type' => 'basic', | |
298 'body' => [ | |
299 'value' => 'The name "llama" was adopted by European settlers from native Peruvians.', | |
300 'format' => 'some_format', | |
301 ], | |
302 ]); | |
303 $block_content->save(); | |
304 $this->drupalPlaceBlock('block_content:' . $block_content->uuid(), [ | |
305 'label' => 'My custom block!', | |
306 ]); | |
307 | |
308 $this->drupalGet(''); | |
309 | |
310 // Initial state. | |
311 $this->awaitQuickEditForEntity('block_content', 1); | |
312 $this->assertEntityInstanceStates([ | |
313 'block_content/1[0]' => 'closed', | |
314 ]); | |
315 | |
316 // Start in-place editing of the article node. | |
317 $this->startQuickEditViaToolbar('block_content', 1, 0); | |
318 $this->assertEntityInstanceStates([ | |
319 'block_content/1[0]' => 'opened', | |
320 ]); | |
321 $this->assertQuickEditEntityToolbar((string) $block_content->label(), 'Body'); | |
322 $this->assertEntityInstanceFieldStates('block_content', 1, 0, [ | |
323 'block_content/1/body/en/full' => 'highlighted', | |
324 ]); | |
325 | |
326 // Click the body field. | |
327 $this->click('[data-quickedit-entity-id="block_content/1"] .field--name-body'); | |
328 $assert_session = $this->assertSession(); | |
329 $assert_session->waitForElement('css', '.quickedit-toolbar-field div[id*="body"]'); | |
330 $this->assertQuickEditEntityToolbar((string) $block_content->label(), 'Body'); | |
331 $this->assertEntityInstanceFieldStates('block_content', 1, 0, [ | |
332 'block_content/1/body/en/full' => 'active', | |
333 ]); | |
334 | |
335 // Wait for CKEditor to load, then verify it has. | |
336 $this->assertJsCondition('CKEDITOR.status === "loaded"'); | |
337 $this->assertEntityInstanceFieldMarkup('block_content', 1, 0, [ | |
338 'block_content/1/body/en/full' => '.cke_editable_inline', | |
339 ]); | |
340 $this->assertSession()->elementExists('css', '#quickedit-entity-toolbar .quickedit-toolgroup.wysiwyg-main > .cke_chrome .cke_top[role="presentation"] .cke_toolbar[role="toolbar"] .cke_toolgroup[role="presentation"] > .cke_button[title~="Bold"][role="button"]'); | |
341 } | |
342 | |
343 } |