Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / migrate_drupal_ui / tests / src / Functional / MigrateUpgradeReviewPageTestBase.php
1 <?php
2
3 namespace Drupal\Tests\migrate_drupal_ui\Functional;
4
5 use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
6
7 /**
8  * Provides a base class for testing the review step of the Upgrade form.
9  */
10 abstract class MigrateUpgradeReviewPageTestBase extends MigrateUpgradeTestBase {
11
12   use CreateTestContentEntitiesTrait;
13
14   /**
15    * An array suitable for drupalPostForm().
16    *
17    * @var array
18    */
19   protected $edits = [];
20
21   /**
22    * {@inheritdoc}
23    */
24   public static $modules = ['migrate_drupal_ui'];
25
26   /**
27    * Tests the migrate upgrade review form.
28    *
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.
34    * Overlay.
35    *
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.
42    *
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.
45    *
46    * @see \Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeExecuteTestBase
47    */
48   public function testMigrateUpgradeReviewPage() {
49     $this->prepare();
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.'));
55
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'));
63
64     // Test the upgrade paths.
65     $available_paths = $this->getAvailablePaths();
66     $missing_paths = $this->getMissingPaths();
67     $this->assertUpgradePaths($session, $available_paths, $missing_paths);
68
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
73     $module = 'help';
74     $query = $this->sourceDatabase->delete('system');
75     $query->condition('type', 'module');
76     $query->condition('name', $module);
77     $query->execute();
78
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.'));
84
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);
90   }
91
92   /**
93    * Performs preparation for the form tests.
94    *
95    * This is not done in setup because setup executes before the source database
96    * is loaded.
97    */
98   public function prepare() {
99     $connection_options = $this->sourceDatabase->getConnectionOptions();
100     $driver = $connection_options['driver'];
101     $connection_options['prefix'] = $connection_options['prefix']['default'];
102
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);
109     $edit = [
110       $driver => $connection_options,
111       'source_private_file_path' => $this->getSourceBasePath(),
112       'version' => $version,
113     ];
114     if ($version == 6) {
115       $edit['d6_source_base_path'] = $this->getSourceBasePath();
116     }
117     else {
118       $edit['source_base_path'] = $this->getSourceBasePath();
119     }
120     if (count($drivers) !== 1) {
121       $edit['driver'] = $driver;
122     }
123     $this->edits = $this->translatePostValues($edit);
124
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);
138     $update->execute();
139   }
140
141   /**
142    * {@inheritdoc}
143    */
144   protected function getEntityCounts() {
145     return [];
146   }
147
148   /**
149    * {@inheritdoc}
150    */
151   protected function getEntityCountsIncremental() {
152     return [];
153   }
154
155 }