Beispiel #1
0
 public function testVerifyEmail()
 {
     $userManager = new UserManager($this->encoderFactoryMock, CustomUser::class);
     $user = new User();
     $this->assertFalse($user->getEmailVerified(), 'Email is not verified at beginning.');
     $userManager->initEmailVerification($user);
     $token = $user->getEmailVerificationToken();
     $resultWrong = $userManager->verifyEmail($user, 'wrong-token');
     $this->assertFalse($resultWrong, 'Cannot verify email on wrong token.');
     $this->assertFalse($user->getEmailVerified(), 'Email is not verified after wrong token.');
     $result = $userManager->verifyEmail($user, $token);
     $this->assertTrue($result, 'Returns true on success.');
     $this->assertTrue($user->getEmailVerified(), 'Email is flagged as verified.');
     $this->assertNull($user->getEmailVerificationToken(), 'Token is reset to null after verification.');
 }
Beispiel #2
0
 public function testDateCreated()
 {
     $user = new User();
     $diffSeconds = $user->getDateCreated()->getTimestamp() - (new \DateTime())->getTimestamp();
     $this->assertLessThan(2, $diffSeconds, 'User created date is well initialized.');
 }
Beispiel #3
0
 /**
  * @param User $user
  * @param type $emailVerificationToken
  *
  * @return bool
  */
 public function verifyEmail(User $user, $emailVerificationToken)
 {
     if ($user->getEmailVerificationToken() === $emailVerificationToken) {
         $user->setEmailVerified(true)->setEmailVerificationToken(null);
         return true;
     } else {
         return false;
     }
 }