コード例 #1
0
ファイル: UserController.php プロジェクト: rgarro/miniVan
 public function createAction()
 {
     $this->allow_admin();
     $user = $this->em->getRepository('ZfcUser\\Entity\\User')->findBy(array('email' => $_GET['user']['email']));
     if (!$user) {
         $options = $this->getServiceLocator()->get('zfcuser_module_options');
         $this->bcrypt = new Bcrypt();
         $this->bcrypt->setCost($options->getPasswordCost());
         $cryptPassword = $this->bcrypt->create($_GET['user']['password']);
         $user = new User();
         $user->setUsername($_GET['user']['username']);
         $user->setEmail($_GET['user']['email']);
         $user->setPassword($cryptPassword);
         $this->em->persist($user);
         $this->em->flush();
         $profile = new Profile();
         $profile->setEmail($_GET['user']['email']);
         $profile->setResource($_GET['profile']['type']);
         $this->em->persist($profile);
         $this->em->flush();
         $return = array("id" => $_GET['user']['email'], 'is_success' => 1, "flash" => "Usuario ha sido creado");
     } else {
         $return = array('invalid_form' => 1, 'error_list' => array("Ya existe:" . $_GET['user']['email']));
     }
     return new JsonModel($return);
 }
コード例 #2
0
 public function testGetUserImage()
 {
     $options = new ModuleOptions(['upload_directory' => 'upload_directory']);
     $storageModel = new StorageModel($options);
     $user = new User();
     $user->setId(4);
     $this->assertEquals('upload_directory/4.png', $storageModel->getUserImage($user));
 }
コード例 #3
0
 public function testGetUserSetting()
 {
     $setting = 'allow_email';
     $user = new User();
     $settingValue = new SettingValue();
     $settingValue->setValue('allow');
     $objectRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $this->objectManager->expects($this->once())->method('getRepository')->with('Eye4web\\ZfcUser\\Settings\\Entity\\SettingValue')->will($this->returnValue($objectRepository));
     $objectRepository->expects($this->once())->method('findOneBy')->with(['user' => $user->getId(), 'setting' => $setting])->will($this->returnValue($settingValue));
     $this->assertSame($settingValue, $this->mapper->getUserSetting($setting, $user));
 }
コード例 #4
0
 public function testExtract()
 {
     $user = new User();
     $user->setId(13);
     $entity = new UserRegistration($user);
     $entity->setToken('fund');
     $requestTime = new \DateTime('2013-09-13 08:08:08');
     $entity->setRequestTime($requestTime);
     $entity->setResponded(true);
     $data = (new UserRegistrationHydrator())->extract($entity);
     $this->assertEquals(13, $data['user_id']);
     $this->assertEquals(true, $data['responded']);
     $this->assertEquals('fund', $data['token']);
     $this->assertEquals($requestTime->getTimestamp(), (new \DateTime($data['request_time']))->getTimestamp());
 }
コード例 #5
0
 /**
  *
  * @dataProvider providerTestRegisterAction
  * @depend testActionControllHasIdentity
  * @depend testRegisterActionIsNotAllowed
  */
 public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $registerSuccess, $loginAfterSuccessWith)
 {
     $controller = $this->controller;
     $redirectUrl = 'http://localhost/redirect1';
     $route_url = '/user/register';
     $expectedResult = null;
     $this->setUpZfcUserAuthenticationPlugin(array('hasIdentity' => false));
     $this->options->expects($this->any())->method('getEnableRegistration')->will($this->returnValue(true));
     $request = $this->getMock('Zend\\Http\\Request');
     $this->helperMakePropertyAccessable($controller, 'request', $request);
     $userService = $this->getMock('\\ZfcUser\\Service\\User');
     $controller->setUserService($userService);
     $form = $this->getMockBuilder('\\Zend\\Form\\Form')->disableOriginalConstructor()->getMock();
     $controller->setRegisterForm($form);
     $this->options->expects($this->any())->method('getUseRedirectParameterIfPresent')->will($this->returnValue((bool) $wantRedirect));
     if ($wantRedirect) {
         $params = new Parameters();
         $params->set('redirect', $redirectUrl);
         $request->expects($this->any())->method('getQuery')->will($this->returnValue($params));
     }
     $url = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\Url');
     $url->expects($this->at(0))->method('fromRoute')->with($controller::ROUTE_REGISTER)->will($this->returnValue($route_url));
     $this->pluginManagerPlugins['url'] = $url;
     $prg = $this->getMock('\\Zend\\Mvc\\Controller\\Plugin\\PostRedirectGet');
     $this->pluginManagerPlugins['prg'] = $prg;
     $redirectQuery = $wantRedirect ? '?redirect=' . rawurlencode($redirectUrl) : '';
     $prg->expects($this->once())->method('__invoke')->with($route_url . $redirectQuery)->will($this->returnValue($postRedirectGetReturn));
     if ($registerSuccess) {
         $user = new UserIdentity();
         $user->setEmail('*****@*****.**');
         $user->setUsername('zfc-user');
         $userService->expects($this->once())->method('register')->with($postRedirectGetReturn)->will($this->returnValue($user));
         $userService->expects($this->any())->method('getOptions')->will($this->returnValue($this->options));
         $this->options->expects($this->once())->method('getLoginAfterRegistration')->will($this->returnValue(!empty($loginAfterSuccessWith)));
         if ($loginAfterSuccessWith) {
             $this->options->expects($this->once())->method('getAuthIdentityFields')->will($this->returnValue(array($loginAfterSuccessWith)));
             $expectedResult = new \stdClass();
             $forwardPlugin = $this->getMockBuilder('Zend\\Mvc\\Controller\\Plugin\\Forward')->disableOriginalConstructor()->getMock();
             $forwardPlugin->expects($this->once())->method('dispatch')->with($controller::CONTROLLER_NAME, array('action' => 'authenticate'))->will($this->returnValue($expectedResult));
             $this->pluginManagerPlugins['forward'] = $forwardPlugin;
         } else {
             $response = new Response();
             $route_url = '/user/login';
             $redirectUrl = isset($postRedirectGetReturn['redirect']) ? $postRedirectGetReturn['redirect'] : null;
             $redirectQuery = $redirectUrl ? '?redirect=' . rawurlencode($redirectUrl) : '';
             $redirect = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\Redirect');
             $redirect->expects($this->once())->method('toUrl')->with($route_url . $redirectQuery)->will($this->returnValue($response));
             $this->pluginManagerPlugins['redirect'] = $redirect;
             $url->expects($this->at(1))->method('fromRoute')->with($controller::ROUTE_LOGIN)->will($this->returnValue($route_url));
         }
     }
     /***********************************************
      * run
      */
     $result = $controller->registerAction();
     /***********************************************
      * assert
      */
     if ($postRedirectGetReturn instanceof Response) {
         $expectedResult = $postRedirectGetReturn;
     }
     if ($expectedResult) {
         $this->assertSame($expectedResult, $result);
         return;
     }
     if ($postRedirectGetReturn === false) {
         $expectedResult = array('registerForm' => $form, 'enableRegistration' => true, 'redirect' => $wantRedirect ? $redirectUrl : false);
     } elseif ($registerSuccess === false) {
         $expectedResult = array('registerForm' => $form, 'enableRegistration' => true, 'redirect' => isset($postRedirectGetReturn['redirect']) ? $postRedirectGetReturn['redirect'] : null);
     }
     if ($expectedResult) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('registerForm', $result);
         $this->assertArrayHasKey('enableRegistration', $result);
         $this->assertArrayHasKey('redirect', $result);
         $this->assertEquals($expectedResult, $result);
     } else {
         $this->assertInstanceOf('\\Zend\\Http\\Response', $result);
         $this->assertSame($response, $result);
     }
 }
コード例 #6
0
ファイル: UserTest.php プロジェクト: projectsmahendra/blogger
 public function providerTestFindBy()
 {
     $user = new Entity();
     $user->setEmail('*****@*****.**');
     $user->setUsername('zfc-user');
     $user->setDisplayName('Zfc-User');
     $user->setId('1');
     $user->setState(1);
     $user->setPassword('zfc-user');
     return array(array('findByEmail', array($user->getEmail()), array('whereArgs' => array(array('email' => $user->getEmail()), 'AND')), array(), $user), array('findByUsername', array($user->getUsername()), array('whereArgs' => array(array('username' => $user->getUsername()), 'AND')), array(), $user), array('findById', array($user->getId()), array('whereArgs' => array(array('user_id' => $user->getId()), 'AND')), array(), $user));
 }
コード例 #7
0
 /**
  * @covers Eye4web\ZfcUser\Pm\Service\PmService::getUnreadConversations
  */
 public function testGetUnreadConversations()
 {
     $user = new User();
     $user->setId(1);
     $conversation1 = new Conversation();
     $conversation2 = new Conversation();
     $this->mapper->expects($this->once())->method('getUnreadConversations')->with($user)->will($this->returnValue([$conversation1, $conversation2]));
     $conversations = $this->service->getUnreadConversations($user);
     $this->assertCount(2, $conversations);
     foreach ($conversations as $conversation) {
         $this->assertInstanceOf('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationInterface', $conversation);
     }
 }
コード例 #8
0
ファイル: EventService.php プロジェクト: WeCamp/Meetspire
 /**
  * @param User $user
  * @param Event $event
  * @return null|object
  */
 public function getRsvpForEventByUser(User $user, Event $event)
 {
     $entityRepository = $this->entityManager->getRepository('Application\\Entity\\RSVP');
     $rsvp = $entityRepository->findOneBy(['event' => $event->getId(), 'user' => $user->getId()]);
     return $rsvp;
 }
コード例 #9
0
 public function getNewGuestUser($id)
 {
     $user = new User();
     $user->setUsername('guest_' . $id)->setDisplayName('guest_' . $id);
     return $user;
 }
コード例 #10
0
 /**
  * @covers Eye4web\ZfcUser\Pm\Mapper\DoctrineORM\PmMapper::isUnread
  */
 public function testIsUnread()
 {
     $conversation = new Conversation();
     $conversation->setId(1);
     $user = new User();
     $user->setId(1);
     $optionsData = ['conversation' => $conversation->getId(), 'to' => $user->getId()];
     $this->options->expects($this->once())->method('getConversationReceiverEntity')->will($this->returnValue('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationReceiver'));
     $objectRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $this->objectManager->expects($this->once())->method('getRepository')->with('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationReceiver')->will($this->returnValue($objectRepository));
     $conversationReceive = $this->getMock('Eye4web\\ZfcUser\\Pm\\Entity\\ConversationReceiver');
     $objectRepository->expects($this->once())->method('findOneBy')->with($optionsData)->will($this->returnValue($conversationReceive));
     $conversationReceive->expects($this->once())->method('getUnread')->will($this->returnValue(true));
     $this->assertTrue($this->mapper->isUnread($conversation, $user));
 }