Exemplo n.º 1
0
 public function testCreate()
 {
     $this->builder->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
     $this->factory->expects($this->once())->method('createItem')->with($this->identicalTo($name))->will($this->returnValue($item = $this->createItemMock()));
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with($this->identicalTo(MenuBuilderEvents::BUILD), $this->callback(function (MenuBuilderEvent $event) use($item) {
         return $event->getFactory() === $this->factory && $event->getItem() === $item;
     }));
     $this->assertSame($item, $this->builder->create());
 }
 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);
 }