function MigrateEntityContentBaseTest::testEntityWithStringId

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentBaseTest::testEntityWithStringId()
  2. 8.9.x core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentBaseTest::testEntityWithStringId()
  3. 11.x core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentBaseTest::testEntityWithStringId()

Tests creation of ID columns table with definitions taken from entity type.

File

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

Class

MigrateEntityContentBaseTest
Tests the EntityContentBase destination.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testEntityWithStringId() : void {
    $this->enableModules([
        'migrate_entity_test',
    ]);
    $this->installEntitySchema('migrate_string_id_entity_test');
    $definition = [
        'source' => [
            'plugin' => 'embedded_data',
            'data_rows' => [
                [
                    'id' => 123,
                    'version' => 'foo',
                ],
                // This integer needs an 'int' schema with 'big' size. If 'destid1'
                // is not correctly taking the definition from the destination entity
                // type, the import will fail with a SQL exception.
[
                    'id' => 123456789012,
                    'version' => 'bar',
                ],
            ],
            'ids' => [
                'id' => [
                    'type' => 'integer',
                    'size' => 'big',
                ],
                'version' => [
                    'type' => 'string',
                ],
            ],
        ],
        'process' => [
            'id' => 'id',
            'version' => 'version',
        ],
        'destination' => [
            'plugin' => 'entity:migrate_string_id_entity_test',
        ],
    ];
    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $executable = new MigrateExecutable($migration);
    $result = $executable->import();
    $this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result);
    
    /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */
    $id_map_plugin = $migration->getIdMap();
    // Check that the destination has been stored.
    $map_row = $id_map_plugin->getRowBySource([
        'id' => 123,
        'version' => 'foo',
    ]);
    $this->assertEquals(123, $map_row['destid1']);
    $map_row = $id_map_plugin->getRowBySource([
        'id' => 123456789012,
        'version' => 'bar',
    ]);
    $this->assertEquals(123456789012, $map_row['destid1']);
}

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