/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The menu has no child named "path" */ public function testGetMenuException() { $options = array(); $menuInstance = $this->getMockBuilder('Knp\\Menu\\ItemInterface')->setMethods(array('getChild'))->getMockForAbstractClass(); $menuInstance->expects($this->once())->method('getChild')->with('path')->will($this->returnValue(null)); $this->menuExtension->getMenu($menuInstance, array('path'), $options); }
/** * @param string $menuName * @param array $options * * @throws \Symfony\Component\Validator\Exception\InvalidArgumentException * @return array */ public function getTabs($menuName, $options = []) { /* @var MenuItem $menu */ $menu = $this->menuExtension->getMenu($menuName, [], $options); $tabs = []; foreach ($menu->getChildren() as $child) { if (!$child->isDisplayed()) { continue; } if (!($url = $child->getUri())) { if ($route = $child->getExtra('widgetRoute')) { $routeParameters = array_merge($child->getExtra('widgetRouteParameters', []), $options); $routeParametersMap = $child->getExtra('widgetRouteParametersMap', []); foreach ($routeParametersMap as $routeParameter => $optionParameter) { if (isset($options[$optionParameter])) { $routeParameters[$routeParameter] = $options[$optionParameter]; unset($routeParameters[$optionParameter]); } } $url = $this->router->generate($route, $routeParameters); } else { throw new InvalidArgumentException(sprintf('Extra parameter "widgetRoute" should be defined for %s', $child->getName())); } } if ($this->securityFacade->isGranted($child->getExtra('widgetAcl'))) { $label = $child->getLabel(); if (!empty($label)) { $label = $this->translator->trans($label); } $tabs[] = ['alias' => $child->getName(), 'label' => $label, 'widgetType' => $child->getExtra('widgetType', self::DEFAULT_WIDGET_TYPE), 'url' => $url]; } } if (empty($tabs)) { $menu->setDisplay(false); } return $tabs; }