Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Classic / ParagraphsEditModesTest.php
1 <?php
2
3 namespace Drupal\paragraphs\Tests\Classic;
4
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
6
7 /**
8  * Tests paragraphs edit modes.
9  *
10  * @group paragraphs
11  */
12 class ParagraphsEditModesTest extends ParagraphsTestBase {
13
14   use FieldUiTestTrait;
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'image',
23     'block_field',
24   ];
25
26   /**
27    * Tests the collapsed summary of paragraphs.
28    */
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']);
32
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', [], []);
42
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'));
48
49     // Add a paragraph.
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);
54
55     // Create a node with an image and text.
56     $edit = [
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',
61     ];
62     $this->drupalPostForm(NULL, $edit, t('Save'));
63
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');
68
69     // Edit and remove alternative text.
70     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
71     $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,
75     ];
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');
79
80     // Remove image.
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'));
84
85     // Assert the summary is correctly generated.
86     $this->clickLink(t('Edit'));
87     $this->assertRaw('<div class="paragraphs-collapsed-description">text_summary');
88
89     // Add a Block Paragraphs type.
90     $this->addParagraphsType('block_paragraph');
91     $this->addFieldtoParagraphType('block_paragraph', 'field_block', 'block_field');
92
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');
96     $edit = [
97       'title[0][value]' => 'Node with a Block Paragraph',
98       'field_paragraphs[0][subform][field_block][0][plugin_id]' => 'system_breadcrumb_block',
99     ];
100     $this->drupalPostForm(NULL, $edit, t('Save'));
101     $this->clickLink(t('Edit'));
102     $this->assertRaw('<div class="paragraphs-collapsed-description">Breadcrumbs');
103   }
104
105 }