b6543723db682e9c70776756985c2eabeefed5c4
[yaffs-website] / web / core / modules / shortcut / tests / src / Kernel / Migrate / d7 / MigrateShortcutSetTest.php
1 <?php
2
3 namespace Drupal\Tests\shortcut\Kernel\Migrate\d7;
4
5 use Drupal\shortcut\Entity\ShortcutSet;
6 use Drupal\shortcut\ShortcutSetInterface;
7 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
8
9 /**
10  * Test shortcut_set migration to ShortcutSet entities.
11  *
12  * @group shortcut
13  */
14 class MigrateShortcutSetTest extends MigrateDrupal7TestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'link',
23     'field',
24     'shortcut',
25     'menu_link_content',
26   ];
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp() {
32     parent::setUp();
33     $this->installEntitySchema('shortcut');
34     $this->installEntitySchema('menu_link_content');
35     \Drupal::service('router.builder')->rebuild();
36     $this->executeMigration('d7_shortcut_set');
37     $this->executeMigration('d7_menu');
38     $this->executeMigration('d7_menu_links');
39     $this->executeMigration('d7_shortcut');
40   }
41
42   /**
43    * Test the shortcut set migration.
44    */
45   public function testShortcutSetMigration() {
46     $this->assertEntity('default', 'Default', 2);
47     $this->assertEntity('shortcut_set_2', 'Alternative shortcut set', 2);
48   }
49
50   /**
51    * Asserts various aspects of a shortcut set entity.
52    *
53    * @param string $id
54    *   The expected shortcut set ID.
55    * @param string $label
56    *   The expected shortcut set label.
57    * @param int $expected_size
58    *   The number of shortcuts expected to be in the set.
59    */
60   protected function assertEntity($id, $label, $expected_size) {
61     $shortcut_set = ShortcutSet::load($id);
62     $this->assertTrue($shortcut_set instanceof ShortcutSetInterface);
63     /** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */
64     $this->assertIdentical($id, $shortcut_set->id());
65     $this->assertIdentical($label, $shortcut_set->label());
66
67     // Check the number of shortcuts in the set.
68     $shortcuts = $shortcut_set->getShortcuts();
69     $this->assertIdentical(count($shortcuts), $expected_size);
70   }
71
72 }