Commit 663848e1 authored by alexpott's avatar alexpott

Issue #2548009 by larowlan, dawehner, bircher: Overridden menu links lose...

Issue #2548009 by larowlan, dawehner, bircher: Overridden menu links lose parent, expanded and enabled (are disabled) status on cache clear
parent be189a88
......@@ -96,7 +96,7 @@ public function updateLink(array $new_definition_values, $persist) {
if ($persist) {
// Always save the menu name as an override to avoid defaulting to tools.
$overrides['menu_name'] = $this->pluginDefinition['menu_name'];
$this->staticOverride->saveOverride($this->getPluginId(), $overrides);
$this->staticOverride->saveOverride($this->getPluginId(), $this->pluginDefinition);
}
return $this->pluginDefinition;
}
......
<?php
/**
* @file
* Contains \Drupal\menu_ui\Tests\MenuLinkReorderTest.
*/
namespace Drupal\menu_ui\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Reorder menu items.
*
* @group menu_ui
*/
class MenuLinkReorderTest extends WebTestBase {
/**
* An administrator user.
*
* @var \Drupal\user\UserInterface
*/
protected $administrator;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('menu_ui', 'test_page_test', 'node', 'block');
/**
* Test creating, editing, deleting menu links via node form widget.
*/
function testDefaultMenuLinkReorder() {
// Add the main menu block.
$this->drupalPlaceBlock('system_menu_block:main');
// Assert that the Home link is available.
$this->drupalGet('test-page');
$this->assertLink('Home');
// The administrator user that can re-order menu links.
$this->administrator = $this->drupalCreateUser(array(
'administer site configuration',
'access administration pages',
'administer menu',
));
$this->drupalLogin($this->administrator);
// Change the weight of the link to a non default value.
$edit = array(
'links[menu_plugin_id:test_page_test.front_page][weight]' => -10,
);
$this->drupalPostForm('admin/structure/menu/manage/main', $edit, t('Save'));
// The link is still there.
$this->drupalGet('test-page');
$this->assertLink('Home');
// Clear all caches.
$this->drupalPostForm('admin/config/development/performance', [], t('Clear all caches'));
// Clearing all caches should not affect the state of the menu link.
$this->drupalGet('test-page');
$this->assertLink('Home');
}
}
......@@ -2,3 +2,7 @@ test_page_test.test_page:
route_name: test_page_test.test_page
title: 'Test front page link'
weight: 0
test_page_test.front_page:
title: 'Home'
route_name: '<front>'
menu_name: main
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Menu\MenuLinkDefaultTest.
*/
namespace Drupal\Tests\Core\Menu;
use Drupal\Core\Menu\MenuLinkDefault;
use Drupal\Core\Menu\StaticMenuLinkOverridesInterface;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\Menu\MenuLinkDefault
* @group Menu
*/
class MenuLinkDefaultTest extends UnitTestCase {
/**
* @covers ::updateLink
*/
public function testUpdateLink() {
$plugin_definition = [
'title' => 'Hey jude',
'enabled' => 1,
'expanded' => 1,
'menu_name' => 'admin',
'parent' => '',
'weight' => 10,
];
$expected_plugin_definition = $plugin_definition;
$expected_plugin_definition['weight'] = -10;
$static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
$static_override->saveOverride('example_menu_link', $expected_plugin_definition);
$static_override = $static_override->reveal();
$menu_link = new MenuLinkDefault([], 'example_menu_link', $plugin_definition, $static_override);
$this->assertEquals($expected_plugin_definition, $menu_link->updateLink(['weight' => -10], TRUE));
}
/**
* @covers ::updateLink
*/
public function testUpdateLinkWithoutPersist() {
$plugin_definition = [
'title' => 'Hey jude',
'enabled' => 1,
'expanded' => 1,
'menu_name' => 'admin',
'parent' => '',
'weight' => 10,
];
$expected_plugin_definition = $plugin_definition;
$expected_plugin_definition['weight'] = -10;
$static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
$static_override->saveOverride()->shouldNotBeCalled();
$static_override = $static_override->reveal();
$menu_link = new MenuLinkDefault([], 'example_menu_link', $plugin_definition, $static_override);
$this->assertEquals($expected_plugin_definition, $menu_link->updateLink(['weight' => -10], FALSE));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment