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