diff --git a/core/modules/menu_link_content/migration_templates/menu_links.yml b/core/modules/menu_link_content/migration_templates/d6_menu_links.yml similarity index 90% rename from core/modules/menu_link_content/migration_templates/menu_links.yml rename to core/modules/menu_link_content/migration_templates/d6_menu_links.yml index b6bcdaf74ab6..c418bfebdd29 100644 --- a/core/modules/menu_link_content/migration_templates/menu_links.yml +++ b/core/modules/menu_link_content/migration_templates/d6_menu_links.yml @@ -1,8 +1,7 @@ -id: menu_links +id: d6_menu_links label: Menu links migration_tags: - Drupal 6 - - Drupal 7 source: plugin: menu_link process: @@ -13,8 +12,11 @@ process: - plugin: migration # The menu migration is in the system module. - migration: menu + migration: d6_menu source: menu_name + - + plugin: skip_on_empty + method: row - plugin: static_map map: @@ -51,4 +53,4 @@ destination: no_stub: true migration_dependencies: required: - - menu + - d6_menu diff --git a/core/modules/menu_link_content/migration_templates/d7_menu_links.yml b/core/modules/menu_link_content/migration_templates/d7_menu_links.yml new file mode 100644 index 000000000000..8581e2c07f60 --- /dev/null +++ b/core/modules/menu_link_content/migration_templates/d7_menu_links.yml @@ -0,0 +1,52 @@ +id: d7_menu_links +label: Menu links +migration_tags: + - Drupal 7 +source: + plugin: menu_link + constants: + bundle: menu_link_content +process: + id: mlid + bundle: 'constants/bundle' + title: link_title + description: description + menu_name: + - + plugin: migration + migration: d7_menu + source: menu_name + - + plugin: skip_on_empty + method: row + 'link/uri': + plugin: d7_internal_uri + source: + - link_path + 'link/options': options + route: + plugin: route + source: + - link_path + - options + route_name: '@route/route_name' + route_parameters: '@route/route_parameters' + url: '@route/url' + options: '@route/options' + external: external + weight: weight + expanded: expanded + enabled: enabled + parent: + plugin: menu_link_parent + source: + - plid + - '@menu_name' + - parent_link_path + changed: updated +destination: + plugin: entity:menu_link_content + no_stub: true +migration_dependencies: + required: + - d7_menu diff --git a/core/modules/menu_link_content/src/Plugin/migrate/process/d7/InternalUri.php b/core/modules/menu_link_content/src/Plugin/migrate/process/d7/InternalUri.php new file mode 100644 index 000000000000..9d373568fccd --- /dev/null +++ b/core/modules/menu_link_content/src/Plugin/migrate/process/d7/InternalUri.php @@ -0,0 +1,43 @@ +') { + return 'internal:/'; + } + else { + return 'internal:/' . $path; + } + } + return $path; + } + +} diff --git a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTest.php b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTest.php index 58171e361751..eea87dbabee2 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTest.php @@ -23,7 +23,7 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase { protected function setUp() { parent::setUp(); $this->installEntitySchema('menu_link_content'); - $this->executeMigrations(['menu', 'menu_links']); + $this->executeMigrations(['d6_menu', 'd6_menu_links']); } /** diff --git a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d7/MigrateMenuLinkTest.php b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d7/MigrateMenuLinkTest.php index 484c5a49da75..0c915d423494 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d7/MigrateMenuLinkTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d7/MigrateMenuLinkTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\menu_link_content\Kernel\Migrate\d7; -use Drupal\Core\Database\Database; use Drupal\Core\Menu\MenuTreeParameters; use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\menu_link_content\MenuLinkContentInterface; @@ -27,7 +26,7 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase { protected function setUp() { parent::setUp(); $this->installEntitySchema('menu_link_content'); - $this->executeMigration('menu'); + $this->executeMigrations(['d7_menu', 'd7_menu_links']); \Drupal::service('router.builder')->rebuild(); } @@ -52,21 +51,24 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase { * The expected URI of the link. * @param int $weight * The expected weight of the link. + * + * @return \Drupal\menu_link_content\MenuLinkContentInterface + * The menu link content. */ protected function assertEntity($id, $title, $menu, $description, $enabled, $expanded, array $attributes, $uri, $weight) { /** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link */ $menu_link = MenuLinkContent::load($id); $this->assertTrue($menu_link instanceof MenuLinkContentInterface); - $this->assertIdentical($title, $menu_link->getTitle()); - $this->assertIdentical($menu, $menu_link->getMenuName()); + $this->assertSame($title, $menu_link->getTitle()); + $this->assertSame($menu, $menu_link->getMenuName()); // The migration sets the description of the link to the value of the // 'title' attribute. Bit strange, but there you go. - $this->assertIdentical($description, $menu_link->getDescription()); - $this->assertIdentical($enabled, $menu_link->isEnabled()); - $this->assertIdentical($expanded, $menu_link->isExpanded()); - $this->assertIdentical($attributes, $menu_link->link->options); - $this->assertIdentical($uri, $menu_link->link->uri); - $this->assertIdentical($weight, $menu_link->getWeight()); + $this->assertSame($description, $menu_link->getDescription()); + $this->assertSame($enabled, $menu_link->isEnabled()); + $this->assertSame($expanded, $menu_link->isExpanded()); + $this->assertSame($attributes, $menu_link->link->options); + $this->assertSame($uri, $menu_link->link->uri); + $this->assertSame($weight, $menu_link->getWeight()); return $menu_link; } @@ -74,31 +76,36 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase { * Tests migration of menu links. */ public function testMenuLinks() { - $this->executeMigration('menu_links'); $this->assertEntity(469, 'Bing', static::MENU_NAME, 'Bing', TRUE, FALSE, ['attributes' => ['title' => 'Bing']], 'http://bing.com', 0); $this->assertEntity(467, 'Google', static::MENU_NAME, 'Google', TRUE, FALSE, ['attributes' => ['title' => 'Google']], 'http://google.com', 0); $this->assertEntity(468, 'Yahoo', static::MENU_NAME, 'Yahoo', TRUE, FALSE, ['attributes' => ['title' => 'Yahoo']], 'http://yahoo.com', 0); + // Tests migrating an external link with an undefined title attribute. + $this->assertEntity(470, 'Ask', static::MENU_NAME, NULL, TRUE, FALSE, [], 'http://ask.com', 0); + $this->assertEntity(245, 'Home', 'main', NULL, TRUE, FALSE, [], 'internal:/', 0); + $this->assertEntity(478, 'custom link test', 'admin', NULL, TRUE, FALSE, ['attributes' => ['title' => '']], 'internal:/admin/content/book', 0); + $this->assertEntity(479, 'node link test', 'tools', 'node 3', TRUE, FALSE, ['attributes' => ['title' => 'node 3']], 'entity:node/3', 3); + $menu_link_tree_service = \Drupal::service('menu.link_tree'); $parameters = new MenuTreeParameters(); $tree = $menu_link_tree_service->load(static::MENU_NAME, $parameters); - $this->assertEqual(2, count($tree)); + $this->assertCount(2, $tree); $children = 0; $google_found = FALSE; foreach ($tree as $menu_link_tree_element) { $children += $menu_link_tree_element->hasChildren; if ($menu_link_tree_element->link->getUrlObject()->toString() == 'http://bing.com') { - $this->assertEqual(reset($menu_link_tree_element->subtree)->link->getUrlObject()->toString(), 'http://google.com'); + $this->assertEquals(reset($menu_link_tree_element->subtree)->link->getUrlObject()->toString(), 'http://google.com'); $google_found = TRUE; } } - $this->assertEqual(1, $children); + $this->assertEquals(1, $children); $this->assertTrue($google_found); // Now find the custom link under a system link. $parameters->root = 'system.admin_structure'; $tree = $menu_link_tree_service->load(static::MENU_NAME, $parameters); $found = FALSE; foreach ($tree as $menu_link_tree_element) { - $this->pass($menu_link_tree_element->link->getUrlObject()->toString()); + $this->assertTrue($menu_link_tree_element->link->getUrlObject()->toString()); if ($menu_link_tree_element->link->getTitle() == 'custom link test') { $found = TRUE; break; @@ -107,20 +114,4 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase { $this->assertTrue($found); } - /** - * Tests migrating a link with an undefined title attribute. - */ - public function testUndefinedLinkTitle() { - Database::getConnection('default', 'migrate') - ->update('menu_links') - ->fields(array( - 'options' => 'a:0:{}', - )) - ->condition('mlid', 467) - ->execute(); - - $this->executeMigration('menu_links'); - $this->assertEntity(467, 'Google', static::MENU_NAME, NULL, TRUE, FALSE, [], 'http://google.com', 0); - } - } diff --git a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d7/InternalUriTest.php b/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d7/InternalUriTest.php new file mode 100644 index 000000000000..9292718ae48c --- /dev/null +++ b/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/process/d7/InternalUriTest.php @@ -0,0 +1,73 @@ +processPlugin = new InternalUri([], 'd7_internal_uri', []); + } + + /** + * Tests InternalUri::transform(). + * + * @param array $value + * The value to pass to InternalUri::transform(). + * @param string $expected + * The expected return value of InternalUri::transform(). + * + * @dataProvider providerTestTransform + * + * @covers ::transform + */ + public function testTransform(array $value, $expected) { + $migrate_executable = $this->prophesize(MigrateExecutableInterface::class); + $row = $this->prophesize(Row::class); + + $actual = $this->processPlugin->transform($value, $migrate_executable->reveal(), $row->reveal(), 'link/uri'); + $this->assertEquals($expected, $actual); + } + + /** + * Provides test cases for InternalUriTest::testTransform(). + * + * @return array + * An array of test cases, each which the following values: + * - The value array to pass to InternalUri::transform(). + * - The expected path returned by InternalUri::transform(). + */ + public function providerTestTransform() { + $tests = []; + $tests['with_scheme'] = [['http://example.com'], 'http://example.com']; + $tests['leading_slash'] = [['/test'], 'internal:/test']; + $tests['without_scheme'] = [['test'], 'internal:/test']; + $tests['front'] = [[''], 'internal:/']; + $tests['node'] = [['node/27'], 'entity:node/27']; + return $tests; + } + +} diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index 119deadeb2bd..98e56382f508 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -19199,6 +19199,33 @@ $connection->insert('menu_links') 'p9' => '0', 'updated' => '0', )) +->values(array( + 'menu_name' => 'menu-test-menu', + 'mlid' => '470', + 'plid' => '469', + 'link_path' => 'http://ask.com', + 'router_path' => '', + 'link_title' => 'Ask', + 'options' => 'a:0:{}', + 'module' => 'menu', + 'hidden' => '0', + 'external' => '1', + 'has_children' => '0', + 'expanded' => '0', + 'weight' => '0', + 'depth' => '2', + 'customized' => '1', + 'p1' => '469', + 'p2' => '470', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', +)) ->values(array( 'menu_name' => 'shortcut-set-2', 'mlid' => '472', @@ -19334,6 +19361,33 @@ $connection->insert('menu_links') 'p9' => '0', 'updated' => '0', )) +->values(array( + 'menu_name' => 'navigation', + 'mlid' => '479', + 'plid' => '0', + 'link_path' => 'node/3', + 'router_path' => 'node/3', + 'link_title' => 'node link test', + 'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:6:"node 3";}}', + 'module' => 'menu', + 'hidden' => '0', + 'external' => '0', + 'has_children' => '0', + 'expanded' => '0', + 'weight' => '3', + 'depth' => '1', + 'customized' => '1', + 'p1' => '479', + 'p2' => '0', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', +)) ->execute(); $connection->schema()->createTable('menu_router', array( diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index 89772f8708b4..2d60c4694c2d 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -290,7 +290,7 @@ class MigrateUpgradeForm extends ConfirmFormBase { 'source_module' => 'locale', 'destination_module' => 'locale', ], - 'menu_links' => [ + 'd6_menu_links' => [ 'source_module' => 'menu', 'destination_module' => 'menu_link_content', ], @@ -298,6 +298,10 @@ class MigrateUpgradeForm extends ConfirmFormBase { 'source_module' => 'menu', 'destination_module' => 'menu_ui', ], + 'd7_menu_links' => [ + 'source_module' => 'menu', + 'destination_module' => 'menu_link_content', + ], 'd6_node' => [ 'source_module' => 'node', 'destination_module' => 'node', @@ -474,7 +478,11 @@ class MigrateUpgradeForm extends ConfirmFormBase { 'source_module' => 'system', 'destination_module' => 'system', ], - 'menu' => [ + 'd6_menu' => [ + 'source_module' => 'menu', + 'destination_module' => 'system', + ], + 'd7_menu' => [ 'source_module' => 'menu', 'destination_module' => 'system', ], diff --git a/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php index 16f2a15bc5c3..74d4237ca953 100644 --- a/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php +++ b/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php @@ -57,13 +57,13 @@ class MigrateUpgrade7Test extends MigrateUpgradeTestBase { 'shortcut' => 6, 'shortcut_set' => 2, 'action' => 16, - 'menu' => 10, + 'menu' => 6, 'taxonomy_term' => 18, 'taxonomy_vocabulary' => 3, 'tour' => 4, 'user' => 4, 'user_role' => 3, - 'menu_link_content' => 9, + 'menu_link_content' => 7, 'view' => 12, 'date_format' => 11, 'entity_form_display' => 16, diff --git a/core/modules/shortcut/migration_templates/d7_shortcut.yml b/core/modules/shortcut/migration_templates/d7_shortcut.yml index ba986eb85300..da3d894940ff 100644 --- a/core/modules/shortcut/migration_templates/d7_shortcut.yml +++ b/core/modules/shortcut/migration_templates/d7_shortcut.yml @@ -23,4 +23,4 @@ destination: migration_dependencies: required: - d7_shortcut_set - - menu_links + - d7_menu_links diff --git a/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetTest.php b/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetTest.php index 316c53f24e68..86582864143d 100644 --- a/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetTest.php +++ b/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetTest.php @@ -34,8 +34,8 @@ class MigrateShortcutSetTest extends MigrateDrupal7TestBase { $this->installEntitySchema('menu_link_content'); \Drupal::service('router.builder')->rebuild(); $this->executeMigration('d7_shortcut_set'); - $this->executeMigration('menu'); - $this->executeMigration('menu_links'); + $this->executeMigration('d7_menu'); + $this->executeMigration('d7_menu_links'); $this->executeMigration('d7_shortcut'); } diff --git a/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetUsersTest.php b/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetUsersTest.php index 6a9ebe346b63..1b15dcdef8c0 100644 --- a/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetUsersTest.php +++ b/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetUsersTest.php @@ -36,8 +36,8 @@ class MigrateShortcutSetUsersTest extends MigrateDrupal7TestBase { $this->executeMigration('d7_user_role'); $this->executeMigration('d7_user'); $this->executeMigration('d7_shortcut_set'); - $this->executeMigration('menu'); - $this->executeMigration('menu_links'); + $this->executeMigration('d7_menu'); + $this->executeMigration('d7_menu_links'); $this->executeMigration('d7_shortcut'); $this->executeMigration('d7_shortcut_set_users'); } diff --git a/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutTest.php b/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutTest.php index 791deb2192e2..18f55170a931 100644 --- a/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutTest.php +++ b/core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutTest.php @@ -34,8 +34,8 @@ class MigrateShortcutTest extends MigrateDrupal7TestBase { $this->installEntitySchema('menu_link_content'); \Drupal::service('router.builder')->rebuild(); $this->executeMigration('d7_shortcut_set'); - $this->executeMigration('menu'); - $this->executeMigration('menu_links'); + $this->executeMigration('d7_menu'); + $this->executeMigration('d7_menu_links'); $this->executeMigration('d7_shortcut'); } diff --git a/core/modules/system/migration_templates/menu.yml b/core/modules/system/migration_templates/d6_menu.yml similarity index 91% rename from core/modules/system/migration_templates/menu.yml rename to core/modules/system/migration_templates/d6_menu.yml index 974a2d68a11e..25ad0af9bf78 100644 --- a/core/modules/system/migration_templates/menu.yml +++ b/core/modules/system/migration_templates/d6_menu.yml @@ -1,9 +1,8 @@ # The menu_settings migration is in the menu_ui module. -id: menu +id: d6_menu label: Menus migration_tags: - Drupal 6 - - Drupal 7 source: plugin: menu process: diff --git a/core/modules/system/migration_templates/d7_menu.yml b/core/modules/system/migration_templates/d7_menu.yml new file mode 100644 index 000000000000..da47b3656db6 --- /dev/null +++ b/core/modules/system/migration_templates/d7_menu.yml @@ -0,0 +1,20 @@ +id: d7_menu +label: Menus +migration_tags: + - Drupal 7 +source: + plugin: menu +process: + id: + plugin: static_map + bypass: true + source: menu_name + map: + main-menu: main + management: admin + navigation: tools + user-menu: account + label: title + description: description +destination: + plugin: entity:menu diff --git a/core/modules/system/tests/src/Kernel/Migrate/MigrateMenuTest.php b/core/modules/system/tests/src/Kernel/Migrate/d6/MigrateMenuTest.php similarity index 75% rename from core/modules/system/tests/src/Kernel/Migrate/MigrateMenuTest.php rename to core/modules/system/tests/src/Kernel/Migrate/d6/MigrateMenuTest.php index c66ca02c7401..e6ac30c8826a 100644 --- a/core/modules/system/tests/src/Kernel/Migrate/MigrateMenuTest.php +++ b/core/modules/system/tests/src/Kernel/Migrate/d6/MigrateMenuTest.php @@ -1,6 +1,6 @@ executeMigration('menu'); + $this->executeMigration('d6_menu'); } /** @@ -26,12 +26,12 @@ class MigrateMenuTest extends MigrateDrupal6TestBase { */ public function testMenu() { $navigation_menu = Menu::load('navigation'); - $this->assertIdentical('navigation', $navigation_menu->id()); - $this->assertIdentical('Navigation', $navigation_menu->label()); + $this->assertSame('navigation', $navigation_menu->id()); + $this->assertSame('Navigation', $navigation_menu->label()); $expected = <<assertIdentical($expected, $navigation_menu->getDescription()); + $this->assertSame($expected, $navigation_menu->getDescription()); // Test that we can re-import using the ConfigEntityBase destination. Database::getConnection('default', 'migrate') @@ -40,14 +40,14 @@ EOT; ->condition('menu_name', 'navigation') ->execute(); - $migration = $this->getMigration('menu'); + $migration = $this->getMigration('d6_menu'); \Drupal::database() ->truncate($migration->getIdMap()->mapTableName()) ->execute(); $this->executeMigration($migration); $navigation_menu = Menu::load('navigation'); - $this->assertIdentical('Home Navigation', $navigation_menu->label()); + $this->assertSame('Home Navigation', $navigation_menu->label()); } } diff --git a/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateMenuTest.php b/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateMenuTest.php new file mode 100644 index 000000000000..987084539698 --- /dev/null +++ b/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateMenuTest.php @@ -0,0 +1,68 @@ +executeMigration('d7_menu'); + } + + /** + * Asserts various aspects of a menu. + * + * @param $id + * The menu ID. + * @param $label + * The menu label. + * @param $description + * The menu description. + */ + protected function assertEntity($id, $label, $description) { + $navigation_menu = Menu::load($id); + $this->assertSame($id, $navigation_menu->id()); + $this->assertSame($label, $navigation_menu->label()); + $this->assertSame($description, $navigation_menu->getDescription()); + } + + /** + * Tests the Drupal 7 menu to Drupal 8 migration. + */ + public function testMenu() { + $this->assertEntity('main', 'Main menu', 'The Main menu is used on many sites to show the major sections of the site, often in a top navigation bar.'); + $this->assertEntity('admin', 'Management', 'The Management menu contains links for administrative tasks.'); + $this->assertEntity('menu-test-menu', 'Test Menu', 'Test menu description.'); + $this->assertEntity('tools', 'Navigation', 'The Navigation menu contains links intended for site visitors. Links are added to the Navigation menu automatically by some modules.'); + $this->assertEntity('account', 'User menu', 'The User menu contains links related to the user\'s account, as well as the \'Log out\' link.'); + + // Test that we can re-import using the ConfigEntityBase destination. + Database::getConnection('default', 'migrate') + ->update('menu_custom') + ->fields(array('title' => 'Home Navigation')) + ->condition('menu_name', 'navigation') + ->execute(); + + $migration = $this->getMigration('d7_menu'); + \Drupal::database() + ->truncate($migration->getIdMap()->mapTableName()) + ->execute(); + $this->executeMigration($migration); + + $navigation_menu = Menu::load('tools'); + $this->assertSame('Home Navigation', $navigation_menu->label()); + } + +}