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 = [
26 * Tests the collapsed summary of paragraphs.
28 public function testCollapsedSummary() {
29 $this->addParagraphedContentType('paragraphed_test', 'field_paragraphs');
30 $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content']);
32 // Add a Paragraph type.
33 $paragraph_type = 'image_text_paragraph';
34 $this->addParagraphsType($paragraph_type);
35 $this->addParagraphsType('text');
36 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'image', 'Image', 'image', [], ['settings[alt_field_required]' => FALSE]);
37 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
39 // Set edit mode to closed.
40 $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
41 $this->drupalPostAjaxForm(NULL, [], "field_paragraphs_settings_edit");
42 $edit = ['fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed'];
43 $this->drupalPostForm(NULL, $edit, t('Save'));
46 $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_image_text_paragraph_add_more');
48 $text = 'Trust me I am an image';
49 file_put_contents('temporary://myImage1.jpg', $text);
51 // Create a node with an image and text.
53 'title[0][value]' => 'Test article',
54 'field_paragraphs[0][subform][field_text][0][value]' => 'text_summary',
55 'files[field_paragraphs_0_subform_field_image_0]' => drupal_realpath('temporary://myImage1.jpg'),
57 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
59 // Assert the summary is correctly generated.
60 $this->clickLink(t('Edit'));
61 $this->assertRaw('<div class="paragraphs-collapsed-description">myImage1.jpg, text_summary');
63 // Edit and remove alternative text.
64 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
66 'field_paragraphs[0][subform][field_image][0][alt]' => 'alternative_text_summary',
67 'field_paragraphs[0][subform][field_image][0][width]' => 300,
68 'field_paragraphs[0][subform][field_image][0][height]' => 300,
70 $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_collapse');
71 // Assert the summary is correctly generated.
72 $this->assertRaw('<div class="paragraphs-collapsed-description">alternative_text_summary, text_summary');
75 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
76 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_subform_field_image_0_remove_button');
77 $this->drupalPostForm(NULL, [], t('Save and keep published'));
79 // Assert the summary is correctly generated.
80 $this->clickLink(t('Edit'));
81 $this->assertRaw('<div class="paragraphs-collapsed-description">text_summary');