19 private $activeMenuItemMock;
24 private $menuItemMock;
34 private $objectManagerHelper;
39 private $menuItemCheckerMock;
44 private $anchorRenderer;
48 $this->activeMenuItemMock = $this->getMockBuilder(Item::class)
49 ->disableOriginalConstructor()
51 $this->menuItemMock = $this->getMockBuilder(Item::class)
52 ->disableOriginalConstructor()
54 $this->menuItemWithoutChildrenMock = $this->getMockBuilder(Item::class)
55 ->disableOriginalConstructor()
57 $this->menuItemCheckerMock = $this->getMockBuilder(MenuItemChecker::class)
58 ->disableOriginalConstructor()
60 $this->escaperMock = $this->getMockBuilder(Escaper::class)
61 ->disableOriginalConstructor()
64 $this->objectManagerHelper =
new ObjectManagerHelper($this);
65 $this->anchorRenderer = $this->objectManagerHelper->getObject(
66 AnchorRenderer::class,
68 'menuItemChecker' => $this->menuItemCheckerMock,
69 'escaper' => $this->escaperMock
78 $this->menuItemMock->expects($this->once())->method(
'getUrl')->willReturn(
'#');
79 $this->menuItemMock->expects($this->once())->method(
'getTitle')->willReturn(
$title);
80 $this->menuItemMock->expects($this->once())->method(
'hasChildren')->willReturn(
true);
81 $this->escaperMock->expects($this->once())->method(
'escapeHtml')->with(
__(
$title))->willReturn($html);
83 $expected =
'<strong class="submenu-group-title" role="presentation">' 84 .
'<span>' . $html .
'</span>' 89 $this->anchorRenderer->renderAnchor($this->activeMenuItemMock, $this->menuItemMock, 1)
95 $this->menuItemWithoutChildrenMock->expects($this->once())->method(
'getUrl')->willReturn(
'#');
96 $this->menuItemWithoutChildrenMock->expects($this->once())->method(
'hasChildren')->willReturn(
false);
102 $this->anchorRenderer->renderAnchor($this->activeMenuItemMock, $this->menuItemWithoutChildrenMock, 1)
116 $tooltip =
'Anchor title';
119 $finalTarget = $hasTarget ? (
'target=' .
$target) :
'';
120 $this->menuItemMock->expects($this->any())->method(
'getTarget')->willReturn($hasTarget ?
$target :
null);
121 $this->menuItemMock->expects($this->once())->method(
'getUrl')->willReturn(
$url);
122 $this->menuItemMock->expects($this->once())->method(
'getTitle')->willReturn(
$title);
123 $this->escaperMock->expects($this->once())->method(
'escapeHtml')->with(
__(
$title))->willReturn($html);
124 $this->menuItemMock->expects($this->once())->method(
'hasTooltip')->willReturn(
true);
125 $this->menuItemMock->expects($this->any())->method(
'getTooltip')->willReturn(
__($tooltip));
126 $this->menuItemMock->expects($this->once())->method(
'hasClickCallback')->willReturn(
true);
127 $this->menuItemMock->expects($this->once())->method(
'getClickCallback')->willReturn($onclick);
128 $this->menuItemCheckerMock->expects($this->once())
129 ->method(
'isItemActive')
130 ->with($this->activeMenuItemMock, $this->menuItemMock, $level)->willReturn(
true);
132 $expected =
'<a href="' .
$url .
'" ' . $finalTarget .
' ' .
'title="' . $tooltip .
'"' 133 .
' onclick="' . $onclick .
'"' 134 .
' class="' .
'_active' 135 .
'">' .
'<span>' . $html
136 .
'</span>' .
'</a>';
140 $this->anchorRenderer->renderAnchor($this->activeMenuItemMock, $this->menuItemMock, $level)
150 'item has target' => [
true],
151 'item does not have target' => [
false]
testRenderAnchorLevelIsNotOne($hasTarget)
testRenderAnchorWithoutChildrenAndLevelIsOne()
testRenderAnchorLevelIsOne()