comparison modules/contrib/migrate_upgrade/tests/src/Unit/MigrateUpgradeDrushRunnerTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\Tests\migrate_upgrade\Unit;
4
5 use Drupal\migrate_upgrade\MigrateUpgradeDrushRunner;
6 use Drupal\Tests\migrate\Unit\MigrateTestCase;
7
8 /**
9 * Tests for the MigrateUpgradeDrushRunner class.
10 *
11 * @group migrate_upgrade
12 * @coversDefaultClass \Drupal\migrate_upgrade\MigrateUpgradeDrushRunner
13 */
14 class MigrateUpgradeDrushRunnerTest extends MigrateTestCase {
15
16 /**
17 * Test the id substitution functions.
18 *
19 * @param array $source
20 * The source data.
21 * @param array $expected
22 * The expected results.
23 *
24 * @covers ::substituteIds
25 * @covers ::substituteMigrationIds
26 *
27 * @dataProvider getData
28 */
29 public function testIdSubstitution(array $source, array $expected) {
30 $runner = new TestMigrateUpgradeDrushRunner();
31 $results = $runner->substituteIds($source);
32 $this->assertArrayEquals($expected, $results);
33 }
34
35 /**
36 * Returns test data for the test.
37 *
38 * @return array
39 * The test data.
40 */
41 public function getData() {
42 return [
43 'Single Migration Lookup' => [
44 'source_data' => [
45 'id' => 'my_migration',
46 'process' => [
47 'element' => [
48 'plugin' => 'migration_lookup',
49 'migration' => 'my_previous_migration',
50 'source' => 'value',
51 ],
52 ],
53 'migration_dependencies' => [
54 'required' => [
55 'my_previous_migration',
56 'required_dependency',
57 ],
58 'optional' => ['optional_dependency'],
59 ],
60 ],
61 'expected_result' => [
62 'id' => 'upgrade_my_migration',
63 'process' => [
64 'element' => [
65 'plugin' => 'migration_lookup',
66 'migration' => 'upgrade_my_previous_migration',
67 'source' => 'value',
68 ],
69 ],
70 'migration_dependencies' => [
71 'required' => [
72 'upgrade_my_previous_migration',
73 'upgrade_required_dependency',
74 ],
75 'optional' => ['upgrade_optional_dependency'],
76 ],
77 ],
78 ],
79 'Dual Migration Lookup' => [
80 'source_data' => [
81 'id' => 'my_migration',
82 'process' => [
83 'element' => [
84 'plugin' => 'migration_lookup',
85 'migration' => [
86 'my_previous_migration_1',
87 'my_previous_migration_2',
88 ],
89 'source_ids' => [
90 'my_previous_migration_1' => ['source_1'],
91 'my_previous_migration_2' => ['source_2'],
92 ],
93 'source' => 'value',
94 ],
95 ],
96 'migration_dependencies' => [
97 'required' => [
98 'my_previous_migration_1',
99 'required_dependency',
100 ],
101 'optional' => [
102 'my_previous_migration_2',
103 'optional_dependency',
104 ],
105 ],
106 ],
107 'expected_result' => [
108 'id' => 'upgrade_my_migration',
109 'process' => [
110 'element' => [
111 'plugin' => 'migration_lookup',
112 'migration' => [
113 'upgrade_my_previous_migration_1',
114 'upgrade_my_previous_migration_2',
115 ],
116 'source_ids' => [
117 'upgrade_my_previous_migration_1' => ['source_1'],
118 'upgrade_my_previous_migration_2' => ['source_2'],
119 ],
120 'source' => 'value',
121 ],
122 ],
123 'migration_dependencies' => [
124 'required' => [
125 'upgrade_my_previous_migration_1',
126 'upgrade_required_dependency',
127 ],
128 'optional' => [
129 'upgrade_my_previous_migration_2',
130 'upgrade_optional_dependency',
131 ],
132 ],
133 ],
134 ],
135 ];
136 }
137
138 }
139
140 /**
141 * Test class to expose protected methods.
142 */
143 class TestMigrateUpgradeDrushRunner extends MigrateUpgradeDrushRunner {
144
145 /**
146 * {@inheritdoc}
147 */
148 public function substituteIds($entity_array) {
149 return parent::substituteIds($entity_array);
150 }
151
152 }
153
154 namespace Drupal\migrate_upgrade;
155
156 if (!function_exists('drush_get_option')) {
157
158 /**
159 * Override for called function.
160 *
161 * @param mixed $option
162 * The name of the option to get
163 * @param mixed $default
164 * Optional. The value to return if the option has not been set
165 * @param mixed $context
166 * Optional. The context to check for the option. If this is set, only this context will be searched.
167 *
168 * @return mixed
169 * The default, for this override.
170 */
171 function drush_get_option($option, $default = NULL, $context = NULL) {
172 return $default;
173 }
174
175 }