/**
  * @covers \ZfcUser\Authentication\Adapter\AdapterChainServiceFactory::createService
  */
 public function testCreateService()
 {
     $adapter = array('adapter1' => $this->getMock('ZfcUser\\Authentication\\Adapter\\AbstractAdapter', array('authenticate', 'logout')), 'adapter2' => $this->getMock('ZfcUser\\Authentication\\Adapter\\AbstractAdapter', array('authenticate', 'logout')));
     $adapterNames = array(100 => 'adapter1', 200 => 'adapter2');
     $this->serviceLocatorArray = array_merge($this->serviceLocatorArray, $adapter);
     $this->options->expects($this->once())->method('getAuthAdapters')->will($this->returnValue($adapterNames));
     $adapterChain = $this->factory->createService($this->serviceLocator);
     $this->assertInstanceOf('ZfcUser\\Authentication\\Adapter\\AdapterChain', $adapterChain);
     $this->assertEquals(array('authenticate', 'logout'), $adapterChain->getEventManager()->getEvents());
 }
 /**
  * @dataProvider providerTestFactory
  */
 public function testFactory($config)
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('Config', $config);
     $factory = new ModuleOptionsFactory();
     $defaultOption = new ModuleOptions(array());
     $object = $factory->createService($serviceManager);
     $this->assertInstanceOf('ZfcUser\\Options\\ModuleOptions', $object);
     if (isset($config['zfcuser'])) {
         $this->assertNotEquals($defaultOption->getLoginRedirectRoute(), $object->getLoginRedirectRoute());
         $this->assertEquals($config['zfcuser']['loginRedirectRoute'], $object->getLoginRedirectRoute());
     } else {
         $this->assertEquals($defaultOption->getLoginRedirectRoute(), $object->getLoginRedirectRoute());
     }
 }
Пример #3
0
 /**
  * Returns the url to redirect to based on current route.
  * If $redirect is set and the option to use redirect is set to true, it
  * will return the $redirect url.
  *
  * @param string $currentRoute        	
  * @param bool $redirect        	
  * @return mixed
  */
 protected function getRedirect($currentRoute, $redirect = false)
 {
     $useRedirect = $this->options->getUseRedirectParameterIfPresent();
     $routeExists = $redirect && $this->routeExists($redirect);
     if (!$useRedirect || !$routeExists) {
         $redirect = false;
     }
     switch ($currentRoute) {
         case 'zfcuser/register':
         case 'zfcuser/login':
         case 'zfcuser/authenticate':
             if ($redirect && ($match = $this->routeExists($redirect)) == true) {
                 $route = $match->getMatchedRouteName();
                 return $this->router->assemble(array(), array('name' => $route));
             } else {
                 $route = $this->options->getLoginRedirectRoute();
                 return $this->router->assemble(array(), array('name' => $route));
             }
             break;
         case 'zfcuser/logout':
             $route = $redirect ?: $this->options->getLogoutRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         default:
             return $this->router->assemble(array(), array('name' => 'zfcuser'));
     }
 }
Пример #4
0
 /**
  * Returns the url to redirect to based on current route.
  * If $redirect is set and the option to use redirect is set to true, it will return the $redirect url.
  *
  * @param  string $currentRoute
  * @param  bool   $redirect
  * @return mixed
  */
 private function getRedirect($currentRoute, $redirect = false)
 {
     $useRedirect = $this->options->getUseRedirectParameterIfPresent();
     $routeExists = $redirect && $this->routeExists($redirect);
     if (!$useRedirect || !$routeExists) {
         $redirect = false;
     }
     switch ($currentRoute) {
         case 'zfcuser/login':
         case 'scn-social-auth-user/login':
         case 'scn-social-auth-user/register':
         case 'scn-social-auth-user/authenticate/provider':
         case 'scn-social-auth-user/add-provider/provider':
             $route = $redirect ?: $this->options->getLoginRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         case 'zfcuser/logout':
         case 'scn-social-auth-user/logout':
             $route = $redirect ?: $this->options->getLogoutRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         default:
             return $this->router->assemble(array(), array('name' => 'zfcuser'));
     }
 }
Пример #5
0
 /**
  * @covers Eye4web\ZfcUser\Pm\Mapper\DoctrineORM\PmMapper::getUserConversations
  */
 public function testGetUserConversations()
 {
     $optionsData = ['to' => 1, 'deleted' => false];
     $this->options->expects($this->any())->method('getConversationReceiverEntity')->will($this->returnValue('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationReceiver'));
     $objectRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $this->objectManager->expects($this->any())->method('getRepository')->with('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationReceiver')->will($this->returnValue($objectRepository));
     $conversationReceivers[0] = new ConversationReceiver();
     $conversationReceivers[0]->setConversation(new Conversation());
     $conversationReceivers[1] = new ConversationReceiver();
     $conversationReceivers[1]->setConversation(new Conversation());
     $objectRepository->expects($this->any())->method('findBy')->with($optionsData)->will($this->returnValue([$conversationReceivers[0], $conversationReceivers[1]]));
     $this->zfcuserOptions->expects($this->any())->method('getUserEntityClass')->will($this->returnValue('ZfcUser\\Entity\\User'));
     $participants = [];
     $user[0] = new User();
     $user[0]->setId(1);
     $user[1] = new User();
     $user[1]->setId(2);
     $conversations = [];
     foreach ($conversationReceivers as $key => $conversationReceiver) {
         $conversations[] = $conversationReceiver->getConversation();
     }
     $conversations = $this->mapper->getUserConversations(1);
     $this->assertCount(2, $conversations);
     foreach ($conversations as $conversation) {
         $this->assertInstanceOf('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationInterface', $conversation);
     }
 }
Пример #6
0
 public function testGetRedirectWithOptionOnRedirectDoesntExists()
 {
     $route = 'zfcuser/login';
     $redirect = 'doesntExists';
     $expectedResult = '/user/login';
     $this->moduleOptions->expects($this->once())->method('getUseRedirectParameterIfPresent')->will($this->returnValue(true));
     $this->router->expects($this->at(0))->method('assemble')->with(array(), array('name' => $redirect))->will($this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException()));
     $this->router->expects($this->at(1))->method('assemble')->with(array(), array('name' => $route))->will($this->returnValue($expectedResult));
     $this->moduleOptions->expects($this->once())->method('getLoginRedirectRoute')->will($this->returnValue($route));
     $method = new \ReflectionMethod('ZfcUser\\Controller\\RedirectCallback', 'getRedirect');
     $method->setAccessible(true);
     $result = $method->invoke($this->redirectCallback, $route, $redirect);
     $this->assertSame($expectedResult, $result);
 }
 /**
  * Returns the url to redirect to based on current url.
  * If $redirect is set and the option to use redirect is set to true, it will return the $redirect url
  * after verifying that the url is in the whitelist.
  *
  * @param string $currentRoute
  * @param bool $redirect
  * @return mixed
  */
 private function getRedirect($currentRoute, $redirect = false)
 {
     $useRedirect = $this->zfcUserOptions->getUseRedirectParameterIfPresent();
     $urlAllowed = $redirect && $this->urlWhitelisted($redirect);
     if ($useRedirect && $urlAllowed) {
         return $redirect;
     }
     switch ($currentRoute) {
         case 'zfcuser/register':
         case 'zfcuser/login':
             $route = $this->zfcUserOptions->getLoginRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         case 'zfcuser/logout':
             $route = $this->zfcUserOptions->getLogoutRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         default:
             return $this->router->assemble(array(), array('name' => 'zfcuser'));
     }
 }
Пример #8
0
 public function newConversationAction()
 {
     if (!$this->zfcUserAuthentication()->hasIdentity()) {
         return $this->redirect()->toRoute($this->zfcUserOptions->getLoginRedirectRoute());
     }
     $users = $this->pmService->getUsers();
     $form = $this->newConversationForm;
     $viewModel = new ViewModel(['users' => $users, 'form' => $form]);
     $viewModel->setTemplate('eye4web/zfc-user/pm/new-conversation.phtml');
     $redirectUrl = $this->url()->fromRoute('eye4web/zfc-user/pm/new-conversation');
     $prg = $this->prg($redirectUrl, true);
     if ($prg instanceof Response) {
         return $prg;
     } elseif ($prg === false) {
         return $viewModel;
     }
     $form->setData($prg);
     if (!$form->isValid()) {
         return $viewModel;
     }
     $user = $this->zfcUserAuthentication()->getIdentity();
     $this->pmService->newConversation($form->getData(), $user);
     return $this->redirect()->toRoute('eye4web/zfc-user/pm/list');
 }
 /**
  * @covers ZfcUser\Options\ModuleOptions::getFormCaptchaOptions
  */
 public function testGetFormCaptchaOptions()
 {
     $expected = array('class' => 'figlet', 'options' => array('wordLen' => 5, 'expiration' => 300, 'timeout' => 300));
     $this->assertEquals($expected, $this->options->getFormCaptchaOptions());
 }
Пример #10
0
 /**
  * @covers ZfcUser\Options\ModuleOptions::getTableName
  */
 public function testGetTableName()
 {
     $this->assertEquals('user', $this->options->getTableName());
 }
Пример #11
0
 /**
  * @param string $userId
  * @return UserInterface
  */
 public function getUser($userId)
 {
     return $this->objectManager->find($this->zfcUserOptions->getUserEntityClass(), $userId);
 }