3 namespace Drupal\paragraphs_demo\Tests;
5 use Drupal\filter\Entity\FilterFormat;
6 use Drupal\simpletest\WebTestBase;
9 * Tests the demo module for Paragraphs.
13 class ParagraphsDemoTest extends WebTestBase {
20 public static $modules = array(
28 protected function setUp() {
30 $this->drupalPlaceBlock('local_tasks_block');
31 $this->drupalPlaceBlock('local_actions_block');
32 $this->drupalPlaceBlock('page_title_block');
36 * Asserts demo paragraphs have been created.
38 protected function testConfigurationsAndCreation() {
39 $basic_html_format = FilterFormat::create(array(
40 'format' => 'basic_html',
41 'name' => 'Basic HTML',
43 $basic_html_format->save();
44 $admin_user = $this->drupalCreateUser(array(
45 'administer site configuration',
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(),
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');
73 // Check for preconfigured languages.
74 $this->drupalGet('admin/config/regional/language');
75 $this->assertText('English');
76 $this->assertText('German');
77 $this->assertText('French');
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');
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');
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');
101 // Make sure we have the paragraphed article listed as a content type.
102 $this->drupalGet('admin/structure/types');
103 $this->assertText('Paragraphed article');
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.');
110 // Check that the Paragraph field is added.
111 $this->clickLink('Manage fields');
112 $this->assertText('Paragraphs');
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');
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.');
128 'title[0][value]' => 'Paragraph title',
129 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Paragraph text',
131 $this->drupalPostForm(NULL, $edit, t('Add User'));
133 'field_paragraphs_demo[1][subform][field_user_demo][0][target_id]' => $admin_user->label() . ' (' . $admin_user->id() . ')',
135 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
137 $this->assertText('Paragraphed article Paragraph title has been created.');
138 $this->assertText('Paragraph title');
139 $this->assertText('Paragraph text');
141 // Search a nested Paragraph text.
143 * @todo Reinstate this after search_api is fixed.
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!');
153 // Search non existent text.
154 $this->drupalGet('paragraphs_search', ['query' => ['search_api_fulltext' => 'foo']]);
155 $this->assertNoRaw('Welcome to the Paragraphs Demo module!');