View source
<?php
namespace Drupal\menu_link_content\Tests\Migrate\d7;
use Drupal\Core\Database\Database;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\menu_link_content\MenuLinkContentInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
class MigrateMenuLinkTest extends MigrateDrupal7TestBase {
public static $modules = array(
'link',
'menu_ui',
'menu_link_content',
);
protected function setUp() {
parent::setUp();
$this
->installSchema('system', [
'router',
]);
$this
->installEntitySchema('menu_link_content');
$this
->executeMigration('menu');
}
protected function assertEntity($id, $title, $menu, $description, $enabled, $expanded, array $attributes, $uri, $weight) {
$menu_link = MenuLinkContent::load($id);
$this
->assertTrue($menu_link instanceof MenuLinkContentInterface);
$this
->assertIdentical($title, $menu_link
->getTitle());
$this
->assertIdentical($menu, $menu_link
->getMenuName());
$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());
}
public function testMenuLinks() {
$this
->executeMigration('d7_menu_links');
$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);
}
public function testUndefinedLinkTitle() {
Database::getConnection('default', 'migrate')
->update('menu_links')
->fields(array(
'options' => 'a:0:{}',
))
->condition('mlid', 467)
->execute();
$this
->executeMigration('d7_menu_links');
$this
->assertEntity(467, 'Google', 'menu-test-menu', NULL, TRUE, FALSE, [], 'http://google.com', 0);
}
}