3 namespace Drupal\paragraphs\Tests\Experimental;
5 use Drupal\Core\Entity\Entity\EntityFormDisplay;
6 use Drupal\field_ui\Tests\FieldUiTestTrait;
9 * Tests the configuration of paragraphs.
13 class ParagraphsExperimentalPreviewTest extends ParagraphsExperimentalTestBase {
22 public static $modules = array(
27 * Tests the revision of paragraphs.
29 public function testParagraphsPreview() {
30 // Create paragraph type Headline + Block.
31 $this->addParagraphedContentType('article', 'field_paragraphs');
33 'administer node display',
34 'create article content',
35 'edit any article content',
36 'delete any article content',
39 // Create paragraph type Headline + Block.
40 $this->addParagraphsType('text');
41 // Create field types for the text.
42 $this->fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array());
43 $this->assertText('Saved Text configuration.');
45 $test_text_1 = 'dummy_preview_text_1';
46 $test_text_2 = 'dummy_preview_text_2';
47 // Create node with two paragraphs.
48 $this->drupalGet('node/add/article');
49 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more');
50 // Set the value of the paragraphs.
52 'title[0][value]' => 'Page_title',
53 'field_paragraphs[0][subform][field_text][0][value]' => $test_text_1,
55 // Preview the article.
56 $this->drupalPostForm(NULL, $edit, t('Preview'));
57 // Check if the text is displayed.
58 $this->assertRaw($test_text_1);
60 // Go back to the editing form.
61 $this->clickLink('Back to content editing');
63 $paragraph_1 = $this->xpath('//*[@id="edit-field-paragraphs-0-subform-field-text-0-value"]')[0];
64 $this->assertEqual($paragraph_1['value'], $test_text_1);
66 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
68 $this->clickLink('Edit');
69 $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more');
71 'field_paragraphs[1][subform][field_text][0][value]' => $test_text_2,
73 // Preview the article.
74 $this->drupalPostForm(NULL, $edit, t('Preview'));
75 $this->assertRaw($test_text_1);
76 $this->assertRaw($test_text_2);
78 // Go back to the editing form.
79 $this->clickLink('Back to content editing');
80 $new_test_text_2 = 'less_dummy_preview_text_2';
83 'field_paragraphs[1][subform][field_text][0][value]' => $new_test_text_2,
85 // Preview the article.
86 $this->drupalPostForm(NULL, $edit, t('Preview'));
87 $this->assertRaw($test_text_1);
88 $this->assertRaw($new_test_text_2);
89 // Go back to the editing form.
90 $this->clickLink('Back to content editing');
91 $paragraph_1 = $this->xpath('//*[@id="edit-field-paragraphs-0-subform-field-text-0-value"]')[0];
92 $paragraph_2 = $this->xpath('//*[@id="edit-field-paragraphs-1-subform-field-text-0-value"]')[0];
93 $this->assertEqual($paragraph_1['value'], $test_text_1);
94 $this->assertEqual($paragraph_2['value'], $new_test_text_2);
95 $this->drupalPostForm(NULL, [], t('Save and keep published'));
97 $this->assertRaw($test_text_1);
98 $this->assertRaw($new_test_text_2);
99 $this->assertRaw('Page_title');