diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorFeedTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorFeedTest.php new file mode 100644 index 0000000..a32d37b --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorFeedTest.php @@ -0,0 +1,64 @@ + 'Migrate variables to aggregator_feed entities.', + 'description' => 'Upgrade variables to aggregator_feed entities', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $migration = entity_load('migration', 'd6_aggregator_feed'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6AggregatorFeed.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Tests migration of aggregator feeds. + */ + public function testAggregatorFeedImport() { + /** @var Feed $feed */ + $feed = entity_load('aggregator_feed', 5); + $this->assertNotNull($feed->uuid()); + $this->assertEqual($feed->title->value, 'Know Your Meme'); + $this->assertEqual($feed->language()->id, Language::LANGCODE_NOT_SPECIFIED); + $this->assertEqual($feed->url->value, 'http://knowyourmeme.com/newsfeed.rss'); + $this->assertEqual($feed->refresh->value, 900); + $this->assertEqual($feed->checked->value, 1387659487); + $this->assertEqual($feed->queued->value, 0); + $this->assertEqual($feed->link->value, 'http://knowyourmeme.com'); + $this->assertEqual($feed->description->value, 'New items added to the News Feed'); + $this->assertEqual($feed->image->value, 'http://b.thumbs.redditmedia.com/harEHsUUZVajabtC.png'); + $this->assertEqual($feed->hash->value, ''); + $this->assertEqual($feed->etag->value, '"213cc1365b96c310e92053c5551f0504"'); + $this->assertEqual($feed->modified->value, 0); + } +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorItemTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorItemTest.php new file mode 100644 index 0000000..6668c53 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorItemTest.php @@ -0,0 +1,85 @@ + 'Migrate aggregator items', + 'description' => 'Upgrade aggregator items', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + // Add some id mappings for the dependant migrations. + $id_mappings = array( + 'd6_aggregator_feed' => array( + array(array(5), array(5)), + ), + ); + $this->prepareIdMappings($id_mappings); + + $entity = entity_create('aggregator_feed', array( + 'fid' => 5, + 'title' => 'Drupal Core', + 'url' => 'https://groups.drupal.org/not_used/167169', + 'refresh' => 900, + 'checked' => 1389919932, + 'description' => 'Drupal Core Group feed', + )); + $entity->enforceIsNew(); + $entity->save(); + /** @var \Drupal\migrate\entity\Migration $migration */ + $migration = entity_load('migration', 'd6_aggregator_item'); + $path = drupal_get_path('module', 'migrate_drupal'); + $dumps = array( + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6AggregatorItem.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Test Drupal 6 aggregator item migration to Drupal 8. + */ + public function testAggregatorItem() { + /** @var Item $item */ + $item = entity_load('aggregator_item', 1); + $this->assertEqual($item->id(), 1); + $this->assertEqual($item->getFeedId(), 5); + $this->assertEqual($item->label(), 'This (three) weeks in Drupal Core - January 10th 2014'); + $this->assertEqual($item->getAuthor(), 'larowlan'); + $this->assertEqual($item->getDescription(), "

What's new with Drupal 8?

"); + $this->assertEqual($item->getLink(), 'https://groups.drupal.org/node/395218'); + $this->assertEqual($item->getPostedTime(), 1389297196); + $this->assertEqual($item->language()->id, Language::LANGCODE_NOT_SPECIFIED); + $this->assertEqual($item->getGuid(), '395218 at https://groups.drupal.org'); + + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBlockTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBlockTest.php new file mode 100644 index 0000000..2bf15b2 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBlockTest.php @@ -0,0 +1,76 @@ + 'Migrate block settings to block.block.*.yml', + 'description' => 'Upgrade block settings to block.block.*.yml', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $entities = array( + entity_create('menu', array('id' => 'primary-links')), + entity_create('menu', array('id' => 'secondary-links')), + entity_create('custom_block', array('id' => 1, 'type' => 'basic')), + ); + foreach ($entities as $entity) { + $entity->enforceIsNew(TRUE); + $entity->save(); + } + $this->prepareIdMappings(array('d6_custom_block' => array(array(array(1), array(1))))); + /** @var \Drupal\migrate\entity\Migration $migration */ + $migration = entity_load('migration', 'd6_block'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Block.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Test the block settings migration. + */ + public function testBlockMigration() { + $blocks = entity_load_multiple('block'); + $this->assertTrue(count($blocks)); + // @TODO add more asserts. + } +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBookTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBookTest.php new file mode 100644 index 0000000..e9a9bfb --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBookTest.php @@ -0,0 +1,87 @@ + 'Migrate book', + 'description' => 'Upgrade book structure', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $id_mappings = array(); + for ($i = 4; $i <= 8; $i++) { + $entity = entity_create('node', array( + 'type' => 'story', + 'nid' => $i, + )); + $entity->enforceIsNew(); + $entity->save(); + $id_mappings['d6_node'][] = array(array($i), array($i)); + } + $this->prepareIdMappings($id_mappings); + // Load database dumps to provide source data. + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Book.php', + ); + $this->loadDumps($dumps); + // Migrate books.. + $migration = entity_load('migration', 'd6_book'); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Tests the Drupal 6 book structure to Drupal 8 migration. + */ + public function testBook() { + $nodes = node_load_multiple(array(4, 5, 6, 7, 8)); + $this->assertEqual($nodes[4]->book['bid'], 4); + $this->assertEqual($nodes[4]->book['pid'], 0); + + $this->assertEqual($nodes[5]->book['bid'], 4); + $this->assertEqual($nodes[5]->book['pid'], 4); + + $this->assertEqual($nodes[6]->book['bid'], 4); + $this->assertEqual($nodes[6]->book['pid'], 5); + + $this->assertEqual($nodes[7]->book['bid'], 4); + $this->assertEqual($nodes[7]->book['pid'], 5); + + $this->assertEqual($nodes[8]->book['bid'], 8); + $this->assertEqual($nodes[8]->book['pid'], 0); + + $tree = \Drupal::service('book.manager')->bookTreeAllData(4); + $this->assertEqual($tree['49990 4']['link']['nid'], 4); + $this->assertEqual($tree['49990 4']['below']['50000 5']['link']['nid'], 5); + $this->assertEqual($tree['49990 4']['below']['50000 5']['below']['50000 6']['link']['nid'], 6); + $this->assertEqual($tree['49990 4']['below']['50000 5']['below']['50000 7']['link']['nid'], 7); + $this->assertIdentical($tree['49990 4']['below']['50000 5']['below']['50000 6']['below'], array()); + $this->assertIdentical($tree['49990 4']['below']['50000 5']['below']['50000 7']['below'], array()); + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCckFieldRevisionTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCckFieldRevisionTest.php new file mode 100644 index 0000000..d18077b --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCckFieldRevisionTest.php @@ -0,0 +1,98 @@ + 'Migrate CCK field revisions', + 'description' => 'CCK field revision migration', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + entity_create('field_config', array( + 'entity_type' => 'node', + 'name' => 'field_test', + 'type' => 'text', + ))->save(); + entity_create('field_instance_config', array( + 'entity_type' => 'node', + 'field_name' => 'field_test', + 'bundle' => 'story', + ))->save(); + entity_create('field_config', array( + 'entity_type' => 'node', + 'name' => 'field_test_two', + 'type' => 'integer', + 'cardinality' => -1, + ))->save(); + entity_create('field_instance_config', array( + 'entity_type' => 'node', + 'field_name' => 'field_test_two', + 'bundle' => 'story', + ))->save(); + + // Add some id mappings for the dependant migrations. + $id_mappings = array( + 'd6_cck_field_values' => array( + array(array(1), array(1)), + ), + 'd6_node' => array( + array(array(1), array(1)), + array(array(2), array(2)), + ), + 'd6_node_revision' => array( + array(array(1), array(1)), + ), + ); + $this->prepareIdMappings($id_mappings); + $path = drupal_get_path('module', 'migrate_drupal'); + $dumps = array( + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6NodeRevision.php', + ); + $this->loadDumps($dumps); + + $migrations = entity_load_multiple('migration', array('d6_cck_field_revision:*')); + foreach ($migrations as $migration) { + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + } + + /** + * Test CCK revision migration from Drupal 6 to 8. + */ + public function testCckFieldRevision() { + $node = \Drupal::entityManager()->getStorage('node')->loadRevision(2); + $this->assertEqual($node->id(), 1, 'Node 1 loaded.'); + $this->assertEqual($node->getRevisionId(), 2, 'Node 1 revision 2loaded.'); + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCckFieldValuesTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCckFieldValuesTest.php new file mode 100644 index 0000000..e9498ba --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCckFieldValuesTest.php @@ -0,0 +1,95 @@ + 'Migrate CCK fields', + 'description' => 'CCK field content migration', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + entity_create('field_config', array( + 'entity_type' => 'node', + 'name' => 'field_test', + 'type' => 'text', + ))->save(); + entity_create('field_instance_config', array( + 'entity_type' => 'node', + 'field_name' => 'field_test', + 'bundle' => 'story', + ))->save(); + entity_create('field_config', array( + 'entity_type' => 'node', + 'name' => 'field_test_two', + 'type' => 'integer', + 'cardinality' => -1, + ))->save(); + entity_create('field_instance_config', array( + 'entity_type' => 'node', + 'field_name' => 'field_test_two', + 'bundle' => 'story', + ))->save(); + + // Add some id mappings for the dependant migrations. + $id_mappings = array( + 'd6_field_formatter_settings' => array( + array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test')), + ), + 'd6_field_instance_widget_settings' => array( + array(array('page', 'field_test'), array('node', 'page', 'default', 'test')), + ), + 'd6_node' => array( + array(array(1), array(1)), + array(array(2), array(2)), + ), + ); + $this->prepareIdMappings($id_mappings); + + $migrations = entity_load_multiple('migration', array('d6_cck_field_values:*')); + foreach ($migrations as $migration) { + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + } + + /** + * Test CCK migration from Drupal 6 to 8. + */ + public function testCckFields() { + $node = node_load(1); + $this->assertEqual($node->field_test->value, 'This is a text field', "Single field storage field is correct."); + $this->assertEqual($node->field_test_two->value, 10, 'Multi field storage field is correct'); + $this->assertEqual($node->field_test_two[1]->value, 20, 'Multi field second value is correct.'); + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php new file mode 100644 index 0000000..06c1340 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php @@ -0,0 +1,89 @@ + 'Migrate comments.', + 'description' => 'Upgrade comments.', + 'group' => 'Migrate Drupal', + ); + } + + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + entity_create('node_type', array('type' => 'page'))->save(); + $node = entity_create('node', array( + 'type' => 'page', + 'nid' => 1, + )); + $node->enforceIsNew(); + $node->save(); + $id_mappings = array( + 'd6_filter_format' => array(array(array(1), array('filtered_html'))), + 'd6_node' => array(array(array(1), array(1))), + 'd6_user' => array(array(array(0), array(0))), + 'd6_comment_entity_display' => array(array(array('page'), array('node', 'page', 'default', 'comment'))), + 'd6_comment_entity_form_display' => array(array(array('page'), array('node', 'page', 'default', 'comment'))), + ); + $this->prepareIdMappings($id_mappings); + + \Drupal::service('comment.manager')->addDefaultField('node', 'page'); + /** @var \Drupal\migrate\entity\Migration $migration */ + $migration = entity_load('migration', 'd6_comment'); + + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Comment.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Tests the Drupal 6 to Drupal 6 comment migration. + */ + public function testComments() { + /** @var Comment $comment */ + $comment = entity_load('comment', 1); + $this->assertEqual('The first comment.', $comment->subject->value); + $this->assertEqual('The first comment body.', $comment->comment_body->value); + $this->assertEqual('filtered_html', $comment->comment_body->format); + $this->assertEqual(0, $comment->pid->value); + $this->assertEqual(1, $comment->entity_id->value); + $this->assertEqual('node', $comment->entity_type->value); + $this->assertEqual(Language::LANGCODE_NOT_SPECIFIED, $comment->language()->id); + + $comment = entity_load('comment', 2); + $this->assertEqual('The response to the second comment.', $comment->subject->value); + $this->assertEqual(3, $comment->pid->value); + + $comment = entity_load('comment', 3); + $this->assertEqual('The second comment.', $comment->subject->value); + $this->assertEqual(0, $comment->pid->value); + } +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactCategoryTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactCategoryTest.php new file mode 100644 index 0000000..f46884c --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactCategoryTest.php @@ -0,0 +1,63 @@ + 'Migrate contact categories.', + 'description' => 'Migrate contact categories to contact.category.*.yml', + 'group' => 'Migrate Drupal', + ); + } + + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $migration = entity_load('migration', 'd6_contact_category'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactCategory.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, new MigrateMessage()); + $executable->import(); + } + + /** + * The Drupal 6 contact categories to Drupal 8 migration. + */ + public function testContactCategory() { + /** @var \Drupal\contact\Entity\Category $contact_category */ + $contact_category = entity_load('contact_category', 'website_feedback'); + $this->assertEqual($contact_category->label, 'Website feedback'); + $this->assertEqual($contact_category->recipients, 'admin@example.com'); + $this->assertEqual($contact_category->reply, ''); + $this->assertEqual($contact_category->weight, 0); + } +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCustomBlockTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCustomBlockTest.php new file mode 100644 index 0000000..7620793 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCustomBlockTest.php @@ -0,0 +1,67 @@ + 'Migrate custom blocks.', + 'description' => 'Upgrade custom blocks.', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $this->prepareIdMappings(array( + 'd6_filter_format' => array( + array(array(2), array('full_html')) + ) + )); + /** @var \Drupal\migrate\entity\Migration $migration */ + $migration = entity_load('migration', 'd6_custom_block'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Box.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Tests the Drupal 6 custom block to Drupal 8 migration. + */ + public function testBlockMigration() { + /** @var CustomBlock $block */ + $block = entity_load('custom_block', 1); + $this->assertEqual('My block 1', $block->label()); + $this->assertEqual(1, $block->getRevisionId()); + $this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time()); + $this->assertEqual(Language::LANGCODE_NOT_SPECIFIED, $block->language()->id); + $this->assertEqual('

My custom block body

', $block->body->value); + $this->assertEqual('full_html', $block->body->format); + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDateFormatTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDateFormatTest.php new file mode 100644 index 0000000..41e7cdc --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDateFormatTest.php @@ -0,0 +1,71 @@ + 'Migrate date formats to system.date_format.*.yml', + 'description' => 'Upgrade date formats to system.date_format.*.yml', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + /** @var \Drupal\migrate\entity\Migration $migration */ + $migration = entity_load('migration', 'd6_date_formats'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6DateFormat.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, new MigrateMessage()); + $executable->import(); + } + + /** + * Tests the Drupal 6 date formats to Drupal 8 migration. + */ + public function testDateFormats() { + $short_date_format = entity_load('date_format', 'short'); + $this->assertEqual('\S\H\O\R\T m/d/Y - H:i', $short_date_format->getPattern(DrupalDateTime::PHP)); + + $medium_date_format = entity_load('date_format', 'medium'); + $this->assertEqual('\M\E\D\I\U\M D, m/d/Y - H:i', $medium_date_format->getPattern(DrupalDateTime::PHP)); + + $long_date_format = entity_load('date_format', 'long'); + $this->assertEqual('\L\O\N\G l, F j, Y - H:i', $long_date_format->getPattern(DrupalDateTime::PHP)); + + // Test that we can re-import using the EntityDateFormat destination. + Database::getConnection('default', 'migrate') + ->update('variable') + ->fields(array('value' => serialize('\S\H\O\R\T d/m/Y - H:i'))) + ->condition('name', 'date_format_short') + ->execute(); + db_truncate(entity_load('migration', 'd6_date_formats')->getIdMap()->mapTableName())->execute(); + $migration = entity_load_unchanged('migration', 'd6_date_formats'); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + + $short_date_format = entity_load('date_format', 'short'); + $this->assertEqual('\S\H\O\R\T d/m/Y - H:i', $short_date_format->getPattern(DrupalDateTime::PHP)); + + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDrupal6Test.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDrupal6Test.php new file mode 100644 index 0000000..6b973c7 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDrupal6Test.php @@ -0,0 +1,350 @@ + 'Migrate Drupal 6', + 'description' => 'Test every Drupal 6 migration', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function tearDown() { + // Move the results of every class under ours. This is solely for + // reporting, the filename will guide developers. + self::getDatabaseConnection() + ->update('simpletest') + ->fields(array('test_class' => get_class($this))) + ->condition('test_id', $this->testId) + ->execute(); + parent::tearDown(); + } + + + /** + * Test the complete Drupal 6 migration. + */ + public function testDrupal6() { + $path = drupal_get_path('module', 'migrate_drupal'); + $dumps = array( + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ActionSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6AggregatorFeed.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6AggregatorItem.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6AggregatorSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Block.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6BookSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Box.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Comment.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6CommentVariable.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactCategory.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6DateFormat.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6DblogSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FieldInstance.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FieldSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6File.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FileSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FilterFormat.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ForumSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6LocaleSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Menu.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6MenuSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6NodeBodyInstance.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Node.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6NodeRevision.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6NodeSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6NodeType.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SearchPage.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SearchSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SimpletestSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6StatisticsSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SyslogSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemCron.php', + // This dump contains the file directory path to the simpletest directory + // where the files are. + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemFile.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemFilter.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemImageGd.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemImage.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemMaintenance.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemPerformance.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemRss.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemSite.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemTheme.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TaxonomySettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TaxonomyTerm.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TaxonomyVocabulary.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TermNode.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TextSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UpdateSettings.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UploadInstance.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6Upload.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UrlAlias.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UserMail.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6User.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UserProfileFields.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UserRole.php', + $path . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6VocabularyField.php', + ); + $this->loadDumps($dumps); + $migrations = array( + 'd6_action_settings', + 'd6_aggregator_settings', + 'd6_aggregator_feed', + 'd6_aggregator_item', + 'd6_block', + 'd6_book_settings', + 'd6_cck_field_values:*', + 'd6_cck_field_revision:*', + 'd6_comment', + 'd6_comment_entity_display', + 'd6_comment_entity_form_display', + 'd6_comment_field', + 'd6_comment_field_instance', + 'd6_contact_category', + 'd6_contact_settings', + 'd6_custom_block', + 'd6_date_formats', + 'd6_dblog_settings', + 'd6_field', + 'd6_field_instance', + 'd6_field_instance_widget_settings', + 'd6_field_settings', + 'd6_field_formatter_settings', + 'd6_file_settings', + 'd6_file', + 'd6_filter_format', + 'd6_forum_settings', + 'd6_locale_settings', + 'd6_menu_settings', + 'd6_menu', + 'd6_node_revision', + 'd6_node', + 'd6_node_settings', + 'd6_node_type', + 'd6_profile_values:user', + 'd6_search_page', + 'd6_search_settings', + 'd6_simpletest_settings', + 'd6_statistics_settings', + 'd6_syslog_settings', + 'd6_system_cron', + 'd6_system_file', + 'd6_system_filter', + 'd6_system_image', + 'd6_system_image_gd', + 'd6_system_maintenance', + 'd6_system_performance', + 'd6_system_rss', + 'd6_system_site', + 'd6_system_theme', + 'd6_taxonomy_settings', + 'd6_taxonomy_term', + 'd6_taxonomy_vocabulary', + 'd6_term_node_revision:*', + 'd6_term_node:*', + 'd6_text_settings', + 'd6_update_settings', + 'd6_upload_entity_display', + 'd6_upload_entity_form_display', + 'd6_upload_field', + 'd6_upload_field_instance', + 'd6_upload', + 'd6_url_alias', + 'd6_user_mail', + 'd6_user_profile_field_instance', + 'd6_user_profile_entity_display', + 'd6_user_profile_entity_form_display', + 'd6_user_profile_field', + 'd6_user_picture_entity_display', + 'd6_user_picture_entity_form_display', + 'd6_user_picture_field_instance', + 'd6_user_picture_field', + 'd6_user_picture_file', + 'd6_user_role', + 'd6_user', + 'd6_view_modes', + 'd6_vocabulary_entity_display', + 'd6_vocabulary_entity_form_display', + 'd6_vocabulary_field_instance', + 'd6_vocabulary_field', + ); + $classes = array( + __NAMESPACE__ . '\MigrateActionConfigsTest', + __NAMESPACE__ . '\MigrateAggregatorConfigsTest', + __NAMESPACE__ . '\MigrateAggregatorFeedTest', + __NAMESPACE__ . '\MigrateAggregatorItemTest', + __NAMESPACE__ . '\MigrateBlockTest', + __NAMESPACE__ . '\MigrateBookConfigsTest', + __NAMESPACE__ . '\MigrateCckFieldValuesTest', + __NAMESPACE__ . '\MigrateCckFieldRevisionTest', + __NAMESPACE__ . '\MigrateCommentTest', + __NAMESPACE__ . '\MigrateCommentVariableEntityDisplay', + __NAMESPACE__ . '\MigrateCommentVariableEntityFormDisplay', + __NAMESPACE__ . '\MigrateCommentVariableField', + __NAMESPACE__ . '\MigrateCommentVariableInstance', + __NAMESPACE__ . '\MigrateContactCategoryTest', + __NAMESPACE__ . '\MigrateContactConfigsTest', + __NAMESPACE__ . '\MigrateCustomBlockTest', + __NAMESPACE__ . '\MigrateDateFormatTest', + __NAMESPACE__ . '\MigrateDblogConfigsTest', + __NAMESPACE__ . '\MigrateFieldConfigsTest', + __NAMESPACE__ . '\MigrateFieldTest', + __NAMESPACE__ . '\MigrateFieldInstanceTest', + __NAMESPACE__ . '\MigrateFieldFormatterSettingsTest', + __NAMESPACE__ . '\MigrateFieldWidgetSettingsTest', + __NAMESPACE__ . '\MigrateFileConfigsTest', + __NAMESPACE__ . '\MigrateFileTest', + __NAMESPACE__ . '\MigrateFilterFormatTest', + __NAMESPACE__ . '\MigrateForumConfigsTest', + __NAMESPACE__ . '\MigrateLocaleConfigsTest', + __NAMESPACE__ . '\MigrateMenuConfigsTest', + __NAMESPACE__ . '\MigrateMenuTest', + __NAMESPACE__ . '\MigrateNodeConfigsTest', + __NAMESPACE__ . '\MigrateNodeRevisionTest', + __NAMESPACE__ . '\MigrateNodeTest', + __NAMESPACE__ . '\MigrateNodeTypeTest', + __NAMESPACE__ . '\MigrateProfileValuesTest', + __NAMESPACE__ . '\MigrateSearchConfigsTest', + __NAMESPACE__ . '\MigrateSearchPageTest', + __NAMESPACE__ . '\MigrateSimpletestConfigsTest', + __NAMESPACE__ . '\MigrateStatisticsConfigsTest', + __NAMESPACE__ . '\MigrateSyslogConfigsTest', + __NAMESPACE__ . '\MigrateSystemCronTest', + __NAMESPACE__ . '\MigrateSystemFileTest', + __NAMESPACE__ . '\MigrateSystemFilterTest', + __NAMESPACE__ . '\MigrateSystemImageGdTest', + __NAMESPACE__ . '\MigrateSystemImageTest', + __NAMESPACE__ . '\MigrateSystemMaintenanceTest', + __NAMESPACE__ . '\MigrateSystemPerformanceTest', + __NAMESPACE__ . '\MigrateSystemRssTest', + __NAMESPACE__ . '\MigrateSystemSiteTest', + __NAMESPACE__ . '\MigrateSystemThemeTest', + __NAMESPACE__ . '\MigrateTaxonomyConfigsTest', + __NAMESPACE__ . '\MigrateTaxonomyTermTest', + __NAMESPACE__ . '\MigrateTaxonomyVocabularyTest', + __NAMESPACE__ . '\MigrateTermNodeRevisionTest', + __NAMESPACE__ . '\MigrateTermNodeTest', + __NAMESPACE__ . '\MigrateTextConfigsTest', + __NAMESPACE__ . '\MigrateUpdateConfigsTest', + __NAMESPACE__ . '\MigrateUploadEntityDisplayTest', + __NAMESPACE__ . '\MigrateUploadEntityFormDisplayTest', + __NAMESPACE__ . '\MigrateUploadFieldTest', + __NAMESPACE__ . '\MigrateUploadInstanceTest', + __NAMESPACE__ . '\MigrateUploadTest', + __NAMESPACE__ . '\MigrateUrlAliasTest', + __NAMESPACE__ . '\MigrateUserConfigsTest', + __NAMESPACE__ . '\MigrateUserProfileEntityDisplayTest', + __NAMESPACE__ . '\MigrateUserProfileEntityFormDisplayTest', + __NAMESPACE__ . '\MigrateUserProfileFieldTest', + __NAMESPACE__ . '\MigrateUserProfileFieldInstanceTest', + __NAMESPACE__ . '\MigrateUserPictureEntityDisplayTest', + __NAMESPACE__ . '\MigrateUserPictureEntityFormDisplayTest', + __NAMESPACE__ . '\MigrateUserPictureFileTest', + __NAMESPACE__ . '\MigrateUserPictureFieldTest', + __NAMESPACE__ . '\MigrateUserPictureInstanceTest', + __NAMESPACE__ . '\MigrateUserRoleTest', + __NAMESPACE__ . '\MigrateUserTest', + __NAMESPACE__ . '\MigrateViewModesTest', + __NAMESPACE__ . '\MigrateVocabularyEntityDisplayTest', + __NAMESPACE__ . '\MigrateVocabularyEntityFormDisplayTest', + __NAMESPACE__ . '\MigrateVocabularyFieldInstanceTest', + __NAMESPACE__ . '\MigrateVocabularyFieldTest', + ); + // Run every migration in the order specified by the storage controller. + foreach (entity_load_multiple('migration', $migrations) as $migration) { + (new MigrateExecutable($migration, $this))->import(); + } + foreach ($classes as $class) { + $test_object = new $class($this->testId); + $test_object->databasePrefix = $this->databasePrefix; + $test_object->container = $this->container; + // run() does a lot of setup and tear down work which we don't need: + // it would setup a new database connection and wouldn't find the + // Drupal 6 dump. Also by skipping the setUp() methods there are no id + // mappings or entities prepared. The tests run against solely migrated + // data. + foreach (get_class_methods($test_object) as $method) { + if (strtolower(substr($method, 0, 4)) == 'test') { + // Insert a fail record. This will be deleted on completion to ensure + // that testing completed. + $method_info = new \ReflectionMethod($class, $method); + $caller = array( + 'file' => $method_info->getFileName(), + 'line' => $method_info->getStartLine(), + 'function' => $class . '->' . $method . '()', + ); + $completion_check_id = TestBase::insertAssert($this->testId, $class, FALSE, 'The test did not complete due to a fatal error.', 'Completion check', $caller); + // Run the test method. + try { + $test_object->$method(); + } + catch (\Exception $e) { + $this->exceptionHandler($e); + } + // Remove the completion check record. + TestBase::deleteAssert($completion_check_id); + } + } + // Add the pass/fail/exception/debug results. + foreach ($this->results as $key => &$value) { + $value += $test_object->results[$key]; + } + } + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldFormatterSettingsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldFormatterSettingsTest.php new file mode 100644 index 0000000..9205c80 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldFormatterSettingsTest.php @@ -0,0 +1,235 @@ + 'Migrate field formatter settings to entity.display.*.*.yml', + 'description' => 'Upgrade field formatter settings to entity.display.*.*.yml', + 'group' => 'Migrate Drupal', + ); + } + + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + + entity_create('node_type', array('type' => 'article'))->save(); + entity_create('node_type', array('type' => 'story'))->save(); + // Create the node preview view mode. + entity_create('view_mode', array('id' => 'node.preview', 'targetEntityType' => 'node'))->save(); + + // Add some id mappings for the dependant migrations. + $id_mappings = array( + 'd6_view_modes' => array( + array(array(1), array('node', 'preview')), + array(array(4), array('node', 'rss')), + array(array('teaser'), array('node', 'teaser')), + array(array('full'), array('node', 'full')), + ), + 'd6_field_instance' => array( + array(array('fieldname', 'page'), array('node', 'fieldname', 'page')), + ), + 'd6_field' => array( + array(array('field_test'), array('node', 'field_test')), + array(array('field_test_two'), array('node', 'field_test_two')), + array(array('field_test_three'), array('node', 'field_test_three')), + array(array('field_test_email'), array('node', 'field_test_email')), + array(array('field_test_link'), array('node', 'field_test_link')), + array(array('field_test_filefield'), array('node', 'field_test_filefield')), + array(array('field_test_imagefield'), array('node', 'field_test_imagefield')), + array(array('field_test_phone'), array('node', 'field_test_phone')), + array(array('field_test_date'), array('node', 'field_test_date')), + array(array('field_test_datestamp'), array('node', 'field_test_datestamp')), + array(array('field_test_datetime'), array('node', 'field_test_datetime')), + ), + ); + $this->prepareIdMappings($id_mappings); + + $migration = entity_load('migration', 'd6_field_formatter_settings'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FieldInstance.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Test that migrated entity display settings can be loaded using D8 API's. + */ + public function testEntityDisplaySettings() { + // Run tests. + $field_name = "field_test"; + $expected = array( + 'weight' => 1, + 'label' => 'above', + 'type' => 'text_trimmed', + 'settings' => array('trim_length' => 600), + ); + + // Make sure we don't have the excluded print entity display. + $display = entity_load('entity_view_display', 'node.story.print'); + $this->assertNull($display, "Print entity display not found."); + // Can we load any entity display. + $display = entity_load('entity_view_display', 'node.story.teaser'); + $this->assertEqual($display->getComponent($field_name), $expected); + + // Test migrate worked with multiple bundles. + $display = entity_load('entity_view_display', 'node.article.teaser'); + $this->assertEqual($display->getComponent($field_name), $expected); + + // Test RSS because that has been converted from 4 to rss. + $display = entity_load('entity_view_display', 'node.story.rss'); + $this->assertEqual($display->getComponent($field_name), $expected); + + // Test the full format with text_default which comes from a static map. + $expected['type'] = 'text_default'; + $expected['settings'] = array(); + $display = entity_load('entity_view_display', 'node.story.full'); + $this->assertEqual($display->getComponent($field_name), $expected); + + // Check that we can migrate multiple fields. + $content = $display->get('content'); + $this->assertTrue(isset($content['field_test']), 'Settings for field_test exist.'); + $this->assertTrue(isset($content['field_test_two']), "Settings for field_test_two exist."); + + // Test the number field formatter settings are correct. + $expected['weight'] = 2; + $expected['type'] = 'number_integer'; + $expected['settings'] = array( + 'scale' => 0, + 'decimal_separator' => '.', + 'thousand_separator' => ',', + 'prefix_suffix' => TRUE, + ); + $component = $display->getComponent('field_test_two'); + $this->assertEqual($component, $expected); + $expected['weight'] = 3; + $expected['type'] = 'number_decimal'; + $expected['settings']['scale'] = 2; + $component = $display->getComponent('field_test_three'); + $this->assertEqual($component, $expected); + + // Test the email field formatter settings are correct. + $expected['weight'] = 4; + $expected['type'] = 'email_mailto'; + $expected['settings'] = array(); + $component = $display->getComponent('field_test_email'); + $this->assertEqual($component, $expected); + + // Test the link field formatter settings. + $expected['weight'] = 5; + $expected['type'] = 'link'; + $expected['settings'] = array( + 'trim_length' => 80, + 'url_only' => 1, + 'url_plain' => 1, + 'rel' => 0, + 'target' => 0, + ); + $component = $display->getComponent('field_test_link'); + $this->assertEqual($component, $expected, "node.story.full field_test_link has correct absolute link settings."); + $expected['settings']['url_only'] = 0; + $expected['settings']['url_plain'] = 0; + $display = entity_load('entity_view_display', 'node.story.teaser'); + $component = $display->getComponent('field_test_link'); + $this->assertEqual($component, $expected, "node.story.teaser field_test_link has correct default link settings."); + + // Test the file field formatter settings. + $expected['weight'] = 7; + $expected['type'] = 'file_default'; + $expected['settings'] = array(); + $component = $display->getComponent('field_test_filefield'); + $this->assertEqual($component, $expected, "node.story.teaser field_test_filefield is of type file_default."); + $display = entity_load('entity_view_display', 'node.story.full'); + $expected['type'] = 'file_url_plain'; + $component = $display->getComponent('field_test_filefield'); + $this->assertEqual($component, $expected, "node.story.full field_test_filefield is of type file_url_plain."); + + // Test the image field formatter settings. + $expected['weight'] = 8; + $expected['type'] = 'image'; + $expected['settings'] = array('image_style' => '', 'image_link' => ''); + $component = $display->getComponent('field_test_imagefield'); + $this->assertEqual($component, $expected, "node.story.full field_test_imagefield is of type image with the correct settings."); + $display = entity_load('entity_view_display', 'node.story.teaser'); + $expected['settings']['image_link'] = 'file'; + $component = $display->getComponent('field_test_imagefield'); + $this->assertEqual($component, $expected, "node.story.teaser field_test_imagefield is of type image with the correct settings."); + + // Test phone field. + $expected['weight'] = 9; + $expected['type'] = 'string'; + $expected['settings'] = array(); + $component = $display->getComponent('field_test_phone'); + $this->assertEqual($component, $expected, "node.story.teaser field_test_phone is of type telephone."); + + // Test date field. + $expected['weight'] = 10; + $expected['type'] = 'datetime_default'; + $expected['settings'] = array('format_type' => 'fallback'); + $component = $display->getComponent('field_test_date'); + $this->assertEqual($component, $expected); + $display = entity_load('entity_view_display', 'node.story.full'); + $expected['settings']['format_type'] = 'long'; + $component = $display->getComponent('field_test_date'); + $this->assertEqual($component, $expected); + + // Test date stamp field. + $expected['weight'] = 11; + $expected['settings']['format_type'] = 'fallback'; + $component = $display->getComponent('field_test_datestamp'); + $this->assertEqual($component, $expected); + $display = entity_load('entity_view_display', 'node.story.teaser'); + $expected['settings'] = array('format_type' => 'medium'); + $component = $display->getComponent('field_test_datestamp'); + $this->assertEqual($component, $expected); + + // Test datetime field. + $expected['weight'] = 12; + $expected['settings'] = array('format_type' => 'short'); + $component = $display->getComponent('field_test_datetime'); + $this->assertEqual($component, $expected); + $display = entity_load('entity_view_display', 'node.story.full'); + $expected['settings']['format_type'] = 'fallback'; + $component = $display->getComponent('field_test_datetime'); + $this->assertEqual($component, $expected); + + // Test a date field with a random format which should be mapped + // to datetime_default. + $display = entity_load('entity_view_display', 'node.story.rss'); + $expected['settings']['format_type'] = 'fallback'; + $component = $display->getComponent('field_test_datetime'); + $this->assertEqual($component, $expected); + // Test that our Id map has the correct data. + $this->assertEqual(array('node', 'story', 'teaser', 'field_test'), entity_load('migration', 'd6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('story', 'teaser', 'node', 'field_test'))); + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldInstanceTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldInstanceTest.php new file mode 100644 index 0000000..5c3da6e --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldInstanceTest.php @@ -0,0 +1,173 @@ + 'Migrate field instances to field.instance.*.*.*.yml', + 'description' => 'Migrate field instances.', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + // Add some id mappings for the dependant migrations. + $id_mappings = array( + 'd6_field' => array( + array(array('field_test'), array('node', 'field_test')), + array(array('field_test_two'), array('node', 'field_test_two')), + array(array('field_test_three'), array('node', 'field_test_three')), + array(array('field_test_email'), array('node', 'field_test_email')), + array(array('field_test_link'), array('node', 'field_test_link')), + array(array('field_test_filefield'), array('node', 'field_test_filefield')), + array(array('field_test_imagefield'), array('node', 'field_test_imagefield')), + array(array('field_test_phone'), array('node', 'field_test_phone')), + array(array('field_test_date'), array('node', 'field_test_date')), + array(array('field_test_datestamp'), array('node', 'field_test_datestamp')), + array(array('field_test_datetime'), array('node', 'field_test_datetime')), + ), + 'd6_node_type' => array( + array(array('page'), array('page')), + array(array('story'), array('story')), + array(array('article'), array('article')), + ), + ); + $this->prepareIdMappings($id_mappings); + entity_create('node_type', array('type' => 'page'))->save(); + entity_create('node_type', array('type' => 'story'))->save(); + entity_create('node_type', array('type' => 'article'))->save(); + + $migration = entity_load('migration', 'd6_field_instance'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FieldInstance.php', + ); + $this->createFields(); + + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + + } + + /* + * Tests migration of file variables to file.settings.yml. + */ + public function testFieldInstanceSettings() { + $entity = entity_create('node', array('type' => 'story')); + // Test a text field. + $field = entity_load('field_instance_config', 'node.story.field_test'); + $this->assertEqual($field->label(), 'Text Field'); + $expected = array('max_length' => 255, 'text_processing' => 1); + $this->assertEqual($field->getSettings(), $expected); + $this->assertEqual('text for default value', $entity->field_test->value); + + // Test a number field. + $field = entity_load('field_instance_config', 'node.story.field_test_two'); + $this->assertEqual($field->label(), 'Integer Field'); + $expected = array( + 'min' => '10', + 'max' => '100', + 'prefix' => 'pref', + 'suffix' => 'suf', + 'unsigned' => '', + ); + $this->assertEqual($field->getSettings(), $expected); + + // Test email field. + $field = entity_load('field_instance_config', 'node.story.field_test_email'); + $this->assertEqual($field->label(), 'Email Field'); + $this->assertEqual('benjy@example.com', $entity->field_test_email->value, 'Field field_test_email default_value is correct.'); + + // Test a filefield. + $field = entity_load('field_instance_config', 'node.story.field_test_filefield'); + $this->assertEqual($field->label(), 'File Field'); + $expected = array( + 'file_extensions' => 'txt pdf doc', + 'file_directory' => 'images', + 'description_field' => TRUE, + 'max_filesize' => '200KB', + 'target_type' => 'file', + 'display_field' => FALSE, + 'display_default' => FALSE, + 'uri_scheme' => 'public', + 'handler' => 'default', + 'target_bundle' => NULL, + ); + // This is the only way to compare arrays. + $this->assertFalse(array_diff_assoc($field->getSettings(), $expected)); + $this->assertFalse(array_diff_assoc($expected, $field->getSettings())); + + // Test a link field. + $field = entity_load('field_instance_config', 'node.story.field_test_link'); + $this->assertEqual($field->label(), 'Link Field'); + $expected = array('title' => 2, 'link_type' => LinkItemInterface::LINK_GENERIC); + $this->assertEqual($field->getSettings(), $expected); + $this->assertEqual('default link title', $entity->field_test_link->title, 'Field field_test_link default title is correct.'); + $this->assertEqual('http://drupal.org', $entity->field_test_link->url, 'Field field_test_link default title is correct.'); + + } + + /** + * Helper to create fields. + */ + protected function createFields() { + $fields = array( + 'field_test' => 'text', + 'field_test_two' => 'integer', + 'field_test_three' => 'decimal', + 'field_test_email' => 'email', + 'field_test_link' => 'link', + 'field_test_filefield' => 'file', + 'field_test_imagefield' => 'image', + 'field_test_phone' => 'telephone', + 'field_test_date' => 'datetime', + 'field_test_datestamp' => 'datetime', + 'field_test_datetime' => 'datetime', + ); + foreach ($fields as $name => $type) { + entity_create('field_config', array( + 'name' => $name, + 'entity_type' => 'node', + 'type' => $type, + ))->save(); + } + + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldTest.php new file mode 100644 index 0000000..005ad53 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldTest.php @@ -0,0 +1,99 @@ + 'Migrate fields to field.*.*.yml', + 'description' => 'Migrate fields', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + /** @var \Drupal\migrate\entity\Migration $migration */ + $migration = entity_load('migration', 'd6_field'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FieldInstance.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Tests the Drupal 6 field to Drupal 8 migration. + */ + public function testFields() { + // Text field. + $field = entity_load('field_config', 'node.field_test'); + $expected = array('max_length' => 255); + $this->assertEqual($field->type, "text", "Field type is text."); + $this->assertEqual($field->status, TRUE, "Status is TRUE"); + $this->assertEqual($field->settings, $expected, "Field type text settings are correct"); + + // Integer field. + $field = entity_load('field_config', 'node.field_test_two'); + $this->assertEqual($field->type, "integer", "Field type is integer."); + + // Float field. + $field = entity_load('field_config', 'node.field_test_three'); + $this->assertEqual($field->type, "decimal", "Field type is decimal."); + + // Link field. + $field = entity_load('field_config', 'node.field_test_link'); + $this->assertEqual($field->type, "link", "Field type is link."); + + // File field. + $field = entity_load('field_config', 'node.field_test_filefield'); + $this->assertEqual($field->type, "file", "Field type is file."); + + /** @var \Drupal\field\Entity\FieldConfig $field */ + $field = entity_load('field_config', 'node.field_test_imagefield'); + $this->assertEqual($field->type, "image", "Field type is image."); + $settings = $field->getSettings(); + $this->assertEqual($settings['column_groups']['alt']['label'], 'Test alt'); + $this->assertEqual($settings['column_groups']['title']['label'], 'Test title'); + $this->assertEqual($settings['target_type'], 'file'); + $this->assertEqual($settings['uri_scheme'], 'public'); + $this->assertEqual($settings['default_image']['fid'], ''); + $this->assertEqual(array_filter($settings['default_image']), array()); + + // Phone field. + $field = entity_load('field_config', 'node.field_test_phone'); + $this->assertEqual($field->type, "telephone", "Field type is telephone."); + + // Date field. + $field = entity_load('field_config', 'node.field_test_datetime'); + $this->assertEqual($field->type, "datetime", "Field type is datetime."); + $this->assertEqual($field->status, FALSE, "Status is FALSE"); + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldWidgetSettingsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldWidgetSettingsTest.php new file mode 100644 index 0000000..c85e388 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldWidgetSettingsTest.php @@ -0,0 +1,159 @@ + 'Migrate field widget settings to entity.form_display.*.*.default.yml', + 'description' => 'Migrate field widget settings.', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + + entity_create('node_type', array('type' => 'article'))->save(); + entity_create('node_type', array('type' => 'story'))->save(); + + // Add some id mappings for the dependant migrations. + $id_mappings = array( + 'd6_field_instance' => array( + array(array('fieldname', 'page'), array('node', 'fieldname', 'page')), + ), + 'd6_field' => array( + array(array('field_test'), array('node', 'field_test')), + array(array('field_test_two'), array('node', 'field_test_two')), + array(array('field_test_three'), array('node', 'field_test_three')), + array(array('field_test_email'), array('node', 'field_test_email')), + array(array('field_test_link'), array('node', 'field_test_link')), + array(array('field_test_filefield'), array('node', 'field_test_filefield')), + array(array('field_test_imagefield'), array('node', 'field_test_imagefield')), + array(array('field_test_phone'), array('node', 'field_test_phone')), + array(array('field_test_date'), array('node', 'field_test_date')), + array(array('field_test_datestamp'), array('node', 'field_test_datestamp')), + array(array('field_test_datetime'), array('node', 'field_test_datetime')), + ), + ); + $this->prepareIdMappings($id_mappings); + $migration = entity_load('migration', 'd6_field_instance_widget_settings'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FieldInstance.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + + } + + /** + * Test that migrated view modes can be loaded using D8 API's. + */ + public function testWidgetSettings() { + // Test the config can be loaded. + $form_display = entity_load('entity_form_display', 'node.story.default'); + $this->assertEqual(is_null($form_display), FALSE, "Form display node.story.default loaded with config."); + + // Text field. + $component = $form_display->getComponent('field_test'); + $expected = array('weight' => 1, 'type' => 'text_textfield'); + $expected['settings'] = array('size' => 60, 'placeholder' => ''); + $this->assertEqual($component, $expected, 'Text field settings are correct.'); + + // Integer field. + $component = $form_display->getComponent('field_test_two'); + $expected['type'] = 'number'; + $expected['weight'] = 2; + $expected['settings'] = array('placeholder' => ''); + $this->assertEqual($component, $expected, 'Integer field settings are correct.'); + + // Float field. + $component = $form_display->getComponent('field_test_three'); + $expected['weight'] = 3; + $this->assertEqual($component, $expected, 'Float field settings are correct.'); + + // Email field. + $component = $form_display->getComponent('field_test_email'); + $expected['type'] = 'email_default'; + $expected['weight'] = 4; + $this->assertEqual($component, $expected, 'Email field settings are correct.'); + + // Link field. + $component = $form_display->getComponent('field_test_link'); + $this->assertEqual($component['type'], 'link_default'); + $this->assertEqual($component['weight'], 5); + $this->assertFalse(array_filter($component['settings'])); + + // File field. + $component = $form_display->getComponent('field_test_filefield'); + $expected['type'] = 'file_generic'; + $expected['weight'] = 7; + $expected['settings'] = array('progress_indicator' => 'bar'); + $this->assertEqual($component, $expected, 'File field settings are correct.'); + + // Image field. + $component = $form_display->getComponent('field_test_imagefield'); + $expected['type'] = 'image_image'; + $expected['weight'] = 8; + $expected['settings'] = array('progress_indicator' => 'bar', 'preview_image_style' => 'thumbnail'); + $this->assertEqual($component, $expected, 'Image field settings are correct.'); + + // Phone field. + $component = $form_display->getComponent('field_test_phone'); + $expected['type'] = 'telephone_default'; + $expected['weight'] = 9; + $expected['settings'] = array('placeholder' => ''); + $this->assertEqual($component, $expected, 'Phone field settings are correct.'); + + // Date fields. + $component = $form_display->getComponent('field_test_date'); + $expected['type'] = 'datetime_default'; + $expected['weight'] = 10; + $expected['settings'] = array(); + $this->assertEqual($component, $expected, 'Date field settings are correct.'); + + $component = $form_display->getComponent('field_test_datestamp'); + $expected['weight'] = 11; + $this->assertEqual($component, $expected, 'Date stamp field settings are correct.'); + + $component = $form_display->getComponent('field_test_datetime'); + $expected['weight'] = 12; + $this->assertEqual($component, $expected, 'Datetime field settings are correct.'); + + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFileTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFileTest.php new file mode 100644 index 0000000..f453641 --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFileTest.php @@ -0,0 +1,82 @@ + 'Migrate files', + 'description' => 'file migration', + 'group' => 'Migrate Drupal', + ); + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6File.php', + ); + /** @var \Drupal\migrate\entity\Migration $migration */ + $migration = entity_load('migration', 'd6_file'); + $migration->source['conf_path'] = 'core/modules/simpletest'; + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + $this->standalone = TRUE; + } + + /** + * Tests the Drupal 6 files to Drupal 8 migration. + */ + public function testFiles() { + /** @var \Drupal\file\FileInterface $file */ + $file = entity_load('file', 1); + $this->assertEqual($file->getFilename(), 'Image1.png'); + $this->assertEqual($file->getSize(), 39325); + $this->assertEqual($file->getFileUri(), 'public://image-1.png'); + $this->assertEqual($file->getMimeType(), 'image/png'); + // It is pointless to run the second half from MigrateDrupal6Test. + if (empty($this->standalone)) { + return; + } + + // Test that we can re-import and also test with file_directory_path set. + db_truncate(entity_load('migration', 'd6_file')->getIdMap()->mapTableName())->execute(); + $migration = entity_load_unchanged('migration', 'd6_file'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemFile.php', + ); + $this->loadDumps($dumps, 'loadMigrateFileStandalone'); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + + $file = entity_load('file', 2); + $this->assertEqual($file->getFileUri(), 'public://core/modules/simpletest/files/image-2.jpg'); + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFilterFormatTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFilterFormatTest.php new file mode 100644 index 0000000..f718ffd --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFilterFormatTest.php @@ -0,0 +1,74 @@ + 'Migrate variables to filter.formats.*.yml', + 'description' => 'Upgrade variables to filter.formats.*.yml', + 'group' => 'Migrate Drupal', + ); + } + + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $migration = entity_load('migration', 'd6_filter_format'); + $dumps = array( + drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FilterFormat.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Tests the Drupal 6 filter format to Drupal 8 migration. + */ + public function testFilterFormat() { + $filter_format = entity_load('filter_format', 'filtered_html'); + + // Check filter status. + $filters = $filter_format->get('filters'); + $this->assertTrue($filters['filter_autop']['status']); + $this->assertTrue($filters['filter_url']['status']); + $this->assertTrue($filters['filter_htmlcorrector']['status']); + $this->assertTrue($filters['filter_html_escape']['status']); + + // These should be false by default. + $this->assertFalse($filters['filter_html']['status']); + $this->assertFalse($filters['filter_caption']['status']); + $this->assertFalse($filters['filter_html_image_secure']['status']); + + // Check variables migrated into filter. + $this->assertIdentical($filters['filter_html_escape']['settings']['allowed_html'], '