public function testShouldUseEmailValidatorWhenDefined() { $this->resetClassExists(); $input = '*****@*****.**'; $emailValidator = $this->getEmailValidatorMock(); $emailValidator->expects($this->once())->method('isValid')->with($input)->will($this->returnValue(true)); $rule = new Email($emailValidator); $this->assertTrue($rule->validate($input)); }
/** * * @link http://www.linuxjournal.com/article/9585?page=0,3 * @param string $value * @return boolean */ public function validate($value) { if (!parent::validate($value)) { return false; } $host = substr(strstr($check[0], '@'), 1) . "."; if (function_exists('getmxrr')) { $tmp = null; if (getmxrr($host, $tmp)) { return true; } // this will catch dns that are not mx. if (checkdnsrr($host, 'ANY')) { return true; } } return $host != gethostbyname($host); }
/** * @abstract A wrapper to the mail function. All parameters are the same accept for $headers. The $to address will be validated * via Email::validate. * * @param mixed $to An email address which to send this email to. Can either be a string address or an EmailAddress object. * @param string $subject The subject of the email. * @param string $message The message of the email. * @param mixed $headers Optional. If a string, then it is passed directly to mail() as it is; otherwise, it is passed to Email::headers() * (default: false). * @return bool True if the mail was sent successfully; otherwise, false. * * @see EmailAddress() * @see Email::validate() * @see Email::headers() */ public static function send($to, $subject, $body, $replyTo = false) { if (!Email::validate($to)) { return false; } $mail = self::newMailer(); $mail->AddAddress($to); $mail->From = MAIL_SENDER_NOREPLY; $mail->FromName = MAIL_SENDER_NOREPLY_NAME; $mail->Subject = $subject; $mail->Body = $body; if ($replyTo) { if (!is_array($replyTo)) { $replyTo = array($replyTo, ''); } $mail->AddReplyTo($replyTo[0], $replyTo[1]); $mail->From = $replyTo[0]; $mail->FromName = $replyTo[1]; } return $mail->Send(); }
/** * @dataProvider providerForInvalidEmail * @expectedException Respect\Validation\Exceptions\EmailException */ public function test_invalid_emails_should_fail_validation($invalidEmail) { $validator = new Email(); $this->assertFalse($validator->validate($invalidEmail)); $this->assertFalse($validator->assert($invalidEmail)); }
public static function create($params) { $user = new User(); $user->username = $params['user']; $user->credential = hasher($params['password']); $user->email = $params['email']; $user->date_joined = date("Y-m-d H:i:s"); $user->ip = $_SERVER['REMOTE_ADDR']; $user->validation = md5(time() . rand()); $user->validated = 0; $user->member_id = $params['member_id']; $user->date_joined = date('Y-m-d H:i:s'); $user->role = 0; $user->last_logged = 0; $user->last_seen = 0; $user->developer = 0; $user->save(); Email::validate($user); }
/** * @dataProvider provideTestFilter */ public function testFilter($options, $raw, $filtered, $valid) { $int = new Email($options); $this->assertEquals($filtered, $int->filter($raw)); $this->assertEquals($valid, $int->validate($raw)); }
public function testValidateValidEmail() { $email = new Email('*****@*****.**', 'as', 'asde'); $this->assertTrue($email->validate()); }
public function testIsGettingErrorMessage() { $constraint = new Email(); $this->assertFalse($constraint->validate('foobar.com')); $this->assertEquals('[field] Invalid email format', $constraint->getErrorMessage('field')); }