PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/web/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeFormStepsTest.php

https://gitlab.com/mohamed_hussein/prodt
PHP | 147 lines | 76 code | 18 blank | 53 comment | 1 complexity | d5757a6eef3b17efd59edd27ffac25b4 MD5 | raw file
  1. <?php
  2. namespace Drupal\Tests\migrate_drupal_ui\Functional;
  3. use Drupal\migrate_drupal\MigrationConfigurationTrait;
  4. use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
  5. use Drupal\Tests\BrowserTestBase;
  6. use Drupal\Tests\WebAssert;
  7. /**
  8. * Tests the flow of the Migrate Drupal UI form.
  9. *
  10. * @group migrate_drupal_ui
  11. */
  12. class MigrateUpgradeFormStepsTest extends BrowserTestBase {
  13. use MigrationConfigurationTrait;
  14. use CreateTestContentEntitiesTrait;
  15. /**
  16. * {@inheritdoc}
  17. */
  18. protected static $modules = ['migrate_drupal_ui'];
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected $defaultTheme = 'stark';
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function setUp(): void {
  27. parent::setUp();
  28. // Log in as user 1. Migrations in the UI can only be performed as user 1.
  29. $this->drupalLogin($this->rootUser);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function getSourceBasePath() {
  35. return __DIR__ . '/files';
  36. }
  37. /**
  38. * Tests the flow of the Migrate Drupal UI form.
  39. *
  40. * The Migrate Drupal UI uses several forms to guide you through the upgrade
  41. * process. The forms displayed depend on if this is an incremental migration
  42. * or if there are potential ID conflicts. The forms are to be displayed in
  43. * this order; Overview or Incremental, if a migration has already been run
  44. * then Credential, Id conflict, if conflicts are detected, and lastly Review.
  45. */
  46. public function testMigrateUpgradeReviewPage() {
  47. /** @var \Drupal\Core\TempStore\PrivateTempStore $store */
  48. $store = \Drupal::service('tempstore.private')->get('migrate_drupal_ui');
  49. $state = \Drupal::service('state');
  50. // Test that when data required by a form is missing that the correct first
  51. // form is displayed. The first form for an initial migration is the
  52. // Overview form and for an incremental migration it is the Incremental
  53. // form.
  54. $session = $this->assertSession();
  55. // Get the current major version.
  56. [$destination_site_version] = explode('.', \Drupal::VERSION, 2);
  57. $expected['initial'] = "Upgrade a site by importing its files and the data from its database into a clean and empty new install of Drupal $destination_site_version.";
  58. $expected['incremental'] = "An upgrade has already been performed on this site.";
  59. foreach (['/upgrade', '/upgrade/incremental'] as $expected) {
  60. if ($expected === '/upgrade/incremental') {
  61. // Set a performed time to signify an incremental migration. The time
  62. // value is a UNIX timestamp.
  63. $state->set('migrate_drupal_ui.performed', 1);
  64. }
  65. // Test that an invalid step to any form goes to the correct first form.
  66. $store->set('step', 'foo');
  67. $this->assertFirstForm($session, $expected);
  68. // Test that an undefined step to any form goes to the correct first form.
  69. $store->delete('step');
  70. $this->assertFirstForm($session, $expected);
  71. // For forms that require data from the private store, test that when that
  72. // data is missing the correct first page is displayed.
  73. // The Id conflict form requires the migrations array.
  74. $store->delete('migrations');
  75. $store->set('step', 'idconflict');
  76. $this->drupalGet('/upgrade/idconflict');
  77. $session->addressEquals($expected);
  78. // The Review form requires version, migrations and system_data. Test
  79. // three times with only one of the variables missing.
  80. $store->delete('version');
  81. $store->set('migrations', ['foo', 'bar']);
  82. $store->set('system_data', ['bar', 'foo']);
  83. $store->set('step', 'review');
  84. $this->drupalGet('/upgrade/review');
  85. $session->addressEquals($expected);
  86. $store->set('version', '6');
  87. $store->delete('migrations');
  88. $store->set('system_data', ['bar', 'foo']);
  89. $store->set('step', 'review');
  90. $this->drupalGet('/upgrade/review');
  91. $session->addressEquals($expected);
  92. $store->set('version', '6');
  93. $store->set('migrations', ['foo', 'bar']);
  94. $store->delete('system_data');
  95. $store->set('step', 'review');
  96. $this->drupalGet('/upgrade/review');
  97. $session->addressEquals($expected);
  98. }
  99. // Test that the credential form is displayed for incremental migrations.
  100. $store->set('step', 'overview');
  101. $this->drupalGet('/upgrade');
  102. $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 $destination_site_version. Rollbacks are not yet supported through the user interface.");
  103. $this->submitForm([], 'Import new configuration and content from old site');
  104. $session->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.');
  105. }
  106. /**
  107. * Helper to test that a path goes to the Overview form.
  108. *
  109. * @param \Drupal\Tests\WebAssert $session
  110. * The WebAssert object.
  111. * @param string $expected
  112. * The expected response text.
  113. *
  114. * @internal
  115. */
  116. protected function assertFirstForm(WebAssert $session, string $expected): void {
  117. $paths = [
  118. '',
  119. '/incremental',
  120. '/credentials',
  121. '/idconflict',
  122. '/review',
  123. ];
  124. foreach ($paths as $path) {
  125. $this->drupalGet('/upgrade' . $path);
  126. $session->addressEquals($expected);
  127. }
  128. }
  129. }