3 namespace Drupal\paragraphs\Tests\Experimental;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
8 * Tests the Paragraphs user interface.
12 class ParagraphsExperimentalUiTest extends ParagraphsExperimentalTestBase {
21 public static $modules = [
26 * Tests displaying an error message a required paragraph field that is empty.
28 public function testEmptyRequiredField() {
29 $admin_user = $this->drupalCreateUser([
30 'administer node fields',
31 'administer paragraph form display',
32 'administer node form display',
33 'create paragraphed_content_demo content',
34 'edit any paragraphed_content_demo content',
36 $this->drupalLogin($admin_user);
38 // Add required field to paragraphed content type.
39 $bundle_path = 'admin/structure/types/manage/paragraphed_content_demo';
40 $field_title = 'Content Test';
41 $field_type = 'field_ui:entity_reference_revisions:paragraph';
45 $this->fieldUIAddNewField($bundle_path, 'content', $field_title, $field_type, [], $field_edit);
47 $form_display_edit = [
48 'fields[field_content][type]' => 'paragraphs',
50 $this->drupalPostForm($bundle_path . '/form-display', $form_display_edit, t('Save'));
52 // Attempt to create a paragraphed node with an empty required field.
54 $this->drupalGet('node/add/paragraphed_content_demo');
55 $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save'));
56 $this->assertText($field_title . ' field is required');
58 // Attempt to create a paragraphed node with only a paragraph in the
59 // "remove" mode in the required field.
60 $title = 'Remove all items';
61 $this->drupalGet('node/add/paragraphed_content_demo');
62 $this->drupalPostAjaxForm(NULL, [], 'field_content_image_text_add_more');
63 $this->drupalPostAjaxForm(NULL, [], 'field_content_0_remove');
64 $this->assertNoText($field_title . ' field is required');
65 $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save'));
66 $this->assertText($field_title . ' field is required');
68 // Attempt to create a paragraphed node with a valid paragraph and a
70 $title = 'Valid Removal';
71 $this->drupalGet('node/add/paragraphed_content_demo');
72 $this->drupalPostAjaxForm(NULL, [], 'field_content_image_text_add_more');
73 $this->drupalPostAjaxForm(NULL, [], 'field_content_image_text_add_more');
74 $this->drupalPostAjaxForm(NULL, [], 'field_content_1_remove');
75 $this->assertNoText($field_title . ' field is required');
76 $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save'));
77 $this->assertNoText($field_title . ' field is required');