function MigrateEntityContentBaseTest::testStubRows

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentBaseTest::testStubRows()
  2. 10 core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentBaseTest::testStubRows()
  3. 11.x 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());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.