3 namespace Drupal\paragraphs\Tests\Classic;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
8 * Tests the paragraphs summary formatter.
12 class ParagraphsSummaryFormatterTest extends ParagraphsTestBase {
21 public static $modules = [
26 * Tests the paragraphs summary formatter.
28 public function testParagraphsSummaryFormatter() {
29 $this->addParagraphedContentType('paragraphed_test', 'field_paragraphs', 'entity_reference_paragraphs');
30 $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content', 'administer node display']);
32 // Add a Paragraph type.
33 $paragraph_type = 'text_paragraph';
34 $this->addParagraphsType($paragraph_type);
35 $title_paragraphs_type = 'title';
36 $this->addParagraphsType($title_paragraphs_type);
37 $this->addParagraphsType('text');
38 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
39 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $title_paragraphs_type, 'title', 'Title', 'string', [], []);
41 // Add a user Paragraph Type
42 $paragraph_type = 'user_paragraph';
43 $this->addParagraphsType($paragraph_type);
44 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'user', 'User', 'entity_reference', ['settings[target_type]' => 'user'], []);
46 // Set display format to paragraphs summary.
47 $this->drupalGet('admin/structure/types/manage/paragraphed_test/display');
48 $edit = ['fields[field_paragraphs][type]' => 'paragraph_summary'];
49 $this->drupalPostForm(NULL, $edit, t('Save'));
51 $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_text_paragraph_add_more');
52 $this->drupalPostAjaxForm(NULL, NULL, 'field_paragraphs_title_add_more');
54 // Create a node with a text.
56 'title[0][value]' => 'Test article',
57 'field_paragraphs[0][subform][field_text][0][value]' => 'text_summary',
58 'field_paragraphs[1][subform][field_title][0][value]' => 'Title example',
60 $this->drupalPostForm(NULL, $edit, t('Save'));
61 $this->clickLink(t('Edit'));
62 $this->drupalPostForm(NULL, [], t('Add user_paragraph'));
64 'field_paragraphs[2][subform][field_user][0][target_id]' => $this->admin_user->label() . ' (' . $this->admin_user->id() . ')',
66 $this->drupalPostForm(NULL, $edit, t('Save'));
68 // Assert the summary is correctly generated.
69 $this->assertText($this->admin_user->label());
70 $this->assertText('Title example');