3 namespace Drupal\paragraphs\Tests\Experimental;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
8 * Tests paragraphs edit modes.
12 class ParagraphsExperimentalEditModesTest extends ParagraphsExperimentalTestBase {
21 public static $modules = [
27 * Tests the collapsed summary of paragraphs.
29 public function testCollapsedSummary() {
30 $this->addParagraphedContentType('paragraphed_test');
31 $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content']);
33 // Add a Paragraph type.
34 $paragraph_type = 'image_text_paragraph';
35 $this->addParagraphsType($paragraph_type);
36 $title_paragraphs_type = 'title';
37 $this->addParagraphsType($title_paragraphs_type);
38 $this->addParagraphsType('text');
39 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'image', 'Image', 'image', [], ['settings[alt_field_required]' => FALSE]);
40 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
41 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $title_paragraphs_type, 'title', 'Title', 'string', [], []);
43 // Add a user Paragraph Type
44 $paragraph_type = 'user_paragraph';
45 $this->addParagraphsType($paragraph_type);
46 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'user', 'User', 'entity_reference', ['settings[target_type]' => 'user'], []);
48 // Set edit mode to closed.
49 $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
50 $this->drupalPostAjaxForm(NULL, [], "field_paragraphs_settings_edit");
51 $edit = ['fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed'];
52 $this->drupalPostForm(NULL, $edit, t('Save'));
54 $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_image_text_paragraph_add_more');
55 $this->drupalPostAjaxForm(NULL, NULL, 'field_paragraphs_title_add_more');
57 $text = 'Trust me I am an image';
58 file_put_contents('temporary://myImage1.jpg', $text);
60 // Create a node with an image and text.
62 'title[0][value]' => 'Test article',
63 'field_paragraphs[0][subform][field_text][0][value]' => 'text_summary',
64 'files[field_paragraphs_0_subform_field_image_0]' => drupal_realpath('temporary://myImage1.jpg'),
65 'field_paragraphs[1][subform][field_title][0][value]' => 'Title example',
67 $this->drupalPostForm(NULL, $edit, t('Save'));
68 $this->clickLink(t('Edit'));
69 $this->drupalPostForm(NULL, [], t('Add user_paragraph'));
71 'field_paragraphs[2][subform][field_user][0][target_id]' => $this->admin_user->label() . ' (' . $this->admin_user->id() . ')',
73 $this->drupalPostForm(NULL, $edit, t('Save'));
75 // Assert the summary is correctly generated.
76 $this->clickLink(t('Edit'));
77 $this->assertRaw('<div class="paragraphs-collapsed-description">myImage1.jpg, text_summary');
78 $this->assertRaw('<div class="paragraphs-collapsed-description">' . $this->admin_user->label());
79 $this->assertRaw('<div class="paragraphs-collapsed-description">Title example');
81 // Edit and remove alternative text.
82 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
84 'field_paragraphs[0][subform][field_image][0][alt]' => 'alternative_text_summary',
85 'field_paragraphs[0][subform][field_image][0][width]' => 300,
86 'field_paragraphs[0][subform][field_image][0][height]' => 300,
88 $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_collapse');
89 // Assert the summary is correctly generated.
90 $this->assertRaw('<div class="paragraphs-collapsed-description">alternative_text_summary, text_summary');
93 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
94 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_subform_field_image_0_remove_button');
95 $this->drupalPostForm(NULL, [], t('Save'));
97 // Assert the summary is correctly generated.
98 $this->clickLink(t('Edit'));
99 $this->assertRaw('<div class="paragraphs-collapsed-description">text_summary');
101 $this->addParagraphsType('nested_paragraph');
102 static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_paragraph', 'nested_content', 'Nested Content', 'entity_reference_revisions', ['settings[target_type]' => 'paragraph'], []);
103 $this->drupalGet('admin/structure/paragraphs_type/nested_paragraph/form-display');
104 $this->drupalPostForm(NULL, ['fields[field_nested_content][type]' => 'entity_reference_paragraphs'], t('Save'));
106 $test_user = $this->drupalCreateUser([]);
108 $this->drupalGet('node/add/paragraphed_test');
109 $this->drupalPostForm(NULL, NULL, t('Add nested_paragraph'));
110 $this->drupalPostAjaxForm(NULL, NULL, t('field_paragraphs_0_subform_field_nested_content_user_paragraph_add_more'));
112 'title[0][value]' => 'Node title',
113 'field_paragraphs[0][subform][field_nested_content][0][subform][field_user][0][target_id]' => $test_user->label() . ' (' . $test_user->id() . ')',
115 $this->drupalPostForm(NULL, $edit, t('Save'));
117 // Create an orphaned ER field item by deleting the target entity.
118 $test_user->delete();
120 $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadByProperties(['title' => 'Node title']);
121 $this->drupalGet('node/' . current($nodes)->id() . '/edit');
122 $this->drupalPostAjaxForm(NULL, [], t('field_paragraphs_0_edit'));
123 $this->drupalPostAjaxForm(NULL, [], t('field_paragraphs_0_collapse'));
124 $this->assertResponse(200);
126 // Add a Block Paragraphs type.
127 $this->addParagraphsType('block_paragraph');
128 $this->addFieldtoParagraphType('block_paragraph', 'field_block', 'block_field');
130 // Test the summary of a Block field.
131 $this->drupalGet('node/add/paragraphed_test');
132 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_block_paragraph_add_more');
134 'field_paragraphs[0][subform][field_block][0][plugin_id]' => 'system_breadcrumb_block',
136 $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_collapse');
137 $this->assertRaw('<div class="paragraphs-collapsed-description">Breadcrumbs');