View source
<?php
namespace Drupal\Tests\commerce_migrate_commerce\Functional\commerce1;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeTestBase;
class MigrateUpgradeCommerce1Test extends MigrateUpgradeTestBase {
public static $modules = [
'block',
'block_content',
'comment',
'dblog',
'field',
'filter',
'node',
'path',
'path_alias',
'search',
'shortcut',
'system',
'taxonomy',
'user',
'address',
'commerce',
'commerce_cart',
'commerce_log',
'commerce_order',
'commerce_payment',
'commerce_price',
'commerce_product',
'commerce_promotion',
'commerce_store',
'commerce_migrate',
'commerce_shipping',
'commerce_tax',
'migrate',
'migrate_drupal',
'migrate_drupal_ui',
'address',
'datetime',
'entity_reference_revisions',
'file',
'image',
'link',
'options',
'telephone',
'text',
'entity',
'profile',
'inline_entity_form',
'state_machine',
'views',
'migrate_plus',
'commerce_migrate_commerce',
];
protected function setUp() {
parent::setUp();
$this
->writeSettings([
'settings' => [
'migrate_node_migrate_type_classic' => (object) [
'value' => TRUE,
'required' => TRUE,
],
],
]);
$this
->loadFixture(drupal_get_path('module', 'commerce_migrate_commerce') . '/tests/fixtures/ck2.php');
}
public function testMigrateUpgrade() {
$connection_options = $this->sourceDatabase
->getConnectionOptions();
$session = $this
->assertSession();
$driver = $connection_options['driver'];
$connection_options['prefix'] = $connection_options['prefix']['default'];
$drivers = drupal_get_database_types();
$form = $drivers[$driver]
->getFormOptions($connection_options);
$connection_options = array_intersect_key($connection_options, $form + $form['advanced_options']);
$version = $this
->getLegacyDrupalVersion($this->sourceDatabase);
$edit = [
$driver => $connection_options,
'source_private_file_path' => $this
->getSourceBasePath(),
'version' => $version,
];
if ($version == 6) {
$edit['d6_source_base_path'] = $this
->getSourceBasePath();
}
else {
$edit['source_base_path'] = $this
->getSourceBasePath();
}
if (count($drivers) !== 1) {
$edit['driver'] = $driver;
}
$edits = $this
->translatePostValues($edit);
$this
->drupalGet('/upgrade');
$this
->drupalPostForm(NULL, [], 'Continue');
$session
->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.');
$session
->fieldExists('mysql[host]');
$this
->drupalPostForm(NULL, $edits, 'Review upgrade');
$session
->statusCodeEquals(200);
$this
->drupalPostForm(NULL, [], 'Perform upgrade');
$this
->resetAll();
$expected_counts = $this
->getEntityCounts();
foreach (array_keys(\Drupal::entityTypeManager()
->getDefinitions()) as $entity_type) {
$real_count = \Drupal::entityQuery($entity_type)
->count()
->execute();
$expected_count = isset($expected_counts[$entity_type]) ? $expected_counts[$entity_type] : 0;
self::assertEquals($expected_count, $real_count, "Found {$real_count} {$entity_type} entities, expected {$expected_count}.");
}
$plugin_manager = \Drupal::service('plugin.manager.migration');
$all_migrations = $plugin_manager
->createInstancesByTag('Drupal ' . $version);
foreach ($all_migrations as $migration) {
$id_map = $migration
->getIdMap();
foreach ($id_map as $source_id => $map) {
$source_id_values = array_values(unserialize($source_id));
$row = $id_map
->getRowBySource($source_id_values);
$destination = serialize($id_map
->currentDestination());
$message = "Migration of {$source_id} to {$destination} as part of the {$migration->id()} migration. The source row status is " . $row['source_row_status'];
if ($row['source_row_status'] == MigrateIdMapInterface::STATUS_FAILED || $row['source_row_status'] == MigrateIdMapInterface::STATUS_NEEDS_UPDATE) {
$this
->fail($message);
}
else {
self::assertNotEmpty($message);
}
}
}
}
protected function getSourceBasePath() {
return __DIR__ . '/files';
}
protected function getEntityCounts() {
return [
'block' => 26,
'block_content' => 0,
'block_content_type' => 1,
'comment' => 0,
'comment_type' => 11,
'commerce_log' => 18,
'commerce_number_pattern' => 1,
'commerce_order' => 5,
'commerce_order_type' => 1,
'commerce_order_item' => 14,
'commerce_order_item_type' => 3,
'commerce_payment_gateway' => 1,
'commerce_payment_method' => 0,
'commerce_payment' => 3,
'commerce_currency' => 1,
'commerce_product_variation' => 84,
'commerce_product' => 20,
'commerce_product_type' => 7,
'commerce_product_variation_type' => 8,
'commerce_product_attribute' => 6,
'commerce_product_attribute_value' => 39,
'commerce_promotion_coupon' => 0,
'commerce_promotion' => 0,
'commerce_shipping_method' => 3,
'commerce_shipment_type' => 1,
'commerce_store' => 1,
'commerce_store_type' => 1,
'commerce_tax_type' => 1,
'contact_form' => 2,
'contact_message' => 0,
'editor' => 2,
'field_storage_config' => 42,
'field_config' => 113,
'file' => 105,
'filter_format' => 6,
'image_style' => 3,
'migration_group' => 1,
'migration' => 0,
'node' => 17,
'node_type' => 11,
'path_alias' => 121,
'profile' => 13,
'profile_type' => 3,
'rdf_mapping' => 5,
'search_page' => 2,
'shortcut' => 2,
'shortcut_set' => 1,
'action' => 27,
'menu' => 10,
'taxonomy_term' => 33,
'taxonomy_vocabulary' => 12,
'tour' => 1,
'user' => 3,
'user_role' => 3,
'menu_link_content' => 0,
'view' => 25,
'base_field_override' => 1,
'date_format' => 11,
'entity_form_display' => 48,
'entity_view_mode' => 46,
'entity_form_mode' => 5,
'entity_view_display' => 153,
];
}
protected function getAvailablePaths() {
return [];
}
protected function getMissingPaths() {
return [];
}
protected function getEntityCountsIncremental() {
}
}