Issue #2382985 by phenaproxima, quietone, -enzo-, benjy: Migration Files for Drupal 7 Menu & Menu Entries

8.0.x
webchick 2015-09-01 12:13:34 -07:00
parent 4cc0d6d440
commit 142d048cd5
15 changed files with 237 additions and 163 deletions

View File

@ -89,6 +89,6 @@ destination:
plugin: entity:block
migration_dependencies:
required:
- d6_menu
- menu
- d6_custom_block
- d6_user_role

View File

@ -53,7 +53,7 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
array(array(1), array(1)),
array(array(2), array(2)),
),
'd6_menu' => array(
'menu' => array(
array(array('menu1'), array('menu')),
),
'd6_user_role' => array(

View File

@ -1,6 +1,6 @@
migrate.source.d6_menu_link:
migrate.source.menu_link:
type: migrate_source_sql
label: 'Drupal 6 menu link'
label: 'Menu link'
mapping:
constants:
type: migrate_entity_constant

View File

@ -3,7 +3,7 @@ label: Drupal 6 menu links
migration_tags:
- Drupal 6
source:
plugin: d6_menu_link
plugin: menu_link
constants:
bundle: menu_link_content
process:
@ -21,7 +21,7 @@ process:
default: ''
menu_name:
plugin: migration
migration: d6_menu
migration: menu
source: menu_name
'link/uri':
plugin: internal_uri
@ -45,4 +45,4 @@ destination:
plugin: entity:menu_link_content
migration_dependencies:
required:
- d6_menu
- menu

View File

@ -0,0 +1,56 @@
id: d7_menu_links
label: Drupal 7 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:
plugin: extract
source:
- options
index:
- 0
- attributes
- title
menu_name:
plugin: migration
migration: menu
source: menu_name
'link/uri':
plugin: 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: skip_on_empty
method: process
source: plid
-
plugin: migration
migration: d7_menu_links
changed: updated
destination:
plugin: entity:menu_link_content
migration_dependencies:
required:
- menu

View File

@ -2,19 +2,19 @@
/**
* @file
* Contains \Drupal\menu_link_content\Plugin\migrate\source\d6\MenuLink.
* Contains \Drupal\menu_link_content\Plugin\migrate\source\MenuLink.
*/
namespace Drupal\menu_link_content\Plugin\migrate\source\d6;
namespace Drupal\menu_link_content\Plugin\migrate\source;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\migrate\Row;
/**
* Drupal 6 menu link source from database.
* Drupal menu link source from database.
*
* @MigrateSource(
* id = "d6_menu_link",
* id = "menu_link",
* )
*/
class MenuLink extends DrupalSqlBase {
@ -23,37 +23,10 @@ class MenuLink extends DrupalSqlBase {
* {@inheritdoc}
*/
public function query() {
$query = $this->select('menu_links', 'ml')
->fields('ml', array(
'menu_name',
'mlid',
'plid',
'link_path',
'router_path',
'link_title',
'options',
'module',
'hidden',
'external',
'has_children',
'expanded',
'weight',
'depth',
'customized',
'p1',
'p2',
'p3',
'p4',
'p5',
'p6',
'p7',
'p8',
'p9',
'updated'
))
return $this->select('menu_links', 'ml')
->fields('ml')
->condition('module', 'menu')
->condition('customized', 1);
return $query;
}
/**

View File

@ -7,6 +7,7 @@
namespace Drupal\menu_link_content\Tests\Migrate\d6;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
@ -28,25 +29,17 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', ['router']);
$this->installEntitySchema('menu_link_content');
$menu = entity_create('menu', array('id' => 'secondary-links'));
$menu->enforceIsNew(TRUE);
$menu->save();
$this->prepareMigrations(array(
'd6_menu' => array(
array(array('secondary-links'), array('secondary-links')),
),
));
$this->executeMigration('menu');
$this->executeMigration('d6_menu_links');
}
/**
* Tests migration of menu links.
*/
public function testMenuLinks() {
$menu_link = entity_load('menu_link_content', 138);
$menu_link = MenuLinkContent::load(138);
$this->assertIdentical('Test 1', $menu_link->getTitle());
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
$this->assertIdentical('Test menu link 1', $menu_link->getDescription());
@ -56,7 +49,7 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
$this->assertIdentical('internal:/user/login', $menu_link->link->uri);
$this->assertIdentical(15, $menu_link->getWeight());
$menu_link = entity_load('menu_link_content', 139);
$menu_link = MenuLinkContent::load(139);
$this->assertIdentical('Test 2', $menu_link->getTitle());
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
$this->assertIdentical('Test menu link 2', $menu_link->getDescription());
@ -66,7 +59,7 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
$this->assertIdentical('internal:/admin', $menu_link->link->uri);
$this->assertIdentical(12, $menu_link->getWeight());
$menu_link = entity_load('menu_link_content', 140);
$menu_link = MenuLinkContent::load(140);
$this->assertIdentical('Drupal.org', $menu_link->getTitle());
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
$this->assertIdentical(NULL, $menu_link->getDescription());
@ -77,7 +70,7 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
$this->assertIdentical(0, $menu_link->getWeight());
// assert that missing title attributes don't stop or break migration.
$menu_link = entity_load('menu_link_content', 393);
$menu_link = MenuLinkContent::load(393);
$this->assertIdentical('Test 3', $menu_link->getTitle());
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
$this->assertIdentical(NULL, $menu_link->getDescription());

View File

@ -0,0 +1,86 @@
<?php
/**
* @file
* Contains \Drupal\menu_link_content\Tests\Migrate\d7\MigrateMenuLinkTest.
*/
namespace Drupal\menu_link_content\Tests\Migrate\d7;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\menu_link_content\MenuLinkContentInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Menu link migration.
*
* @group menu_link_content
*/
class MigrateMenuLinkTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('link', 'menu_ui', 'menu_link_content');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', ['router']);
$this->installEntitySchema('menu_link_content');
$this->executeMigration('menu');
$this->executeMigration('d7_menu_links');
}
/**
* Asserts various aspects of a menu link entity.
*
* @param string $id
* The link ID.
* @param string $title
* The expected title of the link.
* @param string $menu
* The expected ID of the menu to which the link will belong.
* @param string $description
* The link's expected description.
* @param bool $enabled
* Whether the link is enabled.
* @param bool $expanded
* Whether the link is expanded
* @param array $attributes
* Additional attributes the link is expected to have.
* @param string $uri
* The expected URI of the link.
* @param int $weight
* The expected weight of the link.
*/
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());
// 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());
}
/**
* Tests migration of menu links.
*/
public function testMenuLinks() {
$this->assertEntity(467, 'Google', 'menu-test-menu', 'Google', TRUE, FALSE, ['attributes' => ['title' => 'Google']], 'http://google.com', 0);
$this->assertEntity(468, 'Yahoo', 'menu-test-menu', 'Yahoo', TRUE, FALSE, ['attributes' => ['title' => 'Yahoo']], 'http://yahoo.com', 0);
$this->assertEntity(469, 'Bing', 'menu-test-menu', 'Bing', TRUE, FALSE, ['attributes' => ['title' => 'Bing']], 'http://bing.com', 0);
}
}

View File

@ -2,45 +2,25 @@
/**
* @file
* Contains \Drupal\Tests\menu_link_content\Unit\Plugin\migrate\source\d6\MenuLinkSourceTest.
* Contains \Drupal\Tests\menu_link_content\Unit\Plugin\migrate\source\MenuLinkSourceTest.
*/
namespace Drupal\Tests\menu_link_content\Unit\Plugin\migrate\source\d6;
namespace Drupal\Tests\menu_link_content\Unit\Plugin\migrate\source;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 menu link source plugin.
* Tests menu link source plugin.
*
* @group menu_link_content
*/
class MenuLinkSourceTest extends MigrateSqlSourceTestCase {
// The plugin system is not working during unit testing so the source plugin
// class needs to be manually specified.
const PLUGIN_CLASS = 'Drupal\menu_link_content\Plugin\migrate\source\d6\MenuLink';
const PLUGIN_CLASS = 'Drupal\menu_link_content\Plugin\migrate\source\MenuLink';
// The fake Migration configuration entity.
protected $migrationConfiguration = array(
// The ID of the entity, can be any string.
'id' => 'mlid',
// This needs to be the identifier of the actual key: cid for comment, nid
// for node and so on.
'source' => array(
'plugin' => 'drupal6_menu_link',
),
'sourceIds' => array(
'mlid' => array(
// This is where the field schema would go but for now we need to
// specify the table alias for the key. Most likely this will be the
// same as BASE_ALIAS.
'alias' => 'ml',
),
),
'destinationIds' => array(
'mlid' => array(
// This is where the field schema would go.
),
'plugin' => 'menu_link',
),
);
@ -105,10 +85,9 @@ class MenuLinkSourceTest extends MigrateSqlSourceTestCase {
* {@inheritdoc}
*/
public function setUp() {
// This array stores the database.
foreach ($this->expectedResults as $k => $row) {
$row['options'] = serialize($row['options']);
$this->databaseContents['menu_links'][$k] = $row;
$this->databaseContents['menu_links'][$k]['options'] = serialize($this->databaseContents['menu_links'][$k]['options']);
}
parent::setUp();
}

View File

@ -99,7 +99,7 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
'd6_forum_settings',
'locale_settings',
'd6_menu_settings',
'd6_menu',
'menu',
'd6_menu_links',
'd6_node_revision:*',
'd6_node_setting_promote',

View File

@ -1,9 +1,10 @@
id: d6_menu
label: Drupal 6 menus
id: menu
label: Menus
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: d6_menu
plugin: menu
process:
id: menu_name
label: title

View File

@ -2,18 +2,18 @@
/**
* @file
* Contains \Drupal\system\Plugin\migrate\source\d6\Menu.
* Contains \Drupal\system\Plugin\migrate\source\Menu.
*/
namespace Drupal\system\Plugin\migrate\source\d6;
namespace Drupal\system\Plugin\migrate\source;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 6 menu source from database.
* Menu source from database.
*
* @MigrateSource(
* id = "d6_menu",
* id = "menu",
* source_provider = "menu"
* )
*/
@ -23,9 +23,7 @@ class Menu extends DrupalSqlBase {
* {@inheritdoc}
*/
public function query() {
$query = $this->select('menu_custom', 'm')
->fields('m', array('menu_name', 'title', 'description'));
return $query;
return $this->select('menu_custom', 'm')->fields('m');
}
/**

View File

@ -2,12 +2,12 @@
/**
* @file
* Contains \Drupal\system\Tests\Migrate\d6\MigrateMenuTest.
* Contains \Drupal\system\Tests\Migrate\MigrateMenuTest.
*/
namespace Drupal\system\Tests\Migrate\d6;
namespace Drupal\system\Tests\Migrate;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Entity\Migration;
use Drupal\Core\Database\Database;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
use Drupal\system\Entity\Menu;
@ -24,7 +24,7 @@ class MigrateMenuTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_menu');
$this->executeMigration('menu');
}
/**
@ -46,12 +46,11 @@ EOT;
->condition('menu_name', 'navigation')
->execute();
db_truncate(entity_load('migration', 'd6_menu')->getIdMap()->mapTableName())->execute();
$migration = entity_load_unchanged('migration', 'd6_menu');
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$migration = Migration::load('menu');
db_truncate($migration->getIdMap()->mapTableName())->execute();
$this->executeMigration($migration);
$navigation_menu = entity_load_unchanged('menu', 'navigation');
$navigation_menu = Menu::load('navigation');
$this->assertIdentical('Home Navigation', $navigation_menu->label());
}

View File

@ -1,60 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\Tests\system\Unit\Migrate\source\d6\MenuTest.
*/
namespace Drupal\Tests\system\Unit\Migrate\source\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 menu source plugin.
*
* @group system
*/
class MenuTest extends MigrateSqlSourceTestCase {
// The plugin system is not working during unit testing so the source plugin
// class needs to be manually specified.
const PLUGIN_CLASS = 'Drupal\system\Plugin\migrate\source\d6\Menu';
// The fake Migration configuration entity.
protected $migrationConfiguration = array(
// The ID of the entity, can be any string.
'id' => 'test',
// This needs to be the identifier of the actual key: cid for comment, nid
// for node and so on.
'source' => array(
'plugin' => 'd6_menu',
),
);
// We need to set up the database contents; it's easier to do that below.
protected $expectedResults = array(
array(
'menu_name' => 'menu-name-1',
'title' => 'menu custom value 1',
'description' => 'menu custom description value 1',
),
array(
'menu_name' => 'menu-name-2',
'title' => 'menu custom value 2',
'description' => 'menu custom description value 2',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
// This array stores the database.
foreach ($this->expectedResults as $k => $row) {
$this->databaseContents['menu_custom'][$k] = $row;
}
parent::setUp();
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* @file
* Contains \Drupal\Tests\system\Unit\Plugin\migrate\source\MenuTest.
*/
namespace Drupal\Tests\system\Unit\Plugin\migrate\source;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests menu source plugin.
*
* @group system
*/
class MenuTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\system\Plugin\migrate\source\Menu';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'menu',
),
);
protected $expectedResults = array(
array(
'menu_name' => 'menu-name-1',
'title' => 'menu custom value 1',
'description' => 'menu custom description value 1',
),
array(
'menu_name' => 'menu-name-2',
'title' => 'menu custom value 2',
'description' => 'menu custom description value 2',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['menu_custom'] = $this->expectedResults;
parent::setUp();
}
}