3 namespace Drupal\paragraphs\Tests\Classic;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
8 * Tests paragraphs edit modes.
12 class ParagraphsEditModesTest extends ParagraphsTestBase {
21 public static $modules = [
27 * Tests the collapsed summary of paragraphs.
29 public function testCollapsedSummary() {
30 $this->addParagraphedContentType('paragraphed_test', 'field_paragraphs', 'entity_reference_paragraphs');
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 // Set edit mode to closed.
44 $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
45 $this->drupalPostAjaxForm(NULL, [], "field_paragraphs_settings_edit");
46 $edit = ['fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed'];
47 $this->drupalPostForm(NULL, $edit, t('Save'));
50 $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_image_text_paragraph_add_more');
51 $this->drupalPostAjaxForm(NULL, NULL, 'field_paragraphs_title_add_more');
52 $text = 'Trust me I am an image';
53 file_put_contents('temporary://myImage1.jpg', $text);
55 // Create a node with an image and text.
57 'title[0][value]' => 'Test article',
58 'field_paragraphs[0][subform][field_text][0][value]' => 'text_summary',
59 'files[field_paragraphs_0_subform_field_image_0]' => drupal_realpath('temporary://myImage1.jpg'),
60 'field_paragraphs[1][subform][field_title][0][value]' => 'Title example',
62 $this->drupalPostForm(NULL, $edit, t('Save'));
64 // Assert the summary is correctly generated.
65 $this->clickLink(t('Edit'));
66 $this->assertRaw('<div class="paragraphs-collapsed-description">myImage1.jpg, text_summary');
67 $this->assertRaw('<div class="paragraphs-collapsed-description">Title example');
69 // Edit and remove alternative text.
70 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
72 'field_paragraphs[0][subform][field_image][0][alt]' => 'alternative_text_summary',
73 'field_paragraphs[0][subform][field_image][0][width]' => 300,
74 'field_paragraphs[0][subform][field_image][0][height]' => 300,
76 $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_collapse');
77 // Assert the summary is correctly generated.
78 $this->assertRaw('<div class="paragraphs-collapsed-description">alternative_text_summary, text_summary');
81 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
82 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_subform_field_image_0_remove_button');
83 $this->drupalPostForm(NULL, [], t('Save'));
85 // Assert the summary is correctly generated.
86 $this->clickLink(t('Edit'));
87 $this->assertRaw('<div class="paragraphs-collapsed-description">text_summary');
89 // Add a Block Paragraphs type.
90 $this->addParagraphsType('block_paragraph');
91 $this->addFieldtoParagraphType('block_paragraph', 'field_block', 'block_field');
93 // Test the summary of a Block field.
94 $this->drupalGet('node/add/paragraphed_test');
95 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_block_paragraph_add_more');
97 'title[0][value]' => 'Node with a Block Paragraph',
98 'field_paragraphs[0][subform][field_block][0][plugin_id]' => 'system_breadcrumb_block',
100 $this->drupalPostForm(NULL, $edit, t('Save'));
101 $this->clickLink(t('Edit'));
102 $this->assertRaw('<div class="paragraphs-collapsed-description">Breadcrumbs');