public function ParagraphsTest::testParagraphStubCreatedBeforeParent in Multiversion 8
Tests stub handling for paragraph when it is created before parent entity.
File
- tests/
src/ Kernel/ ParagraphsTest.php, line 151
Class
- ParagraphsTest
- Test for paragraphs integration.
Namespace
Drupal\Tests\multiversion\KernelCode
public function testParagraphStubCreatedBeforeParent() {
// Create and save real paragraph.
$paragraph = $this->paragraphStorage
->create([
'title' => 'Real paragraph',
'type' => 'test_paragraph_type',
]);
$paragraph
->save();
// Assert that created paragraph is not a stub and it is the first revision.
$this
->assertRevNumber($paragraph, 1);
// Create stub paragraph with same uuid as real paragraph.
$paragraph_stub_in_node = $this->paragraphStorage
->create([
'type' => 'test_paragraph_type',
'uuid' => $paragraph
->uuid(),
]);
$paragraph_stub_in_node->_rev->is_stub = TRUE;
// Create node with paragraph stub.
$node = $this->nodeStorage
->create([
'type' => 'paragraphs_node_type',
'title' => 'Test node',
'field_paragraph' => $paragraph_stub_in_node,
]);
$node
->save();
$paragraph_entity_id_from_node = $node->field_paragraph->target_id;
$this
->assertEquals($paragraph_entity_id_from_node, $paragraph
->id());
$paragraph_entity = $this->paragraphStorage
->load($paragraph
->id());
$this
->assertRevNumber($paragraph_entity, 1);
}