Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / modules / paragraphs_demo / src / Tests / ParagraphsDemoTest.php
1 <?php
2
3 namespace Drupal\paragraphs_demo\Tests;
4
5 use Drupal\filter\Entity\FilterFormat;
6 use Drupal\paragraphs\Tests\Classic\ParagraphsCoreVersionUiTestTrait;
7 use Drupal\simpletest\WebTestBase;
8
9 /**
10  * Tests the demo module for Paragraphs.
11  *
12  * @group paragraphs
13  */
14 class ParagraphsDemoTest extends WebTestBase {
15
16   use ParagraphsCoreVersionUiTestTrait;
17
18   /**
19    * Modules to enable.
20    *
21    * @var string[]
22    */
23   public static $modules = array(
24     'paragraphs_demo',
25     'block',
26   );
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp() {
32     parent::setUp();
33     $this->drupalPlaceBlock('local_tasks_block');
34     $this->drupalPlaceBlock('local_actions_block');
35     $this->drupalPlaceBlock('page_title_block');
36   }
37
38   /**
39    * Asserts demo paragraphs have been created.
40    */
41   protected function testConfigurationsAndCreation() {
42     $basic_html_format = FilterFormat::create(array(
43       'format' => 'basic_html',
44       'name' => 'Basic HTML',
45     ));
46     $basic_html_format->save();
47     $admin_user = $this->drupalCreateUser(array(
48       'administer site configuration',
49       'create paragraphed_content_demo content',
50       'edit any paragraphed_content_demo content',
51       'delete any paragraphed_content_demo content',
52       'administer content translation',
53       'create content translations',
54       'administer languages',
55       'administer content types',
56       'administer node fields',
57       'administer node display',
58       'administer paragraphs types',
59       'administer paragraph fields',
60       'administer paragraph display',
61       'administer paragraph form display',
62       'administer node form display',
63       $basic_html_format->getPermissionName(),
64     ));
65
66     $this->drupalLogin($admin_user);
67
68     // Set edit mode to open.
69     $this->drupalGet('admin/structure/types/manage/paragraphed_content_demo/form-display');
70     $this->drupalPostAjaxForm(NULL, [], "field_paragraphs_demo_settings_edit");
71     $edit = ['fields[field_paragraphs_demo][settings_edit_form][settings][edit_mode]' => 'open'];
72     $this->drupalPostForm(NULL, $edit, t('Save'));
73
74     // Check for all pre-configured paragraphs_types.
75     $this->drupalGet('admin/structure/paragraphs_type');
76     $this->assertText('Image + Text');
77     $this->assertText('Images');
78     $this->assertText('Text');
79     $this->assertText('Text + Image');
80     $this->assertText('User');
81
82     // Check for preconfigured languages.
83     $this->drupalGet('admin/config/regional/language');
84     $this->assertText('English');
85     $this->assertText('German');
86     $this->assertText('French');
87
88     // Check for Content language translation checks.
89     $this->drupalGet('admin/config/regional/content-language');
90     $this->assertFieldChecked('edit-entity-types-node');
91     $this->assertFieldChecked('edit-entity-types-paragraph');
92     $this->assertFieldChecked('edit-settings-node-paragraphed-content-demo-translatable');
93     $this->assertNoFieldChecked('edit-settings-node-paragraphed-content-demo-fields-field-paragraphs-demo');
94     $this->assertFieldChecked('edit-settings-paragraph-images-translatable');
95     $this->assertFieldChecked('edit-settings-paragraph-image-text-translatable');
96     $this->assertFieldChecked('edit-settings-paragraph-text-translatable');
97     $this->assertFieldChecked('edit-settings-paragraph-text-image-translatable');
98     $this->assertFieldChecked('edit-settings-paragraph-user-translatable');
99
100     // Check for paragraph type Image + text that has the correct fields set.
101     $this->drupalGet('admin/structure/paragraphs_type/image_text/fields');
102     $this->assertText('Text');
103     $this->assertText('Image');
104
105     // Check for paragraph type Text that has the correct fields set.
106     $this->drupalGet('admin/structure/paragraphs_type/text/fields');
107     $this->assertText('Text');
108     $this->assertNoText('Image');
109
110     // Make sure we have the paragraphed article listed as a content type.
111     $this->drupalGet('admin/structure/types');
112     $this->assertText('Paragraphed article');
113
114     // Check that title and the descriptions are set.
115     $this->drupalGet('admin/structure/types/manage/paragraphed_content_demo');
116     $this->assertText('Paragraphed article');
117     $this->assertText('Article with Paragraphs.');
118
119     // Check that the Paragraph field is added.
120     $this->clickLink('Manage fields');
121     $this->assertText('Paragraphs');
122
123     // Check that all paragraphs types are enabled (disabled).
124     $this->clickLink('Edit', 0);
125     $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-image-text-enabled');
126     $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-images-enabled');
127     $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-text-image-enabled');
128     $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-user-enabled');
129     $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-text-enabled');
130
131     $this->drupalGet('node/add/paragraphed_content_demo');
132     $this->assertRaw('<strong data-drupal-selector="edit-field-paragraphs-demo-title">Paragraphs</strong>', 'Field name is present on the page.');
133     $this->drupalPostForm(NULL, NULL, t('Add Text'));
134     $this->assertNoRaw('<strong data-drupal-selector="edit-field-paragraphs-demo-title">Paragraphs</strong>', 'Field name for empty field is not present on the page.');
135     $this->assertRaw('<h4 class="label">Paragraphs</h4>', 'Field name appears in the table header.');
136     $edit = array(
137       'title[0][value]' => 'Paragraph title',
138       'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Paragraph text',
139     );
140     $this->drupalPostForm(NULL, $edit, t('Add User'));
141     $edit = [
142       'field_paragraphs_demo[1][subform][field_user_demo][0][target_id]' => $admin_user->label() . ' (' . $admin_user->id() . ')',
143     ];
144     $this->drupalPostForm(NULL, $edit, t('Save'));
145
146     $this->assertText('Paragraphed article Paragraph title has been created.');
147     $this->assertText('Paragraph title');
148     $this->assertText('Paragraph text');
149
150     // Search a nested Paragraph text.
151     $this->drupalGet('paragraphs_search', ['query' => ['search_api_fulltext' => 'A search api example']]);
152     $this->assertRaw('Welcome to the Paragraphs Demo module!');
153     // Search a node paragraph field text.
154     $this->drupalGet('paragraphs_search', ['query' => ['search_api_fulltext' => 'It allows you']]);
155     $this->assertRaw('Welcome to the Paragraphs Demo module!');
156     // Search non existent text.
157     $this->drupalGet('paragraphs_search', ['query' => ['search_api_fulltext' => 'foo']]);
158     $this->assertNoRaw('Welcome to the Paragraphs Demo module!');
159
160     // Check that the dropbutton of Nested Paragraph has the Duplicate function.
161     // For now, this indicates that it is using the EXPERIMENTAL widget.
162     $this->drupalGet('node/1/edit');
163     $this->assertFieldByName('field_paragraphs_demo_3_subform_field_paragraphs_demo_0_duplicate');
164   }
165
166 }