Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Experimental / ParagraphsExperimentalEditModesTest.php
1 <?php
2
3 namespace Drupal\paragraphs\Tests\Experimental;
4
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
6
7 /**
8  * Tests paragraphs edit modes.
9  *
10  * @group paragraphs
11  */
12 class ParagraphsExperimentalEditModesTest extends ParagraphsExperimentalTestBase {
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');
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     // 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'], []);
47
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'));
53     // Add a paragraph.
54     $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_image_text_paragraph_add_more');
55     $this->drupalPostAjaxForm(NULL, NULL, 'field_paragraphs_title_add_more');
56
57     $text = 'Trust me I am an image';
58     file_put_contents('temporary://myImage1.jpg', $text);
59
60     // Create a node with an image and text.
61     $edit = [
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',
66     ];
67     $this->drupalPostForm(NULL, $edit, t('Save'));
68     $this->clickLink(t('Edit'));
69     $this->drupalPostForm(NULL, [], t('Add user_paragraph'));
70     $edit = [
71       'field_paragraphs[2][subform][field_user][0][target_id]' => $this->admin_user->label() . ' (' . $this->admin_user->id() . ')',
72     ];
73     $this->drupalPostForm(NULL, $edit, t('Save'));
74
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');
80
81     // Edit and remove alternative text.
82     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
83     $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,
87     ];
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');
91
92     // Remove image.
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'));
96
97     // Assert the summary is correctly generated.
98     $this->clickLink(t('Edit'));
99     $this->assertRaw('<div class="paragraphs-collapsed-description">text_summary');
100
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'));
105
106     $test_user = $this->drupalCreateUser([]);
107
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'));
111     $edit = [
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() . ')',
114     ];
115     $this->drupalPostForm(NULL, $edit, t('Save'));
116
117     // Create an orphaned ER field item by deleting the target entity.
118     $test_user->delete();
119
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);
125
126     // Add a Block Paragraphs type.
127     $this->addParagraphsType('block_paragraph');
128     $this->addFieldtoParagraphType('block_paragraph', 'field_block', 'block_field');
129
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');
133     $edit = [
134       'field_paragraphs[0][subform][field_block][0][plugin_id]' => 'system_breadcrumb_block',
135     ];
136     $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_collapse');
137     $this->assertRaw('<div class="paragraphs-collapsed-description">Breadcrumbs');
138   }
139
140 }