diff --git a/src/Form/MigrateUpgradeForm.php b/src/Form/MigrateUpgradeForm.php index 898846e..a77ba0f 100644 --- a/src/Form/MigrateUpgradeForm.php +++ b/src/Form/MigrateUpgradeForm.php @@ -738,16 +738,12 @@ class MigrateUpgradeForm extends FormBase implements ConfirmFormInterface { $drivers = drupal_get_database_types(); $drivers_keys = array_keys($drivers); - - // This does not work unfortunately because this part of the form is not - // re-built on submission because it is a multi-step form. - $input = &$form_state->getUserInput(); - if (isset($input['driver'])) { - $default_driver = $input['driver']; - } - else { - $default_driver = current($drivers_keys); - } + // @todo https://www.drupal.org/node/2678510 Because this is a multi-step + // form, the form is not rebuilt during submission. Ideally we would get + // the chosen driver from form input, if available, in order to use + // #limit_validation_errors in the same way + // \Drupal\Core\Installer\Form\SiteSettingsForm does. + $default_driver = current($drivers_keys); $default_options = []; @@ -773,9 +769,10 @@ class MigrateUpgradeForm extends FormBase implements ConfirmFormInterface { $form['database']['driver']['#options'][$key] = $driver->name(); $form['database']['settings'][$key] = $driver->getFormOptions($default_options); - // The #limit_validation_errors in the submit does not work so it is - // not possible to require the database and username for mysql and psql. - // This is because this is a multi-step form. + // @todo https://www.drupal.org/node/2678510 Using + // #limit_validation_errors in the submit does not work so it is not + // possible to require the database and username for mysql and pgsql. + // This is because this is a multi-step form. $form['database']['settings'][$key]['database']['#required'] = FALSE; $form['database']['settings'][$key]['username']['#required'] = FALSE; $form['database']['settings'][$key]['#prefix'] = '

' . $this->t('@driver_name settings', ['@driver_name' => $driver->name()]) . '

'; @@ -823,10 +820,6 @@ class MigrateUpgradeForm extends FormBase implements ConfirmFormInterface { '#type' => 'submit', '#value' => $this->t('Review upgrade'), '#button_type' => 'primary', -// '#limit_validation_errors' => [ -// ['driver'], -// [$default_driver], -// ], '#validate' => ['::validateCredentialForm'], '#submit' => ['::submitCredentialForm'], ]; diff --git a/src/Tests/MigrateUpgradeTestBase.php b/src/Tests/MigrateUpgradeTestBase.php index 2f25363..c69ac02 100644 --- a/src/Tests/MigrateUpgradeTestBase.php +++ b/src/Tests/MigrateUpgradeTestBase.php @@ -10,9 +10,8 @@ namespace Drupal\migrate_upgrade\Tests; use Drupal\Core\Database\Database; use Drupal\simpletest\WebTestBase; - /** - * Base class for Drupal migration tests. + * Provides a base class for testing migration upgrades in the UI. */ abstract class MigrateUpgradeTestBase extends WebTestBase { @@ -26,11 +25,6 @@ abstract class MigrateUpgradeTestBase extends WebTestBase { protected $strictConfigSchema = FALSE; /** - * User with admin rights. - */ - protected $privilegedUser; - - /** * Use the Standard profile to test help implementations of many core modules. */ protected $profile = 'standard'; @@ -47,7 +41,7 @@ abstract class MigrateUpgradeTestBase extends WebTestBase { * * @var array */ - public static $modules = array('system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'migrate', 'migrate_upgrade'); + public static $modules = ['migrate_upgrade']; /** * {@inheritdoc} @@ -57,14 +51,8 @@ abstract class MigrateUpgradeTestBase extends WebTestBase { $this->createMigrationConnection(); $this->sourceDatabase = Database::getConnection('default', 'migrate_upgrade'); - // Create and log in our privileged user. - // Migrating replaces this user and they don't have permissions :) -// $this->privilegedUser = $this->drupalCreateUser([ -// 'access content', -// 'administer site configuration', -// 'administer software updates', -// ]); - + // Create and log in as user 1. Migrations in the UI can only be performed + // as user 1. $this->drupalLogin($this->rootUser); } @@ -91,9 +79,12 @@ abstract class MigrateUpgradeTestBase extends WebTestBase { * * @todo Remove when we don't use global. https://www.drupal.org/node/2552791 */ - private function createMigrationConnection() { + protected function createMigrationConnection() { $connection_info = Database::getConnectionInfo('default')['default']; if ($connection_info['driver'] === 'sqlite') { + // Create database file in the test site's public file directory so that + // \Drupal\simpletest\TestBase::restoreEnvironment() will delete this once + // the test is complete. $file = $this->publicFilesDirectory . '/' . $this->testId . '-migrate.db.sqlite'; touch($file); $connection_info['database'] = $file; @@ -101,8 +92,10 @@ abstract class MigrateUpgradeTestBase extends WebTestBase { } else { $prefix = is_array($connection_info['prefix']) ? $connection_info['prefix']['default'] : $connection_info['prefix']; - // Simpletest uses 7 character prefixes at most so this can't cause - // collisions. + // Simpletest uses fixed length prefixes. Create a new prefix for the + // source database. Adding to the end of the prefix ensures that + // \Drupal\simpletest\TestBase::restoreEnvironment() will remove the + // additional tables. $connection_info['prefix'] = $prefix . '0'; } @@ -119,7 +112,6 @@ abstract class MigrateUpgradeTestBase extends WebTestBase { /** * Executes all steps of migrations upgrade. - * */ protected function testMigrateUpgrade() { $connection_options = $this->sourceDatabase->getConnectionOptions(); @@ -141,7 +133,7 @@ abstract class MigrateUpgradeTestBase extends WebTestBase { $edits = $this->translatePostValues([ 'driver' => $driver, $driver => $connection_options, - 'source_base_path' => $this->getSourceBasePath() + 'source_base_path' => $this->getSourceBasePath(), ]); $this->drupalPostForm(NULL, $edits, t('Review upgrade')); @@ -152,9 +144,11 @@ abstract class MigrateUpgradeTestBase extends WebTestBase { } /** - * The directory for the test fixtures. + * Gets the source base path for the concrete test. * * @return string + * The source base path. */ abstract protected function getSourceBasePath(); + } diff --git a/src/Tests/d6/MigrateUpgrade6Test.php b/src/Tests/d6/MigrateUpgrade6Test.php index 321b65c..1d7fd09 100644 --- a/src/Tests/d6/MigrateUpgrade6Test.php +++ b/src/Tests/d6/MigrateUpgrade6Test.php @@ -10,6 +10,10 @@ namespace Drupal\migrate_upgrade\Tests\d6; use Drupal\migrate_upgrade\Tests\MigrateUpgradeTestBase; /** + * Tests Drupal 6 upgrade using the migrate UI. + * + * The test method is provided by the MigrateUpgradeTestBase class. + * * @group migrate_upgrade */ class MigrateUpgrade6Test extends MigrateUpgradeTestBase { @@ -19,7 +23,7 @@ class MigrateUpgrade6Test extends MigrateUpgradeTestBase { */ protected function setUp() { parent::setUp(); - $this->loadFixture(drupal_get_path('module','migrate_drupal') . '/tests/fixtures/drupal6.php'); + $this->loadFixture(drupal_get_path('module', 'migrate_drupal') . '/tests/fixtures/drupal6.php'); } /** diff --git a/src/Tests/d7/MigrateUpgrade7Test.php b/src/Tests/d7/MigrateUpgrade7Test.php index 6d5dcaf..071ae4a 100644 --- a/src/Tests/d7/MigrateUpgrade7Test.php +++ b/src/Tests/d7/MigrateUpgrade7Test.php @@ -10,6 +10,10 @@ namespace Drupal\migrate_upgrade\Tests\d7; use Drupal\migrate_upgrade\Tests\MigrateUpgradeTestBase; /** + * Tests Drupal 7 upgrade using the migrate UI. + * + * The test method is provided by the MigrateUpgradeTestBase class. + * * @group migrate_upgrade */ class MigrateUpgrade7Test extends MigrateUpgradeTestBase { @@ -19,7 +23,7 @@ class MigrateUpgrade7Test extends MigrateUpgradeTestBase { */ protected function setUp() { parent::setUp(); - $this->loadFixture(drupal_get_path('module','migrate_drupal') . '/tests/fixtures/drupal7.php'); + $this->loadFixture(drupal_get_path('module', 'migrate_drupal') . '/tests/fixtures/drupal7.php'); } /**