3 namespace Drupal\Tests\migrate_drupal_ui\Functional;
5 use Drupal\migrate_drupal\MigrationConfigurationTrait;
6 use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
7 use Drupal\Tests\BrowserTestBase;
8 use Drupal\Tests\WebAssert;
11 * Tests the flow of the Migrate Drupal UI form.
13 * @group migrate_drupal_ui
15 class MigrateUpgradeFormStepsTest extends BrowserTestBase {
17 use MigrationConfigurationTrait;
18 use CreateTestContentEntitiesTrait;
23 public static $modules = ['migrate_drupal_ui'];
28 protected function setUp() {
30 // Log in as user 1. Migrations in the UI can only be performed as user 1.
31 $this->drupalLogin($this->rootUser);
37 protected function getSourceBasePath() {
38 return __DIR__ . '/files';
42 * Tests the flow of the Migrate Drupal UI form.
44 * The Migrate Drupal UI uses several forms to guide you through the upgrade
45 * process. The forms displayed depend on if this is an incremental migration
46 * or if there are potential ID conflicts. The forms are to be displayed in
47 * this order; Overview or Incremental, if a migration has already been run
48 * then Credential, Id conflict, if conflicts are detected, and lastly Review.
50 public function testMigrateUpgradeReviewPage() {
51 /** @var \Drupal\Core\TempStore\PrivateTempStore $store */
52 $store = \Drupal::service('tempstore.private')->get('migrate_drupal_ui');
53 $state = \Drupal::service('state');
55 // Test that when data required by a form is missing that the correct first
56 // form is displayed. The first form for an initial migration is the
57 // Overview form and for an incremental migration it is the Incremental
59 $session = $this->assertSession();
60 $expected['initial'] = 'Upgrade a site by importing its files and the data from its database into a clean and empty new install of Drupal 8.';
61 $expected['incremental'] = "An upgrade has already been performed on this site.";
63 foreach (['/upgrade', '/upgrade/incremental'] as $expected) {
64 if ($expected === '/upgrade/incremental') {
65 // Set a performed time to signify an incremental migration. The time
66 // value is a UNIX timestamp.
67 $state->set('migrate_drupal_ui.performed', 1);
69 // Test that an invalid step to any form goes to the correct first form.
70 $store->set('step', 'foo');
71 $this->assertFirstForm($session, $expected);
72 // Test that an undefined step to any form goes to the correct first form.
73 $store->delete('step');
74 $this->assertFirstForm($session, $expected);
76 // For forms that require data from the private store, test that when that
77 // data is missing the correct first page is displayed.
78 // The Id conflict form requires the migrations array.
79 $store->delete('migrations');
80 $store->set('step', 'idconflict');
81 $this->drupalGet('/upgrade/idconflict');
82 $session->addressEquals($expected);
84 // The Review form requires version, migrations and system_data. Test
85 // three times with only one of the variables missing.
86 $store->delete('version');
87 $store->set('migrations', ['foo', 'bar']);
88 $store->set('system_data', ['bar', 'foo']);
89 $store->set('step', 'review');
90 $this->drupalGet('/upgrade/review');
91 $session->addressEquals($expected);
93 $store->set('version', '6');
94 $store->delete('migrations');
95 $store->set('system_data', ['bar', 'foo']);
96 $store->set('step', 'review');
97 $this->drupalGet('/upgrade/review');
98 $session->addressEquals($expected);
100 $store->set('version', '6');
101 $store->set('migrations', ['foo', 'bar']);
102 $store->delete('system_data');
103 $store->set('step', 'review');
104 $this->drupalGet('/upgrade/review');
105 $session->addressEquals($expected);
108 // Test that the credential form is displayed for incremental migrations.
109 $store->set('step', 'overview');
110 $this->drupalGet('/upgrade');
111 $session->pageTextContains('An upgrade has already been performed on this site. To perform a new migration, create a clean and empty new install of Drupal 8. Rollbacks are not yet supported through the user interface.');
112 $this->drupalPostForm(NULL, [], t('Import new configuration and content from old site'));
113 $session->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.');
117 * Helper to test that a path goes to the Overview form.
119 * @param \Drupal\Tests\WebAssert $session
120 * The WebAssert object.
121 * @param string $expected
122 * The expected response text.
124 protected function assertFirstForm(WebAssert $session, $expected) {
132 foreach ($paths as $path) {
133 $this->drupalGet('/upgrade' . $path);
134 $session->addressEquals($expected);