public function MenuTreeStorageTest::testMenuLinkMoving in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php \Drupal\system\Tests\Menu\MenuTreeStorageTest::testMenuLinkMoving()
Tests the tree with moving links inside the hierarchy.
File
- core/
modules/ system/ src/ Tests/ Menu/ MenuTreeStorageTest.php, line 107 - Contains \Drupal\system\Tests\Menu\MenuTreeStorageTest.
Class
- MenuTreeStorageTest
- Tests the menu tree storage.
Namespace
Drupal\system\Tests\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', array(
'has_children' => 1,
'depth' => 1,
), array(), array(
'test2',
'test3',
));
$this
->assertMenuLink('test2', array(
'has_children' => 1,
'depth' => 2,
), array(
'test1',
), array(
'test3',
));
$this
->assertMenuLink('test4', array(
'has_children' => 1,
'depth' => 1,
), array(), array(
'test5',
'test6',
));
$this
->assertMenuLink('test5', array(
'has_children' => 1,
'depth' => 2,
), array(
'test4',
), array(
'test6',
));
$this
->assertMenuLink('test6', array(
'has_children' => 0,
'depth' => 3,
), array(
'test5',
'test4',
));
$this
->moveMenuLink('test2', 'test5');
// After the 1st move.
// <tools>
// - test1
// - test4
// -- test5
// --- test2
// ---- test3
// --- test6
$this
->assertMenuLink('test1', array(
'has_children' => 0,
'depth' => 1,
));
$this
->assertMenuLink('test2', array(
'has_children' => 1,
'depth' => 3,
), array(
'test5',
'test4',
), array(
'test3',
));
$this
->assertMenuLink('test3', array(
'has_children' => 0,
'depth' => 4,
), array(
'test2',
'test5',
'test4',
));
$this
->assertMenuLink('test4', array(
'has_children' => 1,
'depth' => 1,
), array(), array(
'test5',
'test2',
'test3',
'test6',
));
$this
->assertMenuLink('test5', array(
'has_children' => 1,
'depth' => 2,
), array(
'test4',
), array(
'test2',
'test3',
'test6',
));
$this
->assertMenuLink('test6', array(
'has_children' => 0,
'depth' => 3,
), array(
'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', array(
'has_children' => 1,
'depth' => 1,
), array(), array(
'test4',
'test5',
'test2',
'test3',
'test6',
));
$this
->assertMenuLink('test2', array(
'has_children' => 0,
'depth' => 4,
), array(
'test5',
'test4',
'test1',
));
$this
->assertMenuLink('test3', array(
'has_children' => 0,
'depth' => 2,
), array(
'test1',
));
$this
->assertMenuLink('test4', array(
'has_children' => 1,
'depth' => 2,
), array(
'test1',
), array(
'test2',
'test5',
'test6',
));
$this
->assertMenuLink('test5', array(
'has_children' => 1,
'depth' => 3,
), array(
'test4',
'test1',
), array(
'test2',
'test6',
));
$this
->assertMenuLink('test6', array(
'has_children' => 0,
'depth' => 4,
), array(
'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', array(
'has_children' => 1,
'depth' => 1,
), array(), array(
'test5',
'test2',
'test3',
'test6',
));
$this
->assertMenuLink('test2', array(
'has_children' => 0,
'depth' => 3,
), array(
'test5',
'test1',
));
$this
->assertMenuLink('test3', array(
'has_children' => 0,
'depth' => 2,
), array(
'test1',
));
$this
->assertFalse($this->treeStorage
->load('test4'));
$this
->assertMenuLink('test5', array(
'has_children' => 1,
'depth' => 2,
), array(
'test1',
), array(
'test2',
'test6',
));
$this
->assertMenuLink('test6', array(
'has_children' => 0,
'depth' => 3,
), array(
'test5',
'test1',
));
}