3 namespace Drupal\Tests\migrate_drupal\Kernel\d6;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\migrate\MigrateExecutable;
8 use Drupal\migrate\MigrateMessageInterface;
9 use Drupal\user\Entity\User;
10 use Prophecy\Argument;
13 * @group migrate_drupal
15 class EntityContentBaseTest extends MigrateDrupal6TestBase {
20 public static $modules = ['migrate_overwrite_test'];
25 protected function setUp() {
28 // Create a field on the user entity so that we can test nested property
30 // @see static::testOverwriteSelectedNestedProperty()
31 FieldStorageConfig::create([
32 'field_name' => 'signature',
33 'entity_type' => 'user',
34 'type' => 'text_long',
38 'field_name' => 'signature',
39 'entity_type' => 'user',
45 'name' => 'Ford Prefect',
46 'mail' => 'ford.prefect@localhost',
49 'value' => 'Bring a towel.',
50 'format' => 'filtered_html',
53 'init' => 'proto@zo.an',
56 $this->executeMigrations(['d6_filter_format', 'd6_user_role']);
60 * Tests overwriting all mapped properties in the destination entity (default
63 public function testOverwriteAllMappedProperties() {
64 $this->executeMigration('d6_user');
65 /** @var \Drupal\user\UserInterface $account */
66 $account = User::load(2);
67 $this->assertIdentical('john.doe', $account->label());
68 $this->assertIdentical('john.doe@example.com', $account->getEmail());
69 $this->assertIdentical('doe@example.com', $account->getInitialEmail());
73 * Tests overwriting selected properties in the destination entity, specified
74 * in the destination configuration.
76 public function testOverwriteProperties() {
77 // Execute the migration in migrate_overwrite_test, which documents how
78 // property overwrites work.
79 $this->executeMigration('users');
81 /** @var \Drupal\user\UserInterface $account */
82 $account = User::load(2);
83 $this->assertIdentical('john.doe', $account->label());
84 $this->assertIdentical('john.doe@example.com', $account->getEmail());
85 $this->assertIdentical('The answer is 42.', $account->signature->value);
86 // This value is not overwritten because it's not listed in
87 // overwrite_properties.
88 $this->assertIdentical('proto@zo.an', $account->getInitialEmail());
92 * Test that translation destination fails for untranslatable entities.
94 public function testUntranslatable() {
95 $this->enableModules(['language_test']);
96 $this->installEntitySchema('no_language_entity_test');
98 /** @var MigrationInterface $migration */
99 $migration = \Drupal::service('plugin.manager.migration')->createStubMigration([
101 'plugin' => 'embedded_data',
102 'ids' => ['id' => ['type' => 'integer']],
103 'data_rows' => [['id' => 1]],
109 'plugin' => 'entity:no_language_entity_test',
110 'translations' => TRUE,
114 $message = $this->prophesize(MigrateMessageInterface::class);
115 // Match the expected message. Can't use default argument types, because
116 // we need to convert to string from TranslatableMarkup.
117 $argument = Argument::that(function ($msg) {
118 return strpos((string) $msg, htmlentities('The "no_language_entity_test" entity type does not support translations.')) !== FALSE;
120 $message->display($argument, Argument::any())
123 $executable = new MigrateExecutable($migration, $message->reveal());
124 $executable->import();