Mercurial > hg > cmmr2012-drupal-site
comparison modules/contrib/migrate_upgrade/tests/src/Kernel/DrushTest.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\migrate_upgrade\Kernel { | |
4 | |
5 use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait; | |
6 use Drupal\migrate_plus\Entity\Migration; | |
7 use Drupal\migrate_upgrade\Commands\MigrateUpgradeCommands; | |
8 use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; | |
9 use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait; | |
10 | |
11 /** | |
12 * Tests the drush command runner for migrate upgrade. | |
13 * | |
14 * @group migrate_upgrade | |
15 * | |
16 * @requires module migrate_plus | |
17 */ | |
18 class DrushTest extends MigrateDrupalTestBase { | |
19 | |
20 use FileSystemModuleDiscoveryDataProviderTrait; | |
21 use CreateMigrationsTrait; | |
22 | |
23 /** | |
24 * The migration plugin manager. | |
25 * | |
26 * @var \Drupal\migrate\Plugin\MigrationPluginManager | |
27 */ | |
28 protected $migrationManager; | |
29 | |
30 /** | |
31 * The Migrate Upgrade Command drush service. | |
32 * | |
33 * @var \Drupal\migrate_upgrade\Commands\MigrateUpgradeCommands | |
34 */ | |
35 protected $commands; | |
36 | |
37 /** | |
38 * The state service. | |
39 * | |
40 * @var \Drupal\Core\State\StateInterface | |
41 */ | |
42 protected $state; | |
43 | |
44 /** | |
45 * {@inheritdoc} | |
46 */ | |
47 protected function setUp() { | |
48 // Enable all modules. | |
49 self::$modules = array_merge(array_keys($this->coreModuleListDataProvider()), [ | |
50 'migrate_plus', | |
51 'migrate_upgrade', | |
52 ]); | |
53 parent::setUp(); | |
54 $this->installSchema('system', ['key_value', 'key_value_expire']); | |
55 $this->installConfig(self::$modules); | |
56 $this->installEntitySchema('migration_group'); | |
57 $this->installEntitySchema('migration'); | |
58 $this->migrationManager = \Drupal::service('plugin.manager.migration'); | |
59 $this->state = $this->container->get('state'); | |
60 $this->commands = new MigrateUpgradeCommands($this->state); | |
61 } | |
62 | |
63 /** | |
64 * Tests that all D6 migrations are generated as migrate plus entities. | |
65 */ | |
66 public function testD6Migrations() { | |
67 $skipped_migrations = [ | |
68 'upgrade_d6_entity_reference_translation_comment__comment_forum', | |
69 ]; | |
70 $migrations = $this->drupal6Migrations(); | |
71 $options = [ | |
72 'configure-only' => TRUE, | |
73 'legacy-db-key' => $this->sourceDatabase->getKey(), | |
74 ]; | |
75 $this->commands->upgrade($options); | |
76 $migrate_plus_migrations = Migration::loadMultiple(); | |
77 $this->assertMigrations($migrations, $migrate_plus_migrations, $skipped_migrations); | |
78 $optional = array_flip($migrate_plus_migrations['upgrade_d6_url_alias']->toArray()['migration_dependencies']['optional']); | |
79 $this->assertArrayHasKey('upgrade_d6_node_translation_page', $optional); | |
80 } | |
81 | |
82 /** | |
83 * Tests that all D7 migrations are generated as migrate plus entities. | |
84 */ | |
85 public function testD7Migrations() { | |
86 $skipped_migrations = [ | |
87 'upgrade_d7_entity_reference_translation_comment__comment_forum', | |
88 ]; | |
89 $migrations = $this->drupal7Migrations(); | |
90 $this->sourceDatabase->update('system') | |
91 ->fields(['status' => 1]) | |
92 ->condition('name', 'profile') | |
93 ->execute(); | |
94 $options = [ | |
95 'configure-only' => TRUE, | |
96 'legacy-db-key' => $this->sourceDatabase->getKey(), | |
97 ]; | |
98 $this->commands->upgrade($options); | |
99 $migrate_plus_migrations = Migration::loadMultiple(); | |
100 $this->assertMigrations($migrations, $migrate_plus_migrations, $skipped_migrations); | |
101 $optional = array_flip($migrate_plus_migrations['upgrade_d7_url_alias']->toArray()['migration_dependencies']['optional']); | |
102 $this->assertArrayHasKey('upgrade_d7_node_translation_page', $optional); | |
103 } | |
104 | |
105 /** | |
106 * Asserts that all migrations are exported as migrate plus entities. | |
107 * | |
108 * @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations | |
109 * The migrations. | |
110 * @param \Drupal\migrate_plus\Entity\MigrationInterface[] $migrate_plus_migrations | |
111 * The migrate plus config entities. | |
112 * @param array $skipped_migrations | |
113 * The migrations to skip. | |
114 */ | |
115 protected function assertMigrations(array $migrations, array $migrate_plus_migrations, array $skipped_migrations) { | |
116 foreach ($migrations as $id => $migration) { | |
117 $migration_id = 'upgrade_' . str_replace(':', '_', $migration->id()); | |
118 if (in_array($migration_id, $skipped_migrations, TRUE)) { | |
119 continue; | |
120 } | |
121 $this->assertArrayHasKey($migration_id, $migrate_plus_migrations); | |
122 } | |
123 } | |
124 | |
125 } | |
126 | |
127 } | |
128 | |
129 namespace { | |
130 | |
131 if (!function_exists('drush_print')) { | |
132 | |
133 /** | |
134 * Stub for drush_print. | |
135 * | |
136 * @param string $message | |
137 * The message to print. | |
138 * @param int $indent | |
139 * The indentation (space chars) | |
140 * @param resource $handle | |
141 * File handle to write to. NULL will write to standard output, STDERR | |
142 * will write to the standard error. See | |
143 * http://php.net/manual/en/features.commandline.io-streams.php. | |
144 * @param bool $newline | |
145 * Add a "\n" to the end of the output. Defaults to TRUE. | |
146 */ | |
147 function drush_print($message = '', $indent = 0, $handle = NULL, $newline = TRUE) { | |
148 // Do nothing. | |
149 } | |
150 | |
151 } | |
152 | |
153 if (!function_exists('dt')) { | |
154 | |
155 /** | |
156 * Stub for dt(). | |
157 * | |
158 * @param string $message | |
159 * The text. | |
160 * @param array $replace | |
161 * The replacement values. | |
162 * | |
163 * @return string | |
164 * The text. | |
165 */ | |
166 function dt($message, array $replace = []) { | |
167 return strtr($message, $replace); | |
168 } | |
169 | |
170 } | |
171 | |
172 if (!function_exists('drush_op')) { | |
173 | |
174 /** | |
175 * Stub for drush_op. | |
176 * | |
177 * @param callable $callable | |
178 * The function to call. | |
179 */ | |
180 function drush_op(callable $callable) { | |
181 $args = func_get_args(); | |
182 array_shift($args); | |
183 call_user_func_array($callable, $args); | |
184 } | |
185 | |
186 } | |
187 | |
188 } |