Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / menu_link_content / tests / src / Kernel / Migrate / d6 / MigrateMenuLinkTest.php
1 <?php
2
3 namespace Drupal\Tests\menu_link_content\Kernel\Migrate\d6;
4
5 use Drupal\menu_link_content\Entity\MenuLinkContent;
6 use Drupal\menu_link_content\MenuLinkContentInterface;
7 use Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeTestBase;
8
9 /**
10  * Menu link migration.
11  *
12  * @group migrate_drupal_6
13  */
14 class MigrateMenuLinkTest extends MigrateNodeTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = [
20     'content_translation',
21     'language',
22     'menu_link_content',
23     // Required for translation migrations.
24     'migrate_drupal_multilingual',
25     'menu_ui',
26   ];
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp() {
32     parent::setUp();
33     $this->installEntitySchema('menu_link_content');
34     $this->executeMigrations([
35       'language',
36       'd6_language_content_settings',
37       'd6_node',
38       'd6_node_translation',
39       'd6_menu',
40       'd6_menu_links',
41       'node_translation_menu_links',
42     ]);
43   }
44
45   /**
46    * Asserts various aspects of a menu link entity.
47    *
48    * @param string $id
49    *   The link ID.
50    * @param string $title
51    *   The expected title of the link.
52    * @param string $menu
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.
62    * @param string $uri
63    *   The expected URI of the link.
64    * @param int $weight
65    *   The expected weight of the link.
66    *
67    * @return \Drupal\menu_link_content\MenuLinkContentInterface
68    *   The menu link content.
69    */
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());
82     return $menu_link;
83   }
84
85   /**
86    * Tests migration of menu links.
87    */
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);
92
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);
95
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);
101
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);
104   }
105
106 }