3 namespace Drupal\Tests\block\Kernel\Migrate\d6;
5 use Drupal\block\Entity\Block;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
9 * Tests migration of blocks to configuration entities.
11 * @group migrate_drupal_6
13 class MigrateBlockTest extends MigrateDrupal6TestBase {
18 public static $modules = [
35 protected function setUp() {
38 // Install the themes used for this test.
39 $this->container->get('theme_installer')->install(['bartik', 'test_theme']);
41 $this->installConfig(['block_content']);
42 $this->installEntitySchema('block_content');
44 // Set Bartik as the default public theme.
45 $config = $this->config('system.theme');
46 $config->set('default', 'bartik');
49 $this->executeMigrations([
52 'block_content_body_field',
61 * Asserts various aspects of a block.
65 * @param array $visibility
66 * The block visibility settings.
67 * @param string $region
69 * @param string $theme
71 * @param string $weight
73 * @param array $settings
74 * (optional) The block settings.
76 * Whether the block is expected to be enabled or disabled.
78 public function assertEntity($id, $visibility, $region, $theme, $weight, array $settings = NULL, $status = TRUE) {
79 $block = Block::load($id);
80 $this->assertTrue($block instanceof Block);
81 $this->assertSame($visibility, $block->getVisibility());
82 $this->assertSame($region, $block->getRegion());
83 $this->assertSame($theme, $block->getTheme());
84 $this->assertSame($weight, $block->getWeight());
85 $this->assertSame($status, $block->status());
87 $block_settings = $block->get('settings');
88 $block_settings['id'] = current(explode(':', $block_settings['id']));
89 $this->assertEquals($settings, $block_settings);
94 * Tests the block migration.
96 public function testBlockMigration() {
97 $blocks = Block::loadMultiple();
98 $this->assertCount(14, $blocks);
100 // Check user blocks.
103 'id' => 'request_path',
105 'pages' => "<front>\n/node/1\n/blog/*",
109 'id' => 'user_login_block',
111 'provider' => 'user',
112 'label_display' => '0',
114 $this->assertEntity('user', $visibility, 'sidebar_first', 'bartik', -10, $settings);
118 'id' => 'system_menu_block',
119 'label' => 'zu - Navigation',
120 'provider' => 'system',
121 'label_display' => 'visible',
125 $this->assertEntity('user_1', $visibility, 'sidebar_first', 'bartik', -11, $settings);
131 'authenticated' => 'authenticated',
133 'context_mapping' => [
134 'user' => '@user.current_user_context:current_user',
142 'provider' => 'core',
143 'label_display' => '0',
144 'items_per_page' => '5',
146 $this->assertEntity('user_2', $visibility, 'sidebar_second', 'bartik', -11, $settings);
152 'migrate_test_role_1' => 'migrate_test_role_1',
154 'context_mapping' => [
155 'user' => '@user.current_user_context:current_user',
163 'provider' => 'core',
164 'label_display' => '0',
165 'items_per_page' => '10',
167 $this->assertEntity('user_3', $visibility, 'sidebar_second', 'bartik', -10, $settings);
169 // Check system block.
172 'id' => 'request_path',
174 'pages' => '/node/1',
178 'id' => 'system_powered_by_block',
180 'provider' => 'system',
181 'label_display' => '0',
183 $this->assertEntity('system', $visibility, 'footer_fifth', 'bartik', -5, $settings);
185 // Check menu blocks.
189 'provider' => 'core',
190 'label_display' => '0',
192 $this->assertEntity('menu', [], 'header', 'bartik', -5, $settings);
194 // Check aggregator block.
196 'id' => 'aggregator_feed_block',
198 'provider' => 'aggregator',
199 'label_display' => '0',
203 $this->assertEntity('aggregator', [], 'sidebar_second', 'bartik', -2, $settings);
207 'id' => 'book_navigation',
209 'provider' => 'book',
210 'label_display' => '0',
211 'block_mode' => 'book pages',
213 $this->assertEntity('book', [], 'sidebar_second', 'bartik', -4, $settings);
215 // Check forum block settings.
217 'id' => 'forum_active_block',
219 'provider' => 'forum',
220 'label_display' => '0',
223 'administrative' => '1',
226 $this->assertEntity('forum', [], 'sidebar_first', 'bartik', -8, $settings);
229 'id' => 'forum_new_block',
231 'provider' => 'forum',
232 'label_display' => '0',
235 'administrative' => '1',
238 $this->assertEntity('forum_1', [], 'sidebar_first', 'bartik', -9, $settings);
240 // Check statistic block settings.
244 'provider' => 'core',
245 'label_display' => '0',
250 $this->assertEntity('statistics', [], 'sidebar_second', 'bartik', 0, $settings);
252 // Check custom blocks.
255 'id' => 'request_path',
257 'pages' => '<front>',
261 'id' => 'block_content',
262 'label' => 'Static Block',
263 'provider' => 'block_content',
264 'label_display' => 'visible',
267 'view_mode' => 'full',
269 $this->assertEntity('block', $visibility, 'content', 'bartik', 0, $settings);
273 'id' => 'request_path',
279 'id' => 'block_content',
280 'label' => 'Another Static Block',
281 'provider' => 'block_content',
282 'label_display' => 'visible',
285 'view_mode' => 'full',
287 // We expect this block to be disabled because '' is not a valid region,
288 // and block_rebuild() will disable any block in an invalid region.
289 $this->assertEntity('block_1', $visibility, '', 'bluemarine', -4, $settings, FALSE);
292 'id' => 'block_content',
294 'provider' => 'block_content',
295 'label_display' => '0',
298 'view_mode' => 'full',
300 $this->assertEntity('block_2', [], 'right', 'test_theme', -7, $settings);
302 // Custom block with php code is not migrated.
303 $block = Block::load('block_3');
304 $this->assertFalse($block instanceof Block);