You are here

public function GatsbyInstantPreviewTest::testBuildRelationshipJson in Gatsby Live Preview & Incremental Builds 2.0.x

Same name and namespace in other branches
  1. 8 modules/gatsby_instantpreview/tests/src/Kernel/GatsbyInstantPreviewTest.php \Drupal\Tests\gatsby_instantpreview\Kernel\GatsbyInstantPreviewTest::testBuildRelationshipJson()

Tests buildRelationshipJson.

File

modules/gatsby_instantpreview/tests/src/Kernel/GatsbyInstantPreviewTest.php, line 71

Class

GatsbyInstantPreviewTest
Defines a test for the GatsbyInstantPreview.

Namespace

Drupal\Tests\gatsby_instantpreview\Kernel

Code

public function testBuildRelationshipJson() {

  /** @var \Drupal\node\NodeInterface $node */
  $node = Node::create([
    'type' => 'page',
    'status' => 1,
    'title' => 'foo',
  ]);
  $node
    ->save();

  /** @var \Drupal\gatsby_instantpreview\GatsbyInstantPreview $preview */
  $preview = \Drupal::service('gatsby.gatsby_instantpreview');
  $entity_data = [];
  $data = $preview
    ->getJson($node);
  $preview
    ->buildRelationshipJson($data['data']['relationships'], $entity_data, [
    'user',
  ]);
  $this
    ->assertTrue(!empty($entity_data[$node->uid->entity
    ->uuid()]));
  $entity_data = [];
  $preview
    ->buildRelationshipJson($data['data']['relationships'], $entity_data);
  $this
    ->assertTrue(!empty($entity_data[$node->uid->entity
    ->uuid()]));
  $node2 = Node::create([
    'type' => 'page',
    'status' => 1,
    'title' => 'foo',
    'field_reference' => $node,
  ]);
  $node2
    ->save();
  $node->field_reference = $node2;
  $node
    ->save();
  $entity_data = [];
  $data = $preview
    ->getJson($node);
  $preview
    ->buildRelationshipJson($data['data']['relationships'], $entity_data, [
    'node',
  ]);
  $this
    ->assertTrue(!empty($entity_data[$node2
    ->uuid()]));
}