/** * @dataProvider getBreadcrumbManagerDataProvider * @param $expected * @param $menu * @param $route */ public function testGetBreadcrumbLabels($expected, $menu, $route) { $this->provider->expects($this->any())->method('get')->will($this->returnCallback(function ($menu) { switch ($menu) { case BreadcrumbManager::FRONTEND_MENU: $item = new MenuItem('frontend_menu__test', $this->factory); $item->setExtra('routes', ['another_route', '/another_route/', 'another*route', 'route_with_frontend_true']); $item1 = new MenuItem('frontend_menu__test1', $this->factory); $item2 = new MenuItem('frontend_menu__sub_item', $this->factory); $item1->addChild($item2); $item1->setExtra('routes', []); $item2->addChild($item); return $item1; case 'test_menu': $item = new MenuItem('test_menu__test', $this->factory); $item->setExtra('routes', ['another_route', '/another_route/', 'another*route', 'route_without_frontend']); $item1 = new MenuItem('test_menu__test1', $this->factory); $item2 = new MenuItem('test_menu__sub_item', $this->factory); $item1->addChild($item2); $item1->setExtra('routes', []); $item2->addChild($item); return $item1; } return null; })); $this->assertEquals($expected, $this->manager->getBreadcrumbLabels($menu, $route)); }
protected function setUp() { $this->container = new Container(); $this->breadcrumbManager = $this->getMockBuilder('Oro\\Bundle\\NavigationBundle\\Menu\\BreadcrumbManager')->disableOriginalConstructor()->getMock(); $this->helper = $this->getMockBuilder('Knp\\Menu\\Twig\\Helper')->disableOriginalConstructor()->setMethods(['render'])->getMock(); $this->factory = $this->getMockBuilder('Knp\\Menu\\MenuFactory')->setMethods(['getRouteInfo', 'processRoute'])->getMock(); $this->factory->expects($this->any())->method('getRouteInfo')->will($this->returnValue(false)); $this->factory->expects($this->any())->method('processRoute')->will($this->returnSelf()); /** @var $eventDispatcher EventDispatcherInterface */ $eventDispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock(); $provider = new BuilderChainProvider($this->factory, $eventDispatcher); $this->builder = new ConfigurationBuilder(); $this->builder->setContainer($this->container); $provider->addBuilder($this->builder); $this->menuExtension = new MenuExtension($this->helper, $provider, $this->breadcrumbManager, $this->container); }
public function testSorting() { $menuName = 'test_menu'; $options = array(); $topMenu = $this->getMockBuilder('Knp\\Menu\\ItemInterface')->getMock(); $topMenu->expects($this->any())->method('hasChildren')->will($this->returnValue(true)); $topMenu->expects($this->any())->method('getDisplayChildren')->will($this->returnValue(true)); $menu = $this->getMockBuilder('Knp\\Menu\\ItemInterface')->getMock(); $menu->expects($this->any())->method('hasChildren')->will($this->returnValue(true)); $menu->expects($this->any())->method('getDisplayChildren')->will($this->returnValue(true)); $childOne = $this->getChildItem('child1', 5); $childTwo = $this->getChildItem('child2', 10); $childThree = $this->getChildItem('child3'); $childFour = $this->getChildItem('child4'); $menu->expects($this->any())->method('getChildren')->will($this->returnValue(array($childThree, $childFour, $childTwo, $childOne))); $topMenu->expects($this->any())->method('getChildren')->will($this->returnValue(array($menu))); $this->factory->expects($this->once())->method('createItem')->with($menuName)->will($this->returnValue($topMenu)); $menu->expects($this->once())->method('reorderChildren')->with(array('child1', 'child2', 'child3', 'child4')); $newMenu = $this->provider->get($menuName, $options); $this->assertInstanceOf('Knp\\Menu\\ItemInterface', $newMenu); }