public function testBuild() { $type = 'history'; $userId = 1; $user = $this->getMockBuilder('stdClass')->setMethods(['getId'])->getMock(); $user->expects($this->once())->method('getId')->will($this->returnValue($userId)); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $token->expects($this->once())->method('getUser')->will($this->returnValue($user)); $this->tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($token)); $item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationItemInterface'); $this->factory->expects($this->once())->method('createItem')->with($type, [])->will($this->returnValue($item)); $repository = $this->getMockBuilder('Oro\\Bundle\\NavigationBundle\\Entity\\Repository\\HistoryItemRepository')->disableOriginalConstructor()->getMock(); $items = [['id' => 1, 'title' => 'test1', 'url' => '/'], ['id' => 2, 'title' => 'test2', 'url' => '/home']]; $repository->expects($this->once())->method('getNavigationItems')->with($userId, $type)->will($this->returnValue($items)); $this->em->expects($this->once())->method('getRepository')->with(get_class($item))->will($this->returnValue($repository)); $menu = $this->getMockBuilder('Knp\\Menu\\MenuItem')->disableOriginalConstructor()->getMock(); $childMock = $this->getMock('Knp\\Menu\\ItemInterface'); $childMock2 = clone $childMock; $children = [$childMock, $childMock2]; $matcher = $this->getMock('\\Knp\\Menu\\Matcher\\Matcher'); $matcher->expects($this->once())->method('isCurrent')->will($this->returnValue(true)); $this->builder->setMatcher($matcher); $menu->expects($this->exactly(2))->method('addChild'); $menu->expects($this->once())->method('setExtra')->with('type', $type); $menu->expects($this->once())->method('getChildren')->will($this->returnValue($children)); $menu->expects($this->once())->method('removeChild'); $n = rand(1, 10); $configMock = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\UserConfigManager')->disableOriginalConstructor()->getMock(); $configMock->expects($this->once())->method('get')->with($this->equalTo('oro_navigation.maxItems'))->will($this->returnValue($n)); $this->manipulator->expects($this->once())->method('slice')->with($menu, 0, $n); $this->builder->setOptions($configMock); $this->builder->build($menu, [], $type); }
public function testNewItem() { $user = new User(); $user->setEmail('*****@*****.**'); $this->factory->expects($this->once())->method('createItem')->will($this->returnValue($this->item)); $repository = $this->getDefaultRepositoryMock(null); $em = $this->getEntityManager($repository); $listener = $this->getListener($this->factory, $this->tokenStorage, $em); $response = $this->getResponse(); $listener->onResponse($this->getEventMock($this->getRequest(), $response)); }
public function testBuild() { $type = 'favorite'; $userId = 1; $user = $this->getMockBuilder('stdClass')->setMethods(array('getId'))->getMock(); $user->expects($this->once($userId))->method('getId')->will($this->returnValue(1)); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $token->expects($this->once())->method('getUser')->will($this->returnValue($user)); $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token)); $item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationItemInterface'); $this->factory->expects($this->once())->method('createItem')->with($type, array())->will($this->returnValue($item)); $repository = $this->getMockBuilder('Oro\\Bundle\\NavigationBundle\\Entity\\Repository\\NavigationItemRepository')->disableOriginalConstructor()->getMock(); $items = array(array('id' => 1, 'title' => 'test1', 'url' => '/', 'type' => $type), array('id' => 2, 'title' => 'test2', 'url' => '/home', 'type' => $type)); $repository->expects($this->once())->method('getNavigationItems')->with($userId, $type)->will($this->returnValue($items)); $this->em->expects($this->once())->method('getRepository')->with(get_class($item))->will($this->returnValue($repository)); $menu = $this->getMockBuilder('Knp\\Menu\\ItemInterface')->getMock(); $menu->expects($this->exactly(2))->method('addChild'); $menu->expects($this->once())->method('setExtra')->with('type', $type); $this->builder->build($menu, array(), $type); }
public function testBuild() { $type = 'mostviewed'; $maxItems = 20; $userId = 1; $user = $this->getMockBuilder('stdClass')->setMethods(array('getId'))->getMock(); $user->expects($this->once())->method('getId')->will($this->returnValue($userId)); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $token->expects($this->once())->method('getUser')->will($this->returnValue($user)); $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token)); $item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationItemInterface'); $this->factory->expects($this->once())->method('createItem')->with($type, array())->will($this->returnValue($item)); $repository = $this->getMockBuilder('Oro\\Bundle\\NavigationBundle\\Entity\\Repository\\HistoryItemRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('getNavigationItems')->with($userId, $type, array('maxItems' => $maxItems, 'orderBy' => array(array('field' => NavigationHistoryItem::NAVIGATION_HISTORY_COLUMN_VISIT_COUNT))))->will($this->returnValue(array())); $this->em->expects($this->once())->method('getRepository')->with(get_class($item))->will($this->returnValue($repository)); $configMock = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\UserConfigManager')->disableOriginalConstructor()->getMock(); $configMock->expects($this->once())->method('get')->with($this->equalTo('oro_navigation.maxItems'))->will($this->returnValue($maxItems)); $menu = $this->getMockBuilder('Knp\\Menu\\ItemInterface')->getMock(); $this->builder->setOptions($configMock); $this->builder->build($menu, array(), $type); }