lookupDestinationIds example

foreach ($users as $source) {
      $rids = Database::getConnection('default', 'migrate')
        ->select('users_roles', 'ur')
        ->fields('ur', ['rid'])
        ->condition('ur.uid', $source->uid)
        ->execute()
        ->fetchCol();
      $roles = [RoleInterface::AUTHENTICATED_ID];
      $id_map = $this->getMigration('d7_user_role')->getIdMap();
      foreach ($rids as $rid) {
        $role = $id_map->lookupDestinationIds([$rid])[0];
        $roles[] = reset($role);
      }

      $entity_translation = Database::getConnection('default', 'migrate')
        ->select('entity_translation', 'et')
        ->fields('et', ['language'])
        ->condition('et.entity_type', 'user')
        ->condition('et.entity_id', $source->uid)
        ->condition('et.source', '')
        ->execute()
        ->fetchField();
      

  public function testUrlAlias() {
    $id_map = $this->getMigration('d6_url_alias')->getIdMap();
    // Test that the field exists.     $conditions = [
      'path' => '/node/1',
      'alias' => '/alias-one',
      'langcode' => 'af',
    ];
    $path_alias = $this->loadPathAliasByConditions($conditions);
    $this->assertPath(1, $conditions$path_alias);
    $this->assertSame([['1']]$id_map->lookupDestinationIds([$path_alias->id()]), "Test IdMap");

    $conditions = [
      'path' => '/node/2',
      'alias' => '/alias-two',
      'langcode' => 'en',
    ];
    $path_alias = $this->loadPathAliasByConditions($conditions);
    $this->assertPath(2, $conditions$path_alias);

    // Test that we can re-import using the UrlAlias destination.     Database::getConnection('default', 'migrate')
      
/** * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration. */
  public function testVocabularyEntityFormDisplay() {
    $this->executeMigration('d6_vocabulary_entity_form_display');

    // Test that the field exists.     $component = EntityFormDisplay::load('node.page.default')->getComponent('field_tags');
    $this->assertSame('options_select', $component['type']);
    $this->assertSame(20, $component['weight']);
    // Test the Id map.     $this->assertSame([['node', 'article', 'default', 'field_tags']]$this->getMigration('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationIds([4, 'article']));

    // Test the term widget tags setting.     $entity_form_display = EntityFormDisplay::load('node.story.default');
    $this->assertSame($entity_form_display->getComponent('field_vocabulary_1_i_0_')['type'], 'options_select');
    $this->assertSame($entity_form_display->getComponent('field_vocabulary_2_i_1_')['type'], 'entity_reference_autocomplete_tags');

    // Tests that a vocabulary named like a D8 base field will be migrated and     // prefixed with 'field_' to avoid conflicts.     $field_type = EntityFormDisplay::load('node.sponsor.default')->getComponent('field_type');
    $this->assertIsArray($field_type);
  }

  
/** * Tests the lookup function. * * @covers ::lookup */
  public function testLookup() {
    $source_ids = ['id' => '1'];

    $destination_ids = [[2]];

    $id_map = $this->prophesize(MigrateIdMapInterface::class);
    $id_map->lookupDestinationIds($source_ids)->willReturn($destination_ids);

    $destination = $this->prophesize(MigrateDestinationInterface::class);
    $destination->getIds()->willReturn(['id' => ['type' => 'integer']]);

    $migration = $this->prophesize(MigrationInterface::class);
    $migration->getIdMap()->willReturn($id_map->reveal());
    $migration->getDestinationPlugin()->willReturn($destination->reveal());

    $plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
    $plugin_manager->createInstances('test_migration')->willReturn([$migration->reveal()]);

    


  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $language = $row->getSourceProperty('ltlanguage');
    $row->setSourceProperty('language', $language);
    $tid = $row->getSourceProperty('tid');

    // If this row has been migrated it is a duplicate then skip it.     if ($this->idMap->lookupDestinationIds(['tid' => $tid, 'language' => $language])) {
      return FALSE;
    }

    // Save the translation for this property.     $property = $row->getSourceProperty('property');
    $row->setSourceProperty($property . '_translated', $row->getSourceProperty('translation'));

    // Get the translation, if one exists, for the property not already in the     // row.     $other_property = ($property == 'name') ? 'description' : 'name';
    $query = $this->select('i18n_strings', 'i18n')
      
$this->assertSame('file_generic', $component['type']);

    $display = EntityFormDisplay::load('node.story.default');
    $component = $display->getComponent('upload');
    $this->assertSame('file_generic', $component['type']);

    // Assure this doesn't exist.     $display = EntityFormDisplay::load('node.article.default');
    $component = $display->getComponent('upload');
    $this->assertNull($component);

    $this->assertSame([['node', 'page', 'default', 'upload']]$this->getMigration('d6_upload_entity_form_display')->getIdMap()->lookupDestinationIds(['page']));
  }

  /** * Tests that entity displays are ignored appropriately. * * Entity displays should be ignored when they belong to node types which * were not migrated. */
  public function testSkipNonExistentNodeType() {
    // The "story" node type is migrated by d6_node_type but we need to pretend     // that it didn't occur, so record that in the map table.
if ($message = trim($e->getMessage())) {
            $msg = sprintf("%s:%s: %s", $this->migration->getPluginId()$destination_property_name$message);
            $this->saveMessage($msg, MigrationInterface::MESSAGE_INFORMATIONAL);
          }
          $save = FALSE;
        }

        if ($save) {
          try {
            $this->getEventDispatcher()
              ->dispatch(new MigratePreRowSaveEvent($this->migration, $this->message, $row), MigrateEvents::PRE_ROW_SAVE);
            $destination_ids = $id_map->lookupDestinationIds($this->sourceIdValues);
            $destination_id_values = $destination_ids ? reset($destination_ids) : [];
            $destination_id_values = $destination->import($row$destination_id_values);
            $this->getEventDispatcher()
              ->dispatch(new MigratePostRowSaveEvent($this->migration, $this->message, $row$destination_id_values), MigrateEvents::POST_ROW_SAVE);
            if ($destination_id_values) {
              // We do not save an idMap entry for config.               if ($destination_id_values !== TRUE) {
                $id_map->saveIdMapping($row$destination_id_values$this->sourceRowStatus, $destination->rollbackAction());
              }
            }
            else {
              
foreach ($users as $source) {
      // Get roles directly from the source.       $rids = Database::getConnection('default', 'migrate')
        ->select('users_roles', 'ur')
        ->fields('ur', ['rid'])
        ->condition('ur.uid', $source->uid)
        ->execute()
        ->fetchCol();
      $roles = [RoleInterface::AUTHENTICATED_ID];
      $id_map = $this->getMigration('d6_user_role')->getIdMap();
      foreach ($rids as $rid) {
        $role = $id_map->lookupDestinationIds([$rid])[0];
        $roles[] = reset($role);
      }

      /** @var \Drupal\user\UserInterface $user */
      $user = User::load($source->uid);
      $this->assertSame($source->uid, $user->id());
      $this->assertSame($source->name, $user->label());
      $this->assertSame($source->mail, $user->getEmail());
      $this->assertSame($source->created, $user->getCreatedTime());
      $this->assertSame($source->access, $user->getLastAccessedTime());
      $this->assertSame($source->login, $user->getLastLoginTime());
      
$field = FieldConfig::load($field_id);
    $this->assertSame($field_id$field->id(), 'Field instance exists on page bundle.');
    $this->assertSame('Tags', $field->label());
    $this->assertTrue($field->isRequired(), 'Field is required');
    $this->assertFalse($field->isTranslatable());

    $settings = $field->getSettings();
    $this->assertSame('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
    $this->assertTargetBundles($field_id['tags' => 'tags']);
    $this->assertTrue($settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');

    $this->assertSame([['node', 'article', 'field_tags']]$this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationIds([4, 'article']));

    // Test the field vocabulary_1_i_0_ with multilingual option,     // 'per language terms'.     $field_id = 'node.story.field_vocabulary_1_i_0_';
    $field = FieldConfig::load($field_id);
    $this->assertFalse($field->isRequired(), 'Field is not required');
    $this->assertTrue($field->isTranslatable());
    $this->assertTargetBundles($field_id['vocabulary_1_i_0_' => 'vocabulary_1_i_0_']);

    // Test the field vocabulary_2_i_0_ with multilingual option,     // 'Set language to vocabulary'.

  protected function assertRole(string $id, array $permissions, int $lookupId, MigrateIdMapInterface $id_map): void {
    /** @var \Drupal\user\RoleInterface $role */
    $role = Role::load($id);
    $this->assertInstanceOf(RoleInterface::class$role);
    $this->assertSame($permissions$role->getPermissions());
    $this->assertSame([[$id]]$id_map->lookupDestinationIds(['rid' => $lookupId]));
  }

  /** * Helper to assert the user roles. * * @param array $permissions * Contains the valid and invalid permissions. * @param \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map * The map table plugin. * * @internal */


  /** * Tests Drupal 6 view modes to Drupal 8 migration. */
  public function testViewModes() {
    // Test a new view mode.     $view_mode = EntityViewMode::load('node.preview');
    $this->assertNotNull($view_mode);
    $this->assertSame('Preview', $view_mode->label(), 'View mode has correct label.');
    // Test the ID map.     $this->assertSame([['node', 'preview']]$this->getMigration('d6_view_modes')->getIdMap()->lookupDestinationIds([1]));
  }

}
protected function setUp(): void {
    parent::setUp();
    $this->migrateFields();
  }

  /** * Tests the Drupal 6 upload settings to Drupal 8 field migration. */
  public function testUpload() {
    $field_storage = FieldStorageConfig::load('node.upload');
    $this->assertSame('node.upload', $field_storage->id());
    $this->assertSame([['node', 'upload']]$this->getMigration('d6_upload_field')->getIdMap()->lookupDestinationIds(['']));
  }

}
$this->assertSame('file_default', $component['type']);

    $display = EntityViewDisplay::load('node.story.default');
    $component = $display->getComponent('upload');
    $this->assertSame('file_default', $component['type']);

    // Assure this doesn't exist.     $display = EntityViewDisplay::load('node.article.default');
    $component = $display->getComponent('upload');
    $this->assertNull($component);

    $this->assertSame([['node', 'page', 'default', 'upload']]$this->getMigration('d6_upload_entity_display')->getIdMap()->lookupDestinationIds(['page']));
  }

  /** * Tests that entity displays are ignored appropriately. * * Entity displays should be ignored when they belong to node types which * were not migrated. */
  public function testSkipNonExistentNodeType() {
    // The "story" node type is migrated by d6_node_type but we need to pretend     // that it didn't occur, so record that in the map table.
$expected['settings']['format_type'] = 'fallback';
    $component = $display->getComponent('field_test_datetime');
    $this->assertSame($expected$component);

    // Test a date field with a random format which should be mapped     // to datetime_default.     $display = EntityViewDisplay::load('node.story.rss');
    $expected['settings']['format_type'] = 'fallback';
    $component = $display->getComponent('field_test_datetime');
    $this->assertSame($expected$component);
    // Test that our Id map has the correct data.     $this->assertSame([['node', 'story', 'teaser', 'field_test']]$this->getMigration('d6_field_formatter_settings')->getIdMap()->lookupDestinationIds(['story', 'teaser', 'node', 'field_test']));

    // Test hidden field.     $this->assertComponentNotExists('node.test_planet.teaser', 'field_test_text_single_checkbox');

    // Test a node reference field, which should be migrated to an entity     // reference field.     $display = EntityViewDisplay::load('node.employee.default');
    $component = $display->getComponent('field_company');
    $this->assertIsArray($component);
    $this->assertSame('entity_reference_label', $component['type']);
    // The default node reference formatter shows the referenced node's title
/** * @covers ::transform */
  public function testTransformWithStubSkipping() {
    $migration_plugin = $this->prophesize(MigrationInterface::class);
    $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);

    $destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
    $destination_migration = $this->prophesize(MigrationInterface::class);
    $destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
    $destination_id_map->lookupDestinationIds([1])->willReturn(NULL);

    // Ensure the migration plugin manager returns our migration.     $migration_plugin_manager->createInstances(Argument::exact(['destination_migration']))
      ->willReturn(['destination_migration' => $destination_migration->reveal()]);

    $configuration = [
      'no_stub' => TRUE,
      'migration' => 'destination_migration',
    ];

    $migration_plugin->id()->willReturn('actual_migration');
    
Home | Imprint | This part of the site doesn't use cookies.