Same name in this branch
  1. 10 core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php \Drupal\Tests\migrate_drupal\Kernel\d6\EntityContentBaseTest
  2. 10 core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php \Drupal\Tests\migrate\Unit\Plugin\migrate\destination\EntityContentBaseTest
Same name and namespace in other branches
  1. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php \Drupal\Tests\migrate_drupal\Kernel\d6\EntityContentBaseTest
  2. 9 core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php \Drupal\Tests\migrate_drupal\Kernel\d6\EntityContentBaseTest

@group migrate_drupal

Hierarchy

Expanded class hierarchy of EntityContentBaseTest

File

core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php, line 15

Namespace

Drupal\Tests\migrate_drupal\Kernel\d6
View source
class EntityContentBaseTest extends MigrateDrupal6TestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'migrate_overwrite_test',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    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' => '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',
    ]);
  }

  /**
   * Tests overwriting all mapped properties in the destination entity.
   *
   * This is the default behavior.
   */
  public function testOverwriteAllMappedProperties() {
    $this
      ->executeMigration('d6_user');

    /** @var \Drupal\user\UserInterface $account */
    $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());
  }

  /**
   * Tests overwriting selected properties in the destination entity.
   *
   * The selected properties are specified in the destination configuration.
   */
  public function testOverwriteProperties() {

    // Execute the migration in migrate_overwrite_test, which documents how
    // property overwrites work.
    $this
      ->executeMigration('users');

    /** @var \Drupal\user\UserInterface $account */
    $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 value is not overwritten because it's not listed in
    // overwrite_properties.
    $this
      ->assertSame('proto@zo.an', $account
      ->getInitialEmail());
  }

  /**
   * Tests that translation destination fails for untranslatable entities.
   */
  public function testUntranslatable() {
    $this
      ->enableModules([
      'language_test',
    ]);
    $this
      ->installEntitySchema('no_language_entity_test');

    /** @var MigrationInterface $migration */
    $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);

    // Match the expected message. Can't use default argument types, because
    // we need to convert to string from TranslatableMarkup.
    $argument = Argument::that(function ($msg) {
      return str_contains((string) $msg, htmlentities('The "no_language_entity_test" entity type does not support translations.'));
    });
    $message
      ->display($argument, Argument::any())
      ->shouldBeCalled();
    $executable = new MigrateExecutable($migration, $message
      ->reveal());
    $executable
      ->import();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityContentBaseTest::$modules protected static property Modules to enable. Overrides MigrateDrupal6TestBase::$modules
EntityContentBaseTest::setUp protected function Overrides MigrateDrupal6TestBase::setUp
EntityContentBaseTest::testOverwriteAllMappedProperties public function Tests overwriting all mapped properties in the destination entity.
EntityContentBaseTest::testOverwriteProperties public function Tests overwriting selected properties in the destination entity.
EntityContentBaseTest::testUntranslatable public function Tests that translation destination fails for untranslatable entities.
MigrateDrupal6TestBase::getFixtureFilePath protected function Gets the path to the fixture file. 13
MigrateDrupal6TestBase::migrateContent protected function Executes all content migrations.
MigrateDrupal6TestBase::migrateContentTypes protected function Migrates node types.
MigrateDrupal6TestBase::migrateFields protected function Executes all field migrations.
MigrateDrupal6TestBase::migrateTaxonomy protected function Executes all taxonomy migrations.
MigrateDrupal6TestBase::migrateUsers protected function Executes all user migrations.
MigrateDrupalTestBase::loadFixture protected function Loads a database fixture into the source database connection.
MigrateTestBase::$collectMessages protected property TRUE to collect messages instead of displaying them.
MigrateTestBase::$logger protected property A logger prophecy object. 2
MigrateTestBase::$migrateMessages protected property A two dimensional array of messages.
MigrateTestBase::$migration protected property The primary migration being tested. 1
MigrateTestBase::$sourceDatabase protected property The source database connection.
MigrateTestBase::cleanupMigrateConnection private function Cleans up the test migrate connection.
MigrateTestBase::createMigrationConnection private function Changes the database connection to the prefixed one.
MigrateTestBase::display public function Displays a migrate message. Overrides MigrateMessageInterface::display
MigrateTestBase::executeMigration protected function Executes a single migration.
MigrateTestBase::executeMigrations protected function Executes a set of migrations in dependency order.
MigrateTestBase::getMigration protected function Gets the migration plugin.
MigrateTestBase::mockFailure protected function Records a failure in the map table of a specific migration.
MigrateTestBase::prepareMigration protected function Modify a migration's configuration before executing it.
MigrateTestBase::prepareMigrations protected function Prepare any dependent migrations.
MigrateTestBase::setTestLogger protected function Injects the test logger into the container.
MigrateTestBase::startCollectingMessages public function Start collecting messages and erase previous messages.
MigrateTestBase::stopCollectingMessages public function Stop collecting messages.
MigrateTestBase::tearDown protected function
NodeMigrateTypeTestTrait::$tableName public property The migrate_map table name.
NodeMigrateTypeTestTrait::getTableName protected function Gets the migrate_map table name.
NodeMigrateTypeTestTrait::makeNodeMigrateMapTable protected function Create a node migrate_map table.
NodeMigrateTypeTestTrait::nodeMigrateMapTableCount protected function Gets the numbers of complete and classic node migrate_map tables.
NodeMigrateTypeTestTrait::removeNodeMigrateMapTable protected function Remove the node migrate map table.