diff -u b/core/modules/migrate_drupal/src/Tests/d6/EntityContentBaseTest.php b/core/modules/migrate_drupal/src/Tests/d6/EntityContentBaseTest.php --- b/core/modules/migrate_drupal/src/Tests/d6/EntityContentBaseTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/EntityContentBaseTest.php @@ -7,6 +7,8 @@ namespace Drupal\migrate_drupal\Tests\d6; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\migrate\Entity\Migration; use Drupal\user\Entity\User; @@ -21,20 +23,41 @@ public function setUp() { parent::setUp(); + // Create a field on the user entity so that we can test nested property + // overwrites. + // @see static::testOverwriteSelectedNestedProperty() + FieldStorageConfig::create([ + 'field_name' => 'signature', + 'entity_type' => 'user', + 'type' => 'text_long', + ])->save(); + + FieldConfig::create([ + 'field_name' => 'signature', + 'entity_type' => 'user', + 'bundle' => 'user', + ])->save(); + User::create([ 'uid' => 2, - 'name' => 'Michael Palin', - 'mail' => 'mike@monty.py', + 'name' => 'Ford Prefect', + 'mail' => 'ford.prefect@localhost', + 'signature' => array( + array( + 'value' => 'Bring a towel.', + 'format' => 'filtered_html', + ), + ), ])->save(); $this->executeMigrations(['d6_filter_format', 'd6_user_role']); } /** - * Tests overwriting all properties in the destination entity (default + * Tests overwriting all mapped properties in the destination entity (default * behavior). */ - public function testOverwriteAllProperties() { + public function testOverwriteAllMappedProperties() { $this->executeMigration('d6_user'); /** @var \Drupal\user\UserInterface $account */ $account = User::load(2); @@ -55,8 +78,34 @@ /** @var \Drupal\user\UserInterface $account */ $account = User::load(2); - $this->assertIdentical('Michael Palin', $account->label()); + $this->assertIdentical('Ford Prefect', $account->label()); $this->assertIdentical('john.doe@example.com', $account->getEmail()); + $this->assertIdentical('Bring a towel.', $account->signature->value); + } + + /** + * Tests overwriting selected nested properties in the destination entity, + * specified in the destination configuration. + */ + public function testOverwriteSelectedNestedProperty() { + /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ + $migration = Migration::load('d6_user'); + $destination = $migration->get('destination'); + // Migrate a static value into the signature, and ignore everything else. + $destination['overwrite_properties'][] = 'signature/value'; + $migration->set('destination', $destination); + $process = array( + 'plugin' => 'default_value', + 'default_value' => 'The answer is 42.', + ); + $migration->setProcessOfProperty('signature/value', $process); + $this->executeMigration($migration); + + /** @var \Drupal\user\UserInterface $account */ + $account = User::load(2); + $this->assertIdentical('Ford Prefect', $account->label()); + $this->assertIdentical('ford.prefect@localhost', $account->getEmail()); + $this->assertIdentical('The answer is 42.', $account->signature->value); } }