public function ParagraphsTest::testDefaultParagraphsBehaviour in Multiversion 8
Tests that paragraphs revisions created right when saving parent entity.
File
- tests/
src/ Kernel/ ParagraphsTest.php, line 81
Class
- ParagraphsTest
- Test for paragraphs integration.
Namespace
Drupal\Tests\multiversion\KernelCode
public function testDefaultParagraphsBehaviour() {
$paragraph = $this->paragraphStorage
->create([
'title' => 'Stub of real paragraph',
'type' => 'test_paragraph_type',
'field_test_field' => 'First revision title',
]);
$node = $this->nodeStorage
->create([
'type' => 'paragraphs_node_type',
'title' => 'Test node',
'field_paragraph' => $paragraph,
]);
$node
->save();
$node_revision_id = $node
->getRevisionId();
$paragraph_entity_id = $node->field_paragraph->target_id;
$paragraph_entity = $this->paragraphStorage
->load($paragraph_entity_id);
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph_entity */
list($i, $hash) = explode('-', $paragraph_entity->_rev->value);
$this
->assertEquals($i, '1', 'After saving new node with paragraph we have new paragraph with one revision.');
$paragraph->field_test_field = 'Second revision title';
$node->field_paragraph = $paragraph;
$node
->save();
$paragraph_entity_revision_id = $node->field_paragraph->target_revision_id;
$paragraph_entity = $this->paragraphStorage
->loadRevision($paragraph_entity_revision_id);
$this
->assertRevNumber($paragraph_entity, 2);
$this
->assertEquals($paragraph_entity->field_test_field->value, 'Second revision title');
$node_first_revision = $this->nodeStorage
->loadRevision($node_revision_id);
$paragraph_entity_revision_id = $node_first_revision->field_paragraph->target_revision_id;
$paragraph_entity = $this->paragraphStorage
->loadRevision($paragraph_entity_revision_id);
$this
->assertEquals($paragraph_entity->field_test_field->value, 'First revision title');
}