X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate%2Ftests%2Fsrc%2FKernel%2FMigrateEntityContentBaseTest.php;fp=web%2Fcore%2Fmodules%2Fmigrate%2Ftests%2Fsrc%2FKernel%2FMigrateEntityContentBaseTest.php;h=7337e35e8cdb6c48dc8a305ae7e8deb1a9eb4fc3;hp=0ebc719ec90c53ef37b0816e1cff464ef48e2517;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php b/web/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php index 0ebc719ec..7337e35e8 100644 --- a/web/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php +++ b/web/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php @@ -10,6 +10,7 @@ use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; +use Drupal\migrate_entity_test\Entity\StringIdEntityTest; /** * Tests the EntityContentBase destination. @@ -204,4 +205,65 @@ class MigrateEntityContentBaseTest extends KernelTestBase { $this->assertEquals(123456789012, $map_row['destid1']); } + /** + * Tests empty destinations. + */ + public function testEmptyDestinations() { + $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 an SQL exception. + ['id' => 123456789012, 'version' => 'bar'], + ], + 'ids' => [ + 'id' => ['type' => 'integer', 'size' => 'big'], + 'version' => ['type' => 'string'], + ], + 'constants' => ['null' => NULL], + ], + '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, new MigrateMessage()); + $executable->import(); + + /** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */ + $entity = StringIdEntityTest::load('123'); + $this->assertSame('foo', $entity->version->value); + $entity = StringIdEntityTest::load('123456789012'); + $this->assertSame('bar', $entity->version->value); + + // Rerun the migration forcing the version to NULL. + $definition['process'] = [ + 'id' => 'id', + 'version' => 'constants/null', + ]; + + $migration = \Drupal::service('plugin.manager.migration') + ->createStubMigration($definition); + $executable = new MigrateExecutable($migration, new MigrateMessage()); + $executable->import(); + + /** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */ + $entity = StringIdEntityTest::load('123'); + $this->assertNull($entity->version->value); + $entity = StringIdEntityTest::load('123456789012'); + $this->assertNull($entity->version->value); + } + }