createInstancesByTag example

$this->assertInstanceOf(AuditResult::class$result);
      $this->assertTrue($result->passed());
    }
  }

  /** * Tests all migrations with no ID conflicts. */
  public function testAllMigrationsWithNoIdConflicts() {
    $migrations = $this->container
      ->get('plugin.manager.migration')
      ->createInstancesByTag('Drupal 6');

    // Audit all Drupal 6 migrations that support it. There should be no     // conflicts since no content has been created.     $results = (new IdAuditor())->auditMultiple($migrations);
    /** @var \Drupal\migrate\Audit\AuditResult $result */
    foreach ($results as $result) {
      $this->assertInstanceOf(AuditResult::class$result);
      $this->assertTrue($result->passed());
    }
  }

  
parent::setUp();
  }

  /** * Tests that calling getProcess() on a migration does not throw an exception. * * @throws \Exception */
  public function testGetProcess() {
    /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */
    $plugin_manager = $this->container->get('plugin.manager.migration');
    $migrations = $plugin_manager->createInstancesByTag('Drupal 7');
    foreach ($migrations as $migration) {
      try {
        $process = $migration->getProcess();
      }
      catch (\Exception $e) {
        $this->fail(sprintf("Migration %s process failed with error: %s", $migration->label()$e->getMessage()));
      }
      $this->assertNotNull($process);
    }
  }

}
// Assert the correct number of entities exists.     $actual_entity_counts = [];
    foreach ($entity_definitions as $entity_type) {
      $actual_entity_counts[$entity_type] = (int) \Drupal::entityQuery($entity_type)->accessCheck(FALSE)->count()->execute();
    }
    $this->assertSame($entity_counts$actual_entity_counts);

    $plugin_manager = \Drupal::service('plugin.manager.migration');
    $version = $this->getLegacyDrupalVersion($this->sourceDatabase);
    /** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
    $all_migrations = $plugin_manager->createInstancesByTag('Drupal ' . $version);
    foreach ($all_migrations as $migration) {
      $id_map = $migration->getIdMap();
      foreach ($id_map as $source_id => $map) {
        // Convert $source_id into a keyless array so that         // \Drupal\migrate\Plugin\migrate\id_map\Sql::getSourceHash() works as         // expected.         $source_id_values = array_values(unserialize($source_id));
        $row = $id_map->getRowBySource($source_id_values);
        $destination = serialize($id_map->currentDestination());
        $message = "Migration of $source_id to $destination as part of the {$migration->id()} migration. The source row status is " . $row['source_row_status'];
        // A completed migration should have maps with

  protected function getMigrations($database_state_key$drupal_version) {
    $version_tag = 'Drupal ' . $drupal_version;
    /** @var \Drupal\migrate\Plugin\MigrationInterface[] $all_migrations */
    $all_migrations = $this->getMigrationPluginManager()->createInstancesByTag($version_tag);

    // Unset the node migrations that should not run based on the type of node     // migration. That is, if this is a complete node migration then unset the     // classic node migrations and if this is a classic node migration then     // unset the complete node migrations.     $type = NodeMigrateType::getNodeMigrateType(\Drupal::database()$drupal_version);
    switch ($type) {
      case NodeMigrateType::NODE_MIGRATE_TYPE_COMPLETE:
        $patterns = '/(d' . $drupal_version . '_node:)|(d' . $drupal_version . '_node_translation:)|(d' . $drupal_version . '_node_revision:)|(d7_node_entity_translation:)/';
        break;

      
/** * Create instances of all Drupal 6 migrations. * * @return \Drupal\migrate\Plugin\MigrationInterface[] * The migrations */
  public function drupal6Migrations() {
    $dirs = \Drupal::service('module_handler')->getModuleDirectories();
    $migrate_drupal_directory = $dirs['migrate_drupal'];
    $this->loadFixture("$migrate_drupal_directory/tests/fixtures/drupal6.php");
    return \Drupal::service('plugin.manager.migration')->createInstancesByTag('Drupal 6');
  }

  /** * Create instances of all Drupal 7 migrations. * * @return \Drupal\migrate\Plugin\MigrationInterface[] * The migrations */
  public function drupal7Migrations() {
    $dirs = \Drupal::service('module_handler')->getModuleDirectories();
    $migrate_drupal_directory = $dirs['migrate_drupal'];
    

  public function testCreateInstancesByTag($tags$expected) {
    // The test module includes a migration that does not use the migration_tags     // property. It is there to confirm that it is not included in the results.     // We create it to ensure it is a valid migration.     $migration = $this->migrationPluginManager->createInstances(['tag_test_no_tag']);
    $this->assertArrayHasKey('tag_test_no_tag', $migration);
    $migrations = $this->migrationPluginManager->createInstancesByTag($tags);
    $actual = array_keys($migrations);
    $this->assertSame($expected$actual);
  }

  /** * Data provider for testCreateInstancesByTag. */
  public function providerCreateInstanceByTag() {
    return [
      'get test' => [
        'test',
        [
$this->enableAllModules();

    $version = (string) $this->getLegacyDrupalVersion($this->sourceDatabase);

    // Build an array for each migration keyed by provider. The value is a     // string consisting of the version number, the provider, the source_module     // and the destination module.     $discovered = [];
    /** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
    $plugin_manager = $this->container->get('plugin.manager.migration');
    $migrations = $plugin_manager->createInstancesByTag('Drupal ' . $version);
    /** @var \Drupal\migrate\Plugin\Migration $migration */
    foreach ($migrations as $migration) {
      $definition = $migration->getPluginDefinition();
      if (is_array($definition['provider'])) {
        $provider = reset($definition['provider']);
      }
      else {
        $provider = $definition['provider'];
      }

      $source_module = $migration->getSourcePlugin()->getSourceModule();
      
parent::setUp();
  }

  /** * Tests that calling getProcess() on a migration does not throw an exception. * * @throws \Exception */
  public function testGetProcess() {
    /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */
    $plugin_manager = $this->container->get('plugin.manager.migration');
    $migrations = $plugin_manager->createInstancesByTag('Drupal 6');
    foreach ($migrations as $migration) {
      try {
        $process = $migration->getProcess();
      }
      catch (\Exception $e) {
        $this->fail(sprintf("Migration %s process failed with error: %s", $migration->label()$e->getMessage()));
      }
      $this->assertNotNull($process);
    }
  }

}
$this->assertInstanceOf(AuditResult::class$result);
      $this->assertTrue($result->passed());
    }
  }

  /** * Tests all migrations with no ID conflicts. */
  public function testAllMigrationsWithNoIdConflicts() {
    $migrations = $this->container
      ->get('plugin.manager.migration')
      ->createInstancesByTag('Drupal 7');

    // Audit the IDs of all Drupal 7 migrations. There should be no conflicts     // since no content has been created.     $results = (new IdAuditor())->auditMultiple($migrations);
    /** @var \Drupal\migrate\Audit\AuditResult $result */
    foreach ($results as $result) {
      $this->assertInstanceOf(AuditResult::class$result);
      $this->assertTrue($result->passed());
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.