You are here

public function LinkStubReplicationTest::testLinkStubReplication in Replication 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/LinkStubReplicationTest.php \Drupal\Tests\replication\Kernel\LinkStubReplicationTest::testLinkStubReplication()

Tests replication of link stubs.

File

tests/src/Kernel/LinkStubReplicationTest.php, line 62

Class

LinkStubReplicationTest
Tests link stub replication.

Namespace

Drupal\Tests\replication\Kernel

Code

public function testLinkStubReplication() {
  $workspace = Workspace::load(1);
  $referenced_node = [
    '@context' => [
      '_id' => '@id',
      '@language' => 'en',
    ],
    '@type' => 'node',
    '_id' => 'c0b478b6-3a86-4571-8a83-a32c2f18ecd7',
    '_rev' => '1-9340f2de88f2a238083c7afd92c5651a',
    'en' => [
      '@context' => [
        '@language' => 'en',
      ],
      'langcode' => [
        [
          'value' => 'en',
        ],
      ],
      'type' => [
        [
          'target_id' => 'article',
        ],
      ],
      'title' => [
        [
          'value' => 'Article node',
        ],
      ],
      'uid' => [
        [
          'target_id' => 0,
        ],
      ],
      'status' => [
        [
          'value' => TRUE,
        ],
      ],
      'created' => [
        [
          'value' => 1492122137,
        ],
      ],
      'changed' => [
        [
          'value' => 1492122137,
        ],
      ],
      '_rev' => [
        [
          'value' => '1-9340f2de88f2a238083c7afd92c5651a',
        ],
      ],
      'field_test' => [
        [
          'value' => 'Test value',
        ],
      ],
    ],
  ];
  $node_with_reference = [
    '@context' => [
      '_id' => '@id',
      '@language' => 'en',
    ],
    '@type' => 'node',
    '_id' => 'e3bb9038-157b-4822-8fe0-ed4a9f414a10',
    '_rev' => '1-b939e3b3c3fac61095cd8cb75e5855e6',
    'en' => [
      '@context' => [
        '@language' => 'en',
      ],
      'langcode' => [
        [
          'value' => 'en',
        ],
      ],
      'type' => [
        [
          'target_id' => 'article_with_link',
        ],
      ],
      'title' => [
        [
          'value' => 'rc2zpt2S',
        ],
      ],
      'uid' => [
        [
          'target_id' => 0,
        ],
      ],
      'status' => [
        [
          'value' => TRUE,
        ],
      ],
      'created' => [
        [
          'value' => 1492120498,
        ],
      ],
      'changed' => [
        [
          'value' => 1492120498,
        ],
      ],
      'default_langcode' => [
        [
          'value' => TRUE,
        ],
      ],
      '_rev' => [
        [
          'value' => '1-b939e3b3c3fac61095cd8cb75e5855e6',
        ],
      ],
      'field_link' => [
        [
          'uri' => 'entity:node/1',
          'entity_type_id' => 'node',
          'target_uuid' => 'c0b478b6-3a86-4571-8a83-a32c2f18ecd7',
          'type' => 'article',
        ],
      ],
    ],
  ];
  $data = [
    'docs' => [
      $node_with_reference,
      $referenced_node,
    ],
    'new_edits' => FALSE,
  ];

  /** @var \Drupal\replication\BulkDocs\BulkDocs $bulk_docs */
  $bulk_docs = $this->serializer
    ->denormalize($data, 'Drupal\\replication\\BulkDocs\\BulkDocs', 'json', [
    'workspace' => $workspace,
  ]);
  $bulk_docs
    ->save();
  $node = $this->container
    ->get('entity.repository')
    ->loadEntityByUuid('node', 'c0b478b6-3a86-4571-8a83-a32c2f18ecd7');
  $this
    ->assertEquals('Test value', $node->field_test->value);
}