Mercurial > hg > cmmr2012-drupal-site
comparison modules/contrib/migrate_plus/src/Tests/MigrationGroupTest.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\migrate_plus\Tests; | |
4 | |
5 use Drupal\KernelTests\KernelTestBase; | |
6 use Drupal\migrate_plus\Entity\Migration; | |
7 use Drupal\migrate_plus\Entity\MigrationGroup; | |
8 use Drupal\migrate_plus\Entity\MigrationGroupInterface; | |
9 | |
10 /** | |
11 * Test migration groups. | |
12 * | |
13 * @group migrate_plus | |
14 */ | |
15 class MigrationGroupTest extends KernelTestBase { | |
16 | |
17 public static $modules = ['migrate', 'migrate_plus']; | |
18 | |
19 /** | |
20 * Test that group configuration is properly merged into specific migrations. | |
21 */ | |
22 public function testConfigurationMerge() { | |
23 $group_id = 'test_group'; | |
24 | |
25 /** @var MigrationGroupInterface $migration_group */ | |
26 $group_configuration = [ | |
27 'id' => $group_id, | |
28 'shared_configuration' => [ | |
29 'migration_tags' => ['Drupal 6'], // In migration, so will be overridden. | |
30 'source' => [ | |
31 'constants' => [ | |
32 'type' => 'image', // Not in migration, so will be added. | |
33 'cardinality' => '1', // In migration, so will be overridden. | |
34 ], | |
35 ], | |
36 'destination' => ['plugin' => 'field_storage_config'], // Not in migration, so will be added. | |
37 ], | |
38 ]; | |
39 $this->container->get('entity_type.manager')->getStorage('migration_group') | |
40 ->create($group_configuration)->save(); | |
41 | |
42 /** @var \Drupal\migrate_plus\Entity\MigrationInterface $migration */ | |
43 $migration = $this->container->get('entity_type.manager') | |
44 ->getStorage('migration')->create([ | |
45 'id' => 'specific_migration', | |
46 'load' => [], | |
47 'migration_group' => $group_id, | |
48 'label' => 'Unaffected by the group', | |
49 'migration_tags' => ['Drupal 7'], // Overrides group. | |
50 'destination' => [], | |
51 'source' => [], | |
52 'migration_dependencies' => [], | |
53 ]); | |
54 $migration->set('source', [ | |
55 'plugin' => 'empty', // Not in group, persists. | |
56 'constants' => [ | |
57 'entity_type' => 'user', // Not in group, persists. | |
58 'cardinality' => '3', // Overrides group. | |
59 ], | |
60 ]); | |
61 $migration->save(); | |
62 | |
63 $expected_config = [ | |
64 'migration_group' => $group_id, | |
65 'label' => 'Unaffected by the group', | |
66 'migration_tags' => ['Drupal 7'], | |
67 'source' => [ | |
68 'plugin' => 'empty', | |
69 'constants' => [ | |
70 'entity_type' => 'user', | |
71 'type' => 'image', | |
72 'cardinality' => '3', | |
73 ], | |
74 ], | |
75 'destination' => ['plugin' => 'field_storage_config'], | |
76 ]; | |
77 /** @var \Drupal\migrate\Plugin\MigrationInterface $loaded_migration */ | |
78 $loaded_migration = $this->container->get('plugin.manager.config_entity_migration') | |
79 ->createInstance('specific_migration'); | |
80 foreach ($expected_config as $key => $expected_value) { | |
81 $actual_value = $loaded_migration->get($key); | |
82 $this->assertEquals($expected_value, $actual_value); | |
83 } | |
84 } | |
85 | |
86 /** | |
87 * Test that deleting a group deletes its migrations. | |
88 */ | |
89 public function testDelete() { | |
90 /** @var MigrationGroupInterface $migration_group */ | |
91 $group_configuration = [ | |
92 'id' => 'test_group', | |
93 ]; | |
94 $migration_group = $this->container->get('entity_type.manager') | |
95 ->getStorage('migration_group')->create($group_configuration); | |
96 $migration_group->save(); | |
97 | |
98 /** @var \Drupal\migrate_plus\Entity\MigrationInterface $migration */ | |
99 $migration = $this->container->get('entity_type.manager') | |
100 ->getStorage('migration')->create([ | |
101 'id' => 'specific_migration', | |
102 'migration_group' => 'test_group', | |
103 'migration_tags' => [], | |
104 'load' => [], | |
105 'destination' => [], | |
106 'source' => [], | |
107 'migration_dependencies' => [], | |
108 ]); | |
109 $migration->save(); | |
110 | |
111 /** @var \Drupal\migrate_plus\Entity\MigrationGroupInterface $loaded_migration_group */ | |
112 $loaded_migration_group = MigrationGroup::load('test_group'); | |
113 $loaded_migration_group->delete(); | |
114 | |
115 /** @var \Drupal\migrate_plus\Entity\MigrationInterface $loaded_migration */ | |
116 $loaded_migration = Migration::load('specific_migration'); | |
117 $this->assertNull($loaded_migration); | |
118 } | |
119 | |
120 } |