3 namespace Drupal\Tests\menu_link_content\Kernel\Migrate\d6;
5 use Drupal\menu_link_content\Entity\MenuLinkContent;
6 use Drupal\menu_link_content\MenuLinkContentInterface;
7 use Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeTestBase;
10 * Menu link migration.
12 * @group migrate_drupal_6
14 class MigrateMenuLinkTest extends MigrateNodeTestBase {
19 public static $modules = [
20 'content_translation',
23 // Required for translation migrations.
24 'migrate_drupal_multilingual',
31 protected function setUp() {
33 $this->installEntitySchema('menu_link_content');
34 $this->executeMigrations([
36 'd6_language_content_settings',
38 'd6_node_translation',
41 'node_translation_menu_links',
46 * Asserts various aspects of a menu link entity.
50 * @param string $title
51 * The expected title of the link.
53 * The expected ID of the menu to which the link will belong.
54 * @param string $description
55 * The link's expected description.
56 * @param bool $enabled
57 * Whether the link is enabled.
58 * @param bool $expanded
59 * Whether the link is expanded.
60 * @param array $attributes
61 * Additional attributes the link is expected to have.
63 * The expected URI of the link.
65 * The expected weight of the link.
67 * @return \Drupal\menu_link_content\MenuLinkContentInterface
68 * The menu link content.
70 protected function assertEntity($id, $title, $menu, $description, $enabled, $expanded, array $attributes, $uri, $weight) {
71 /** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link */
72 $menu_link = MenuLinkContent::load($id);
73 $this->assertInstanceOf(MenuLinkContentInterface::class, $menu_link);
74 $this->assertSame($title, $menu_link->getTitle());
75 $this->assertSame($menu, $menu_link->getMenuName());
76 $this->assertSame($description, $menu_link->getDescription());
77 $this->assertSame($enabled, $menu_link->isEnabled());
78 $this->assertSame($expanded, $menu_link->isExpanded());
79 $this->assertSame($attributes, $menu_link->link->options);
80 $this->assertSame($uri, $menu_link->link->uri);
81 $this->assertSame($weight, $menu_link->getWeight());
86 * Tests migration of menu links.
88 public function testMenuLinks() {
89 $this->assertEntity('138', 'Test 1', 'secondary-links', 'Test menu link 1', TRUE, FALSE, ['attributes' => ['title' => 'Test menu link 1'], 'langcode' => 'en'], 'internal:/user/login', -50);
90 $this->assertEntity('139', 'Test 2', 'secondary-links', 'Test menu link 2', TRUE, TRUE, ['query' => 'foo=bar', 'attributes' => ['title' => 'Test menu link 2']], 'internal:/admin', -49);
91 $this->assertEntity('140', 'Drupal.org', 'secondary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => '']], 'https://www.drupal.org', -50);
93 // Assert that missing title attributes don't stop or break migration.
94 $this->assertEntity('393', 'Test 3', 'secondary-links', NULL, TRUE, FALSE, [], 'internal:/user/login', -47);
96 // Test the migration of menu links for translated nodes.
97 $this->assertEntity('459', 'The Real McCoy', 'primary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => ''], 'alter' => TRUE], 'entity:node/10', 0);
98 $this->assertEntity('460', 'Le Vrai McCoy', 'primary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => ''], 'alter' => TRUE], 'entity:node/10', 0);
99 $this->assertEntity('461', 'Abantu zulu', 'primary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => ''], 'alter' => TRUE], 'entity:node/12', 0);
100 $this->assertEntity('462', 'The Zulu People', 'primary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => ''], 'alter' => TRUE], 'entity:node/12', 0);
102 // Test the migration of menu links translation.
103 $this->assertEntity('463', 'fr - Test 1', 'secondary-links', 'fr - Test menu link 1', TRUE, FALSE, ['attributes' => ['title' => 'fr - Test menu link 1'], 'langcode' => 'fr', 'alter' => TRUE], 'internal:/user/login', -49);