3 namespace Drupal\Tests\migrate_drupal_ui\Functional;
5 use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
8 * Provides a base class for testing the review step of the Upgrade form.
10 abstract class MigrateUpgradeReviewPageTestBase extends MigrateUpgradeTestBase {
12 use CreateTestContentEntitiesTrait;
15 * An array suitable for drupalPostForm().
19 protected $edits = [];
24 public static $modules = ['migrate_drupal_ui'];
27 * Tests the migrate upgrade review form.
29 * The upgrade review form displays a list of modules that will be upgraded
30 * and a list of modules that will not be upgraded. This test is to ensure
31 * that the review page works correctly for all contributed Drupal 6 and
32 * Drupal 7 modules that have moved to core, e.g. Views, and for modules that
33 * were in Drupal 6 or Drupal 7 core but are not in Drupal 8 core, e.g.
36 * To do this all modules in the source fixtures are enabled, except test and
37 * example modules. This means that we can test that the modules listed in the
38 * the $noUpgradePath property of the update form class are correct, since
39 * there will be no available migrations which declare those modules as their
40 * source_module. It is assumed that the test fixtures include all modules
41 * that have moved to or dropped from core.
43 * The upgrade review form will also display errors for each migration that
44 * does not have a source_module definition. That function is not tested here.
46 * @see \Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeExecuteTestBase
48 public function testMigrateUpgradeReviewPage() {
50 // Start the upgrade process.
51 $this->drupalGet('/upgrade');
52 $this->drupalPostForm(NULL, [], t('Continue'));
53 $this->drupalPostForm(NULL, $this->edits, t('Review upgrade'));
54 $this->drupalPostForm(NULL, [], t('I acknowledge I may lose data. Continue anyway.'));
56 // Ensure there are no errors about missing modules from the test module.
57 $session = $this->assertSession();
58 $session->pageTextNotContains(t('Source module not found for migration_provider_no_annotation.'));
59 $session->pageTextNotContains(t('Source module not found for migration_provider_test.'));
60 $session->pageTextNotContains(t('Destination module not found for migration_provider_test'));
61 // Ensure there are no errors about any other missing migration providers.
62 $session->pageTextNotContains(t('module not found'));
64 // Test the upgrade paths.
65 $available_paths = $this->getAvailablePaths();
66 $missing_paths = $this->getMissingPaths();
67 $this->assertUpgradePaths($session, $available_paths, $missing_paths);
69 // Check there are no errors when a module in noUpgradePaths is not in the
70 // source system tables. Test with a module that is listed in noUpgradePaths
71 // for both Drupal 6 and Drupal 7.
72 // @see \Drupal\migrate_drupal_ui\Form\ReviewForm::$noUpgradePaths
74 $query = $this->sourceDatabase->delete('system');
75 $query->condition('type', 'module');
76 $query->condition('name', $module);
79 // Start the upgrade process.
80 $this->drupalGet('/upgrade');
81 $this->drupalPostForm(NULL, [], t('Continue'));
82 $this->drupalPostForm(NULL, $this->edits, t('Review upgrade'));
83 $this->drupalPostForm(NULL, [], t('I acknowledge I may lose data. Continue anyway.'));
85 // Test the upgrade paths.
86 $available_paths = $this->getAvailablePaths();
87 $available_paths = array_diff($available_paths, [$module]);
88 $missing_paths = $this->getMissingPaths();
89 $this->assertUpgradePaths($session, $available_paths, $missing_paths);
93 * Performs preparation for the form tests.
95 * This is not done in setup because setup executes before the source database
98 public function prepare() {
99 $connection_options = $this->sourceDatabase->getConnectionOptions();
100 $driver = $connection_options['driver'];
101 $connection_options['prefix'] = $connection_options['prefix']['default'];
103 // Use the driver connection form to get the correct options out of the
104 // database settings. This supports all of the databases we test against.
105 $drivers = drupal_get_database_types();
106 $form = $drivers[$driver]->getFormOptions($connection_options);
107 $connection_options = array_intersect_key($connection_options, $form + $form['advanced_options']);
108 $version = $this->getLegacyDrupalVersion($this->sourceDatabase);
110 $driver => $connection_options,
111 'source_private_file_path' => $this->getSourceBasePath(),
112 'version' => $version,
115 $edit['d6_source_base_path'] = $this->getSourceBasePath();
118 $edit['source_base_path'] = $this->getSourceBasePath();
120 if (count($drivers) !== 1) {
121 $edit['driver'] = $driver;
123 $this->edits = $this->translatePostValues($edit);
125 // Enable all modules in the source except test and example modules, but
126 // include simpletest.
127 /** @var \Drupal\Core\Database\Query\SelectInterface $update */
128 $update = $this->sourceDatabase->update('system')
129 ->fields(['status' => 1])
130 ->condition('type', 'module');
131 $and = $update->andConditionGroup()
132 ->condition('name', '%test%', 'NOT LIKE')
133 ->condition('name', '%example%', 'NOT LIKE');
134 $conditions = $update->orConditionGroup();
135 $conditions->condition($and);
136 $conditions->condition('name', 'simpletest');
137 $update->condition($conditions);
144 protected function getEntityCounts() {
151 protected function getEntityCountsIncremental() {