3 namespace Drupal\paragraphs\Tests\Classic;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
6 use Drupal\paragraphs\Entity\Paragraph;
9 * Tests the configuration of paragraphs.
13 class ParagraphsAdministrationTest extends ParagraphsTestBase {
22 public static $modules = array(
31 protected function setUp() {
33 // Create paragraphs content type.
34 $this->drupalCreateContentType(array('type' => 'paragraphs', 'name' => 'Paragraphs'));
37 * Tests the revision of paragraphs.
39 public function testParagraphsRevisions() {
40 $this->addParagraphedContentType('article', 'paragraphs');
42 'create paragraphs content',
43 'administer node display',
44 'edit any paragraphs content',
47 // Create paragraphs type Headline + Block.
48 $this->addParagraphsType('text');
49 // Create field types for the text.
50 static::fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array());
51 $this->assertText('Saved Text configuration.');
53 // Create an article with paragraphs field.
54 static::fieldUIAddNewField('admin/structure/types/manage/paragraphs', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array(
55 'settings[target_type]' => 'paragraph',
56 'cardinality' => '-1',
58 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => TRUE,
60 // Configure article fields.
61 $this->drupalGet('admin/structure/types/manage/paragraphs/fields');
62 $this->clickLink(t('Manage form display'));
63 $this->drupalPostForm(NULL, array('fields[field_paragraphs][type]' => 'entity_reference_paragraphs'), t('Save'));
65 // Create node with our paragraphs.
66 $this->drupalGet('node/add/paragraphs');
67 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more');
68 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more');
70 'title[0][value]' => 'TEST TITEL',
71 'field_paragraphs[0][subform][field_text][0][value]' => 'Test text 1',
72 'field_paragraphs[1][subform][field_text][0][value]' => 'Test text 2',
74 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
76 $node = $this->drupalGetNodeByTitle('TEST TITEL');
77 $paragraph1 = $node->field_paragraphs[0]->target_id;
78 $paragraph2 = $node->field_paragraphs[1]->target_id;
80 $this->countRevisions($node, $paragraph1, $paragraph2, 1);
82 // Edit the node without creating a revision. There should still be only 1
83 // revision for nodes and paragraphs.
85 'field_paragraphs[0][subform][field_text][0][value]' => 'Foo Bar 1',
88 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
90 $this->countRevisions($node, $paragraph1, $paragraph2, 1);
92 // Edit the just created node. Create new revision. Now we should have 2
93 // revisions for nodes and paragraphs.
95 'title[0][value]' => 'TEST TITLE',
96 'field_paragraphs[0][subform][field_text][0][value]' => 'Foo Bar 2',
99 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
101 $this->countRevisions($node, $paragraph1, $paragraph2, 2);
103 // Assert the paragraphs have been changed.
104 $this->assertNoText('Foo Bar 1');
105 $this->assertText('Test text 2');
106 $this->assertText('Foo Bar 2');
107 $this->assertText('TEST TITLE');
109 // Check out the revisions page and assert there are 2 revisions.
110 $this->drupalGet('node/' . $node->id() . '/revisions');
111 $rows = $this->xpath('//tbody/tr');
112 // Make sure two revisions available.
113 $this->assertEqual(count($rows), 2);
114 // Revert to the old version.
115 $this->clickLink(t('Revert'));
116 $this->drupalPostForm(NULL, [], t('Revert'));
117 $this->drupalGet('node/' . $node->id());
118 // Assert the node has been reverted.
119 $this->assertNoText('Foo Bar 2');
120 $this->assertText('Test text 2');
121 $this->assertText('Foo Bar 1');
122 $this->assertText('TEST TITEL');
127 * Tests the paragraph creation.
129 public function testParagraphsCreation() {
130 // Create an article with paragraphs field.
131 $this->addParagraphedContentType('article', 'field_paragraphs');
132 $this->loginAsAdmin([
133 'administer site configuration',
134 'create article content',
135 'create paragraphs content',
136 'administer node display',
137 'administer paragraph display',
138 'edit any article content',
139 'delete any article content',
140 'access files overview',
143 // Assert suggested 'Add a paragraph type' link when there is no type yet.
144 $this->drupalGet('admin/structure/paragraphs_type');
145 $this->assertText('There is no Paragraphs type yet.');
146 $this->drupalGet('admin/structure/types/manage/paragraphs/fields/add-field');
148 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph',
149 'label' => 'Paragraph',
150 'field_name' => 'paragraph',
152 $this->drupalPostForm(NULL, $edit, 'Save and continue');
153 $this->drupalPostForm(NULL, [], 'Save field settings');
154 $this->assertLinkByHref('admin/structure/paragraphs_type/add');
155 $this->clickLink('here');
156 $this->assertUrl('admin/structure/paragraphs_type/add');
158 $this->drupalGet('admin/structure/paragraphs_type');
159 $this->clickLink(t('Add paragraphs type'));
160 $this->assertTitle('Add paragraphs type | Drupal');
161 // Create paragraph type text + image.
162 $this->addParagraphsType('text_image');
163 $this->drupalGet('admin/structure/paragraphs_type/text_image');
164 $this->assertTitle('Edit text_image paragraph type | Drupal');
165 // Create field types for text and image.
166 static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'text', 'Text', 'text_long', array(), array());
167 $this->assertText('Saved Text configuration.');
168 static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'image', 'Image', 'image', array(), array('settings[alt_field_required]' => FALSE));
169 $this->assertText('Saved Image configuration.');
171 // Create paragraph type Nested test.
172 $this->addParagraphsType('nested_test');
174 static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_test', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array(
175 'settings[target_type]' => 'paragraph',
176 'cardinality' => '-1',
179 // Change the add more button to select mode.
180 $this->clickLink(t('Manage form display'));
181 $this->drupalPostAjaxForm(NULL, ['fields[field_paragraphs][type]' => 'entity_reference_paragraphs'], 'field_paragraphs_settings_edit');
182 $this->drupalPostForm(NULL, ['fields[field_paragraphs][settings_edit_form][settings][add_mode]' => 'select'], t('Update'));
183 $this->drupalPostForm(NULL, [], t('Save'));
185 // Create paragraph type image.
186 $this->addParagraphsType('image');
187 // Create field types for image.
188 static::fieldUIAddNewField('admin/structure/paragraphs_type/image', 'image_only', 'Image only', 'image', array(), array());
189 $this->assertText('Saved Image only configuration.');
191 $this->drupalGet('admin/structure/paragraphs_type');
192 $rows = $this->xpath('//tbody/tr');
193 // Make sure 2 types are available with their label.
194 $this->assertEqual(count($rows), 3);
195 $this->assertText('text_image');
196 $this->assertText('image');
197 // Make sure there is an edit link for each type.
198 $this->clickLink(t('Edit'));
199 // Make sure the field UI appears.
200 $this->assertLink('Manage fields');
201 $this->assertLink('Manage form display');
202 $this->assertLink('Manage display');
203 $this->assertTitle('Edit image paragraph type | Drupal');
205 // Test for "Add mode" setting.
206 $this->drupalGet('admin/structure/types/manage/article/form-display');
207 $field_name = 'field_paragraphs';
209 // Click on the widget settings button to open the widget settings form.
210 $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
213 $edit = array('fields[' . $field_name . '][settings_edit_form][settings][add_mode]' => 'button');
214 $this->drupalPostForm(NULL, $edit, t('Save'));
216 // Check if the setting is stored.
217 $this->drupalGet('admin/structure/types/manage/article/form-display');
218 $this->assertText('Add mode: Buttons', 'Checking the settings value.');
220 $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
221 // Assert the 'Buttons' option is selected.
222 $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-add-mode', 'button', 'Updated value is correct!.');
224 // Add two Text + Image paragraphs in article.
225 $this->drupalGet('node/add/article');
227 // Checking changes on article.
228 $this->assertRaw('<div class="paragraphs-dropbutton-wrapper"><input', 'Updated value in article.');
230 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_image_add_more');
231 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_image_add_more');
232 // Create an 'image' file, upload it.
233 $text = 'Trust me I\'m an image';
234 file_put_contents('temporary://myImage1.jpg', $text);
235 file_put_contents('temporary://myImage2.jpg', $text);
238 'title[0][value]' => 'Test article',
239 'field_paragraphs[0][subform][field_text][0][value]' => 'Test text 1',
240 'files[field_paragraphs_0_subform_field_image_0]' => drupal_realpath('temporary://myImage1.jpg'),
241 'field_paragraphs[1][subform][field_text][0][value]' => 'Test text 2',
242 'files[field_paragraphs_1_subform_field_image_0]' => drupal_realpath('temporary://myImage2.jpg'),
244 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
246 $node = $this->drupalGetNodeByTitle('Test article');
247 $img1_url = file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/myImage1.jpg'));
248 $img2_url = file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/myImage2.jpg'));
250 // Check the text and image after publish.
251 $this->assertText('Test text 1');
252 $this->assertRaw('<img src="' . file_url_transform_relative($img1_url));
253 $this->assertText('Test text 2');
254 $this->assertRaw('<img src="' . file_url_transform_relative($img2_url));
256 // Tests for "Edit mode" settings.
257 // Test for closed setting.
258 $this->drupalGet('admin/structure/types/manage/article/form-display');
259 // Click on the widget settings button to open the widget settings form.
260 $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
262 $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed');
263 $this->drupalPostForm(NULL, $edit, t('Save'));
264 // Check if the setting is stored.
265 $this->assertText('Edit mode: Closed', 'Checking the settings value.');
266 $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
267 // Assert the 'Closed' option is selected.
268 $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed', 'Updated value correctly.');
269 $this->drupalGet('node/1/edit');
270 // The textareas for paragraphs should not be visible.
271 $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]');
272 $this->assertNoRaw('field_paragraphs[1][subform][field_text][0][value]');
273 $this->assertRaw('<div class="paragraphs-collapsed-description">myImage1.jpg, Test text 1');
274 $this->assertRaw('<div class="paragraphs-collapsed-description">myImage2.jpg, Test text 2');
276 // Test for preview option.
277 $this->drupalGet('admin/structure/types/manage/article/form-display');
278 $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
279 $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'preview');
280 $this->drupalPostForm(NULL, $edit, t('Save'));
281 $this->assertText('Edit mode: Preview', 'Checking the settings value.');
282 $this->drupalGet('node/1/edit');
283 // The texts in the paragraphs should be visible.
284 $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]');
285 $this->assertNoRaw('field_paragraphs[1][subform][field_text][0][value]');
286 $this->assertText('Test text 1');
287 $this->assertText('Test text 2');
289 // Test for open option.
290 $this->drupalGet('admin/structure/types/manage/article/form-display');
291 $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
292 // Assert the 'Preview' option is selected.
293 $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'preview', 'Updated value correctly.');
294 // Restore the value to Open for next test.
295 $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'open');
296 $this->drupalPostForm(NULL, $edit, t('Save'));
297 $this->drupalGet('node/1/edit');
298 // The textareas for paragraphs should be visible.
299 $this->assertRaw('field_paragraphs[0][subform][field_text][0][value]');
300 $this->assertRaw('field_paragraphs[1][subform][field_text][0][value]');
302 $paragraphs = Paragraph::loadMultiple();
303 $this->assertEqual(count($paragraphs), 2, 'Two paragraphs in article');
305 // Check article edit page.
306 $this->drupalGet('node/' . $node->id() . '/edit');
307 // Check both paragraphs in edit page.
308 $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'Test text 1');
309 $this->assertRaw('<a href="' . $img1_url . '" type="image/jpeg; length=21">myImage1.jpg</a>');
310 $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'Test text 2');
311 $this->assertRaw('<a href="' . $img2_url . '" type="image/jpeg; length=21">myImage2.jpg</a>');
312 // Remove 2nd paragraph.
313 $this->drupalPostForm(NULL, NULL, t('Remove'));
314 $this->assertNoField('field_paragraphs[1][subform][field_text][0][value]');
315 $this->assertNoRaw('<a href="' . $img2_url . '" type="image/jpeg; length=21">myImage2.jpg</a>');
317 $this->drupalPostForm(NULL, NULL, t('Restore'));
318 $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'Test text 2');
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="entity_reference_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 // Attempt to remove the Paragraph.
490 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_remove');
491 $elements = $this->xpath('//*[@name="field_paragraphs_0_confirm_remove"]');
492 $this->assertTrue(!empty($elements), "'Confirm removal' button appears.");
493 // Restore the Paragraph and fix the broken reference.
494 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_restore');
495 $node = $this->drupalGetNodeByTitle('Example publish/unpublish');
496 $this->drupalPostForm(NULL, ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => $node->label() . ' (' . $node->id() . ')'], t('Save and keep published'));
497 $this->assertText('choke test has been updated.');
498 $this->assertLink('Example publish/unpublish');
499 // Delete the new referenced node.
502 // Set the Paragraph field edit mode to 'Preview'.
503 $this->drupalPostAjaxForm('admin/structure/types/manage/article/form-display', [], 'field_paragraphs_settings_edit');
504 $this->drupalPostForm(NULL, ['fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'preview'], t('Update'));
505 $this->drupalPostForm(NULL, [], t('Save'));
507 $node = $this->drupalGetNodeByTitle('choke test');
508 // Attempt to edit the Paragraph.
509 $this->drupalPostAjaxForm('node/' . $node->id() . '/edit', [], 'field_paragraphs_0_edit');
510 // Try to collapse with an invalid reference.
511 $this->drupalPostAjaxForm(NULL, ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => 'foo'], 'field_paragraphs_0_collapse');
512 $this->assertText('There are no entities matching "foo".');
513 // Remove the Paragraph and save the node.
514 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_remove');
515 $elements = $this->xpath('//*[@name="field_paragraphs_0_confirm_remove"]');
516 $this->assertTrue(!empty($elements), "'Confirm removal' button appears.");
517 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_confirm_remove');
518 $this->drupalPostForm(NULL, [], t('Save and keep published'));
519 $this->assertText('choke test has been updated.');
521 // Verify that the text displayed is correct when no paragraph has been
523 $this->drupalGet('node/add/article');
524 $this->assertText('No Paragraph added yet.');
526 $this->drupalGet('admin/content/files');
527 $this->clickLink('1 place');
528 $label = $this->xpath('//tbody/tr/td[1]');
529 $this->assertEqual(trim(htmlspecialchars_decode(strip_tags($label[0]->asXML()))), 'test required > field_paragraphs > Paragraphs');
533 * Asserts that a select option in the current page is checked.
536 * ID of select field to assert.
537 * @param string $option
539 * @param string $message
540 * (optional) A message to display with the assertion. Do not translate
541 * messages: use format_string() to embed variables in the message text, not
542 * t(). If left blank, a default message will be displayed.
543 * @param string $group
544 * (optional) The group this message is in, which is displayed in a column
545 * in test output. Use 'Debug' to indicate this is debugging output. Do not
546 * translate this string. Defaults to 'Browser'; most tests do not override
550 * TRUE on pass, FALSE on fail.
552 * @todo Remove function once core issue is resolved: https://www.drupal.org/node/2530092
554 protected function assertOptionSelected($id, $option, $message = '', $group = 'Browser') {
555 $elements = $this->xpath('//select[contains(@id, :id)]//option[@value=:option]', array(':id' => $id, ':option' => $option));
556 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);
560 * Helper function for revision counting.
562 private function countRevisions($node, $paragraph1, $paragraph2, $revisions_count) {
563 $node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute();
564 $this->assertEqual($node_revisions_count, $revisions_count);
565 $this->assertEqual(\Drupal::entityQuery('paragraph')->condition('id', $paragraph1)->allRevisions()->count()->execute(), $revisions_count);
566 $this->assertEqual(\Drupal::entityQuery('paragraph')->condition('id', $paragraph2)->allRevisions()->count()->execute(), $revisions_count);