Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / tests / src / FunctionalJavascript / ParagraphsExperimentalAddWidgetTest.php
1 <?php
2
3 namespace Drupal\Tests\paragraphs\FunctionalJavascript;
4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
7 use Drupal\Core\Entity\Entity\EntityFormDisplay;
8 use Drupal\Core\Entity\Entity\EntityViewDisplay;
9 use Drupal\field\Entity\FieldConfig;
10 use Drupal\field\Entity\FieldStorageConfig;
11 use Drupal\field_ui\Tests\FieldUiTestTrait;
12 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
13 use Drupal\node\Entity\NodeType;
14 use Drupal\paragraphs\Entity\ParagraphsType;
15 use Drupal\paragraphs\Tests\Classic\ParagraphsCoreVersionUiTestTrait;
16 use Drupal\Tests\paragraphs\FunctionalJavascript\LoginAdminTrait;
17
18 /**
19  * Test paragraphs user interface.
20  *
21  * @group paragraphs
22  */
23 class ParagraphsExperimentalAddWidgetTest extends JavascriptTestBase {
24
25   use LoginAdminTrait;
26   use FieldUiTestTrait;
27   use ParagraphsTestBaseTrait;
28   use ParagraphsCoreVersionUiTestTrait;
29
30   /**
31    * Modules to enable.
32    *
33    * @var array
34    */
35   public static $modules = [
36     'node',
37     'paragraphs_test',
38     'paragraphs',
39     'field',
40     'field_ui',
41     'block',
42     'link',
43   ];
44
45   /**
46    * {@inheritdoc}
47    */
48   protected function setUp()
49   {
50     parent::setUp();
51     // Place the breadcrumb, tested in fieldUIAddNewField().
52     $this->drupalPlaceBlock('system_breadcrumb_block');
53     $this->drupalPlaceBlock('local_tasks_block');
54     $this->drupalPlaceBlock('local_actions_block');
55     $this->drupalPlaceBlock('page_title_block');
56
57   }
58
59   /**
60    * Tests the add widget button with modal form.
61    */
62   public function testAddWidgetButton() {
63     $this->addParagraphedContentType('paragraphed_test');
64     $this->loginAsAdmin([
65       'administer content types',
66       'administer node form display',
67       'edit any paragraphed_test content',
68       'create paragraphed_test content',
69     ]);
70     // Set the add mode on the content type to modal form widget.
71     $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
72     $page = $this->getSession()->getPage();
73     $page->pressButton('field_paragraphs_settings_edit');
74     $this->assertSession()->assertWaitOnAjaxRequest();
75     $edit = [
76       'fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed',
77       'fields[field_paragraphs][settings_edit_form][settings][add_mode]' => 'modal'
78     ];
79     $this->drupalPostForm(NULL, $edit, 'Update');
80     $this->assertSession()->assertWaitOnAjaxRequest();
81
82     $this->drupalPostForm(NULL, [], t('Save'));
83
84     // Add a Paragraph type.
85     $paragraph_type = 'text_paragraph';
86     $this->addParagraphsType($paragraph_type);
87     $this->addParagraphsType('text');
88
89     // Add icons to the paragraphs types.
90     $icon_one = $this->addParagraphsTypeIcon($paragraph_type);
91     $icon_two = $this->addParagraphsTypeIcon('text');
92
93     // Add a text field to the text_paragraph type.
94     static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
95
96     // Create paragraph type Nested test.
97     $this->addParagraphsType('nested_test');
98
99     static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_test', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', [
100       'settings[target_type]' => 'paragraph',
101       'cardinality' => '-1',
102     ], []);
103
104     // Set the settings for the field in the nested paragraph.
105     $component = [
106       'type' => 'paragraphs',
107       'region' => 'content',
108       'settings' => [
109         'edit_mode' => 'closed',
110         'add_mode' => 'modal',
111         'form_display_mode' => 'default',
112       ],
113     ];
114     EntityFormDisplay::load('paragraph.nested_test.default')->setComponent('field_paragraphs', $component)->save();
115
116     // Add a paragraphed test.
117     $this->drupalGet('node/add/paragraphed_test');
118
119     // Add a nested paragraph with the add widget.
120     $page->pressButton('Add Paragraph');
121     $this->assertSession()->assertWaitOnAjaxRequest();
122     $this->assertSession()->elementTextContains('css', '.ui-dialog-title', 'Add Paragraph');
123     $page->pressButton('nested_test');
124     $this->assertSession()->assertWaitOnAjaxRequest();
125
126     // Verify that the paragraphs type icons are being displayed.
127     $button_one = $this->assertSession()->buttonExists($paragraph_type);
128     $button_two = $this->assertSession()->buttonExists('text');
129     $this->assertContains($icon_one->getFilename(), $button_one->getAttribute('style'));
130     $this->assertContains($icon_two->getFilename(), $button_two->getAttribute('style'));
131
132     // Find the add button in the nested paragraph with xpath.
133     $element = $this->xpath('//div[contains(@class, "form-wrapper")]/div[contains(@class, "paragraph-type-add-modal")]/input');
134     $element[0]->click();
135     $this->assertSession()->assertWaitOnAjaxRequest();
136
137     // Add a text inside the nested paragraph.
138     $page = $this->getSession()->getPage();
139     $dialog = $page->find('xpath', '//div[contains(@class, "ui-dialog")]');
140     $dialog->pressButton('text');
141     $this->assertSession()->assertWaitOnAjaxRequest();
142     $edit = [
143       'title[0][value]' => 'Example title',
144     ];
145     $this->drupalPostForm(NULL, $edit, t('Save'));
146
147
148     // Check the created paragraphed test.
149     $this->assertText('paragraphed_test Example title has been created.');
150     $this->assertRaw('paragraph--type--nested-test');
151     $this->assertRaw('paragraph--type--text');
152
153     // Add a paragraphs field with another paragraphs widget title to the
154     // paragraphed_test content type.
155     $this->addParagraphsField('paragraphed_test', 'field_paragraphs_two', 'node');
156     $settings = [
157       'title' => 'Renamed paragraph',
158       'title_plural' => 'Renamed paragraphs',
159       'add_mode' => 'modal',
160     ];
161     $this->setParagraphsWidgetSettings('paragraphed_test', 'field_paragraphs_two', $settings);
162
163     // Check that the "add" buttons and modal form windows are labeled
164     // correctly.
165     $this->drupalGet('node/add/paragraphed_test');
166     $page->pressButton('Add Paragraph');
167     $this->assertSession()->assertWaitOnAjaxRequest();
168     $this->assertSession()->elementTextContains('css', '.ui-dialog-title', 'Add Paragraph');
169     $this->assertSession()->elementTextNotContains('css', '.ui-dialog-title', 'Add Renamed paragraph');
170     $this->assertSession()->elementExists('css', '.ui-dialog-titlebar-close')->press();
171     $page->pressButton('Add Renamed paragraph');
172     $this->assertSession()->assertWaitOnAjaxRequest();
173     $this->assertSession()->elementTextContains('css', '.ui-dialog-title', 'Add Renamed paragraph');
174     $this->assertSession()->elementTextNotContains('css', '.ui-dialog-title', 'Add Paragraph');
175   }
176 }