/**
  * 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->sc = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\SecurityContextInterface')->getMock();
     $this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock();
     $this->sc->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->sc, $this->rh);
 }
 public function testBuild()
 {
     $organization = new Organization();
     $type = 'history';
     $userId = 1;
     $user = $this->getMockBuilder('stdClass')->setMethods(array('getId'))->getMock();
     $user->expects($this->once())->method('getId')->will($this->returnValue($userId));
     $token = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\UsernamePasswordOrganizationToken')->disableOriginalConstructor()->getMock();
     $token->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $token->expects($this->once())->method('getOrganizationContext')->will($this->returnValue($organization));
     $this->securityContext->expects($this->atLeastOnce())->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();
     $items = array(array('id' => 1, 'title' => 'test1', 'url' => '/'), array('id' => 2, 'title' => 'test2', 'url' => '/home'));
     $repository->expects($this->once())->method('getNavigationItems')->with($userId, $organization, $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 = array($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\\ConfigManager')->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, array(), $type);
 }
 public function setUp()
 {
     $dbManager = $this->db('PHPCR');
     $dbManager->loadFixtures(array('Symfony\\Cmf\\Bundle\\CoreBundle\\Tests\\Resources\\DataFixture\\LoadHierarchyRouteData'));
     $this->pwc = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $this->pwc->expects($this->any())->method('isGranted')->will($this->returnValue(true));
     $this->helper = new CmfHelper($this->pwc, $dbManager->getRegistry(), 'default');
 }
 public function setUp()
 {
     $this->securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $this->configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $token = $this->getMockForAbstractClass('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->user = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\User')->disableOriginalConstructor()->getMock();
     $token->expects($this->any())->method('getUser')->will($this->returnValue($this->user));
     $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->provider = new VariablesProvider($this->securityContext, $this->configProvider);
 }
 public function testIsGrantedWithException()
 {
     $this->setExpectedException('RuntimeException', 'Something is wrong');
     $this->admin->expects($this->any())->method('getCode')->will($this->returnValue('foo.bar'));
     $this->securityContext->expects($this->any())->method('isGranted')->will($this->returnCallback(function (array $attributes, $object) {
         throw new \RuntimeException('Something is wrong');
     }));
     $handler = $this->getRoleSecurityHandler(array('ROLE_BATMAN'));
     $handler->isGranted($this->admin, 'BAZ');
 }
 protected function setUp()
 {
     $this->factory = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\Builder\\ItemFactory');
     $this->securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $user = new User();
     $user->setEmail('*****@*****.**');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $this->securityContext->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'));
 }
 /**
  * setup mocks
  */
 protected function setUp()
 {
     $this->loader = $this->getMock('\\Twig_Loader_String');
     $this->securityPolicy = $this->getMockBuilder('\\Twig_Sandbox_SecurityPolicy')->disableOriginalConstructor()->getMock();
     $this->sandbox = $this->getMockBuilder('\\Twig_Extension_Sandbox')->disableOriginalConstructor()->getMock();
     $this->sandbox->expects($this->once())->method('getName')->will($this->returnValue('sandbox'));
     $this->sandbox->expects($this->once())->method('getSecurityPolicy')->will($this->returnValue($this->securityPolicy));
     $this->securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $token = $this->getMockForAbstractClass('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->user = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\User')->disableOriginalConstructor()->getMock();
     $token->expects($this->any())->method('getUser')->will($this->returnValue($this->user));
     $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $this->cache = $this->getMockBuilder('Doctrine\\Common\\Cache\\Cache')->disableOriginalConstructor()->getMock();
 }
 /**
  * Test using the block loader with two different document managers.
  */
 public function testLoadWithAlternativeDocumentManager()
 {
     $absoluteBlockPath = '/some/absolute/path';
     $block = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface');
     $block->expects($this->any())->method('getName')->will($this->returnValue('the-block'));
     $altBlock = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface');
     $altBlock->expects($this->any())->method('getName')->will($this->returnValue('alt-block'));
     $this->dmMock->expects($this->once())->method('find')->with($this->equalTo(null), $this->equalTo($absoluteBlockPath))->will($this->returnValue($block));
     $altDmMock = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock();
     $altDmMock->expects($this->once())->method('find')->with($this->equalTo(null), $this->equalTo($absoluteBlockPath))->will($this->returnValue($altBlock));
     $this->securityMock->expects($this->at(0))->method('isGranted')->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($block))->will($this->returnValue(true));
     $this->securityMock->expects($this->at(1))->method('isGranted')->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($altBlock))->will($this->returnValue(true));
     $registryMock = $this->getMockBuilder('Doctrine\\Bundle\\PHPCRBundle\\ManagerRegistry')->disableOriginalConstructor()->getMock();
     $registryMock->expects($this->at(0))->method('getManager')->with($this->equalTo('themanager'))->will($this->returnValue($this->dmMock));
     $registryMock->expects($this->at(1))->method('getManager')->with($this->equalTo('altmanager'))->will($this->returnValue($altDmMock));
     $blockLoader = new PhpcrBlockLoader($registryMock, $this->securityMock, null, 'emptyblocktype');
     $blockLoader->setManagerName('themanager');
     $foundBlock = $blockLoader->load(array('name' => $absoluteBlockPath));
     $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $foundBlock);
     $this->assertEquals('the-block', $foundBlock->getName());
     $blockLoader->setManagerName('altmanager');
     $foundBlock = $blockLoader->load(array('name' => $absoluteBlockPath));
     $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $foundBlock);
     $this->assertEquals('alt-block', $foundBlock->getName());
 }
 protected function setUp()
 {
     $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->object = new UserConfigManager($this->om, $this->settings);
     $this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $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->security->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', array('loadStoredSettings'), array($this->om, $this->settings));
 }
 /**
  * @dataProvider getUser
  */
 public function testRedirect($granted, $path)
 {
     $default = new Netizen(new Author('kirk'));
     $default->setCredential(new OAuth('1701', 'ufp'));
     $request = new Request();
     $token = new Token('secured_area', 'ufp', '1701');
     $token->setUser($default);
     $this->security->expects($this->atLeast(1))->method('isGranted')->will($this->returnCallback(function ($role) use($granted) {
         return $role == $granted;
     }));
     $this->urlGenerator->expects($this->once())->method('generate')->with($path)->willReturn('ok');
     $response = $this->sut->onAuthenticationSuccess($request, $token);
     $cookie = $response->headers->getCookies()[0];
     $this->assertEquals('oauth_provider', $cookie->getName());
     $this->assertEquals('ufp', $cookie->getValue());
 }
 protected function setUp()
 {
     $repo = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock();
     $repo->expects($this->any())->method('loadSettings');
     $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repo));
     $this->object = new UserScopeManager($this->om);
     $this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->security->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $token->expects($this->any())->method('getUser')->will($this->returnValue($this->getUser()));
     $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $this->container->expects($this->any())->method('get')->will($this->returnValueMap([['security.context', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->security]]));
     $this->object = new UserScopeManager($this->om);
     $this->object->setContainer($this->container);
 }
 public function testNoFirewall()
 {
     $token = new AnonymousToken('', '');
     $this->sc->expects($this->any())->method('getToken')->will($this->returnValue(null));
     $this->sc->expects($this->never())->method('isGranted');
     $this->adm->expects($this->once())->method('decide')->with($token, array(PublishWorkflowChecker::VIEW_ATTRIBUTE), $this->doc)->will($this->returnValue(true));
     $this->assertTrue($this->pwfc->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->doc));
 }
 /**
  * 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->sc = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\SecurityContextInterface')->getMock();
     $this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock();
     $this->sc->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->sc, $this->rh);
 }
 protected function setUp()
 {
     $repo = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock();
     $repo->expects($this->any())->method('loadSettings');
     $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repo));
     $this->object = new UserScopeManager($this->om);
     $this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $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->security->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 = new UserScopeManager($this->om);
 }
 /**
  * @dataProvider renderDataProvider
  * @param string $widgetUrl
  * @param string $widgetType
  * @param string $expectedWidgetUrl
  */
 public function testRender($widgetUrl, $widgetType, $expectedWidgetUrl)
 {
     $user = $this->getMock('stdClass');
     $token = $this->getMockBuilder('stdClass')->setMethods(array('getUser'))->getMock();
     $token->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $normalStateData = array('cleanUrl' => $widgetUrl, 'type' => $widgetType);
     $normalState = $this->getStateMock(1, $normalStateData);
     $badState = $this->getStateMock(2, null);
     $states = array($normalState, $badState);
     $repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $repository->expects($this->once())->method('findBy')->with(array('user' => $user))->will($this->returnValue($states));
     $this->em->expects($this->once())->method('getRepository')->with('OroWindowsBundle:WindowsState')->will($this->returnValue($repository));
     $this->em->expects($this->once())->method('remove')->with($badState);
     $this->em->expects($this->once())->method('flush');
     $output = 'RENDERED';
     $expectedStates = array('cleanUrl' => $expectedWidgetUrl, 'type' => $widgetType);
     $this->environment->expects($this->once())->method('render')->with("OroWindowsBundle::states.html.twig", array("states" => array(1 => $expectedStates)))->will($this->returnValue($output));
     $this->assertEquals($output, $this->extension->render($this->environment));
 }
 /**
  * @test
  */
 public function taskUserTracker()
 {
     $user = new User();
     $task = new Task();
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($this->token));
     $this->token->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $tracker = new Tracker($user, $task, new \DateTime('now'));
     $this->trackerRepository->expects($this->once())->method('retrieveUserTracker')->with($user)->will($this->returnValue($tracker));
     $result = $this->twigExtension->userTracker();
     $this->assertEquals($tracker, $result);
 }
 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);
 }
Beispiel #19
0
 public function testSend()
 {
     $user = $this->getMockForAbstractClass('Symfony\\Component\\Security\\Core\\User\\UserInterface');
     $user->expects($this->any())->method('getUserName')->will($this->returnValue(self::TEST_USERNAME));
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $that = $this;
     $this->publisher->expects($this->once())->method('send')->will($this->returnCallback(function ($topic, $payload) use($that) {
         $that->assertSame('oro/data/update', $topic, 'Should be the same as frontend code expects');
         $tags = json_decode($payload, true);
         $that->assertCount(2, $tags);
         foreach ($tags as $tag) {
             $that->assertArrayHasKey('username', $tag);
             $that->assertArrayHasKey('tagname', $tag);
             $that->assertSame(self::TEST_USERNAME, $tag['username']);
         }
     }));
     $tags = [self::TEST_TAG1, self::TEST_TAG2];
     $this->sender->send($tags);
 }
 public function testOnKernelRequest()
 {
     $this->configResolver->expects($this->once())->method('getParameter')->with('legacy_mode')->will($this->returnValue(true));
     $userService = $this->getMock('eZ\\Publish\\API\\Repository\\UserService');
     $this->repository->expects($this->once())->method('getUserService')->will($this->returnValue($userService));
     $userId = 123;
     $apiUser = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\User');
     $userService->expects($this->once())->method('loadUser')->with($userId)->will($this->returnValue($apiUser));
     $this->repository->expects($this->once())->method('setCurrentUser')->with($apiUser);
     $session = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface');
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request', array('getSession'));
     $request->expects($this->any())->method('getSession')->will($this->returnValue($session));
     $session->expects($this->once())->method('has')->with('eZUserLoggedInID')->will($this->returnValue(true));
     $session->expects($this->once())->method('get')->with('eZUserLoggedInID')->will($this->returnValue($userId));
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $token->expects($this->once())->method('setUser')->with($this->isInstanceOf('eZ\\Publish\\Core\\MVC\\Symfony\\Security\\User'));
     $token->expects($this->once())->method('setAuthenticated')->with(true);
     $event = new GetResponseEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
     $listener = new RequestListener($this->configResolver, $this->repository, $this->securityContext);
     $listener->onKernelRequest($event);
 }
 /**
  * {@inheritdoc}
  * @dataProvider supportedMethods
  */
 public function testProcessSupportedRequest($method, $isValid, $isProcessed)
 {
     $organization = null;
     if ($isValid) {
         $organization = new Organization();
         $organization->setName('test');
         $organizationToken = $this->getMock('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\OrganizationContextTokenInterface');
         $organizationToken->expects($this->any())->method('getOrganizationContext')->willReturn($organization);
         $this->securityContext->expects($this->any())->method('getToken')->willReturn($organizationToken);
         $this->form->expects($this->at(2))->method('get')->with('passwordGenerate')->will($this->returnValue($this->passwordGenerateForm));
         $this->form->expects($this->at(3))->method('get')->with('sendEmail')->will($this->returnValue($this->sendEmailForm));
         $this->passwordGenerateForm->expects($this->once())->method('getData')->will($this->returnValue(false));
         $this->sendEmailForm->expects($this->once())->method('getData')->will($this->returnValue(false));
     }
     $this->form->expects($this->any())->method('isValid')->will($this->returnValue($isValid));
     $this->request->setMethod($method);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->assertEquals($isProcessed, $this->handler->process($this->entity));
     if ($organization) {
         $this->assertEquals($organization, $this->entity->getOrganization());
         $this->assertTrue($this->entity->hasOrganization($organization));
     }
 }
 public function testAuthenticatedWithInvalidNetizen()
 {
     $token = new Token('secu', 'dummy', '123456');
     $user = new Netizen(new Author('kirk'));
     $token->setUser($user);
     $event = $this->createEvent(new AccessDeniedHttpException());
     $this->security->expects($this->once())->method('getToken')->willReturn($token);
     $this->security->expects($this->once())->method('isGranted')->with(TicketVoter::SUPPORTED_ATTRIBUTE)->willReturn(false);
     $bag = new \Symfony\Component\HttpFoundation\Session\Flash\FlashBag();
     $this->session->expects($this->once())->method('getFlashBag')->willReturn($bag);
     $this->sut->onKernelException($event);
     $this->assertTrue($event->hasResponse());
     $this->assertCount(1, $bag);
 }
 /**
  * @test
  */
 public function handleReturnToken()
 {
     $token = new WsseToken();
     $token->setUser('admin');
     $token->setAttribute('digest', 'admin');
     $token->setAttribute('nonce', 'admin');
     $token->setAttribute('created', '2010-12-12 20:00:00');
     $this->tokenMock->expects($this->atLeastOnce())->method('getUser')->will($this->returnValue($this->userMock));
     $this->userMock->expects($this->once())->method('isActive')->will($this->returnValue(true));
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->will($this->returnValue($this->tokenMock));
     /** @noinspection PhpUndefinedMethodInspection */
     $this->securityContext->expects($this->once())->method('setToken')->with($this->tokenMock);
     $this->request->headers->add(array('X-WSSE' => 'UsernameToken Username="******", PasswordDigest="admin", Nonce="admin", Created="2010-12-12 20:00:00"'));
     $this->wsseListener->handle($this->responseEvent);
 }
 /**
  * @param $withWhat
  * @param $permission
  * @param $returnValue
  */
 protected function contextExpect($withWhat, $permission, $returnValue)
 {
     $this->context->expects($this->once())->method('isGranted')->with($this->equalTo($permission), $this->equalTo($withWhat))->will($this->returnValue($returnValue));
 }