Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Experimental / ParagraphsExperimentalWidgetButtonsTest.php
1 <?php
2
3 namespace Drupal\paragraphs\Tests\Experimental;
4
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
6 use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
7
8 /**
9  * Tests paragraphs experimental widget buttons.
10  *
11  * @group paragraphs
12  */
13 class ParagraphsExperimentalWidgetButtonsTest extends ParagraphsExperimentalTestBase {
14
15   use FieldUiTestTrait;
16   use ParagraphsTestBaseTrait;
17
18   /**
19    * Modules to enable.
20    *
21    * @var array
22    */
23   public static $modules = [
24     'paragraphs_test',
25   ];
26
27   /**
28    * Tests the widget buttons of paragraphs.
29    */
30   public function testWidgetButtons() {
31     $this->addParagraphedContentType('paragraphed_test');
32
33     $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content']);
34     // Add a Paragraph type.
35     $paragraph_type = 'text_paragraph';
36     $this->addParagraphsType($paragraph_type);
37     $this->addParagraphsType('text');
38
39     // Add a text field to the text_paragraph type.
40     static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
41     $edit = [
42       'fields[field_paragraphs][type]' => 'paragraphs',
43     ];
44     $this->drupalPostForm('admin/structure/types/manage/paragraphed_test/form-display', $edit, t('Save'));
45     $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_text_paragraph_add_more');
46
47     // Create a node with a Paragraph.
48     $text = 'recognizable_text';
49     $edit = [
50       'title[0][value]' => 'paragraphs_mode_test',
51       'field_paragraphs[0][subform][field_text][0][value]' => $text,
52     ];
53     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_text_paragraph_add_more');
54     $this->drupalPostForm(NULL, $edit, t('Save'));
55     $node = $this->drupalGetNodeByTitle('paragraphs_mode_test');
56
57     // Test the 'Open' edit mode.
58     $this->drupalGet('node/' . $node->id() . '/edit');
59     $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $text);
60     $this->drupalPostForm(NULL, [], t('Save'));
61     $this->assertText($text);
62
63     // Test the 'Closed' edit mode.
64     $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed');
65     $this->drupalGet('node/' . $node->id() . '/edit');
66     // Click "Edit" button.
67     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
68     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_1_edit');
69     $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $text);
70     $closed_mode_text = 'closed_mode_text';
71     // Click "Collapse" button on both paragraphs.
72     $edit = ['field_paragraphs[0][subform][field_text][0][value]' => $closed_mode_text];
73     $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_collapse');
74     $edit = ['field_paragraphs[1][subform][field_text][0][value]' => $closed_mode_text];
75     $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_1_collapse');
76     // Verify that we have warning message for each paragraph.
77     $this->assertEqual(2, count($this->xpath("//*[contains(@class, 'paragraphs-icon-changed')]")));
78     $this->assertRaw('<div class="paragraphs-collapsed-description">' . $closed_mode_text);
79     $this->drupalPostForm(NULL, [], t('Save'));
80     $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.');
81     $this->assertText($closed_mode_text);
82
83     // Test the 'Preview' closed mode.
84     $this->setParagraphsWidgetSettings('paragraphed_test', 'field_paragraphs', ['closed_mode' => 'preview']);
85     $this->drupalGet('node/' . $node->id() . '/edit');
86     // Click "Edit" button.
87     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
88     $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $closed_mode_text);
89     $preview_mode_text = 'preview_mode_text';
90     $edit = ['field_paragraphs[0][subform][field_text][0][value]' => $preview_mode_text];
91     // Click "Collapse" button.
92     $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_collapse');
93     $this->assertText('You have unsaved changes on this Paragraph item.');
94     $this->assertEqual(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-changed')]")));
95     $this->assertText($preview_mode_text);
96     $this->drupalPostForm(NULL, [], t('Save'));
97     $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.');
98     $this->assertText($preview_mode_text);
99
100     // Test the remove function.
101     $this->drupalGet('node/' . $node->id() . '/edit');
102     // Click "Remove" button.
103     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_remove');
104     $this->drupalPostForm(NULL, [], t('Save'));
105     $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.');
106     $this->assertNoText($preview_mode_text);
107   }
108
109   /**
110    * Tests if buttons are present for each widget mode.
111    */
112   public function testButtonsVisibility() {
113     $this->addParagraphedContentType('paragraphed_test');
114
115     $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content']);
116     // Add a Paragraph type.
117     $paragraph_type = 'text_paragraph';
118     $this->addParagraphsType($paragraph_type);
119     $this->addParagraphsType('text');
120
121     // Add a text field to the text_paragraph type.
122     static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
123     $edit = [
124       'fields[field_paragraphs][type]' => 'paragraphs',
125     ];
126     $this->drupalPostForm('admin/structure/types/manage/paragraphed_test/form-display', $edit, t('Save'));
127     $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_text_paragraph_add_more');
128
129     // Create a node with a Paragraph.
130     $text = 'recognizable_text';
131     $edit = [
132       'title[0][value]' => 'paragraphs_mode_test',
133       'field_paragraphs[0][subform][field_text][0][value]' => $text,
134     ];
135     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_text_paragraph_add_more');
136     $this->drupalPostForm(NULL, $edit, t('Save'));
137     $node = $this->drupalGetNodeByTitle('paragraphs_mode_test');
138
139     // Checking visible buttons on "Open" mode.
140     $this->drupalGet('node/' . $node->id() . '/edit');
141     $this->assertField('field_paragraphs_0_collapse');
142     $this->assertField('field_paragraphs_0_remove');
143     $this->assertField('field_paragraphs_0_duplicate');
144
145     // Checking visible buttons on "Closed" mode.
146     $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed');
147     $this->drupalGet('node/' . $node->id() . '/edit');
148     $this->assertField('field_paragraphs_0_edit');
149     $this->assertField('field_paragraphs_0_remove');
150     $this->assertField('field_paragraphs_0_duplicate');
151
152     // Checking visible buttons on "Preview" mode.
153     $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed');
154     $this->drupalGet('node/' . $node->id() . '/edit');
155     $this->assertField('field_paragraphs_0_edit');
156     $this->assertField('field_paragraphs_0_remove');
157     $this->assertField('field_paragraphs_0_duplicate');
158
159     // Checking always show collapse and edit actions.
160     $this->addParagraphsType('nested_paragraph');
161     static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_paragraph', 'nested', 'Nested', 'field_ui:entity_reference_revisions:paragraph', [
162       'settings[target_type]' => 'paragraph',
163       'cardinality' => '-1',
164     ], []);
165     $this->drupalGet('admin/structure/paragraphs_type/nested_paragraph/form-display');
166     $edit = [
167       'fields[field_nested][type]' => 'paragraphs',
168     ];
169     $this->drupalPostForm(NULL, $edit, t('Save'));
170     $this->drupalGet('node/' . $node->id() . '/edit');
171     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_nested_paragraph_add_more');
172     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_2_subform_field_nested_nested_paragraph_add_more');
173     // Collapse is present on each nesting level.
174     $this->assertFieldByName('field_paragraphs_2_collapse');
175     $this->assertFieldByName('field_paragraphs_2_subform_field_nested_0_collapse');
176
177     // Tests hook_paragraphs_widget_actions_alter.
178     $this->drupalGet('node/add/paragraphed_test');
179     $this->drupalPostForm(NULL, NULL, t('Add text'));
180     $this->assertNoField('edit-field-paragraphs-0-top-links-test-button');
181     \Drupal::state()->set('paragraphs_test_dropbutton', TRUE);
182     $this->drupalGet('node/add/paragraphed_test');
183     $this->drupalPostForm(NULL, NULL, t('Add text'));
184     $this->assertNoField('edit-field-paragraphs-0-top-links-test-button');
185   }
186
187 }