From e672f610e42a183b689ac64025a65f2f524d1e45 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sat, 15 Oct 2016 06:31:41 +0100 Subject: [PATCH] Issue #2807905 by svendecabooter: Convert Menu_link_content's Migrate source tests to new base class --- .../Plugin/migrate/source/MenuLinkTest.php | 225 ++++++++++++++++++ .../migrate/source/MenuLinkSourceTest.php | 217 ----------------- 2 files changed, 225 insertions(+), 217 deletions(-) create mode 100644 core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/MenuLinkTest.php delete mode 100644 core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/source/MenuLinkSourceTest.php diff --git a/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/MenuLinkTest.php b/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/MenuLinkTest.php new file mode 100644 index 000000000000..db6c5472c27e --- /dev/null +++ b/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/MenuLinkTest.php @@ -0,0 +1,225 @@ +<?php + +namespace Drupal\Tests\menu_link_content\Kernel\Plugin\migrate\source; + +use Drupal\Component\Utility\Unicode; +use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase; + +/** + * Tests the menu link source plugin. + * + * @covers \Drupal\menu_link_content\Plugin\migrate\source\MenuLink + * + * @group menu_link_content + */ +class MenuLinkTest extends MigrateSqlSourceTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['menu_link_content', 'migrate_drupal']; + + /** + * {@inheritdoc} + */ + public function providerSource() { + $tests = []; + + // The source data. + $tests[0]['source_data']['menu_links'] = [ + [ + // Customized menu link, provided by system module. + 'menu_name' => 'menu-test-menu', + 'mlid' => 140, + 'plid' => 0, + 'link_path' => 'admin/config/system/cron', + 'router_path' => 'admin/config/system/cron', + 'link_title' => 'Cron', + 'options' => array(), + 'module' => 'system', + 'hidden' => 0, + 'external' => 0, + 'has_children' => 0, + 'expanded' => 0, + 'weight' => 0, + 'depth' => 0, + 'customized' => 1, + 'p1' => '0', + 'p2' => '0', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', + 'description' => '', + ], + [ + // D6 customized menu link, provided by menu module. + 'menu_name' => 'menu-test-menu', + 'mlid' => 141, + 'plid' => 0, + 'link_path' => 'node/141', + 'router_path' => 'node/%', + 'link_title' => 'Node 141', + 'options' => array(), + 'module' => 'menu', + 'hidden' => 0, + 'external' => 0, + 'has_children' => 0, + 'expanded' => 0, + 'weight' => 0, + 'depth' => 0, + 'customized' => 1, + 'p1' => '0', + 'p2' => '0', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', + 'description' => '', + ], + [ + // D6 non-customized menu link, provided by menu module. + 'menu_name' => 'menu-test-menu', + 'mlid' => 142, + 'plid' => 0, + 'link_path' => 'node/142', + 'router_path' => 'node/%', + 'link_title' => 'Node 142', + 'options' => array(), + 'module' => 'menu', + 'hidden' => 0, + 'external' => 0, + 'has_children' => 0, + 'expanded' => 0, + 'weight' => 0, + 'depth' => 0, + 'customized' => 0, + 'p1' => '0', + 'p2' => '0', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', + 'description' => '', + ], + [ + 'menu_name' => 'menu-test-menu', + 'mlid' => 138, + 'plid' => 0, + 'link_path' => 'admin', + 'router_path' => 'admin', + 'link_title' => 'Test 1', + 'options' => array('attributes' => array('title' => 'Test menu link 1')), + 'module' => 'menu', + 'hidden' => 0, + 'external' => 0, + 'has_children' => 1, + 'expanded' => 0, + 'weight' => 15, + 'depth' => 1, + 'customized' => 1, + 'p1' => '138', + 'p2' => '0', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', + 'description' => 'Test menu link 1', + ], + [ + 'menu_name' => 'menu-test-menu', + 'mlid' => 139, + 'plid' => 138, + 'link_path' => 'admin/modules', + 'router_path' => 'admin/modules', + 'link_title' => 'Test 2', + 'options' => array('attributes' => array('title' => 'Test menu link 2')), + 'module' => 'menu', + 'hidden' => 0, + 'external' => 0, + 'has_children' => 0, + 'expanded' => 0, + 'weight' => 12, + 'depth' => 2, + 'customized' => 1, + 'p1' => '138', + 'p2' => '139', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', + 'description' => 'Test menu link 2', + ], + [ + 'menu_name' => 'menu-user', + 'mlid' => 143, + 'plid' => 0, + 'link_path' => 'admin/build/menu-customize/navigation', + 'router_path' => 'admin/build/menu-customize/%', + 'link_title' => 'Navigation', + 'options' => array(), + 'module' => 'menu', + 'hidden' => 0, + 'external' => 0, + 'has_children' => 0, + 'expanded' => 0, + 'weight' => 0, + 'depth' => 0, + 'customized' => 0, + 'p1' => '0', + 'p2' => '0', + 'p3' => '0', + 'p4' => '0', + 'p5' => '0', + 'p6' => '0', + 'p7' => '0', + 'p8' => '0', + 'p9' => '0', + 'updated' => '0', + 'description' => '', + ], + ]; + + // Add long link title attributes to source data. + $title = $this->getRandomGenerator()->string('500'); + $tests[0]['source_data']['menu_links'][0]['options']['attributes']['title'] = $title; + + // Build the expected results. + $expected = $tests[0]['source_data']['menu_links']; + + // Add long link title attributes to expected results. + $expected[0]['description'] = Unicode::truncate($title, 255); + + // Don't expect D6 menu link to a custom menu, provided by menu module. + unset($expected[5]); + + array_walk($tests[0]['source_data']['menu_links'], function (&$row) { + $row['options'] = serialize($row['options']); + }); + + $tests[0]['expected_data'] = $expected; + + return $tests; + } + +} diff --git a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/source/MenuLinkSourceTest.php b/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/source/MenuLinkSourceTest.php deleted file mode 100644 index 3c087dbeba35..000000000000 --- a/core/modules/menu_link_content/tests/src/Unit/Plugin/migrate/source/MenuLinkSourceTest.php +++ /dev/null @@ -1,217 +0,0 @@ -<?php - -namespace Drupal\Tests\menu_link_content\Unit\Plugin\migrate\source; - -use Drupal\Component\Utility\Unicode; -use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase; - -/** - * Tests menu link source plugin. - * - * @group menu_link_content - */ -class MenuLinkSourceTest extends MigrateSqlSourceTestCase { - - const PLUGIN_CLASS = 'Drupal\menu_link_content\Plugin\migrate\source\MenuLink'; - - protected $migrationConfiguration = array( - 'id' => 'mlid', - 'source' => array( - 'plugin' => 'menu_link', - ), - ); - - protected $expectedResults = array( - array( - // Customized menu link, provided by system module. - 'menu_name' => 'menu-test-menu', - 'mlid' => 140, - 'plid' => 0, - 'link_path' => 'admin/config/system/cron', - 'router_path' => 'admin/config/system/cron', - 'link_title' => 'Cron', - 'options' => array(), - 'module' => 'system', - 'hidden' => 0, - 'external' => 0, - 'has_children' => 0, - 'expanded' => 0, - 'weight' => 0, - 'depth' => 0, - 'customized' => 1, - 'p1' => '0', - 'p2' => '0', - 'p3' => '0', - 'p4' => '0', - 'p5' => '0', - 'p6' => '0', - 'p7' => '0', - 'p8' => '0', - 'p9' => '0', - 'updated' => '0', - ), - array( - // D6 customized menu link, provided by menu module. - 'menu_name' => 'menu-test-menu', - 'mlid' => 141, - 'plid' => 0, - 'link_path' => 'node/141', - 'router_path' => 'node/%', - 'link_title' => 'Node 141', - 'options' => array(), - 'module' => 'menu', - 'hidden' => 0, - 'external' => 0, - 'has_children' => 0, - 'expanded' => 0, - 'weight' => 0, - 'depth' => 0, - 'customized' => 1, - 'p1' => '0', - 'p2' => '0', - 'p3' => '0', - 'p4' => '0', - 'p5' => '0', - 'p6' => '0', - 'p7' => '0', - 'p8' => '0', - 'p9' => '0', - 'updated' => '0', - 'description' => '', - ), - array( - // D6 non-customized menu link, provided by menu module. - 'menu_name' => 'menu-test-menu', - 'mlid' => 142, - 'plid' => 0, - 'link_path' => 'node/142', - 'router_path' => 'node/%', - 'link_title' => 'Node 142', - 'options' => array(), - 'module' => 'menu', - 'hidden' => 0, - 'external' => 0, - 'has_children' => 0, - 'expanded' => 0, - 'weight' => 0, - 'depth' => 0, - 'customized' => 0, - 'p1' => '0', - 'p2' => '0', - 'p3' => '0', - 'p4' => '0', - 'p5' => '0', - 'p6' => '0', - 'p7' => '0', - 'p8' => '0', - 'p9' => '0', - 'updated' => '0', - 'description' => '', - ), - array( - 'menu_name' => 'menu-test-menu', - 'mlid' => 138, - 'plid' => 0, - 'link_path' => 'admin', - 'router_path' => 'admin', - 'link_title' => 'Test 1', - 'options' => array('attributes' => array('title' => 'Test menu link 1')), - 'module' => 'menu', - 'hidden' => 0, - 'external' => 0, - 'has_children' => 1, - 'expanded' => 0, - 'weight' => 15, - 'depth' => 1, - 'customized' => 1, - 'p1' => '138', - 'p2' => '0', - 'p3' => '0', - 'p4' => '0', - 'p5' => '0', - 'p6' => '0', - 'p7' => '0', - 'p8' => '0', - 'p9' => '0', - 'updated' => '0', - 'description' => 'Test menu link 1', - ), - array( - 'menu_name' => 'menu-test-menu', - 'mlid' => 139, - 'plid' => 138, - 'link_path' => 'admin/modules', - 'router_path' => 'admin/modules', - 'link_title' => 'Test 2', - 'options' => array('attributes' => array('title' => 'Test menu link 2')), - 'module' => 'menu', - 'hidden' => 0, - 'external' => 0, - 'has_children' => 0, - 'expanded' => 0, - 'weight' => 12, - 'depth' => 2, - 'customized' => 1, - 'p1' => '138', - 'p2' => '139', - 'p3' => '0', - 'p4' => '0', - 'p5' => '0', - 'p6' => '0', - 'p7' => '0', - 'p8' => '0', - 'p9' => '0', - 'updated' => '0', - 'description' => 'Test menu link 2', - ), - ); - - /** - * {@inheritdoc} - */ - protected function setUp() { - $this->databaseContents['menu_links'] = $this->expectedResults; - - // Add long link title attributes. - $title = $this->getRandomGenerator()->string('500'); - $this->databaseContents['menu_links'][0]['options']['attributes']['title'] = $title; - $this->expectedResults[0]['description'] = Unicode::truncate($title, 255); - - // D6 menu link to a custom menu, provided by menu module. - $this->databaseContents['menu_links'][] = [ - 'menu_name' => 'menu-user', - 'mlid' => 143, - 'plid' => 0, - 'link_path' => 'admin/build/menu-customize/navigation', - 'router_path' => 'admin/build/menu-customize/%', - 'link_title' => 'Navigation', - 'options' => array(), - 'module' => 'menu', - 'hidden' => 0, - 'external' => 0, - 'has_children' => 0, - 'expanded' => 0, - 'weight' => 0, - 'depth' => 0, - 'customized' => 0, - 'p1' => '0', - 'p2' => '0', - 'p3' => '0', - 'p4' => '0', - 'p5' => '0', - 'p6' => '0', - 'p7' => '0', - 'p8' => '0', - 'p9' => '0', - 'updated' => '0', - 'description' => '', - ]; - - array_walk($this->databaseContents['menu_links'], function (&$row) { - $row['options'] = serialize($row['options']); - }); - - parent::setUp(); - } - -} -- GitLab