/**
  * @dataProvider voteProvider
  */
 public function testVote(Attribute $attribute, $repositoryCanUser, $expectedResult)
 {
     $voter = new ValueObjectVoter($this->repository);
     $targets = isset($attribute->limitations['targets']) ? $attribute->limitations['targets'] : null;
     $this->repository->expects($this->once())->method('canUser')->with($attribute->module, $attribute->function, $attribute->limitations['valueObject'], $targets)->will($this->returnValue($repositoryCanUser));
     $this->assertSame($expectedResult, $voter->vote($this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'), new \stdClass(), array($attribute)));
 }
 /**
  * @dataProvider voteProvider
  */
 public function testVote(Attribute $attribute, $repositoryCanUser, $expectedResult)
 {
     $voter = new CoreVoter($this->repository);
     if ($repositoryCanUser !== null) {
         $this->repository->expects($this->once())->method('hasAccess')->with($attribute->module, $attribute->function)->will($this->returnValue($repositoryCanUser));
     } else {
         $this->repository->expects($this->never())->method('hasAccess');
     }
     $this->assertSame($expectedResult, $voter->vote($this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'), new \stdClass(), array($attribute)));
 }
 public function testAuthenticate()
 {
     $anonymousUserId = 10;
     $this->configResolver->expects($this->once())->method('getParameter')->with('anonymous_user_id')->will($this->returnValue($anonymousUserId));
     $this->repository->expects($this->once())->method('setCurrentUser')->with(new UserReference($anonymousUserId));
     $key = 'some_key';
     $authProvider = new AnonymousAuthenticationProvider($key);
     $authProvider->setRepository($this->repository);
     $authProvider->setConfigResolver($this->configResolver);
     $anonymousToken = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\AnonymousToken')->setConstructorArgs(array($key, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface')))->getMockForAbstractClass();
     $this->assertSame($anonymousToken, $authProvider->authenticate($anonymousToken));
 }
 public function testOnKernelBuilt()
 {
     $kernelHandler = $this->getMock('ezpWebBasedKernelHandler');
     $legacyKernel = $this->getMockBuilder('eZ\\Publish\\Core\\MVC\\Legacy\\Kernel')->setConstructorArgs(array($kernelHandler, 'foo', 'bar'))->getMock();
     $event = new PostBuildKernelEvent($legacyKernel, $kernelHandler);
     $this->configResolver->expects($this->once())->method('getParameter')->with('legacy_mode')->will($this->returnValue(false));
     $this->securityContext->expects($this->once())->method('isGranted')->with('IS_AUTHENTICATED_REMEMBERED')->will($this->returnValue(true));
     $userId = 123;
     $user = $this->generateUser($userId);
     $this->repository->expects($this->once())->method('getCurrentUser')->will($this->returnValue($user));
     $legacyKernel->expects($this->once())->method('runCallback');
     $listener = new Security($this->repository, $this->configResolver, $this->securityContext);
     $listener->onKernelBuilt($event);
 }
 public function testCheckAuthentication()
 {
     $user = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\Security\\User');
     $userName = '******';
     $password = '******';
     $token = new UsernamePasswordToken($userName, $password, 'bar');
     $apiUser = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\User\\User');
     $userService = $this->getMock('eZ\\Publish\\API\\Repository\\UserService');
     $userService->expects($this->once())->method('loadUserByCredentials')->with($userName, $password)->will($this->returnValue($apiUser));
     $this->repository->expects($this->once())->method('getUserService')->will($this->returnValue($userService));
     $this->repository->expects($this->once())->method('setCurrentUser')->with($apiUser);
     $method = new \ReflectionMethod($this->authProvider, 'checkAuthentication');
     $method->setAccessible(true);
     $method->invoke($this->authProvider, $user, $token);
 }
 public function testRenderLocationWithClosure()
 {
     $content = new Content(['versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo()])]);
     $location = new Location(['contentInfo' => new ContentInfo()]);
     // Configuring view provider behaviour
     $closure = function ($params) {
         return serialize(array_keys($params));
     };
     $params = array('foo' => 'bar');
     $this->viewConfigurator->expects($this->once())->method('configure')->will($this->returnCallback(function (View $view) use($closure) {
         $view->setTemplateIdentifier($closure);
     }));
     $contentService = $this->getMockBuilder('eZ\\Publish\\Core\\Repository\\ContentService')->disableOriginalConstructor()->getMock();
     $contentService->expects($this->any())->method('loadContentByContentInfo')->with($content->contentInfo)->will($this->returnValue($content));
     $this->repositoryMock->expects($this->any())->method('getContentService')->will($this->returnValue($contentService));
     // Configuring template engine behaviour
     $params += array('location' => $location, 'content' => $content, 'viewbaseLayout' => $this->viewBaseLayout);
     $this->templateEngineMock->expects($this->never())->method('render');
     $expectedTemplateResult = array_keys($params);
     $templateResult = unserialize($this->viewManager->renderLocation($location, 'full', $params));
     sort($expectedTemplateResult);
     sort($templateResult);
     self::assertSame($expectedTemplateResult, $templateResult);
 }