getMigration example

->execute()
      ->fetchAll();

    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', '')
        
// Default implementation for test classes not requiring modification.   }

  /** * Executes a single migration. * * @param string|\Drupal\migrate\Plugin\MigrationInterface $migration * The migration to execute, or its ID. */
  protected function executeMigration($migration) {
    if (is_string($migration)) {
      $this->migration = $this->getMigration($migration);
    }
    else {
      $this->migration = $migration;
    }
    if ($this instanceof MigrateDumpAlterInterface) {
      static::migrateDumpAlter($this);
    }

    $this->prepareMigration($this->migration);
    (new MigrateExecutable($this->migration, $this))->import();
  }

  
$this->assertSame('menu_link_content', $config->getTargetBundle());
    $this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
    $this->assertTrue($config->isLanguageAlterable());

    // Test that menus are not alterable when the i18nmenu is not enabled.     $this->sourceDatabase->update('system')
      ->fields(['status' => 0])
      ->condition('name', 'i18nmenu')
      ->execute();

    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('d6_language_content_menu_settings');
    // Indicate we're rerunning a migration that's already run.     $migration->getIdMap()->prepareUpdate();
    $this->executeMigration($migration);

    $config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
    $this->assertSame('menu_link_content', $config->getTargetBundle());
    $this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
    $this->assertFalse($config->isLanguageAlterable());
  }

}
parent::setUp();
    $this->executeMigration('d6_taxonomy_vocabulary');
  }

  /** * Tests the Drupal 6 taxonomy vocabularies to Drupal 8 migration. */
  public function testTaxonomyVocabulary() {
    for ($i = 0; $i < 3; $i++) {
      $j = $i + 1;
      $vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
      $this->assertSame($this->getMigration('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationIds([$j])[[$vocabulary->id()]]);
      $this->assertSame("vocabulary $j (i=$i)", $vocabulary->label());
      $this->assertSame("description of vocabulary $j (i=$i)", $vocabulary->getDescription());
      $this->assertSame(4 + $i$vocabulary->get('weight'));
    }
    $vocabulary = Vocabulary::load('vocabulary_name_much_longer_th');
    $this->assertSame('vocabulary name much longer than thirty two characters', $vocabulary->label());
    $this->assertSame('description of vocabulary name much longer than thirty two characters', $vocabulary->getDescription());
    $this->assertSame(7, $vocabulary->get('weight'));
  }

}
$migration_ids = array_keys($migrations);
    // Check if there are conflicts. If none, just skip this form!     $migrations = $this->migrationPluginManager->createInstances($migration_ids);

    $translated_content_conflicts = $content_conflicts = [];

    $results = (new IdAuditor())->auditMultiple($migrations);

    /** @var \Drupal\migrate\Audit\AuditResult $result */
    foreach ($results as $result) {
      $destination = $result->getMigration()->getDestinationPlugin();
      if ($destination instanceof EntityContentBase && $destination->isTranslationDestination()) {
        // Translations are not yet supported by the audit system. For now, we         // only warn the user to be cautious when migrating translated content.         // I18n support should be added in https://www.drupal.org/node/2905759.         $translated_content_conflicts[] = $result;
      }
      elseif (!$result->passed()) {
        $content_conflicts[] = $result;
      }
    }

    
protected function setUp(): void {
    parent::setUp();
    $this->sourceDatabase->schema()->dropTable('i18n_variable');
  }

  /** * Tests exception in thrown when the i18n_variable table does not exist. */
  public function testCheckRequirements() {
    $this->expectException(RequirementsException::class);
    $this->expectExceptionMessage("Source database table 'i18n_variable' does not exist");
    $this->getMigration('d6_system_maintenance_translation')
      ->getSourcePlugin()
      ->checkRequirements();
  }

}
$this->cleanUpSalesChannels();

        $this->languages = $this->fetchLanguages();

        $this->createSalesChannels();
        $this->createUserForEachLanguage();
    }

    public function testMigrationCopiesSalesChannelIdsIntoUserConfig(): void
    {
        $migration = $this->getMigration();
        $migration->update($this->connection);

        $expectedIds = $this->fetchExpectedSalesChannelIds(array_values($this->languages));
        $configs = $this->fetchConfigs();

        foreach ($configs as $locale => $config) {
            $language = $this->languages[$locale];

            $actual = json_decode((string) $config, null, 512, \JSON_THROW_ON_ERROR);
            $expected = \array_slice($expectedIds[$language], 0, self::MAX_RESULTS);

            
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $plugin = 'placeholder_id';
    /** @var \Drupal\Core\State\StateInterface $state */
    $state = $this->createMock('Drupal\Core\State\StateInterface');
    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
    $entity_type_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface');
    $this->base = new TestDrupal6SqlBase($this->migrationConfiguration, $plugin[]$this->getMigration()$state$entity_type_manager);
    $this->base->setDatabase($this->getDatabase($this->databaseContents));
  }

  /** * Tests for Drupal6SqlBase::getSystemData(). */
  public function testGetSystemData() {
    $system_data = $this->base->getSystemData();
    // Should be 1 theme and 2 modules.     $this->assertCount(1, $system_data['theme']);
    $this->assertCount(2, $system_data['module']);

    

  protected $memoryLimit = 10000000;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->migration = $this->getMigration();
    $this->message = $this->createMock('Drupal\migrate\MigrateMessageInterface');

    $this->executable = new TestMigrateExecutable($this->migration, $this->message);
    $this->executable->setStringTranslation($this->getStringTranslationStub());
  }

  /** * Runs the actual test. * * @param string $message * The second message to assert. * @param bool $memory_exceeded * Whether to test the memory exceeded case. * @param int|null $memory_usage_first * (optional) The first memory usage value. Defaults to NULL. * @param int|null $memory_usage_second * (optional) The fake amount of memory usage reported after memory reclaim. * Defaults to NULL. * @param int|null $memory_limit * (optional) The memory limit. Defaults to NULL. */

class UserMigrationClassTest extends MigrateDrupal7TestBase {

  /** * Tests that the profile value process is added to the pipeline. * * Ensures profile fields are merged into the d7_profile_values migration's * process pipeline. */
  public function testClass() {
    $migration = $this->getMigration('d7_user');
    /** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
    $this->assertSame('d7_user', $migration->id());
    $process = $migration->getProcess();
    $this->assertSame('field_file', $process['field_file'][0]['source']);
  }

}


    foreach ($user_register_map as $map) {
      // Tests migration of user_register = 1.       Database::getConnection('default', 'migrate')
        ->update('variable')
        ->fields(['value' => serialize($map[0])])
        ->condition('name', 'user_register')
        ->execute();

      /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
      $migration = $this->getMigration('d7_user_settings');
      // Indicate we're rerunning a migration that's already run.       $migration->getIdMap()->prepareUpdate();
      $this->executeMigration($migration);
      $form = $this->container->get('form_builder')->getForm(AccountSettingsForm::create($this->container));
      $this->assertSame($map[1]$form['registration_cancellation']['user_register']['#value']);
    }
  }

}
$long_date_format = DateFormat::load('long');
    $this->assertSame('\L\O\N\G l, F j, Y - H:i', $long_date_format->getPattern());

    // Test that we can re-import using the EntityDateFormat destination.     Database::getConnection('default', 'migrate')
      ->update('variable')
      ->fields(['value' => serialize('\S\H\O\R\T d/m/Y - H:i')])
      ->condition('name', 'date_format_short')
      ->execute();

    $migration = $this->getMigration('d6_date_formats');
    \Drupal::database()
      ->truncate($migration->getIdMap()->mapTableName())
      ->execute();

    $this->executeMigration($migration);

    $short_date_format = DateFormat::load('short');
    $this->assertSame('\S\H\O\R\T d/m/Y - H:i', $short_date_format->getPattern());

  }

}

  public function testCheckCommentTypeRequirements(array $disabled_source_modules, string $exception_message, string $migration_plugin_id) {
    if (!empty($disabled_source_modules)) {
      $this->sourceDatabase->update('system')
        ->condition('name', $disabled_source_modules, 'IN')
        ->fields(['status' => 0])
        ->execute();
    }

    $this->expectException(RequirementsException::class);
    $this->expectExceptionMessage($exception_message);
    $this->getMigration($migration_plugin_id)
      ->getSourcePlugin()
      ->checkRequirements();
  }

  /** * Test cases for ::testCheckCommentTypeRequirements(). */
  public function providerTestCheckCommentTypeRequirements() {
    return [
      'D6 comment is disabled on source' => [
        'Disabled source modules' => ['comment'],
        
The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users. EOT;
    $this->assertSame($expected$navigation_menu->getDescription());

    // Test that we can re-import using the ConfigEntityBase destination.     Database::getConnection('default', 'migrate')
      ->update('menu_custom')
      ->fields(['title' => 'Home Navigation'])
      ->condition('menu_name', 'navigation')
      ->execute();

    $migration = $this->getMigration('d6_menu');
    \Drupal::database()
      ->truncate($migration->getIdMap()->mapTableName())
      ->execute();
    $this->executeMigration($migration);

    $navigation_menu = Menu::load('navigation');
    $this->assertSame('Home Navigation', $navigation_menu->label());
  }

}

  protected $migrationConfiguration = [
    'id' => 'test',
  ];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    static::$idMapRecords = [];
    $this->migration = $this->getMigration();
    $this->message = $this->createMock('Drupal\migrate\MigrateMessageInterface');
    $this->eventDispatcher = $this->createMock('Symfony\Contracts\EventDispatcher\EventDispatcherInterface');
    $this->executable = new TestMigrateExecutable($this->migration, $this->message, $this->eventDispatcher);
    $this->executable->setStringTranslation($this->getStringTranslationStub());
  }

  /** * Tests an import with an incomplete rewinding. */
  public function testImportWithFailingRewind() {
    $exception_message = $this->getRandomGenerator()->string();
    
Home | Imprint | This part of the site doesn't use cookies.