You are here

protected function MediaMigrationAssertionsForMediaSourceTrait::assertNode1FieldValues in Media Migration 8

Assertions of node 1.

5 calls to MediaMigrationAssertionsForMediaSourceTrait::assertNode1FieldValues()
MediaMigrationTest::testMediaMigration in tests/src/Kernel/Migrate/MediaMigrationTest.php
Tests the migration of media entities.
MediaMigrationWithoutImageTitleTest::testMediaWithoutImageTitleMigration in tests/src/Kernel/Migrate/MediaMigrationWithoutImageTitleTest.php
Tests the migration of media entities without image title.
MigrateEmbedMediaTokenToEntityEmbedTest::testMediaTokenToEntityEmbedTransform in tests/src/Functional/MigrateEmbedMediaTokenToEntityEmbedTest.php
Tests the result of Media Migration's embed media token transform.
MigrateEmbedMediaTokenToMediaEmbedTest::testMediaTokenToMediaEmbedTransform in tests/src/Functional/MigrateEmbedMediaTokenToMediaEmbedTest.php
Tests the result of Media Migration's embed media token transform.
MigrateMediaTest::testMediaMigrate in tests/src/Functional/MigrateMediaTest.php
Tests the result of the media migration.

File

tests/src/Traits/MediaMigrationAssertionsForMediaSourceTrait.php, line 394

Class

MediaMigrationAssertionsForMediaSourceTrait
Trait for media migration tests.

Namespace

Drupal\Tests\media_migration\Traits

Code

protected function assertNode1FieldValues(array $expected_node1_embed_attributes = []) {
  $node = $this->container
    ->get('entity_type.manager')
    ->getStorage('node')
    ->load(1);
  assert($node instanceof NodeInterface);

  // Ignore body field.
  $important_properties = $this
    ->getImportantEntityProperties($node);
  unset($important_properties['body']);
  $this
    ->assertEquals([
    'nid' => [
      [
        'value' => 1,
      ],
    ],
    'type' => [
      [
        'target_id' => 'article',
      ],
    ],
    'status' => [
      [
        'value' => 1,
      ],
    ],
    'uid' => [
      [
        'target_id' => 1,
      ],
    ],
    'title' => [
      [
        'value' => 'Article with embed image media',
      ],
    ],
    'created' => [
      [
        'value' => 1587730322,
      ],
    ],
    'changed' => [
      [
        'value' => 1587730609,
      ],
    ],
    'promote' => [
      [
        'value' => 1,
      ],
    ],
    'sticky' => [
      [
        'value' => 0,
      ],
    ],
    'field_image' => [
      [
        'target_id' => '2',
      ],
    ],
    'field_media' => [
      [
        'target_id' => '3',
      ],
      [
        'target_id' => '4',
      ],
    ],
  ], $important_properties);

  // Test that the image and file fields are referencing media entities.
  $media_fields = [
    'field_image' => 1,
    'field_media' => 2,
  ];
  foreach ($media_fields as $field_name => $expected_count) {
    $referred_entities = $this
      ->getReferencedEntities($node, $field_name, $expected_count);
    assert($referred_entities[0] instanceof MediaInterface);
  }
  if (!empty($expected_node1_embed_attributes)) {
    $node_body_text = preg_replace('/\\s+/', ' ', $node->body->value);
    $this
      ->assertEmbedTokenHtmlTags($node_body_text, $expected_node1_embed_attributes);
  }
}