Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
1ce7344e
Commit
1ce7344e
authored
Jul 31, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional tests in EmailValidator.
parent
1c57661e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
EmailValidator.php
framework/yii/validators/EmailValidator.php
+2
-0
EmailValidatorTest.php
tests/unit/framework/validators/EmailValidatorTest.php
+30
-0
No files found.
framework/yii/validators/EmailValidator.php
View file @
1ce7344e
...
@@ -64,7 +64,9 @@ class EmailValidator extends Validator
...
@@ -64,7 +64,9 @@ class EmailValidator extends Validator
{
{
parent
::
init
();
parent
::
init
();
if
(
$this
->
enableIDN
&&
!
function_exists
(
'idn_to_ascii'
))
{
if
(
$this
->
enableIDN
&&
!
function_exists
(
'idn_to_ascii'
))
{
// @codeCoverageIgnoreStart
throw
new
InvalidConfigException
(
'In order to use IDN validation intl extension must be installed and enabled.'
);
throw
new
InvalidConfigException
(
'In order to use IDN validation intl extension must be installed and enabled.'
);
// @codeCoverageIgnoreEnd
}
}
if
(
$this
->
message
===
null
)
{
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii'
,
'{attribute} is not a valid email address.'
);
$this
->
message
=
Yii
::
t
(
'yii'
,
'{attribute} is not a valid email address.'
);
...
...
tests/unit/framework/validators/EmailValidatorTest.php
View file @
1ce7344e
<?php
<?php
namespace
yiiunit\framework\validators
;
namespace
yiiunit\framework\validators
;
use
yii\validators\EmailValidator
;
use
yii\validators\EmailValidator
;
use
yiiunit\TestCase
;
use
yiiunit\TestCase
;
...
@@ -25,4 +26,33 @@ class EmailValidatorTest extends TestCase
...
@@ -25,4 +26,33 @@ class EmailValidatorTest extends TestCase
$this
->
assertTrue
(
$validator
->
validateValue
(
'5011@gmail.com'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'5011@gmail.com'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'test@example.com'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'test@example.com'
));
}
}
public
function
testValidateAttribute
()
{
$val
=
new
EmailValidator
();
$model
=
new
FakedValidationModel
();
$model
->
attr_email
=
'5011@gmail.com'
;
$val
->
validateAttribute
(
$model
,
'attr_email'
);
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_email'
));
}
public
function
testValidateValueIdn
()
{
if
(
!
function_exists
(
'idn_to_ascii'
))
{
$this
->
markTestSkipped
(
'Intl extension required'
);
return
;
}
$val
=
new
EmailValidator
(
array
(
'enableIDN'
=>
true
));
$this
->
assertTrue
(
$val
->
validateValue
(
'5011@example.com'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'example@äüößìà.de'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'example@xn--zcack7ayc9a.de'
));
}
public
function
testValidateValueWithName
()
{
$val
=
new
EmailValidator
(
array
(
'allowName'
=>
true
));
$this
->
assertTrue
(
$val
->
validateValue
(
'test@example.com'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'John Smith <john.smith@example.com>'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'John Smith <example.com>'
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment