You are here

public function MigrateEntityContentBaseTest::testStubRows in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentBaseTest::testStubRows()

Tests stub rows.

File

core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php, line 277

Class

MigrateEntityContentBaseTest
Tests the EntityContentBase destination.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testStubRows() {

  // Create a destination.
  $this
    ->createDestination([]);

  // Import a stub row.
  $row = new Row([], [], TRUE);
  $row
    ->setDestinationProperty('type', 'test');
  $ids = $this->destination
    ->import($row);
  $this
    ->assertCount(1, $ids);

  // Make sure the entity was saved.
  $entity = EntityTestMul::load(reset($ids));
  $this
    ->assertInstanceOf(EntityTestMul::class, $entity);

  // Make sure the default value was applied to the required fields.
  $single_field_name = 'required_default_field';
  $single_default_value = $entity
    ->getFieldDefinition($single_field_name)
    ->getDefaultValueLiteral();
  $this
    ->assertSame($single_default_value, $entity
    ->get($single_field_name)
    ->getValue());
  $multi_field_name = 'required_multi_default_field';
  $multi_default_value = $entity
    ->getFieldDefinition($multi_field_name)
    ->getDefaultValueLiteral();
  $count = 3;
  $this
    ->assertCount($count, $multi_default_value);
  for ($i = 0; $i < $count; ++$i) {
    $this
      ->assertSame($multi_default_value[$i], $entity
      ->get($multi_field_name)
      ->get($i)
      ->getValue());
  }
}