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);
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     /* @var $conn Connection */
     $conn = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $conn->expects($this->any())->method('getDatabase')->will($this->returnValue('myDatabase'));
     /* @var $platform AbstractPlatform */
     $platform = $this->getMockForAbstractClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform');
     $conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     /* @var $stmt Statement */
     $stmt = $this->getMockForAbstractClass('Kunstmaan\\AdminBundle\\Tests\\Mocks\\StatementMock');
     $conn->expects($this->any())->method('executeQuery')->will($this->returnValue($stmt));
     $this->em->expects($this->any())->method('getConnection')->will($this->returnValue($conn));
     /* @var $conf Configuration */
     $conf = $this->getMockBuilder('Doctrine\\ORM\\Configuration')->disableOriginalConstructor()->getMock();
     /* @var $strat QuoteStrategy */
     $strat = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\QuoteStrategy')->disableOriginalConstructor()->getMock();
     $strat->expects($this->any())->method('getTableName')->will($this->returnValue('rootTable'));
     $conf->expects($this->any())->method('getQuoteStrategy')->will($this->returnValue($strat));
     $conf->expects($this->any())->method('getDefaultQueryHints')->willReturn(array());
     $conf->expects($this->any())->method('isSecondLevelCacheEnabled')->willReturn(false);
     $this->em->expects($this->any())->method('getConfiguration')->will($this->returnValue($conf));
     /* @var $meta ClassMetadata */
     $meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta));
     $this->tokenStorage = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface')->getMock();
     $this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock();
     $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($this->token));
     $this->rh = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface')->getMock();
     $this->object = new AclHelper($this->em, $this->tokenStorage, $this->rh);
 }
 /**
  * @param object|null $user
  */
 protected function assertAccountUserTokenCall($user = null)
 {
     if (!$user) {
         $user = new AccountUser();
     }
     $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));
 }
 public function setUp()
 {
     $this->factory = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\Builder\\ItemFactory');
     $this->tokenStorage = $this->getMock('Symfony\\Component\\Security\\Core\\TokenStorageInterface');
     $user = new User();
     $user->setEmail('*****@*****.**');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->exactly(2))->method('getUser')->will($this->returnValue($user));
     $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationHistoryItem');
     $this->serializedTitle = json_encode(array('titleTemplate' => 'Test title template'));
 }
 /**
  * @test
  */
 public function it_authenticates_and_stores_valid_tokens()
 {
     $tokenString = 'headers.payload.signature';
     $jwt = new Jwt(['alg' => 'none'], [], null, ['headers', 'payload']);
     $token = new JwtUserToken($jwt);
     $authenticatedToken = new JwtUserToken($jwt, true);
     $request = new Request([], [], [], [], [], ['HTTP_AUTHORIZATION' => 'Bearer ' . $tokenString], '');
     $this->getResponseEvent->expects($this->any())->method('getRequest')->willReturn($request);
     $this->jwtDecoderService->expects($this->once())->method('parse')->with(new StringLiteral($tokenString))->willReturn($jwt);
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->willReturn($authenticatedToken);
     $this->tokenStorage->expects($this->once())->method('setToken')->with($authenticatedToken);
     $this->listener->handle($this->getResponseEvent);
 }
Пример #6
0
 /**
  * @test
  */
 public function handleReturnToken()
 {
     $token = new WsseToken();
     $token->setUser('admin');
     $token->digest = 'admin';
     $token->nonce = 'admin';
     $token->created = '2010-12-12 20:00:00';
     $tokenMock2 = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->will($this->returnValue($tokenMock2));
     $this->securityContext->expects($this->once())->method('setToken')->with($tokenMock2);
     $this->request->headers->add(array('X-WSSE' => 'UsernameToken Username="******"' . ', PasswordDigest="admin", Nonce="admin", Created="2010-12-12 20:00:00"'));
     $listener = new WsseListener($this->securityContext, $this->authenticationManager);
     $listener->handle($this->responseEvent);
 }
 protected function setUp()
 {
     $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->object = new UserConfigManager($this->om, $this->settings);
     $this->tokenStorage = $this->getMock('Symfony\\Component\\Security\\Core\\TokenStorageInterface');
     $this->group1 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group');
     $this->group2 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $user = new User();
     $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->group1->expects($this->any())->method('getId')->will($this->returnValue(2));
     $this->group2->expects($this->any())->method('getId')->will($this->returnValue(3));
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $user->setId(1)->addGroup($this->group1)->addGroup($this->group2);
     $this->object = $this->getMock('Oro\\Bundle\\ConfigBundle\\Config\\UserConfigManager', ['loadStoredSettings'], [$this->om, $this->settings]);
 }
Пример #8
0
 public function testIsApplicable()
 {
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->once())->method('getUser')->willReturn(new User());
     $this->tokenStorage->expects($this->once())->method('getToken')->willReturn($token);
     $this->assertTrue($this->manager->isApplicable());
 }
 /**
  * Tests onLogout() method.
  */
 public function testOnLogout()
 {
     // Given
     $event = $this->getMock('Parenthesis\\WPBundle\\Event\\WordpressEvent');
     // When - Then
     $this->session->expects($this->once())->method('clear');
     $this->tokenStorage->expects($this->once())->method('setToken')->with(null);
     $this->listener->onLogout($event);
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->conn = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $this->conn->expects($this->any())->method('getDatabase')->will($this->returnValue('myDatabase'));
     /* @var $platform AbstractPlatform */
     $platform = $this->getMockForAbstractClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform');
     $this->conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     $this->em->expects($this->any())->method('getConnection')->will($this->returnValue($this->conn));
     /* @var $meta ClassMetadata */
     $meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta));
     $this->tokenStorage = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface')->getMock();
     $this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock();
     $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($this->token));
     $this->rh = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface')->getMock();
     $this->object = new AclNativeHelper($this->em, $this->tokenStorage, $this->rh);
 }
 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->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, 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->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, 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);
 }
 /**
  * @test
  */
 public function it_grants_access_when_authenticated()
 {
     $this->userSessionService->setMinimalUserInfo($this->minimalUserInfo);
     $user = new User();
     $user->id = $this->minimalUserInfo->getId();
     $authToken = new UiTIDToken($user->getRoles());
     $authToken->setUser($user);
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($this->minimalToken)->willReturn($authToken);
     $this->tokenStorage->expects($this->once())->method('setToken')->with($authToken);
     // Make sure no Response is set, so the request can be handled by the
     // actual controllers.
     $this->event->expects($this->never())->method('setResponse');
     $this->listener->handle($this->event);
 }
 /**
  * @dataProvider visitDatasourceDataProvider
  * @param string $currency
  */
 public function testVisitDatasource($currency)
 {
     if ($currency) {
         /** @var \PHPUnit_Framework_MockObject_MockObject|Request $request */
         $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
         $this->extension->setRequest($request);
         $request->expects($this->once())->method('get')->with(ProductSelectionGridExtension::CURRENCY_KEY)->willReturn($currency);
     }
     $gridName = 'products-select-grid-frontend';
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->will($this->returnValue(new AccountUser()));
     /** @var \PHPUnit_Framework_MockObject_MockObject|DatagridConfiguration $config */
     $config = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datagrid\\Common\\DatagridConfiguration')->disableOriginalConstructor()->getMock();
     $config->expects($this->once())->method('getName')->will($this->returnValue($gridName));
     $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     /** @var \PHPUnit_Framework_MockObject_MockObject|OrmDatasource $dataSource */
     $dataSource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock();
     $dataSource->expects($this->once())->method('getQueryBuilder')->will($this->returnValue($qb, $currency));
     $this->productListModifier->expects($this->once())->method('applyPriceListLimitations')->with($qb);
     $this->extension->visitDatasource($config, $dataSource);
     // Check that limits are applied only once
     $this->extension->visitDatasource($config, $dataSource);
 }