3 namespace Drupal\paragraphs\Tests\Classic;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
8 * Tests the Paragraphs user interface.
12 class ParagraphsUiTest extends ParagraphsTestBase {
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_name = 'content';
41 $field_title = 'Content Test';
42 $field_type = 'field_ui:entity_reference_revisions:paragraph';
46 $this->fieldUIAddNewField($bundle_path, $field_name, $field_title, $field_type, [], $field_edit);
48 $form_display_edit = [
49 'fields[field_content][type]' => 'entity_reference_paragraphs',
51 $this->drupalPostForm($bundle_path . '/form-display', $form_display_edit, t('Save'));
53 // Attempt to create a paragraphed node with an empty required field.
55 $this->drupalGet('node/add/paragraphed_content_demo');
56 $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save'));
57 $this->assertText($field_title . ' field is required');
59 // Attempt to create a paragraphed node with only a paragraph in the
60 // "remove" mode in the required field.
61 $title = 'Remove mode';
62 $this->drupalGet('node/add/paragraphed_content_demo');
63 $this->drupalPostAjaxForm(NULL, [], 'field_content_image_text_add_more');
64 $this->drupalPostAjaxForm(NULL, [], 'field_content_0_remove');
65 $this->assertNoText($field_title . ' field is required');
66 $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save'));
67 $this->assertText($field_title . ' field is required');