View source  
  trait ParagraphsNodeMigrationAssertionsTrait {
  
  protected function assertNode8Paragraphs() {
    $node_8 = Node::load(8);
    assert($node_8 instanceof NodeInterface);
    
    $node_8_field_collection_field_entities = $this
      ->getReferencedEntities($node_8, 'field_field_collection_test', 2);
    $this
      ->assertEquals('Field Collection Text Data One UND', $node_8_field_collection_field_entities[0]->field_text->value);
    $this
      ->assertEquals('1', $node_8_field_collection_field_entities[0]->field_integer_list->value);
    $this
      ->assertEquals('Field Collection Text Data Two UND', $node_8_field_collection_field_entities[1]->field_text->value);
    $this
      ->assertNull($node_8_field_collection_field_entities[1]->field_integer_list->value);
    
    $node_8_field_any_paragraph_entities = $this
      ->getReferencedEntities($node_8, 'field_any_paragraph', 2);
    $this
      ->assertEquals('Paragraph Field One Bundle One UND', $node_8_field_any_paragraph_entities[0]->field_text->value);
    $this
      ->assertEquals('Some Text', $node_8_field_any_paragraph_entities[0]->field_text_list->value);
    $this
      ->assertEquals('Paragraph Field One Bundle Two UND', $node_8_field_any_paragraph_entities[1]->field_text->value);
    $this
      ->assertEquals('joe@joe.com', $node_8_field_any_paragraph_entities[1]->field_email->value);
    
    $node_8_field_paragraph_one_only_entities = $this
      ->getReferencedEntities($node_8, 'field_paragraph_one_only', 1);
    $this
      ->assertEquals('Paragraph Field Two Bundle One Revision Two UND', $node_8_field_paragraph_one_only_entities[0]->field_text->value);
    $this
      ->assertEquals('Some more text', $node_8_field_paragraph_one_only_entities[0]->field_text_list->value);
    
    $node_8_field_nested_fc_outer_entities = $this
      ->getReferencedEntities($node_8, 'field_nested_fc_outer', 1);
    assert($node_8_field_nested_fc_outer_entities[0] instanceof ParagraphInterface);
    $node_8_inner_nested_fc_0_entities = $this
      ->getReferencedEntities($node_8_field_nested_fc_outer_entities[0], 'field_nested_fc_inner', 1);
    $this
      ->assertEquals('Nested FC test text', $node_8_inner_nested_fc_0_entities[0]->field_text->value);
  }
  
  protected function assertNode9Paragraphs() {
    $node_9 = Node::load(9);
    assert($node_9 instanceof NodeInterface);
    if ($this->container
      ->get('module_handler')
      ->moduleExists('content_translation') && $node_9 instanceof TranslatableInterface) {
      
      $node_9 = $node_9
        ->getUntranslated();
      $this
        ->assertSame('en', $node_9
        ->language()
        ->getId());
    }
    
    $node_9_field_collection_field_entities = $this
      ->getReferencedEntities($node_9, 'field_field_collection_test', 1);
    $this
      ->assertEquals('Field Collection Text Data Two EN', $node_9_field_collection_field_entities[0]->field_text->value);
    $this
      ->assertEquals('2', $node_9_field_collection_field_entities[0]->field_integer_list->value);
    
    $node_9_field_any_paragraph_entities = $this
      ->getReferencedEntities($node_9, 'field_any_paragraph', 2);
    $this
      ->assertEquals('Paragraph Field One Bundle One EN', $node_9_field_any_paragraph_entities[0]->field_text->value);
    $this
      ->assertEquals('Some Text', $node_9_field_any_paragraph_entities[0]->field_text_list->value);
    $this
      ->assertEquals('Paragraph Field One Bundle Two EN', $node_9_field_any_paragraph_entities[1]->field_text->value);
    $this
      ->assertEquals('jose@jose.com', $node_9_field_any_paragraph_entities[1]->field_email->value);
    
    $node_9_field_paragraph_one_only_entities = $this
      ->getReferencedEntities($node_9, 'field_paragraph_one_only', 1);
    $this
      ->assertEquals('Paragraph Field Two Bundle One EN', $node_9_field_paragraph_one_only_entities[0]->field_text->value);
    $this
      ->assertEquals('Some Text', $node_9_field_paragraph_one_only_entities[0]->field_text_list->value);
    
    $this
      ->getReferencedEntities($node_9, 'field_nested_fc_outer', 0);
  }
  
  protected function assertIcelandicNode9Paragraphs() {
    
    $node_9 = Node::load(9);
    assert($node_9 instanceof NodeInterface);
    assert($node_9 instanceof TranslatableInterface);
    $node_9_translation_languages = $node_9
      ->getTranslationLanguages(FALSE);
    $this
      ->assertEquals([
      'is',
    ], array_keys($node_9_translation_languages));
    $node_9 = $node_9
      ->getTranslation('is');
    $this
      ->assertSame('is', $node_9
      ->language()
      ->getId());
    
    $node_9_field_collection_field_entities = $this
      ->getReferencedEntities($node_9, 'field_field_collection_test', 3);
    $this
      ->assertEquals('Field Collection Text Data One IS', $node_9_field_collection_field_entities[0]->field_text->value);
    $this
      ->assertEquals('1', $node_9_field_collection_field_entities[0]->field_integer_list->value);
    $this
      ->assertEquals('Field Collection Text Data Two IS', $node_9_field_collection_field_entities[1]->field_text->value);
    $this
      ->assertEquals('2', $node_9_field_collection_field_entities[1]->field_integer_list->value);
    $this
      ->assertEquals('Field Collection Text Data Three IS', $node_9_field_collection_field_entities[2]->field_text->value);
    $this
      ->assertEquals('3', $node_9_field_collection_field_entities[2]->field_integer_list->value);
    
    $node_9_field_any_paragraph_entities = $this
      ->getReferencedEntities($node_9, 'field_any_paragraph', 3);
    $this
      ->assertEquals('Paragraph Field One Bundle One IS', $node_9_field_any_paragraph_entities[0]->field_text->value);
    $this
      ->assertEquals('Some Text', $node_9_field_any_paragraph_entities[0]->field_text_list->value);
    $this
      ->assertEquals('Paragraph Field One Bundle Two IS', $node_9_field_any_paragraph_entities[1]->field_text->value);
    $this
      ->assertEquals('jose@jose.com', $node_9_field_any_paragraph_entities[1]->field_email->value);
    $this
      ->assertEquals('Paragraph Field One Bundle Two Delta 3 IS', $node_9_field_any_paragraph_entities[2]->field_text->value);
    $this
      ->assertEquals('john@john.com', $node_9_field_any_paragraph_entities[2]->field_email->value);
    
    $node_9_field_paragraph_one_only_entities = $this
      ->getReferencedEntities($node_9, 'field_paragraph_one_only', 1);
    $this
      ->assertEquals('Paragraph Field Two Bundle One IS', $node_9_field_paragraph_one_only_entities[0]->field_text->value);
    $this
      ->assertEquals('Some more text', $node_9_field_paragraph_one_only_entities[0]->field_text_list->value);
    
    $this
      ->getReferencedEntities($node_9, 'field_nested_fc_outer', 0);
  }
  
  protected function getReferencedEntities(ContentEntityInterface $entity, $field_name, int $expected_count) {
    $entity_field = $entity
      ->hasField($field_name) ? $entity
      ->get($field_name) : NULL;
    assert($entity_field instanceof EntityReferenceRevisionsFieldItemList);
    $entity_field_entities = $entity_field
      ->referencedEntities();
    $this
      ->assertCount($expected_count, $entity_field_entities);
    return $entity_field_entities;
  }
}