You are here

public function MissingEntityReferenceTest::testMissingReferenceEntityValue in Entity Share 8.3

Same name and namespace in other branches
  1. 8.2 modules/entity_share_client/tests/src/Functional/MissingEntityReferenceTest.php \Drupal\Tests\entity_share_client\Functional\MissingEntityReferenceTest::testMissingReferenceEntityValue()

Test that a missing reference entity value is removed.

It shows that a missing entity reference does not fail the import.

File

modules/entity_share_client/tests/src/Functional/MissingEntityReferenceTest.php, line 127

Class

MissingEntityReferenceTest
Functional test class for entity reference field with missing entity.

Namespace

Drupal\Tests\entity_share_client\Functional

Code

public function testMissingReferenceEntityValue() {
  $this
    ->pullEveryChannels();
  $existing_entities = $this->entityTypeManager
    ->getStorage('node')
    ->loadByProperties([
    'uuid' => 'es_test_content_reference',
  ]);
  $this
    ->assertNotEmpty($existing_entities, 'The content has been imported');
  if (!empty($existing_entities)) {
    $node = array_shift($existing_entities);
    $content_reference_value = $node
      ->get('field_es_test_content_reference')
      ->getValue();
    $expected_content_reference_value = [];
    $this
      ->assertEquals($expected_content_reference_value, $content_reference_value, 'The content reference field is empty.');
    $term_reference_value = $node
      ->get('field_es_test_taxonomy')
      ->getValue();
    $expected_term_reference_value = [
      [
        'target_id' => $this
          ->getEntityId('taxonomy_term', 'es_test_tag'),
      ],
      [
        'target_id' => $this
          ->getEntityId('taxonomy_term', 'es_test_tag_2'),
      ],
    ];
    $this
      ->assertEquals($expected_term_reference_value, $term_reference_value, 'The term reference field does not have the missing entity value and only reference 2 entities.');
  }

  // Check that the deleted tag and node had not been created.
  $deleted_taxonomy_term_id = $this
    ->getEntityId('taxonomy_term', 'es_test_tag_deleted');
  $this
    ->assertEmpty($deleted_taxonomy_term_id, 'The deleted taxonomy term has not been recreated.');
  $deleted_node_id = $this
    ->getEntityId('node', 'es_test_to_be_deleted');
  $this
    ->assertEmpty($deleted_node_id, 'The deleted node has not been recreated.');
}