/**
  * Test that only a invited user have access to the registration form
  * User should follow link in her Invitation Email, who contain a security token for registration
  *
  * @dataProvider userProvider
  * @param $invitationEmail
  * @param $expectedStatusCode
  * @param $message
  */
 public function testRegistrationAccessForm($invitationEmail, $expectedStatusCode, $message)
 {
     $client = static::createClient();
     $em = $client->getContainer()->get('doctrine')->getManager();
     /** @var Invitation $invitation */
     $invitation = $em->getRepository('GPCoreBundle:Invitation')->findOneByEmail($invitationEmail);
     // They are no invitation found for '*****@*****.**'
     if (!$invitation) {
         // We set a fake token to test invalid access
         $invitation = new Invitation();
         $invitation->setConfirmationToken('toto');
     }
     $url = $this->generateRoute('register', array('token' => $invitation->getConfirmationToken()));
     $client->request('GET', $url);
     $this->assertStatusCode($expectedStatusCode, $client, $message);
 }
 /**
  * Send an Invitation email to the given user email adress
  *
  * @param Invitation $invitation
  */
 public function sendUserInvitationNotification(Invitation $invitation)
 {
     $template = ':Email:user_invitation.html.twig';
     $from = $this->senderEmail;
     $to = $invitation->getEmail();
     $subject = $this->setSubjectPrefix() . 'Codes Inscription';
     $body = $this->templating->render($template, array('invitation' => $invitation));
     $this->sendMessage($from, $to, $subject, $body);
 }
 /**
  * Update invitation status after successfull user registration
  *
  * @param Invitation $invitation
  */
 private function updateInvitationStatus(Invitation $invitation)
 {
     $invitation->setStatus(Invitation::STATUS_ACCEPTED);
     $em = $this->getDoctrine()->getManager();
     $em->persist($invitation);
     $em->flush();
 }