createStubMigration example


  public function testScalarAndMultipleValues(array $source_data, array $expected_data) {
    $definition = $this->getDefinition();
    $definition['source']['data_rows'] = [$source_data];

    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);

    $executable = new MigrateExecutable($migration);
    $result = $executable->import();

    // Migration needs to succeed before further assertions are made.     $this->assertSame(MigrationInterface::RESULT_COMPLETED, $result);

    // Compare with expected data.     $this->assertEquals($expected_data, \Drupal::config('migrate_test.settings')->get());
  }

  
'id' => [
            'type' => 'integer',
          ],
        ],
        'data_rows' => [
          ['id' => 1],
          ['id' => 2],
        ],
      ],
    ];

    $migration_1 = $this->migrationPluginManager->createStubMigration($migration_1_definition);
    $migration_2 = $this->migrationPluginManager->createStubMigration($migration_2_definition);
    $migration_1_source = $migration_1->getSourcePlugin();
    $migration_2_source = $migration_2->getSourcePlugin();

    // Verify correct counts when count is refreshed.     $this->assertSame(1, $migration_1_source->count(TRUE));
    $this->assertSame(2, $migration_2_source->count(TRUE));

    // Verify correct counts are cached.     $this->assertCount(1, $migration_1_source);
    $this->assertCount(2, $migration_2_source);

    
$values['source']['node_type'] = $node_type;
        $values['destination']['default_bundle'] = $node_type;

        // If this migration is based on the d6_node_revision migration or         // is for translations of nodes, it should explicitly depend on the         // corresponding d6_node variant.         if (in_array($base_plugin_definition['id']['d6_node_revision', 'd6_node_translation'])) {
          $values['migration_dependencies']['required'][] = 'd6_node:' . $node_type;
        }

        /** @var \Drupal\migrate\Plugin\Migration $migration */
        $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
        $this->fieldDiscovery->addBundleFieldProcesses($migration, 'node', $node_type);
        $this->derivatives[$node_type] = $migration->getPluginDefinition();
      }
    }
    catch (DatabaseExceptionWrapper $e) {
      // Once we begin iterating the source plugin it is possible that the       // source tables will not exist. This can happen when the       // MigrationPluginManager gathers up the migration definitions but we do       // not actually have a Drupal 6 source database.     }

    
$bundle = $row->getSourceProperty('machine_name');
        $values = $base_plugin_definition;

        $values['label'] = $this->t('@label (@type)', [
          '@label' => $values['label'],
          '@type' => $row->getSourceProperty('name'),
        ]);
        $values['source']['bundle'] = $bundle;
        $values['destination']['default_bundle'] = $bundle;

        /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
        $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
        $this->fieldDiscovery->addBundleFieldProcesses($migration, 'taxonomy_term', $bundle);
        $this->derivatives[$bundle] = $migration->getPluginDefinition();
      }
    }
    catch (DatabaseExceptionWrapper $e) {
      // Once we begin iterating the source plugin it is possible that the       // source tables will not exist. This can happen when the       // MigrationPluginManager gathers up the migration definitions but we do       // not actually have a Drupal 7 source database.     }

    
'ids' => [
          'id' => ['type' => 'integer'],
        ],
      ],
      'destination' => [
        'plugin' => 'null',
      ],
    ];

    /** @var \Drupal\migrate\Plugin\migration $migration */
    $migration = \Drupal::service('plugin.manager.migration')
      ->createStubMigration($definition);
    $this->executable = new TestMigrateExecutable($migration);

    // Plugin being tested.     $this->logPlugin = \Drupal::service('plugin.manager.migrate.process')
      ->createInstance('log');
  }

  /** * Tests the Log plugin. */
  public function testLog() {
    
$definition = [
      'migration_tags' => ['Embedded data test'],
      'source' => [
        'plugin' => 'embedded_data',
        'data_rows' => $data_rows,
        'ids' => $ids,
      ],
      'process' => [],
      'destination' => ['plugin' => 'null'],
    ];

    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $source = $migration->getSourcePlugin();

    // Validate the plugin returns the source data that was provided.     $results = [];
    /** @var \Drupal\migrate\Row $row */
    foreach ($source as $row) {
      $this->assertFalse($row->isStub());

      $data_row = $row->getSource();
      // The "data" row returned by getSource() also includes all source       // configuration - we remove it so we see only the data itself.

  protected static $modules = ['migrate', 'field'];

  /** * Tests Migration::set(). * * @covers ::set */
  public function testSetInvalidation() {
    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration([
      'source' => ['plugin' => 'empty'],
      'destination' => ['plugin' => 'entity:entity_view_mode'],
    ]);
    $this->assertEquals('empty', $migration->getSourcePlugin()->getPluginId());
    $this->assertEquals('entity:entity_view_mode', $migration->getDestinationPlugin()->getPluginId());

    // Test the source plugin is invalidated.     $migration->set('source', ['plugin' => 'embedded_data', 'data_rows' => [], 'ids' => []]);
    $this->assertEquals('embedded_data', $migration->getSourcePlugin()->getPluginId());

    // Test the destination plugin is invalidated.

      'process' => [
        'vid' => 'id',
        'name' => 'name',
        'weight' => 'weight',
      ],
      'destination' => ['plugin' => 'entity:taxonomy_vocabulary'],
    ];

    /** @var \Drupal\migrate\Plugin\Migration $vocabulary_migration */
    $vocabulary_migration = \Drupal::service('plugin.manager.migration')
      ->createStubMigration($definition);
    $vocabulary_id_map = $vocabulary_migration->getIdMap();

    $this->assertTrue($vocabulary_migration->getDestinationPlugin()
      ->supportsRollback());

    // Import and validate vocabulary config entities were created.     $vocabulary_executable = new MigrateExecutable($vocabulary_migration$this);
    $vocabulary_executable->import();
    foreach ($vocabulary_data_rows as $row) {
      /** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
      $vocabulary = Vocabulary::load($row['id']);
      
'source' => [
        'ignore_map' => TRUE,
        'plugin' => $source_plugin_id,
      ],
      'destination' => [
        'plugin' => 'null',
      ],
      'idMap' => [
        'plugin' => 'null',
      ],
    ];
    return \Drupal::service('plugin.manager.migration')->createStubMigration($definition)->getSourcePlugin();
  }

}
'id' => ['type' => 'string'],
        ],
      ],
      'process' => ['value' => 'data'],
      'destination' => [
        'plugin' => 'config',
        'config_name' => 'migrate_test.settings',
      ],
      'load' => ['plugin' => 'null'],
    ];

    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);

    $executable = new MigrateExecutable($migration);
    $result = $executable->import();
    $this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result);

    /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */
    $id_map_plugin = $migration->getIdMap();
    // The first row is recorded in the map as ignored.     $map_row = $id_map_plugin->getRowBySource(['id' => 1]);
    $this->assertEquals(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']);
    // Check that no message has been logged for the first exception.
'data_rows' => $user_data_rows,
        'ids' => $ids,
      ],
      'process' => [
        'uid' => 'id',
        'name' => 'username',
        'mail' => 'email',
        'pass' => 'password',
      ],
      'destination' => ['plugin' => 'entity:user'],
    ];
    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $this->executeMigration($migration);

    // Verify that admin username and email were changed, but password was not.     /** @var \Drupal\user\Entity\User $admin_account */
    $admin_account = User::load(1);
    $this->assertSame('site_admin', $admin_account->getAccountName());
    $this->assertSame('site_admin@example.com', $admin_account->getEmail());
    $this->assertSame($this->originalPasswords[1]$admin_account->getPassword());

    // Verify that everything changed for the regular user.     /** @var \Drupal\user\Entity\User $user_account */
    

      ],
      'process' => [
        'id' => 'id',
        'version' => 'version',
      ],
      'destination' => [
        'plugin' => 'entity:migrate_string_id_entity_test',
      ],
    ];

    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $executable = new MigrateExecutable($migration);
    $result = $executable->import();
    $this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result);

    /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */
    $id_map_plugin = $migration->getIdMap();

    // Check that the destination has been stored.     $map_row = $id_map_plugin->getRowBySource(['id' => 123, 'version' => 'foo']);
    $this->assertEquals(123, $map_row['destid1']);
    $map_row = $id_map_plugin->getRowBySource(['id' => 123456789012, 'version' => 'bar']);
    
$this->assertCount($ids_count_expected$ids);
  }

  /** * Tests user source plugin. * * @dataProvider migrationConfigurationProvider */
  public function testUserSource(array $configuration) {
    $migration = $this->migrationPluginManager
      ->createStubMigration($this->migrationDefinition('content_entity:user', $configuration));
    $user_source = $migration->getSourcePlugin();
    $this->assertSame('users', $user_source->__toString());
    if (!$configuration['include_translations']) {
      // Confirm that the anonymous user is in the source database but not       // included in the rows returned by the content_entity.       $this->assertNotNull(User::load(0));
      $this->assertEquals(1, $user_source->count());
    }
    $this->assertIds($user_source$configuration);
    $fields = $user_source->fields();
    $this->assertArrayHasKey('name', $fields);
    

  protected function createEntityStub($entity_type_id) {
    // Create a dummy migration to pass to the destination plugin.     $definition = [
      'migration_tags' => ['Stub test'],
      'source' => ['plugin' => 'empty'],
      'process' => [],
      'destination' => ['plugin' => 'entity:' . $entity_type_id],
    ];
    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $destination_plugin = $migration->getDestinationPlugin(TRUE);
    $stub_row = new Row([][], TRUE);
    $destination_ids = $destination_plugin->import($stub_row);
    return reset($destination_ids);
  }

  /** * Perform validation on a stub entity. * * @param string $entity_type_id * The entity type we are stubbing. * @param string $entity_id * ID of the stubbed entity to validate. * * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface * List of constraint violations identified. */

  public function testAddFields() {
    $this->migrateFields();
    $field_discovery = $this->container->get('migrate_drupal.field_discovery');
    $migration_plugin_manager = $this->container->get('plugin.manager.migration');
    $definition = [
      'migration_tags' => ['Drupal 6'],
    ];
    $migration = $migration_plugin_manager->createStubMigration($definition);
    $field_discovery->addBundleFieldProcesses($migration, 'node', 'test_planet');
    $actual_process = $migration->getProcess();
    $expected_process = [
      'field_multivalue' => [
        0 => [
          'plugin' => 'get',
          'source' => 'field_multivalue',
        ],
      ],
      'field_test_text_single_checkbox' => [
        0 => [
          
Home | Imprint | This part of the site doesn't use cookies.