3 namespace Drupal\paragraphs\Tests\Classic;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
8 * Tests the configuration of paragraphs.
12 class ParagraphsPreviewTest extends ParagraphsTestBase {
21 public static $modules = array(
26 * Tests the revision of paragraphs.
28 public function testParagraphsPreview() {
29 // Create paragraph type Headline + Block.
30 $this->addParagraphedContentType('article', 'field_paragraphs', 'entity_reference_paragraphs');
32 'administer node display',
33 'create article content',
34 'edit any article content',
35 'delete any article content',
38 // Create paragraph type Headline + Block.
39 $this->addParagraphsType('text');
40 // Create field types for the text.
41 $this->fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array());
42 $this->assertText('Saved Text configuration.');
44 $test_text_1 = 'dummy_preview_text_1';
45 $test_text_2 = 'dummy_preview_text_2';
46 // Create node with two paragraphs.
47 $this->drupalGet('node/add/article');
48 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more');
49 // Set the value of the paragraphs.
51 'title[0][value]' => 'Page_title',
52 'field_paragraphs[0][subform][field_text][0][value]' => $test_text_1,
54 // Preview the article.
55 $this->drupalPostForm(NULL, $edit, t('Preview'));
56 // Check if the text is displayed.
57 $this->assertRaw($test_text_1);
59 // Go back to the editing form.
60 $this->clickLink('Back to content editing');
62 $paragraph_1 = $this->xpath('//*[@id="edit-field-paragraphs-0-subform-field-text-0-value"]')[0];
63 $this->assertEqual($paragraph_1['value'], $test_text_1);
65 $this->drupalPostForm(NULL, $edit, t('Save'));
67 $this->clickLink('Edit');
68 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more');
70 'field_paragraphs[1][subform][field_text][0][value]' => $test_text_2,
72 // Preview the article.
73 $this->drupalPostForm(NULL, $edit, t('Preview'));
74 $this->assertRaw($test_text_1);
75 $this->assertRaw($test_text_2);
77 // Go back to the editing form.
78 $this->clickLink('Back to content editing');
79 $new_test_text_2 = 'less_dummy_preview_text_2';
82 'field_paragraphs[1][subform][field_text][0][value]' => $new_test_text_2,
84 // Preview the article.
85 $this->drupalPostForm(NULL, $edit, t('Preview'));
86 $this->assertRaw($test_text_1);
87 $this->assertRaw($new_test_text_2);
88 // Go back to the editing form.
89 $this->clickLink('Back to content editing');
90 $paragraph_1 = $this->xpath('//*[@id="edit-field-paragraphs-0-subform-field-text-0-value"]')[0];
91 $paragraph_2 = $this->xpath('//*[@id="edit-field-paragraphs-1-subform-field-text-0-value"]')[0];
92 $this->assertEqual($paragraph_1['value'], $test_text_1);
93 $this->assertEqual($paragraph_2['value'], $new_test_text_2);
94 $this->drupalPostForm(NULL, [], t('Save'));
96 $this->assertRaw($test_text_1);
97 $this->assertRaw($new_test_text_2);
98 $this->assertRaw('Page_title');