Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / migrate / tests / src / Kernel / MigrateEntityContentBaseTest.php
index 0ebc719ec90c53ef37b0816e1cff464ef48e2517..7337e35e8cdb6c48dc8a305ae7e8deb1a9eb4fc3 100644 (file)
@@ -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);
+  }
+
 }