public function MenuTreeStorageTest::testMenuLinkMoving in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testMenuLinkMoving()
Tests the tree with moving links inside the hierarchy.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Menu/ MenuTreeStorageTest.php, line 95
Class
- MenuTreeStorageTest
- Tests the menu tree storage.
Namespace
Drupal\KernelTests\Core\MenuCode
public function testMenuLinkMoving() {
// Before the move.
// <tools>
// - test1
// -- test2
// --- test3
// - test4
// -- test5
// --- test6
$this
->addMenuLink('test1', '');
$this
->addMenuLink('test2', 'test1');
$this
->addMenuLink('test3', 'test2');
$this
->addMenuLink('test4', '');
$this
->addMenuLink('test5', 'test4');
$this
->addMenuLink('test6', 'test5');
$this
->assertMenuLink('test1', [
'has_children' => 1,
'depth' => 1,
], [], [
'test2',
'test3',
]);
$this
->assertMenuLink('test2', [
'has_children' => 1,
'depth' => 2,
], [
'test1',
], [
'test3',
]);
$this
->assertMenuLink('test4', [
'has_children' => 1,
'depth' => 1,
], [], [
'test5',
'test6',
]);
$this
->assertMenuLink('test5', [
'has_children' => 1,
'depth' => 2,
], [
'test4',
], [
'test6',
]);
$this
->assertMenuLink('test6', [
'has_children' => 0,
'depth' => 3,
], [
'test5',
'test4',
]);
$this
->moveMenuLink('test2', 'test5');
// After the 1st move.
// <tools>
// - test1
// - test4
// -- test5
// --- test2
// ---- test3
// --- test6
$this
->assertMenuLink('test1', [
'has_children' => 0,
'depth' => 1,
]);
$this
->assertMenuLink('test2', [
'has_children' => 1,
'depth' => 3,
], [
'test5',
'test4',
], [
'test3',
]);
$this
->assertMenuLink('test3', [
'has_children' => 0,
'depth' => 4,
], [
'test2',
'test5',
'test4',
]);
$this
->assertMenuLink('test4', [
'has_children' => 1,
'depth' => 1,
], [], [
'test5',
'test2',
'test3',
'test6',
]);
$this
->assertMenuLink('test5', [
'has_children' => 1,
'depth' => 2,
], [
'test4',
], [
'test2',
'test3',
'test6',
]);
$this
->assertMenuLink('test6', [
'has_children' => 0,
'depth' => 3,
], [
'test5',
'test4',
]);
$this
->moveMenuLink('test4', 'test1');
$this
->moveMenuLink('test3', 'test1');
// After the next 2 moves.
// <tools>
// - test1
// -- test3
// -- test4
// --- test5
// ---- test2
// ---- test6
$this
->assertMenuLink('test1', [
'has_children' => 1,
'depth' => 1,
], [], [
'test4',
'test5',
'test2',
'test3',
'test6',
]);
$this
->assertMenuLink('test2', [
'has_children' => 0,
'depth' => 4,
], [
'test5',
'test4',
'test1',
]);
$this
->assertMenuLink('test3', [
'has_children' => 0,
'depth' => 2,
], [
'test1',
]);
$this
->assertMenuLink('test4', [
'has_children' => 1,
'depth' => 2,
], [
'test1',
], [
'test2',
'test5',
'test6',
]);
$this
->assertMenuLink('test5', [
'has_children' => 1,
'depth' => 3,
], [
'test4',
'test1',
], [
'test2',
'test6',
]);
$this
->assertMenuLink('test6', [
'has_children' => 0,
'depth' => 4,
], [
'test5',
'test4',
'test1',
]);
// Deleting a link in the middle should re-attach child links to the parent.
$this->treeStorage
->delete('test4');
// After the delete.
// <tools>
// - test1
// -- test3
// -- test5
// --- test2
// --- test6
$this
->assertMenuLink('test1', [
'has_children' => 1,
'depth' => 1,
], [], [
'test5',
'test2',
'test3',
'test6',
]);
$this
->assertMenuLink('test2', [
'has_children' => 0,
'depth' => 3,
], [
'test5',
'test1',
]);
$this
->assertMenuLink('test3', [
'has_children' => 0,
'depth' => 2,
], [
'test1',
]);
$this
->assertFalse($this->treeStorage
->load('test4'));
$this
->assertMenuLink('test5', [
'has_children' => 1,
'depth' => 2,
], [
'test1',
], [
'test2',
'test6',
]);
$this
->assertMenuLink('test6', [
'has_children' => 0,
'depth' => 3,
], [
'test5',
'test1',
]);
}