3 namespace Drupal\paragraphs\Tests\Experimental;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
6 use Drupal\paragraphs\Entity\Paragraph;
9 * Tests the configuration of paragraphs.
13 class ParagraphsExperimentalAdministrationTest extends ParagraphsExperimentalTestBase {
22 public static $modules = array(
31 protected function setUp() {
33 // Create paragraphs content type.
34 $this->drupalCreateContentType(array('type' => 'paragraphs', 'name' => 'Paragraphs'));
38 * Tests the revision of paragraphs.
40 public function testParagraphsRevisions() {
41 $this->addParagraphedContentType('article', 'paragraphs');
43 'create paragraphs content',
44 'administer node display',
45 'edit any paragraphs content',
48 // Create paragraphs type Headline + Block.
49 $this->addParagraphsType('text');
50 // Create field types for the text.
51 static::fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array());
52 $this->assertText('Saved Text configuration.');
54 // Create an article with paragraphs field.
55 static::fieldUIAddNewField('admin/structure/types/manage/paragraphs', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array(
56 'settings[target_type]' => 'paragraph',
57 'cardinality' => '-1',
59 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => TRUE,
61 // Configure article fields.
62 $this->drupalGet('admin/structure/types/manage/paragraphs/fields');
63 $this->clickLink(t('Manage form display'));
64 $this->drupalPostForm(NULL, array('fields[field_paragraphs][type]' => 'paragraphs'), t('Save'));
66 // Create node with our paragraphs.
67 $this->drupalGet('node/add/paragraphs');
68 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more');
69 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more');
71 'title[0][value]' => 'TEST TITEL',
72 'field_paragraphs[0][subform][field_text][0][value]' => 'Test text 1',
73 'field_paragraphs[1][subform][field_text][0][value]' => 'Test text 2',
75 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
77 $node = $this->drupalGetNodeByTitle('TEST TITEL');
78 $paragraph1 = $node->field_paragraphs[0]->target_id;
79 $paragraph2 = $node->field_paragraphs[1]->target_id;
81 $this->countRevisions($node, $paragraph1, $paragraph2, 1);
83 // Edit the node without creating a revision. There should still be only 1
84 // revision for nodes and paragraphs.
86 'field_paragraphs[0][subform][field_text][0][value]' => 'Foo Bar 1',
89 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
91 $this->countRevisions($node, $paragraph1, $paragraph2, 1);
93 // Edit the just created node. Create new revision. Now we should have 2
94 // revisions for nodes and paragraphs.
96 'title[0][value]' => 'TEST TITLE',
97 'field_paragraphs[0][subform][field_text][0][value]' => 'Foo Bar 2',
100 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
102 $this->countRevisions($node, $paragraph1, $paragraph2, 2);
104 // Assert the paragraphs have been changed.
105 $this->assertNoText('Foo Bar 1');
106 $this->assertText('Test text 2');
107 $this->assertText('Foo Bar 2');
108 $this->assertText('TEST TITLE');
110 // Check out the revisions page and assert there are 2 revisions.
111 $this->drupalGet('node/' . $node->id() . '/revisions');
112 $rows = $this->xpath('//tbody/tr');
113 // Make sure two revisions available.
114 $this->assertEqual(count($rows), 2);
115 // Revert to the old version.
116 $this->clickLink(t('Revert'));
117 $this->drupalPostForm(NULL, [], t('Revert'));
118 $this->drupalGet('node/' . $node->id());
119 // Assert the node has been reverted.
120 $this->assertNoText('Foo Bar 2');
121 $this->assertText('Test text 2');
122 $this->assertText('Foo Bar 1');
123 $this->assertText('TEST TITEL');
128 * Tests the paragraph creation.
130 public function testParagraphsCreation() {
131 // Create an article with paragraphs field.
132 $this->addParagraphedContentType('article', 'field_paragraphs');
133 $this->loginAsAdmin([
134 'administer site configuration',
135 'create article content',
136 'create paragraphs content',
137 'administer node display',
138 'administer paragraph display',
139 'edit any article content',
140 'delete any article content',
141 'access files overview',
144 // Assert suggested 'Add a paragraph type' link when there is no type yet.
145 $this->drupalGet('admin/structure/paragraphs_type');
146 $this->assertText('There is no Paragraphs type yet.');
147 $this->drupalGet('admin/structure/types/manage/paragraphs/fields/add-field');
149 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph',
150 'label' => 'Paragraph',
151 'field_name' => 'paragraph',
153 $this->drupalPostForm(NULL, $edit, 'Save and continue');
154 $this->drupalPostForm(NULL, [], 'Save field settings');
155 $this->assertLinkByHref('admin/structure/paragraphs_type/add');
156 $this->clickLink('here');
157 $this->assertUrl('admin/structure/paragraphs_type/add');
159 $this->drupalGet('admin/structure/paragraphs_type');
160 $this->clickLink(t('Add paragraphs type'));
161 $this->assertTitle('Add paragraphs type | Drupal');
162 // Create paragraph type text + image.
163 $this->addParagraphsType('text_image');
164 $this->drupalGet('admin/structure/paragraphs_type/text_image');
165 $this->assertTitle('Edit text_image paragraph type | Drupal');
166 // Create field types for text and image.
167 static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'text', 'Text', 'text_long', array(), array());
168 $this->assertText('Saved Text configuration.');
169 static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'image', 'Image', 'image', array(), array('settings[alt_field_required]' => FALSE));
170 $this->assertText('Saved Image configuration.');
172 // Create paragraph type Nested test.
173 $this->addParagraphsType('nested_test');
175 static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_test', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array(
176 'settings[target_type]' => 'paragraph',
177 'cardinality' => '-1',
180 // Change the add more button to select mode.
181 $this->clickLink(t('Manage form display'));
182 $this->drupalPostAjaxForm(NULL, ['fields[field_paragraphs][type]' => 'paragraphs'], 'field_paragraphs_settings_edit');
183 $this->drupalPostForm(NULL, ['fields[field_paragraphs][settings_edit_form][settings][add_mode]' => 'select'], t('Update'));
184 $this->drupalPostForm(NULL, [], t('Save'));
186 // Create paragraph type image.
187 $this->addParagraphsType('image');
188 // Create field types for image.
189 static::fieldUIAddNewField('admin/structure/paragraphs_type/image', 'image_only', 'Image only', 'image', array(), array());
190 $this->assertText('Saved Image only configuration.');
192 $this->drupalGet('admin/structure/paragraphs_type');
193 $rows = $this->xpath('//tbody/tr');
194 // Make sure 2 types are available with their label.
195 $this->assertEqual(count($rows), 3);
196 $this->assertText('text_image');
197 $this->assertText('image');
198 // Make sure there is an edit link for each type.
199 $this->clickLink(t('Edit'));
200 // Make sure the field UI appears.
201 $this->assertLink('Manage fields');
202 $this->assertLink('Manage form display');
203 $this->assertLink('Manage display');
204 $this->assertTitle('Edit image paragraph type | Drupal');
206 // Test for "Add mode" setting.
207 $this->drupalGet('admin/structure/types/manage/article/form-display');
208 $field_name = 'field_paragraphs';
210 // Click on the widget settings button to open the widget settings form.
211 $this->drupalPostAjaxForm(NULL, ['fields[field_paragraphs][type]' => 'paragraphs'], $field_name . "_settings_edit");
214 $edit = array('fields[' . $field_name . '][settings_edit_form][settings][add_mode]' => 'button');
215 $this->drupalPostForm(NULL, $edit, t('Save'));
217 // Check if the setting is stored.
218 $this->drupalGet('admin/structure/types/manage/article/form-display');
219 $this->assertText('Add mode: Buttons', 'Checking the settings value.');
221 $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
222 // Assert the 'Buttons' option is selected.
223 $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-add-mode', 'button', 'Updated value is correct!.');
225 // Add two Text + Image paragraphs in article.
226 $this->drupalGet('node/add/article');
228 // Checking changes on article.
229 $this->assertRaw('<div class="paragraphs-dropbutton-wrapper"><input', 'Updated value in article.');
231 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_image_add_more');
232 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_image_add_more');
233 // Create an 'image' file, upload it.
234 $text = 'Trust me I\'m an image';
235 file_put_contents('temporary://myImage1.jpg', $text);
236 file_put_contents('temporary://myImage2.jpg', $text);
239 'title[0][value]' => 'Test article',
240 'field_paragraphs[0][subform][field_text][0][value]' => 'Test text 1',
241 'files[field_paragraphs_0_subform_field_image_0]' => drupal_realpath('temporary://myImage1.jpg'),
242 'field_paragraphs[1][subform][field_text][0][value]' => 'Test text 2',
243 'files[field_paragraphs_1_subform_field_image_0]' => drupal_realpath('temporary://myImage2.jpg'),
245 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
247 $node = $this->drupalGetNodeByTitle('Test article');
248 $img1_url = file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/myImage1.jpg'));
249 $img2_url = file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/myImage2.jpg'));
251 // Check the text and image after publish.
252 $this->assertText('Test text 1');
253 $this->assertRaw('<img src="' . file_url_transform_relative($img1_url));
254 $this->assertText('Test text 2');
255 $this->assertRaw('<img src="' . file_url_transform_relative($img2_url));
257 // Tests for "Edit mode" settings.
258 // Test for closed setting.
259 $this->drupalGet('admin/structure/types/manage/article/form-display');
260 // Click on the widget settings button to open the widget settings form.
261 $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
263 $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed');
264 $this->drupalPostForm(NULL, $edit, t('Save'));
265 // Check if the setting is stored.
266 $this->assertText('Edit mode: Closed', 'Checking the settings value.');
267 $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
268 // Assert the 'Closed' option is selected.
269 $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed', 'Updated value correctly.');
270 $this->drupalGet('node/1/edit');
271 // The textareas for paragraphs should not be visible.
272 $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]');
273 $this->assertNoRaw('field_paragraphs[1][subform][field_text][0][value]');
274 $this->assertRaw('<div class="paragraphs-collapsed-description">myImage1.jpg, Test text 1');
275 $this->assertRaw('<div class="paragraphs-collapsed-description">myImage2.jpg, Test text 2');
277 // Test for preview option.
278 $this->drupalGet('admin/structure/types/manage/article/form-display');
279 $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
280 $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'preview');
281 $this->drupalPostForm(NULL, $edit, t('Save'));
282 $this->assertText('Edit mode: Preview', 'Checking the settings value.');
283 $this->drupalGet('node/1/edit');
284 // The texts in the paragraphs should be visible.
285 $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]');
286 $this->assertNoRaw('field_paragraphs[1][subform][field_text][0][value]');
287 $this->assertText('Test text 1');
288 $this->assertText('Test text 2');
290 // Test for open option.
291 $this->drupalGet('admin/structure/types/manage/article/form-display');
292 $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
293 // Assert the 'Preview' option is selected.
294 $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'preview', 'Updated value correctly.');
295 // Restore the value to Open for next test.
296 $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'open');
297 $this->drupalPostForm(NULL, $edit, t('Save'));
298 $this->drupalGet('node/1/edit');
299 // The textareas for paragraphs should be visible.
300 $this->assertRaw('field_paragraphs[0][subform][field_text][0][value]');
301 $this->assertRaw('field_paragraphs[1][subform][field_text][0][value]');
303 $paragraphs = Paragraph::loadMultiple();
304 $this->assertEqual(count($paragraphs), 2, 'Two paragraphs in article');
306 // Check article edit page.
307 $this->drupalGet('node/' . $node->id() . '/edit');
308 // Check both paragraphs in edit page.
309 $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'Test text 1');
310 $this->assertRaw('<a href="' . $img1_url . '" type="image/jpeg; length=21">myImage1.jpg</a>');
311 $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'Test text 2');
312 $this->assertRaw('<a href="' . $img2_url . '" type="image/jpeg; length=21">myImage2.jpg</a>');
313 // Remove 2nd paragraph.
314 $this->drupalPostForm(NULL, NULL, t('Remove'));
315 $this->assertNoField('field_paragraphs[1][subform][field_text][0][value]');
316 $this->assertNoRaw('<a href="' . $img2_url . '" type="image/jpeg; length=21">myImage2.jpg</a>');
317 // Assert the paragraph is not deleted unless the user saves the node.
318 $this->drupalGet('node/' . $node->id() . '/edit');
319 $this->assertRaw('<a href="' . $img2_url . '" type="image/jpeg; length=21">myImage2.jpg</a>');
320 // Remove the second paragraph.
321 $this->drupalPostForm(NULL, [], t('Remove'));
322 $this->assertNoRaw('<a href="' . $img2_url . '" type="image/jpeg; length=21">myImage2.jpg</a>');
324 'field_paragraphs[0][subform][field_image][0][alt]' => 'test_alt',
325 'field_paragraphs[0][subform][field_image][0][width]' => 300,
326 'field_paragraphs[0][subform][field_image][0][height]' => 300,
328 $this->drupalPostForm(NULL, $edit, t('Save and keep published'));
329 // Assert the paragraph is deleted after the user saves the node.
330 $this->drupalGet('node/' . $node->id() . '/edit');
331 $this->assertNoRaw('<a href="' . $img2_url . '" type="image/jpeg; length=21">myImage2.jpg</a>');
334 $this->clickLink(t('Delete'));
335 $this->drupalPostForm(NULL, NULL, t('Delete'));
336 $this->assertText('Test article has been deleted.');
338 // Check if the publish/unpublish option works.
339 $this->drupalGet('admin/structure/paragraphs_type/text_image/form-display');
341 'fields[status][type]' => 'boolean_checkbox',
342 'fields[status][region]' => 'content',
345 $this->drupalPostForm(NULL, $edit, t('Save'));
346 $this->drupalGet('node/add/article');
347 $this->drupalPostForm(NULL, NULL, t('Add text_image'));
348 $this->assertRaw('edit-field-paragraphs-0-subform-status-value');
350 'title[0][value]' => 'Example publish/unpublish',
351 'field_paragraphs[0][subform][field_text][0][value]' => 'Example published and unpublished',
353 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
354 $this->assertText(t('Example published and unpublished'));
355 $this->clickLink(t('Edit'));
357 'field_paragraphs[0][subform][status][value]' => FALSE,
359 $this->drupalPostForm(NULL, $edit, t('Save and keep published'));
360 $this->assertNoText(t('Example published and unpublished'));
362 // Set the fields as required.
363 $this->drupalGet('admin/structure/types/manage/article/fields');
364 $this->clickLink('Edit', 1);
365 $this->drupalPostForm(NULL, ['preview_mode' => '1'], t('Save content type'));
366 $this->drupalGet('admin/structure/paragraphs_type/nested_test/fields');
367 $this->clickLink('Edit');
368 $this->drupalPostForm(NULL, ['required' => TRUE], t('Save settings'));
370 // Add a new article.
371 $this->drupalGet('node/add/article');
372 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_nested_test_add_more');
374 'field_paragraphs[0][subform][field_paragraphs][add_more][add_more_select]' => 'image',
376 $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_subform_field_paragraphs_add_more');
377 // Test the new field is displayed.
378 $this->assertFieldByName('files[field_paragraphs_0_subform_field_paragraphs_0_subform_field_image_only_0]');
380 // Add an image to the required field.
382 'title[0][value]' => 'test required',
383 'files[field_paragraphs_0_subform_field_paragraphs_0_subform_field_image_only_0]' => drupal_realpath('temporary://myImage2.jpg'),
385 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
387 'field_paragraphs[0][subform][field_paragraphs][0][subform][field_image_only][0][width]' => 100,
388 'field_paragraphs[0][subform][field_paragraphs][0][subform][field_image_only][0][height]' => 100,
389 'field_paragraphs[0][subform][field_paragraphs][0][subform][field_image_only][0][alt]' => 'Alternative_text',
391 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
392 $this->assertText('test required has been created.');
393 $this->assertNoRaw('This value should not be null.');
395 // Test that unsupported widgets are not displayed.
396 $this->drupalGet('admin/structure/types/manage/article/form-display');
397 $select = $this->xpath('//*[@id="edit-fields-field-paragraphs-type"]')[0];
398 $this->assertEqual(count($select->option), 2);
399 $this->assertRaw('value="paragraphs" selected="selected"');
401 // Check that Paragraphs is not displayed as an entity_reference field
403 $this->drupalGet('admin/structure/types/manage/article/fields/add-field');
405 'new_storage_type' => 'entity_reference',
406 'label' => 'unsupported field',
407 'field_name' => 'unsupportedfield',
409 $this->drupalPostForm(NULL, $edit, t('Save and continue'));
410 $this->assertNoOption('edit-settings-target-type', 'paragraph');
412 // Test that all paragraph types can be referenced if none is selected.
413 $this->addParagraphsType('nested_double_test');
414 static::fieldUIAddExistingField('admin/structure/paragraphs_type/nested_double_test', 'field_paragraphs', 'paragraphs_1');
415 $this->clickLink(t('Manage form display'));
416 $this->drupalPostForm(NULL, [], 'Save');
417 //$this->drupalPostForm(NULL, array('fields[field_paragraphs][type]' => 'entity_reference_revisions_entity_view'), t('Save'));
418 static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_double_test', 'paragraphs_2', 'paragraphs_2', 'entity_reference_revisions', array(
419 'settings[target_type]' => 'paragraph',
420 'cardinality' => '-1',
422 $this->clickLink(t('Manage form display'));
423 $this->drupalPostForm(NULL, [], 'Save');
424 $this->drupalPostAjaxForm('node/add/article', [], 'field_paragraphs_nested_test_add_more');
426 'field_paragraphs[0][subform][field_paragraphs][add_more][add_more_select]' => 'nested_double_test',
428 $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_subform_field_paragraphs_add_more');
429 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_subform_field_paragraphs_0_subform_field_paragraphs_image_add_more');
431 'title[0][value]' => 'Nested twins',
433 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
434 $this->assertText('Nested twins has been created.');
435 $this->assertNoText('This entity (paragraph: ) cannot be referenced.');
437 // Set the fields as not required.
438 $this->drupalGet('admin/structure/types/manage/article/fields');
439 $this->clickLink('Edit', 1);
440 $this->drupalPostForm(NULL, ['required' => FALSE], t('Save settings'));
442 // Set the Paragraph field edit mode to 'Closed'.
443 $this->drupalPostAjaxForm('admin/structure/types/manage/article/form-display', [], 'field_paragraphs_settings_edit');
444 $this->drupalPostForm(NULL, ['fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed'], t('Update'));
445 $this->drupalPostForm(NULL, [], t('Save'));
447 $this->addParagraphsType('node_test');
449 // Add a required node reference field.
450 static::fieldUIAddNewField('admin/structure/paragraphs_type/node_test', 'entity_reference', 'Entity reference', 'entity_reference', array(
451 'settings[target_type]' => 'node',
452 'cardinality' => '-1'
454 'settings[handler_settings][target_bundles][article]' => TRUE,
457 $node = $this->drupalGetNodeByTitle('Nested twins');
459 // Create a node with a reference in a Paragraph.
460 $this->drupalPostAjaxForm('node/add/article', [], 'field_paragraphs_node_test_add_more');
461 \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
463 'field_paragraphs[0][subform][field_entity_reference][0][target_id]' => $node->label() . ' (' . $node->id() . ')',
464 'title[0][value]' => 'choke test',
466 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
467 // Delete the referenced node.
469 // Edit the node with the reference.
470 $this->clickLink(t('Edit'));
471 // Since we have validation error (reference to deleted node), paragraph is
472 // by default in edit mode.
473 $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][0][target_id]');
474 $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][1][target_id]');
475 // Assert the validation error message.
476 $this->assertText('The referenced entity (node: 4) does not exist');
477 // Triggering unrelated button, assert that error message is still present.
478 $this->drupalPostForm(NULL, [], t('Add another item'));
479 $this->assertText('The referenced entity (node: 4) does not exist');
480 $this->assertText('Entity reference (value 1) field is required.');
481 // Try to collapse with an invalid reference.
482 $this->drupalPostAjaxForm(NULL, ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => 'foo'], 'field_paragraphs_0_collapse');
483 // Paragraph should be still in edit mode.
484 $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][0][target_id]');
485 $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][1][target_id]');
486 $this->drupalPostForm(NULL, [], t('Add another item'));
487 // Assert the validation message.
488 $this->assertText('There are no entities matching "foo".');
489 // Fix the broken reference.
490 $node = $this->drupalGetNodeByTitle('Example publish/unpublish');
491 $this->drupalPostForm(NULL, ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => $node->label() . ' (' . $node->id() . ')'], t('Save and keep published'));
492 $this->assertText('choke test has been updated.');
493 $this->assertLink('Example publish/unpublish');
494 // Delete the new referenced node.
497 // Set the Paragraph field edit mode to 'Preview'.
498 $this->drupalPostAjaxForm('admin/structure/types/manage/article/form-display', [], 'field_paragraphs_settings_edit');
499 $this->drupalPostForm(NULL, ['fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'preview'], t('Update'));
500 $this->drupalPostForm(NULL, [], t('Save'));
502 $node = $this->drupalGetNodeByTitle('choke test');
503 // Attempt to edit the Paragraph.
504 $this->drupalPostAjaxForm('node/' . $node->id() . '/edit', [], 'field_paragraphs_0_edit');
505 // Try to collapse with an invalid reference.
506 $this->drupalPostAjaxForm(NULL, ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => 'foo'], 'field_paragraphs_0_collapse');
507 $this->assertText('There are no entities matching "foo".');
508 // Remove the Paragraph and save the node.
509 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_remove');
510 $this->drupalPostForm(NULL, [], t('Save and keep published'));
511 $this->assertText('choke test has been updated.');
513 // Verify that the text displayed is correct when no paragraph has been
515 $this->drupalGet('node/add/article');
516 $this->assertText('No Paragraph added yet.');
518 $this->drupalGet('admin/content/files');
519 $this->clickLink('1 place');
520 $label = $this->xpath('//tbody/tr/td[1]');
521 $this->assertEqual(trim(htmlspecialchars_decode(strip_tags($label[0]->asXML()))), 'test required > field_paragraphs > Paragraphs');
525 * Asserts that a select option in the current page is checked.
528 * ID of select field to assert.
529 * @param string $option
531 * @param string $message
532 * (optional) A message to display with the assertion. Do not translate
533 * messages: use format_string() to embed variables in the message text, not
534 * t(). If left blank, a default message will be displayed.
535 * @param string $group
536 * (optional) The group this message is in, which is displayed in a column
537 * in test output. Use 'Debug' to indicate this is debugging output. Do not
538 * translate this string. Defaults to 'Browser'; most tests do not override
542 * TRUE on pass, FALSE on fail.
544 * @todo Remove function once core issue is resolved: https://www.drupal.org/node/2530092
546 protected function assertOptionSelected($id, $option, $message = '', $group = 'Browser') {
547 $elements = $this->xpath('//select[contains(@id, :id)]//option[@value=:option]', array(':id' => $id, ':option' => $option));
548 return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['selected']), $message ? $message : SafeMarkup::format('Option @option for field @id is selected.', array('@option' => $option, '@id' => $id)), $group);
552 * Helper function for revision counting.
554 private function countRevisions($node, $paragraph1, $paragraph2, $revisions_count) {
555 $node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute();
556 $this->assertEqual($node_revisions_count, $revisions_count);
557 $this->assertEqual(\Drupal::entityQuery('paragraph')->condition('id', $paragraph1)->allRevisions()->count()->execute(), $revisions_count);
558 $this->assertEqual(\Drupal::entityQuery('paragraph')->condition('id', $paragraph2)->allRevisions()->count()->execute(), $revisions_count);