public function ParagraphsAdministrationTest::testParagraphsRevisions in Paragraphs 8
Same name in this branch
- 8 tests/src/Functional/WidgetLegacy/ParagraphsAdministrationTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsAdministrationTest::testParagraphsRevisions()
- 8 tests/src/Functional/WidgetStable/ParagraphsAdministrationTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsAdministrationTest::testParagraphsRevisions()
Tests the revision of paragraphs.
File
- tests/
src/ Functional/ WidgetStable/ ParagraphsAdministrationTest.php, line 40
Class
- ParagraphsAdministrationTest
- Tests the configuration of paragraphs.
Namespace
Drupal\Tests\paragraphs\Functional\WidgetStableCode
public function testParagraphsRevisions() {
$this
->addParagraphedContentType('article', 'paragraphs');
$this
->loginAsAdmin([
'create paragraphs content',
'administer node display',
'edit any paragraphs content',
'administer nodes',
]);
// Create paragraphs type Headline + Block.
$this
->addParagraphsType('text');
// Create field types for the text.
static::fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array());
$this
->assertSession()
->pageTextContains('Saved Text configuration.');
// Create an article with paragraphs field.
static::fieldUIAddNewField('admin/structure/types/manage/paragraphs', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array(
'settings[target_type]' => 'paragraph',
'cardinality' => '-1',
), array(
'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => TRUE,
));
// Configure article fields.
$this
->drupalGet('admin/structure/types/manage/paragraphs/fields');
$this
->clickLink('Manage form display');
$this
->submitForm(array(
'fields[field_paragraphs][type]' => 'paragraphs',
), 'Save');
// Create node with our paragraphs.
$this
->drupalGet('node/add/paragraphs');
$this
->submitForm(array(), 'field_paragraphs_text_add_more');
$this
->submitForm(array(), 'field_paragraphs_text_add_more');
$edit = [
'title[0][value]' => 'TEST TITEL',
'field_paragraphs[0][subform][field_text][0][value]' => 'Test text 1',
'field_paragraphs[1][subform][field_text][0][value]' => 'Test text 2',
];
$this
->submitForm($edit + [
'status[value]' => TRUE,
], 'Save');
$node = $this
->drupalGetNodeByTitle('TEST TITEL');
$paragraph1 = $node->field_paragraphs[0]->target_id;
$paragraph2 = $node->field_paragraphs[1]->target_id;
$this
->countRevisions($node, $paragraph1, $paragraph2, 1);
// Edit the node without creating a revision. There should still be only 1
// revision for nodes and paragraphs.
$edit = [
'field_paragraphs[0][subform][field_text][0][value]' => 'Foo Bar 1',
'revision' => FALSE,
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->countRevisions($node, $paragraph1, $paragraph2, 1);
// Edit the just created node. Create new revision. Now we should have 2
// revisions for nodes and paragraphs.
$edit = [
'title[0][value]' => 'TEST TITLE',
'field_paragraphs[0][subform][field_text][0][value]' => 'Foo Bar 2',
'revision' => TRUE,
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->countRevisions($node, $paragraph1, $paragraph2, 2);
// Assert the paragraphs have been changed.
$this
->assertSession()
->pageTextNotContains('Foo Bar 1');
$this
->assertSession()
->pageTextContains('Test text 2');
$this
->assertSession()
->pageTextContains('Foo Bar 2');
$this
->assertSession()
->pageTextContains('TEST TITLE');
// Check out the revisions page and assert there are 2 revisions.
$this
->drupalGet('node/' . $node
->id() . '/revisions');
$rows = $this
->xpath('//tbody/tr');
// Make sure two revisions available.
$this
->assertEquals(count($rows), 2);
// Revert to the old version.
$this
->clickLink('Revert');
$this
->submitForm([], 'Revert');
$this
->drupalGet('node/' . $node
->id());
// Assert the node has been reverted.
$this
->assertSession()
->pageTextNotContains('Foo Bar 2');
$this
->assertSession()
->pageTextContains('Test text 2');
$this
->assertSession()
->pageTextContains('Foo Bar 1');
$this
->assertSession()
->pageTextContains('TEST TITEL');
}