/**
  * @expectedException HealthCareAbroad\UserBundle\Services\Exception\FailedAccountRequestException
  */
 public function testCreateWithMissingFields()
 {
     $institution = $this->getDoctrine()->getRepository('InstitutionBundle:Institution')->find(1);
     $institutionUserType = $this->getDoctrine()->getRepository('UserBundle:InstitutionUserType')->find(1);
     $user = new InstitutionUser();
     $user->setEmail(null);
     $user->setPassword($this->commonPassword);
     $user->setFirstName('');
     $user->setMiddleName('');
     $user->setLastName('User');
     $user->setInstitution($institution);
     $user->setInstitutionUserType($institutionUserType);
     $user->setStatus(SiteUser::STATUS_ACTIVE);
     $user = $this->service->create($user);
     return $user;
 }
 public function testSendInstitutionUserLoginCredentials()
 {
     // create temporary 10 character password
     $temporaryPassword = \substr(SecurityHelper::hash_sha256(time()), 0, 10);
     // get data for institution
     $institution = $this->doctrine->getRepository('InstitutionBundle:Institution')->find(1);
     //get data for institutionUserType
     $institutionUserType = $this->doctrine->getRepository('UserBundle:InstitutionUserType')->find(1);
     $user = new InstitutionUser();
     $user->setInstitution($institution);
     $user->setInstitutionUserType($institutionUserType);
     $user->setEmail('*****@*****.**');
     $user->setPassword($temporaryPassword);
     $user->setFirstName('alnie');
     $user->setMiddleName('leones');
     $user->setLastName('jacobe');
     $user->setStatus('1');
     $sendingResult = $this->service->sendInstitutionUserLoginCredentials($user, $temporaryPassword);
     $this->assertEquals(1, $sendingResult);
     return $sendingResult;
 }
 /**
  * Add new User and Institution
  * @author Chaztine Blance
  */
 public function addAction(Request $request)
 {
     $factory = $this->get('services.institution.factory');
     $institution = $factory->createInstance();
     $institutionUser = new InstitutionUser();
     $this->get('services.contact_detail')->initializeContactDetails($institutionUser, array(ContactDetailTypes::PHONE, ContactDetailTypes::MOBILE));
     $form = $this->createForm(new InstitutionUserSignUpFormType(), $institutionUser, array('include_terms_agreement' => false));
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $postData = $request->get('institutionUserSignUp');
             $institutionUser = $form->getData();
             // initialize required database fields
             $institution->setName(uniqid());
             $institution->setAddress1('');
             $institution->setContactEmail('');
             $institution->setContactNumber('');
             $institution->setDescription('');
             $institution->setLogo(null);
             $institution->setCoordinates('');
             $institution->setType(trim($postData['type']));
             /* FIX ME! */
             $institution->setWebsites('');
             $institution->setStatus(InstitutionStatus::getBitValueForInactiveStatus());
             $institution->setZipCode('');
             $institution->setSignupStepStatus(0);
             // Temporary Code to mark a newly added institution as added internally.
             // Added By: Adelbert Silla
             $institution->setIsFromInternalAdmin(1);
             $factory->save($institution);
             // create Institution user
             $institutionUser = new InstitutionUser();
             $institutionUser->setEmail($form->get('email')->getData());
             $institutionUser->setFirstName($institution->getName());
             $institutionUser->setLastName('Admin');
             $institutionUser->setPassword(SecurityHelper::hash_sha256($form->get('password')->getData()));
             $institutionUser->setInstitution($institution);
             $institutionUser->setStatus(SiteUser::STATUS_ACTIVE);
             $this->get('services.contact_detail')->removeInvalidContactDetails($institutionUser);
             //                     var_dump($institutionUser->getContactDetails()); exit;
             // dispatch event
             $this->get('event_dispatcher')->dispatch(InstitutionBundleEvents::ON_ADD_INSTITUTION, $this->get('events.factory')->create(InstitutionBundleEvents::ON_ADD_INSTITUTION, $institution, array('institutionUser' => $institutionUser)));
             return $this->redirect($this->generateUrl('admin_institution_add_details', array('institutionId' => $institution->getId())));
         } else {
         }
     }
     return $this->render('AdminBundle:Institution:add.html.twig', array('form' => $form->createView(), 'institutionTypes' => InstitutionTypes::getFormChoices()));
 }