View source
<?php
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessageInterface;
use Drupal\user\Entity\User;
use Prophecy\Argument;
class EntityContentBaseTest extends MigrateDrupal6TestBase {
protected static $modules = [
'migrate_overwrite_test',
];
protected function setUp() : void {
parent::setUp();
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' => 'Ford Prefect',
'mail' => 'ford.prefect@localhost',
'signature' => [
[
'value' => 'Bring a towel.',
'format' => 'filtered_html',
],
],
'init' => 'proto@zo.an',
])
->save();
$this
->executeMigrations([
'd6_filter_format',
'd6_user_role',
]);
}
public function testOverwriteAllMappedProperties() {
$this
->executeMigration('d6_user');
$account = User::load(2);
$this
->assertSame('john.doe', $account
->label());
$this
->assertSame('john.doe@example.com', $account
->getEmail());
$this
->assertSame('doe@example.com', $account
->getInitialEmail());
}
public function testOverwriteProperties() {
$this
->executeMigration('users');
$account = User::load(2);
$this
->assertSame('john.doe', $account
->label());
$this
->assertSame('john.doe@example.com', $account
->getEmail());
$this
->assertSame('The answer is 42.', $account->signature->value);
$this
->assertSame('proto@zo.an', $account
->getInitialEmail());
}
public function testUntranslatable() {
$this
->enableModules([
'language_test',
]);
$this
->installEntitySchema('no_language_entity_test');
$migration = \Drupal::service('plugin.manager.migration')
->createStubMigration([
'source' => [
'plugin' => 'embedded_data',
'ids' => [
'id' => [
'type' => 'integer',
],
],
'data_rows' => [
[
'id' => 1,
],
],
],
'process' => [
'id' => 'id',
],
'destination' => [
'plugin' => 'entity:no_language_entity_test',
'translations' => TRUE,
],
]);
$message = $this
->prophesize(MigrateMessageInterface::class);
$argument = Argument::that(function ($msg) {
return strpos((string) $msg, htmlentities('The "no_language_entity_test" entity type does not support translations.')) !== FALSE;
});
$message
->display($argument, Argument::any())
->shouldBeCalled();
$executable = new MigrateExecutable($migration, $message
->reveal());
$executable
->import();
}
}