Update to Drupal 8.2.2. For more information, see https://www.drupal.org/project/drupal/releases/8.2.2

This commit is contained in:
Pantheon Automation 2016-11-02 11:43:31 -07:00 committed by Greg Anderson
parent 23ffed3665
commit 507b45a0ed
378 changed files with 11434 additions and 5542 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,43 @@
<?php
namespace Drupal\menu_link_content\Plugin\migrate\process\d7;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Process a path into an 'internal:' URI.
*
* @MigrateProcessPlugin(
* id = "d7_internal_uri"
* )
*/
class InternalUri extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($path) = $value;
$path = ltrim($path, '/');
if (parse_url($path, PHP_URL_SCHEME) == NULL) {
// If $path is the node page (i.e. node/[nid]) then return entity path.
if (preg_match('/^node\/\d+$/', $path)) {
// "entity: URI"s enable the menu link to appear in the Menu Settings
// section on the node edit page. Other entities (e.g. taxonomy terms,
// users) do not have the Menu Settings section.
return 'entity:' . $path;
}
elseif ($path == '<front>') {
return 'internal:/';
}
else {
return 'internal:/' . $path;
}
}
return $path;
}
}

View file

@ -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']);
}
/**

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,73 @@
<?php
namespace Drupal\Tests\menu_link_content\Unit\Plugin\migrate\process\d7;
use Drupal\menu_link_content\Plugin\migrate\process\d7\InternalUri;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\Tests\UnitTestCase;
/**
* Tests \Drupal\menu_link_content\Plugin\migrate\process\d7\InternalUri.
*
* @group menu_link_content
*
* @coversDefaultClass \Drupal\menu_link_content\Plugin\migrate\process\d7\InternalUri
*/
class InternalUriTest extends UnitTestCase {
/**
* The 'd7_internal_uri' process plugin being tested.
*
* @var \Drupal\menu_link_content\Plugin\migrate\process\d7\InternalUri
*/
protected $processPlugin;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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'] = [['<front>'], 'internal:/'];
$tests['node'] = [['node/27'], 'entity:node/27'];
return $tests;
}
}

View file

@ -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();
}
}