You are here

public function ParagraphsTest::testParagraphStubCreatedAfterParent in Multiversion 8

Tests stub handling for paragraph when it is created after parent entity.

File

tests/src/Kernel/ParagraphsTest.php, line 120

Class

ParagraphsTest
Test for paragraphs integration.

Namespace

Drupal\Tests\multiversion\Kernel

Code

public function testParagraphStubCreatedAfterParent() {
  $paragraph_stub = $this->paragraphStorage
    ->create([
    'title' => 'Stub of real paragraph',
    'type' => 'test_paragraph_type',
  ]);
  $paragraph_stub->_rev->is_stub = TRUE;
  $node = $this->nodeStorage
    ->create([
    'type' => 'paragraphs_node_type',
    'title' => 'Test node',
    'field_paragraph' => $paragraph_stub,
  ]);
  $node
    ->save();
  $paragraph_stub_entity_id = $node->field_paragraph->target_id;
  $paragraph_stub_entity = $this->paragraphStorage
    ->load($paragraph_stub_entity_id);
  $this
    ->assertRevNumber($paragraph_stub_entity, 0);
  $paragraph_real = $this->paragraphStorage
    ->create([
    'type' => 'test_paragraph_type',
    'id' => $paragraph_stub_entity
      ->id(),
  ]);
  $paragraph_real
    ->enforceIsNew(FALSE);
  $paragraph_real->_rev->is_stub = FALSE;
  $paragraph_real
    ->save();
  $this
    ->assertEquals($paragraph_real
    ->id(), $paragraph_stub_entity_id);
  $this
    ->assertRevNumber($paragraph_real, 1);
}