public function testGetBreadcrumbLabels()
 {
     $item = new MenuItem('test', $this->factory);
     $item->setExtra('routes', array('another_route', '/another_route/', 'another*route', 'test_route'));
     $item1 = new MenuItem('test1', $this->factory);
     $item2 = new MenuItem('sub_item', $this->factory);
     $item1->addChild($item2);
     $item1->setExtra('routes', array());
     $item2->addChild($item);
     $this->provider->expects($this->once())->method('get')->will($this->returnValue($item1));
     $this->assertEquals(array('test', 'sub_item', 'test1'), $this->manager->getBreadcrumbLabels('test_menu', 'test_route'));
 }
예제 #2
0
 public function testLabelTranslationDomainOverride()
 {
     $translatorProphecy = $this->prophesize('Symfony\\Component\\Translation\\TranslatorInterface');
     $translatorProphecy->trans('some-label', array(), 'my_local_domain', null)->willReturn('my-translation');
     $translatorProphecy->trans('some-other-label', array(), 'my_global_domain', null)->willReturn('my-other-translation');
     $this->translator = $translatorProphecy->reveal();
     $factory = new MenuFactory();
     $menu = new MenuItem('test-menu', $factory);
     $menu->setExtra('translation_domain', 'my_global_domain');
     $menu->addChild('some-label', array('uri' => '/whatever'))->setExtra('translation_domain', 'my_local_domain');
     $menu->addChild('some-other-label', array('uri' => '/whatever'));
     $html = $this->renderMenu($menu);
     $this->assertContains('my-translation', $html);
     $this->assertContains('my-other-translation', $html);
 }
 /**
  * @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));
 }
예제 #4
0
 private function active(\Knp\Menu\MenuItem $vm)
 {
     if (!$vm->isRoot()) {
         $vm->setExtra('active', true);
         $vm->setAttribute('class', 'active');
         $this->active($vm->getParent());
     }
 }