コード例 #1
0
ファイル: MigrationTest.php プロジェクト: ddrozdik/dmaps
 /**
  * @covers ::calculateDependencies
  */
 public function testCalculateDependencies()
 {
     $fixture_migrations = ['d6_node__article' => 'd6_node', 'd6_node__page' => 'd6_node', 'd6_variables' => 'd6_variables'];
     foreach ($fixture_migrations as $id => $template) {
         $values = ['id' => $id, 'template' => $template, 'source' => ['plugin' => 'empty'], 'destination' => ['plugin' => 'null'], 'migration_tags' => []];
         Migration::create($values)->save();
     }
     $values = ['migration_dependencies' => ['required' => ['d6_node:*', 'd6_variables']], 'source' => ['plugin' => 'empty'], 'destination' => ['plugin' => 'null']];
     $migration = new Migration($values, 'migration');
     $expected = ['migrate.migration.d6_node__article', 'migrate.migration.d6_node__page', 'migrate.migration.d6_variables'];
     $migration->calculateDependencies();
     $this->assertEquals($expected, $migration->getDependencies()['config']);
 }
コード例 #2
0
 /**
  * Asserts various aspects of a migration entity.
  *
  * @param string $id
  *   The migration ID.
  * @param string $label
  *   The label.
  */
 protected function assertEntity($id, $label)
 {
     $migration = Migration::load($id);
     $this->assertTrue($migration instanceof Migration);
     $this->assertIdentical($id, $migration->Id());
     $this->assertIdentical($label, $migration->label());
 }
コード例 #3
0
 /**
  * Tests creation of stubs when weight is mapped.
  */
 public function testStubWithWeightMapping()
 {
     // Create a vocabulary via migration for the terms to reference.
     $vocabulary_data_rows = [['id' => '1', 'name' => 'tags']];
     $ids = ['id' => ['type' => 'integer']];
     $config = ['id' => 'vocabularies', 'migration_tags' => ['Stub test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => $vocabulary_data_rows, 'ids' => $ids], 'process' => ['vid' => 'id', 'name' => 'name'], 'destination' => ['plugin' => 'entity:taxonomy_vocabulary']];
     $vocabulary_migration = Migration::create($config);
     $vocabulary_executable = new MigrateExecutable($vocabulary_migration, $this);
     $vocabulary_executable->import();
     // We have a term referencing an unmigrated parent, forcing a stub to be
     // created.
     $term_data_rows = [['id' => '1', 'vocab' => '1', 'name' => 'music', 'parent' => '2']];
     $ids = ['id' => ['type' => 'integer']];
     $config = ['id' => 'terms', 'migration_tags' => ['Import and rollback test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => $term_data_rows, 'ids' => $ids], 'process' => ['tid' => 'id', 'vid' => 'vocab', 'name' => 'name', 'weight' => 'weight', 'parent' => ['plugin' => 'migration', 'migration' => 'terms', 'source' => 'parent']], 'destination' => ['plugin' => 'entity:taxonomy_term'], 'migration_dependencies' => ['required' => ['vocabularies']]];
     $term_migration = Migration::create($config);
     $term_migration->save();
     $term_executable = new MigrateExecutable($term_migration, $this);
     $term_executable->import();
     // Load the referenced term, which should exist as a stub.
     /** @var \Drupal\Core\Entity\ContentEntityBase $stub_entity */
     $stub_entity = Term::load(2);
     $this->assertTrue($stub_entity, 'Stub successfully created');
     if ($stub_entity) {
         $this->assertIdentical(count($stub_entity->validate()), 0, 'Stub is a valid entity');
     }
 }
コード例 #4
0
ファイル: CckMigration.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function buildMigrations(array $template)
 {
     $migration = Migration::create($template);
     $source_plugin = $migration->getSourcePlugin();
     // The source plugin will throw RequirementsException if CCK is not enabled,
     // in which case there is nothing else for us to do.
     if ($source_plugin instanceof RequirementsInterface) {
         try {
             $source_plugin->checkRequirements();
         } catch (RequirementsException $e) {
             return [$migration];
         }
     }
     // Loop through every field that will be migrated.
     foreach ($source_plugin as $field) {
         $field_type = $field->getSourceProperty('type');
         // Each field type should only be processed once.
         if (in_array($field_type, $this->processedFieldTypes)) {
             continue;
         } elseif ($this->cckPluginManager->hasDefinition($field_type)) {
             $this->processedFieldTypes[] = $field_type;
             // Allow the cckfield plugin to alter the migration as necessary so that
             // it knows how to handle fields of this type.
             $this->cckPluginManager->createInstance($field_type, [], $migration)->{$this->configuration['cck_plugin_method']}($migration);
         }
     }
     return [$migration];
 }
コード例 #5
0
 /**
  * Test node migration from Drupal 6 to 8.
  */
 public function testNode()
 {
     $node = Node::load(1);
     $this->assertIdentical('1', $node->id(), 'Node 1 loaded.');
     $this->assertIdentical('und', $node->langcode->value);
     $this->assertIdentical('test', $node->body->value);
     $this->assertIdentical('test', $node->body->summary);
     $this->assertIdentical('filtered_html', $node->body->format);
     $this->assertIdentical('story', $node->getType(), 'Node has the correct bundle.');
     $this->assertIdentical('Test title', $node->getTitle(), 'Node has the correct title.');
     $this->assertIdentical('1388271197', $node->getCreatedTime(), 'Node has the correct created time.');
     $this->assertIdentical(FALSE, $node->isSticky());
     $this->assertIdentical('1', $node->getOwnerId());
     $this->assertIdentical('1420861423', $node->getRevisionCreationTime());
     /** @var \Drupal\node\NodeInterface $node_revision */
     $node_revision = \Drupal::entityManager()->getStorage('node')->loadRevision(1);
     $this->assertIdentical('Test title', $node_revision->getTitle());
     $this->assertIdentical('1', $node_revision->getRevisionAuthor()->id(), 'Node revision has the correct user');
     // This is empty on the first revision.
     $this->assertIdentical(NULL, $node_revision->revision_log->value);
     // Test that we can re-import using the EntityContentBase destination.
     $connection = Database::getConnection('default', 'migrate');
     $connection->update('node_revisions')->fields(array('title' => 'New node title', 'format' => 2))->condition('vid', 1)->execute();
     $connection->delete('content_field_test_two')->condition('delta', 1)->execute();
     $migration = Migration::load('d6_node__story');
     $this->executeMigration($migration);
     $node = Node::load(1);
     $this->assertIdentical('New node title', $node->getTitle());
     // Test a multi-column fields are correctly upgraded.
     $this->assertIdentical('test', $node->body->value);
     $this->assertIdentical('full_html', $node->body->format);
 }
コード例 #6
0
 /**
  * Displays a listing of migration messages.
  *
  * Messages are truncated at 56 chars.
  *
  * @return array
  *   A render array as expected by drupal_render().
  */
 public function overview($migration_group, $migration)
 {
     $rows = [];
     $classes = static::getLogLevelClassMap();
     /** @var MigrationInterface $migration */
     $migration = Migration::load($migration);
     $source_id_field_names = array_keys($migration->getSourcePlugin()->getIds());
     $column_number = 1;
     foreach ($source_id_field_names as $source_id_field_name) {
         $header[] = ['data' => $source_id_field_name, 'field' => 'sourceid' . $column_number++, 'class' => [RESPONSIVE_PRIORITY_MEDIUM]];
     }
     $header[] = ['data' => $this->t('Severity level'), 'field' => 'level', 'class' => [RESPONSIVE_PRIORITY_LOW]];
     $header[] = ['data' => $this->t('Message'), 'field' => 'message'];
     $message_table = $migration->getIdMap()->messageTableName();
     $query = $this->database->select($message_table, 'm')->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
     $query->fields('m');
     $result = $query->limit(50)->orderByHeader($header)->execute();
     foreach ($result as $message_row) {
         $column_number = 1;
         foreach ($source_id_field_names as $source_id_field_name) {
             $column_name = 'sourceid' . $column_number++;
             $row[$column_name] = $message_row->{$column_name};
         }
         $row['level'] = $message_row->level;
         $row['message'] = $message_row->message;
         $row['class'] = [Html::getClass('migrate-message-' . $message_row->level), $classes[$message_row->level]];
         $rows[] = $row;
     }
     $build['message_table'] = ['#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => ['id' => $message_table, 'class' => [$message_table]], '#empty' => $this->t('No messages for this migration.')];
     $build['message_pager'] = ['#type' => 'pager'];
     return $build;
 }
コード例 #7
0
ファイル: Node.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function buildMigrations(array $template)
 {
     $migrations = [];
     // Read all field instance definitions in the source database.
     $fields = array();
     foreach ($this->getSourcePlugin('d7_field_instance', $template['source']) as $field) {
         $info = $field->getSource();
         $fields[$info['entity_type']][$info['bundle']][$info['field_name']] = $info;
     }
     foreach ($this->getSourcePlugin('d7_node_type', $template['source']) as $node_type) {
         $bundle = $node_type->getSourceProperty('type');
         $values = $template;
         $values['id'] .= '__' . $bundle;
         $values['label'] = $this->t('@label (@type)', ['@label' => $values['label'], '@type' => $node_type->getSourceProperty('name')]);
         $values['source']['node_type'] = $bundle;
         $migration = Migration::create($values);
         if (isset($fields['node'][$bundle])) {
             foreach ($fields['node'][$bundle] as $field => $data) {
                 if ($this->cckPluginManager->hasDefinition($data['type'])) {
                     $this->getCckPlugin($data['type'])->processCckFieldValues($migration, $field, $data);
                 } else {
                     $migration->setProcessOfProperty($field, $field);
                 }
             }
         }
         $migrations[] = $migration;
     }
     return $migrations;
 }
コード例 #8
0
 /**
  * Tests Drupal 6 node type to Drupal 8 migration.
  */
 public function testNodeType()
 {
     $id_map = Migration::load('d6_node_type')->getIdMap();
     // Test the test_page content type.
     $node_type_page = NodeType::load('test_page');
     $this->assertIdentical('test_page', $node_type_page->id(), 'Node type test_page loaded');
     $this->assertIdentical(TRUE, $node_type_page->displaySubmitted());
     $this->assertIdentical(FALSE, $node_type_page->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
     $this->assertIdentical($id_map->lookupDestinationID(array('test_page')), array('test_page'));
     // Test we have a body field.
     $field = FieldConfig::loadByName('node', 'test_page', 'body');
     $this->assertIdentical('This is the body field label', $field->getLabel(), 'Body field was found.');
     // Test the test_story content type.
     $node_type_story = NodeType::load('test_story');
     $this->assertIdentical('test_story', $node_type_story->id(), 'Node type test_story loaded');
     $this->assertIdentical(TRUE, $node_type_story->displaySubmitted());
     $this->assertIdentical(FALSE, $node_type_story->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
     $this->assertIdentical($id_map->lookupDestinationID(array('test_story')), array('test_story'));
     // Test we don't have a body field.
     $field = FieldConfig::loadByName('node', 'test_story', 'body');
     $this->assertIdentical(NULL, $field, 'No body field found');
     // Test the test_event content type.
     $node_type_event = NodeType::load('test_event');
     $this->assertIdentical('test_event', $node_type_event->id(), 'Node type test_event loaded');
     $this->assertIdentical(TRUE, $node_type_event->displaySubmitted());
     $this->assertIdentical(TRUE, $node_type_event->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_event->getPreviewMode());
     $this->assertIdentical($id_map->lookupDestinationID(array('test_event')), array('test_event'));
     // Test we have a body field.
     $field = FieldConfig::loadByName('node', 'test_event', 'body');
     $this->assertIdentical('Body', $field->getLabel(), 'Body field was found.');
 }
コード例 #9
0
 /**
  * Tests the embedded_data source plugin.
  */
 public function testEmbeddedData()
 {
     $data_rows = [['key' => '1', 'field1' => 'f1value1', 'field2' => 'f2value1'], ['key' => '2', 'field1' => 'f1value2', 'field2' => 'f2value2']];
     $ids = ['key' => ['type' => 'integer']];
     $config = ['id' => 'sample_data', 'migration_tags' => ['Embedded data test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => $data_rows, 'ids' => $ids], 'process' => [], 'destination' => ['plugin' => 'null']];
     $migration = Migration::create($config);
     $source = $migration->getSourcePlugin();
     // Validate the plugin returns the source data that was provided.
     $results = [];
     /** @var Row $row */
     foreach ($source as $row) {
         $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.
         unset($data_row['plugin']);
         unset($data_row['data_rows']);
         unset($data_row['ids']);
         $results[] = $data_row;
     }
     $this->assertIdentical($results, $data_rows);
     // Validate the public APIs.
     $this->assertIdentical($source->count(), count($data_rows));
     $this->assertIdentical($source->getIds(), $ids);
     $expected_fields = ['key' => 'key', 'field1' => 'field1', 'field2' => 'field2'];
     $this->assertIdentical($source->fields(), $expected_fields);
 }
コード例 #10
0
ファイル: Node.php プロジェクト: ravindrasingh22/Drupal-8-rc
 /**
  * {@inheritdoc}
  */
 public function buildMigrations(array $template)
 {
     $migrations = [];
     $fields = [];
     foreach ($this->getSourcePlugin('d7_field_instance', $template['source']) as $field) {
         $entity_type = $field->getSourceProperty('entity_type');
         $bundle = $field->getSourceProperty('bundle');
         $field_name = $field->getSourceProperty('field_name');
         $fields[$entity_type][$bundle][$field_name] = $field->getSource();
     }
     foreach ($this->getSourcePlugin('d7_node_type', $template['source']) as $node_type) {
         $bundle = $node_type->getSourceProperty('type');
         $values = $template;
         $values['id'] .= '__' . $bundle;
         $values['label'] = $this->t('@label (@type)', ['@label' => $values['label'], '@type' => $node_type->getSourceProperty('name')]);
         $values['source']['node_type'] = $bundle;
         $migration = Migration::create($values);
         if (isset($fields['node'][$bundle])) {
             foreach (array_keys($fields['node'][$bundle]) as $field) {
                 $migration->setProcessOfProperty($field, $field);
             }
         }
         $migrations[] = $migration;
     }
     return $migrations;
 }
コード例 #11
0
 /**
  * Tests user role migration.
  */
 public function testUserRole()
 {
     /** @var \Drupal\migrate\entity\Migration $migration */
     $id_map = Migration::load('d6_user_role')->getIdMap();
     $rid = 'anonymous';
     $anonymous = Role::load($rid);
     $this->assertIdentical($rid, $anonymous->id());
     $this->assertIdentical(array('migrate test anonymous permission', 'use text format filtered_html'), $anonymous->getPermissions());
     $this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(1)));
     $rid = 'authenticated';
     $authenticated = Role::load($rid);
     $this->assertIdentical($rid, $authenticated->id());
     $this->assertIdentical(array('migrate test authenticated permission', 'use text format filtered_html'), $authenticated->getPermissions());
     $this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(2)));
     $rid = 'migrate_test_role_1';
     $migrate_test_role_1 = Role::load($rid);
     $this->assertIdentical($rid, $migrate_test_role_1->id());
     $this->assertIdentical(array('migrate test role 1 test permission', 'use text format full_html', 'use text format php_code'), $migrate_test_role_1->getPermissions());
     $this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(3)));
     $rid = 'migrate_test_role_2';
     $migrate_test_role_2 = Role::load($rid);
     $this->assertIdentical(array('migrate test role 2 test permission', 'use PHP for settings', 'administer contact forms', 'skip comment approval', 'edit own blog content', 'edit any blog content', 'delete own blog content', 'delete any blog content', 'create forum content', 'delete any forum content', 'delete own forum content', 'edit any forum content', 'edit own forum content', 'administer nodes', 'access content overview', 'use text format php_code'), $migrate_test_role_2->getPermissions());
     $this->assertIdentical($rid, $migrate_test_role_2->id());
     $this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(4)));
     $rid = 'migrate_test_role_3_that_is_long';
     $migrate_test_role_3 = Role::load($rid);
     $this->assertIdentical($rid, $migrate_test_role_3->id());
     $this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(5)));
 }
コード例 #12
0
ファイル: Node.php プロジェクト: komejo/article-test
 /**
  * {@inheritdoc}
  */
 public function buildMigrations(array $template)
 {
     $migrations = [];
     // Read all CCK field instance definitions in the source database.
     $fields = array();
     foreach ($this->getSourcePlugin('d6_field_instance', $template['source']) as $field) {
         $info = $field->getSource();
         $fields[$info['type_name']][$info['field_name']] = $info;
     }
     foreach ($this->getSourcePlugin('d6_node_type', $template['source']) as $row) {
         $node_type = $row->getSourceProperty('type');
         $values = $template;
         $values['id'] = $template['id'] . '__' . $node_type;
         $label = $template['label'];
         $values['label'] = $this->t("@label (@type)", ['@label' => $label, '@type' => $node_type]);
         $values['source']['node_type'] = $node_type;
         $migration = Migration::create($values);
         if (isset($fields[$node_type])) {
             foreach ($fields[$node_type] as $field => $info) {
                 if ($this->cckPluginManager->hasDefinition($info['type'])) {
                     $this->getCckPlugin($info['type'])->processCckFieldValues($migration, $field, $info);
                 } else {
                     $migration->setProcessOfProperty($field, $field);
                 }
             }
         }
         $migrations[] = $migration;
     }
     return $migrations;
 }
コード例 #13
0
ファイル: MigrateUploadTest.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installEntitySchema('node');
     $this->installSchema('file', ['file_usage']);
     $this->installSchema('node', ['node_access']);
     $id_mappings = array('d6_file' => array());
     // Create new file entities.
     for ($i = 1; $i <= 3; $i++) {
         $file = File::create(array('fid' => $i, 'uid' => 1, 'filename' => 'druplicon.txt', 'uri' => "public://druplicon-{$i}.txt", 'filemime' => 'text/plain', 'created' => 1, 'changed' => 1, 'status' => FILE_STATUS_PERMANENT));
         $file->enforceIsNew();
         file_put_contents($file->getFileUri(), 'hello world');
         // Save it, inserting a new record.
         $file->save();
         $id_mappings['d6_file'][] = array(array($i), array($i));
     }
     $this->prepareMigrations($id_mappings);
     $this->migrateContent();
     // Since we are only testing a subset of the file migration, do not check
     // that the full file migration has been run.
     $migration = Migration::load('d6_upload');
     $migration->set('requirements', []);
     $this->executeMigration($migration);
 }
コード例 #14
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $id_mappings = array('d6_node:*' => array(array(array(0), array(0))));
     $this->prepareMigrations($id_mappings);
     $migrations = Migration::loadMultiple(['d6_term_node:*']);
     array_walk($migrations, [$this, 'executeMigration']);
 }
コード例 #15
0
 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyEntityFormDisplay()
 {
     // Test that the field exists.
     $component = EntityFormDisplay::load('node.page.default')->getComponent('tags');
     $this->assertIdentical('options_select', $component['type']);
     $this->assertIdentical(20, $component['weight']);
     // Test the Id map.
     $this->assertIdentical(array('node', 'article', 'default', 'tags'), Migration::load('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
 }
コード例 #16
0
 /**
  * Tests Drupal 6 view modes to Drupal 8 migration.
  */
 public function testViewModes()
 {
     // Test a new view mode.
     $view_mode = EntityViewMode::load('node.preview');
     $this->assertIdentical(FALSE, is_null($view_mode), 'Preview view mode loaded.');
     $this->assertIdentical('Preview', $view_mode->label(), 'View mode has correct label.');
     // Test the ID map.
     $this->assertIdentical(array('node', 'preview'), Migration::load('d6_view_modes')->getIdMap()->lookupDestinationID(array(1)));
 }
コード例 #17
0
ファイル: MigrateMessageTest.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installConfig(['system']);
     // A simple migration, which will generate a message to the id map because
     // the concat plugin throws an exception if its source is not an array.
     $config = ['id' => 'sample_data', 'migration_tags' => ['Message test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => [['name' => 'source_message', 'value' => 'a message']], 'ids' => ['name' => ['type' => 'string']]], 'process' => ['message' => ['plugin' => 'concat', 'source' => 'value']], 'destination' => ['plugin' => 'config', 'config_name' => 'system.maintenance']];
     $this->migration = Migration::create($config);
 }
コード例 #18
0
ファイル: StubTestTrait.php プロジェクト: sarahwillem/OD8
 /**
  * Create a stub of the given entity type.
  *
  * @param string $entity_type_id
  *   The entity type we are stubbing.
  *
  * @return int
  *   ID of the created entity.
  */
 protected function createStub($entity_type_id)
 {
     // Create a dummy migration to pass to the destination plugin.
     $config = ['id' => 'dummy', 'migration_tags' => ['Stub test'], 'source' => ['plugin' => 'empty'], 'process' => [], 'destination' => ['plugin' => 'entity:' . $entity_type_id]];
     $migration = Migration::create($config);
     $destination_plugin = $migration->getDestinationPlugin(TRUE);
     $stub_row = new Row([], [], TRUE);
     $destination_ids = $destination_plugin->import($stub_row);
     return reset($destination_ids);
 }
コード例 #19
0
 /**
  * Tests dependencies on the migration of aggregator feeds & items.
  */
 public function testAggregatorMigrateDependencies()
 {
     /** @var \Drupal\migrate\entity\Migration $migration */
     $migration = Migration::load('d6_aggregator_item');
     $executable = new MigrateExecutable($migration, $this);
     $this->startCollectingMessages();
     $executable->import();
     $this->assertEqual($this->migrateMessages['error'], array(SafeMarkup::format('Migration @id did not meet the requirements. Missing migrations d6_aggregator_feed. requirements: d6_aggregator_feed.', array('@id' => $migration->id()))));
     $this->collectMessages = FALSE;
 }
コード例 #20
0
ファイル: MigrateSourceTest.php プロジェクト: ddrozdik/dmaps
 /**
  * Test that an outdated highwater mark does not cause a row to be imported.
  */
 public function testOutdatedHighwater()
 {
     $source = $this->getSource([], [], MigrateIdMapInterface::STATUS_IMPORTED);
     // Set the originalHighwater to something higher than our timestamp.
     $this->migration->expects($this->any())->method('getHighwater')->willReturn($this->row['timestamp'] + 1);
     // The current highwater mark is now higher than the row timestamp so no row
     // is expected.
     $source->rewind();
     $this->assertNull($source->current(), 'Original highwater mark is higher than incoming row timestamp.');
 }
コード例 #21
0
 /**
  * Tests that an exception is thrown when ImageCache is not installed.
  */
 public function testMissingTable()
 {
     $this->sourceDatabase->update('system')->fields(array('status' => 0))->condition('name', 'imagecache')->condition('type', 'module')->execute();
     try {
         Migration::load('d6_imagecache_presets')->getSourcePlugin()->checkRequirements();
         $this->fail('Did not catch expected RequirementsException.');
     } catch (RequirementsException $e) {
         $this->pass('Caught expected RequirementsException: ' . $e->getMessage());
     }
 }
コード例 #22
0
 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyField()
 {
     // Test that the field exists.
     $field_storage_id = 'node.tags';
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertIdentical($field_storage_id, $field_storage->id());
     $settings = $field_storage->getSettings();
     $this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct.");
     $this->assertIdentical(array('node', 'tags'), Migration::load('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
 }
コード例 #23
0
ファイル: MigrateUserTest.php プロジェクト: ddrozdik/dmaps
 /**
  * Tests the Drupal6 user to Drupal 8 migration.
  */
 public function testUser()
 {
     $users = Database::getConnection('default', 'migrate')->select('users', 'u')->fields('u')->condition('uid', 0, '>')->execute()->fetchAll();
     foreach ($users as $source) {
         // Get roles directly from the source.
         $rids = Database::getConnection('default', 'migrate')->select('users_roles', 'ur')->fields('ur', array('rid'))->condition('ur.uid', $source->uid)->execute()->fetchCol();
         $roles = array(RoleInterface::AUTHENTICATED_ID);
         $id_map = Migration::load('d6_user_role')->getIdMap();
         foreach ($rids as $rid) {
             $role = $id_map->lookupDestinationId(array($rid));
             $roles[] = reset($role);
         }
         /** @var \Drupal\user\UserInterface $user */
         $user = User::load($source->uid);
         $this->assertIdentical($source->uid, $user->id());
         $this->assertIdentical($source->name, $user->label());
         $this->assertIdentical($source->mail, $user->getEmail());
         $this->assertIdentical($source->created, $user->getCreatedTime());
         $this->assertIdentical($source->access, $user->getLastAccessedTime());
         $this->assertIdentical($source->login, $user->getLastLoginTime());
         $is_blocked = $source->status == 0;
         $this->assertIdentical($is_blocked, $user->isBlocked());
         // $user->getPreferredLangcode() might fallback to default language if the
         // user preferred language is not configured on the site. We just want to
         // test if the value was imported correctly.
         $this->assertIdentical($source->language, $user->preferred_langcode->value);
         $expected_timezone_name = $source->timezone_name ?: $this->config('system.date')->get('timezone.default');
         $this->assertIdentical($expected_timezone_name, $user->getTimeZone());
         $this->assertIdentical($source->init, $user->getInitialEmail());
         $this->assertIdentical($roles, $user->getRoles());
         // We have one empty picture in the data so don't try load that.
         if (!empty($source->picture)) {
             // Test the user picture.
             $file = File::load($user->user_picture->target_id);
             $this->assertIdentical(basename($source->picture), $file->getFilename());
         }
         // Use the API to check if the password has been salted and re-hashed to
         // conform to Drupal >= 7 for non-admin users.
         if ($user->id() != 1) {
             $this->assertTrue(\Drupal::service('password')->check($source->pass_plain, $user->getPassword()));
         }
     }
     // Rollback the migration and make sure everything is deleted but uid 1.
     (new MigrateExecutable($this->migration, $this))->rollback();
     $users = Database::getConnection('default', 'migrate')->select('users', 'u')->fields('u', ['uid'])->condition('uid', 0, '>')->execute()->fetchCol();
     foreach ($users as $uid) {
         $account = User::load($uid);
         if ($uid == 1) {
             $this->assertNotNull($account, 'User 1 was preserved after rollback');
         } else {
             $this->assertNull($account);
         }
     }
 }
コード例 #24
0
ファイル: PathRedirectTest.php プロジェクト: isramv/camp-gdl
 /**
  * Tests the Drupal 6 path redirect to Drupal 8 migration.
  */
 public function testPathRedirect()
 {
     /** @var Redirect $redirect */
     $redirect = Redirect::load(5);
     $this->assertIdentical(Migration::load('d6_path_redirect')->getIdMap()->lookupDestinationID(array(5)), array($redirect->id()));
     $this->assertIdentical("/test/source/url", $redirect->getSourceUrl());
     $this->assertIdentical("base:test/redirect/url", $redirect->getRedirectUrl()->toUriString());
     $redirect = Redirect::load(7);
     $this->assertIdentical("/test/source/url2", $redirect->getSourceUrl());
     $this->assertIdentical("http://test/external/redirect/url?foo=bar&biz=buz", $redirect->getRedirectUrl()->toUriString());
 }
コード例 #25
0
 /**
  * Tests that term associations are ignored when they belong to nodes which
  * were not migrated.
  */
 public function testSkipNonExistentNode()
 {
     // Node 2 is migrated by d6_node__story, but we need to pretend that it
     // failed, so record that in the map table.
     $this->mockFailure('d6_node__story', ['nid' => 2]);
     // d6_term_node__2 should skip over node 2 (a.k.a. revision 3) because,
     // according to the map table, it failed.
     $migration = Migration::load('d6_term_node__2');
     $this->executeMigration($migration);
     $this->assertNull($migration->getIdMap()->lookupDestinationId(['vid' => 3])[0]);
 }
コード例 #26
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     /** @var \Drupal\migrate\Entity\MigrationInterface $migration */
     $migration = Migration::load('d6_user_picture_file');
     $source = $migration->get('source');
     $source['site_path'] = 'core/modules/simpletest';
     $migration->set('source', $source);
     $this->executeMigration($migration);
 }
コード例 #27
0
 /**
  * Run the configured migrations.
  */
 public function import()
 {
     $log = new DrushLogMigrateMessage();
     foreach ($this->migrationList as $migration_id) {
         /** @var MigrationInterface $migration */
         $migration = Migration::load($migration_id);
         drush_print(dt('Upgrading !migration', ['!migration' => $migration_id]));
         $executable = new MigrateExecutable($migration, $log);
         // drush_op() provides --simulate support.
         drush_op([$executable, 'import']);
     }
 }
コード例 #28
0
 /**
  * Tests Migration::set()
  *
  * @covers ::set()
  */
 public function testSetInvalidation()
 {
     $migration = Migration::create(['source' => ['plugin' => 'empty'], 'destination' => ['plugin' => 'entity:entity_view_mode']]);
     $this->assertEqual('empty', $migration->getSourcePlugin()->getPluginId());
     $this->assertEqual('entity:entity_view_mode', $migration->getDestinationPlugin()->getPluginId());
     // Test the source plugin is invalidated.
     $migration->set('source', ['plugin' => 'd6_field']);
     $this->assertEqual('d6_field', $migration->getSourcePlugin()->getPluginId());
     // Test the destination plugin is invalidated.
     $migration->set('destination', ['plugin' => 'null']);
     $this->assertEqual('null', $migration->getDestinationPlugin()->getPluginId());
 }
コード例 #29
0
 /**
  * Set up the relevant migrations for import from the provided database
  * connection.
  *
  * @param \Drupal\Core\Database\Database $database
  *   Database array representing the source Drupal database.
  * @param string $source_base_path
  *   Address of the source Drupal site (e.g., http://example.com/).
  *
  * @return array
  */
 protected function createMigrations(array $database, $source_base_path)
 {
     // Set up the connection.
     Database::addConnectionInfo('upgrade', 'default', $database);
     $connection = Database::getConnection('default', 'upgrade');
     if (!($drupal_version = $this->getLegacyDrupalVersion($connection))) {
         throw new \Exception($this->t('Source database does not contain a recognizable Drupal version.'));
     }
     $database_state['key'] = 'upgrade';
     $database_state['database'] = $database;
     $database_state_key = 'migrate_upgrade_' . $drupal_version;
     \Drupal::state()->set($database_state_key, $database_state);
     $version_tag = 'Drupal ' . $drupal_version;
     $template_storage = \Drupal::service('migrate.template_storage');
     $migration_templates = $template_storage->findTemplatesByTag($version_tag);
     foreach ($migration_templates as $id => $template) {
         $migration_templates[$id]['source']['database_state_key'] = $database_state_key;
         // Configure file migrations so they can find the files.
         if ($template['destination']['plugin'] == 'entity:file') {
             if ($source_base_path) {
                 // Make sure we have a single trailing slash.
                 $source_base_path = rtrim($source_base_path, '/') . '/';
                 $migration_templates[$id]['destination']['source_base_path'] = $source_base_path;
             }
         }
     }
     // Let the builder service create our migration configuration entities from
     // the templates, expanding them to multiple entities where necessary.
     /** @var \Drupal\migrate\MigrationBuilder $builder */
     $builder = \Drupal::service('migrate.migration_builder');
     $migrations = $builder->createMigrations($migration_templates);
     $migration_ids = [];
     foreach ($migrations as $migration) {
         try {
             if ($migration->getSourcePlugin() instanceof RequirementsInterface) {
                 $migration->getSourcePlugin()->checkRequirements();
             }
             if ($migration->getDestinationPlugin() instanceof RequirementsInterface) {
                 $migration->getDestinationPlugin()->checkRequirements();
             }
             // Don't try to resave migrations that already exist.
             if (!Migration::load($migration->id())) {
                 $migration->save();
             }
             $migration_ids[] = $migration->id();
         } catch (RequirementsException $e) {
         } catch (PluginNotFoundException $e) {
         }
     }
     // loadMultiple will sort the migrations in dependency order.
     return array_keys(Migration::loadMultiple($migration_ids));
 }
コード例 #30
0
 /**
  * Tests the migrated comment types.
  */
 public function testMigration()
 {
     $this->assertEntity('comment_node_page', 'Basic page comment');
     $this->assertEntity('comment_node_article', 'Article comment');
     $this->assertEntity('comment_node_blog', 'Blog entry comment');
     $this->assertEntity('comment_node_book', 'Book page comment');
     $this->assertEntity('comment_node_forum', 'Forum topic comment');
     $this->assertEntity('comment_node_test_content_type', 'Test content type comment');
     // Validate that the source count and processed count match up.
     /** @var \Drupal\migrate\Entity\MigrationInterface $migration */
     $migration = Migration::load('d7_comment_type');
     $this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
 }