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
1c57661e
Commit
1c57661e
authored
Jul 31, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'add-tests' of github.com:suralc/yii2 into add-tests
parents
a23f2334
777ff792
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
442 additions
and
0 deletions
+442
-0
BooleanValidator.php
framework/yii/validators/BooleanValidator.php
+1
-0
CaptchaValidator.php
framework/yii/validators/CaptchaValidator.php
+1
-0
CompareValidator.php
framework/yii/validators/CompareValidator.php
+1
-0
EmailValidator.php
framework/yii/validators/EmailValidator.php
+1
-0
NumberValidator.php
framework/yii/validators/NumberValidator.php
+1
-0
RangeValidator.php
framework/yii/validators/RangeValidator.php
+1
-0
RegularExpressionValidator.php
framework/yii/validators/RegularExpressionValidator.php
+1
-0
RequiredValidator.php
framework/yii/validators/RequiredValidator.php
+1
-0
StringValidator.php
framework/yii/validators/StringValidator.php
+1
-0
UrlValidator.php
framework/yii/validators/UrlValidator.php
+3
-0
BooleanValidatorTest.php
tests/unit/framework/validators/BooleanValidatorTest.php
+54
-0
CompareValidatorTest.php
tests/unit/framework/validators/CompareValidatorTest.php
+161
-0
DateValidatorTest.php
tests/unit/framework/validators/DateValidatorTest.php
+62
-0
DefaultValueValidatorTest.php
...s/unit/framework/validators/DefaultValueValidatorTest.php
+32
-0
FakedValidationModel.php
tests/unit/framework/validators/FakedValidationModel.php
+32
-0
UrlValidatorTest.php
tests/unit/framework/validators/UrlValidatorTest.php
+89
-0
No files found.
framework/yii/validators/BooleanValidator.php
View file @
1c57661e
...
...
@@ -82,6 +82,7 @@ class BooleanValidator extends Validator
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/CaptchaValidator.php
View file @
1c57661e
...
...
@@ -97,6 +97,7 @@ class CaptchaValidator extends Validator
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/CompareValidator.php
View file @
1c57661e
...
...
@@ -181,6 +181,7 @@ class CompareValidator extends Validator
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @throws InvalidConfigException if CompareValidator::operator is invalid
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/EmailValidator.php
View file @
1c57661e
...
...
@@ -122,6 +122,7 @@ class EmailValidator extends Validator
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/NumberValidator.php
View file @
1c57661e
...
...
@@ -117,6 +117,7 @@ class NumberValidator extends Validator
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/RangeValidator.php
View file @
1c57661e
...
...
@@ -84,6 +84,7 @@ class RangeValidator extends Validator
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/RegularExpressionValidator.php
View file @
1c57661e
...
...
@@ -83,6 +83,7 @@ class RegularExpressionValidator extends Validator
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @throws InvalidConfigException if the "pattern" is not a valid regular expression
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/RequiredValidator.php
View file @
1c57661e
...
...
@@ -105,6 +105,7 @@ class RequiredValidator extends Validator
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/StringValidator.php
View file @
1c57661e
...
...
@@ -145,6 +145,7 @@ class StringValidator extends Validator
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
framework/yii/validators/UrlValidator.php
View file @
1c57661e
...
...
@@ -54,7 +54,9 @@ class UrlValidator extends Validator
{
parent
::
init
();
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.'
);
// @codeCoverageIgnoreEnd
}
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii'
,
'{attribute} is not a valid URL.'
);
...
...
@@ -119,6 +121,7 @@ class UrlValidator extends Validator
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @see \yii\Web\ActiveForm::enableClientValidation
* @codeCoverageIgnore
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
...
...
tests/unit/framework/validators/BooleanValidatorTest.php
0 → 100644
View file @
1c57661e
<?php
namespace
yiiunit\framework\validators
;
use
yiiunit\framework\validators\FakedValidationModel
;
use
yii\validators\BooleanValidator
;
use
yiiunit\TestCase
;
require_once
__DIR__
.
'/FakedValidationModel.php'
;
/**
* BooleanValidatorTest
*/
class
BooleanValidatorTest
extends
TestCase
{
public
function
testValidateValue
()
{
$val
=
new
BooleanValidator
;
$this
->
assertTrue
(
$val
->
validateValue
(
true
));
$this
->
assertTrue
(
$val
->
validateValue
(
false
));
$this
->
assertTrue
(
$val
->
validateValue
(
'0'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'1'
));
$this
->
assertFalse
(
$val
->
validateValue
(
null
));
$this
->
assertFalse
(
$val
->
validateValue
(
array
()));
$val
->
strict
=
true
;
$this
->
assertTrue
(
$val
->
validateValue
(
'0'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'1'
));
$this
->
assertFalse
(
$val
->
validateValue
(
true
));
$this
->
assertFalse
(
$val
->
validateValue
(
false
));
$val
->
trueValue
=
true
;
$val
->
falseValue
=
false
;
$this
->
assertFalse
(
$val
->
validateValue
(
'0'
));
$this
->
assertFalse
(
$val
->
validateValue
(
array
()));
$this
->
assertTrue
(
$val
->
validateValue
(
true
));
$this
->
assertTrue
(
$val
->
validateValue
(
false
));
}
public
function
testValidateAttributeAndError
()
{
$obj
=
new
FakedValidationModel
;
$obj
->
attrA
=
true
;
$obj
->
attrB
=
'1'
;
$obj
->
attrC
=
'0'
;
$obj
->
attrD
=
array
();
$val
=
new
BooleanValidator
;
$val
->
validateAttribute
(
$obj
,
'attrA'
);
$this
->
assertFalse
(
$obj
->
hasErrors
(
'attrA'
));
$val
->
validateAttribute
(
$obj
,
'attrC'
);
$this
->
assertFalse
(
$obj
->
hasErrors
(
'attrC'
));
$val
->
strict
=
true
;
$val
->
validateAttribute
(
$obj
,
'attrB'
);
$this
->
assertFalse
(
$obj
->
hasErrors
(
'attrB'
));
$val
->
validateAttribute
(
$obj
,
'attrD'
);
$this
->
assertTrue
(
$obj
->
hasErrors
(
'attrD'
));
}
}
tests/unit/framework/validators/CompareValidatorTest.php
0 → 100644
View file @
1c57661e
<?php
namespace
yiiunit\framework\validators
;
use
yii\base\InvalidConfigException
;
use
yii\validators\CompareValidator
;
use
yiiunit\TestCase
;
require_once
__DIR__
.
'/FakedValidationModel.php'
;
class
CompareValidatorTest
extends
TestCase
{
public
function
testValidateValueException
()
{
$this
->
setExpectedException
(
'yii\base\InvalidConfigException'
);
$val
=
new
CompareValidator
;
$val
->
validateValue
(
'val'
);
}
public
function
testValidateValue
()
{
$value
=
18449
;
// default config
$val
=
new
CompareValidator
(
array
(
'compareValue'
=>
$value
));
$this
->
assertTrue
(
$val
->
validateValue
(
$value
));
$this
->
assertTrue
(
$val
->
validateValue
((
string
)
$value
));
$this
->
assertFalse
(
$val
->
validateValue
(
$value
+
1
));
foreach
(
$this
->
getOperationTestData
(
$value
)
as
$op
=>
$tests
)
{
$val
=
new
CompareValidator
(
array
(
'compareValue'
=>
$value
));
$val
->
operator
=
$op
;
foreach
(
$tests
as
$test
)
{
$this
->
assertEquals
(
$test
[
1
],
$val
->
validateValue
(
$test
[
0
]));
}
}
}
protected
function
getOperationTestData
(
$value
)
{
return
array
(
'==='
=>
array
(
array
(
$value
,
true
),
array
((
string
)
$value
,
false
),
array
((
float
)
$value
,
false
),
array
(
$value
+
1
,
false
),
),
'!='
=>
array
(
array
(
$value
,
false
),
array
((
string
)
$value
,
false
),
array
((
float
)
$value
,
false
),
array
(
$value
+
0.00001
,
true
),
array
(
false
,
true
),
),
'!=='
=>
array
(
array
(
$value
,
false
),
array
((
string
)
$value
,
true
),
array
((
float
)
$value
,
true
),
array
(
false
,
true
),
),
'>'
=>
array
(
array
(
$value
,
false
),
array
(
$value
+
1
,
true
),
array
(
$value
-
1
,
false
),
),
'>='
=>
array
(
array
(
$value
,
true
),
array
(
$value
+
1
,
true
),
array
(
$value
-
1
,
false
),
),
'<'
=>
array
(
array
(
$value
,
false
),
array
(
$value
+
1
,
false
),
array
(
$value
-
1
,
true
),
),
'<='
=>
array
(
array
(
$value
,
true
),
array
(
$value
+
1
,
false
),
array
(
$value
-
1
,
true
),
),
);
}
public
function
testValidateAttribute
()
{
// invalid-array
$val
=
new
CompareValidator
;
$model
=
new
FakedValidationModel
;
$model
->
attr
=
array
(
'test_val'
);
$val
->
validateAttribute
(
$model
,
'attr'
);
$this
->
assertTrue
(
$model
->
hasErrors
(
'attr'
));
$val
=
new
CompareValidator
(
array
(
'compareValue'
=>
'test-string'
));
$model
=
new
FakedValidationModel
;
$model
->
attr_test
=
'test-string'
;
$val
->
validateAttribute
(
$model
,
'attr_test'
);
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_test'
));
$val
=
new
CompareValidator
(
array
(
'compareAttribute'
=>
'attr_test_val'
));
$model
=
new
FakedValidationModel
;
$model
->
attr_test
=
'test-string'
;
$model
->
attr_test_val
=
'test-string'
;
$val
->
validateAttribute
(
$model
,
'attr_test'
);
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_test'
));
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_test_val'
));
$val
=
new
CompareValidator
(
array
(
'compareAttribute'
=>
'attr_test_val'
));
$model
=
new
FakedValidationModel
;
$model
->
attr_test
=
'test-string'
;
$model
->
attr_test_val
=
'test-string-false'
;
$val
->
validateAttribute
(
$model
,
'attr_test'
);
$this
->
assertTrue
(
$model
->
hasErrors
(
'attr_test'
));
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_test_val'
));
// assume: _repeat
$val
=
new
CompareValidator
;
$model
=
new
FakedValidationModel
;
$model
->
attr_test
=
'test-string'
;
$model
->
attr_test_repeat
=
'test-string'
;
$val
->
validateAttribute
(
$model
,
'attr_test'
);
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_test'
));
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_test_repeat'
));
$val
=
new
CompareValidator
;
$model
=
new
FakedValidationModel
;
$model
->
attr_test
=
'test-string'
;
$model
->
attr_test_repeat
=
'test-string2'
;
$val
->
validateAttribute
(
$model
,
'attr_test'
);
$this
->
assertTrue
(
$model
->
hasErrors
(
'attr_test'
));
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_test_repeat'
));
}
public
function
testValidateAttributeOperators
()
{
$value
=
55
;
foreach
(
$this
->
getOperationTestData
(
$value
)
as
$operator
=>
$tests
)
{
$val
=
new
CompareValidator
(
array
(
'operator'
=>
$operator
,
'compareValue'
=>
$value
));
foreach
(
$tests
as
$test
)
{
$model
=
new
FakedValidationModel
;
$model
->
attr_test
=
$test
[
0
];
$val
->
validateAttribute
(
$model
,
'attr_test'
);
$this
->
assertEquals
(
$test
[
1
],
!
$model
->
hasErrors
(
'attr_test'
));
}
}
}
public
function
testEnsureMessageSetOnInit
()
{
foreach
(
$this
->
getOperationTestData
(
1337
)
as
$operator
=>
$tests
)
{
$val
=
new
CompareValidator
(
array
(
'operator'
=>
$operator
));
$this
->
assertTrue
(
strlen
(
$val
->
message
)
>
1
);
}
try
{
$val
=
new
CompareValidator
(
array
(
'operator'
=>
'<>'
));
}
catch
(
InvalidConfigException
$e
)
{
return
;
}
catch
(
\Exception
$e
)
{
$this
->
fail
(
'InvalidConfigException expected'
.
get_class
(
$e
)
.
'received'
);
return
;
}
$this
->
fail
(
'InvalidConfigException expected none received'
);
}
}
\ No newline at end of file
tests/unit/framework/validators/DateValidatorTest.php
0 → 100644
View file @
1c57661e
<?php
namespace
yiiunit\framework\validators
;
use
DateTime
;
use
yii\validators\DateValidator
;
use
yiiunit\TestCase
;
require_once
__DIR__
.
'/FakedValidationModel.php'
;
class
DateValidatorTest
extends
TestCase
{
public
function
testEnsureMessageIsSet
()
{
$val
=
new
DateValidator
;
$this
->
assertTrue
(
$val
->
message
!==
null
&&
strlen
(
$val
->
message
)
>
1
);
}
public
function
testValidateValue
()
{
$val
=
new
DateValidator
;
$this
->
assertTrue
(
$val
->
validateValue
(
'2013-09-13'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'31.7.2013'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'31-7-2013'
));
$this
->
assertFalse
(
$val
->
validateValue
(
time
()));
$val
->
format
=
'U'
;
$this
->
assertTrue
(
$val
->
validateValue
(
time
()));
$val
->
format
=
'd.m.Y'
;
$this
->
assertTrue
(
$val
->
validateValue
(
'31.7.2013'
));
$val
->
format
=
'Y-m-!d H:i:s'
;
$this
->
assertTrue
(
$val
->
validateValue
(
'2009-02-15 15:16:17'
));
}
public
function
testValidateAttribute
()
{
// error-array-add
$val
=
new
DateValidator
;
$model
=
new
FakedValidationModel
;
$model
->
attr_date
=
'2013-09-13'
;
$val
->
validateAttribute
(
$model
,
'attr_date'
);
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_date'
));
$model
=
new
FakedValidationModel
;
$model
->
attr_date
=
'1375293913'
;
$val
->
validateAttribute
(
$model
,
'attr_date'
);
$this
->
assertTrue
(
$model
->
hasErrors
(
'attr_date'
));
//// timestamp attribute
$val
=
new
DateValidator
(
array
(
'timestampAttribute'
=>
'attr_timestamp'
));
$model
=
new
FakedValidationModel
;
$model
->
attr_date
=
'2013-09-13'
;
$model
->
attr_timestamp
=
true
;
$val
->
validateAttribute
(
$model
,
'attr_date'
);
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_date'
));
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_timestamp'
));
$this
->
assertEquals
(
DateTime
::
createFromFormat
(
$val
->
format
,
'2013-09-13'
)
->
getTimestamp
(),
$model
->
attr_timestamp
);
}
}
\ No newline at end of file
tests/unit/framework/validators/DefaultValueValidatorTest.php
0 → 100644
View file @
1c57661e
<?php
namespace
yiiunit\framework\validators
;
use
yii\validators\DefaultValueValidator
;
use
yiiunit\TestCase
;
/**
* DefaultValueValidatorTest
*/
class
DefaultValueValidatorTest
extends
TestCase
{
public
function
testValidateAttribute
()
{
$val
=
new
DefaultValueValidator
;
$val
->
value
=
'test_value'
;
$obj
=
new
\stdclass
;
$obj
->
attrA
=
'attrA'
;
$obj
->
attrB
=
null
;
$obj
->
attrC
=
''
;
// original values to chek which attritubes where modified
$objB
=
clone
$obj
;
$val
->
validateAttribute
(
$obj
,
'attrB'
);
$this
->
assertEquals
(
$val
->
value
,
$obj
->
attrB
);
$this
->
assertEquals
(
$objB
->
attrA
,
$obj
->
attrA
);
$val
->
value
=
'new_test_value'
;
$obj
=
clone
$objB
;
// get clean object
$val
->
validateAttribute
(
$obj
,
'attrC'
);
$this
->
assertEquals
(
'new_test_value'
,
$obj
->
attrC
);
$this
->
assertEquals
(
$objB
->
attrA
,
$obj
->
attrA
);
$val
->
validateAttribute
(
$obj
,
'attrA'
);
$this
->
assertEquals
(
$objB
->
attrA
,
$obj
->
attrA
);
}
}
tests/unit/framework/validators/FakedValidationModel.php
0 → 100644
View file @
1c57661e
<?php
namespace
yiiunit\framework\validators
;
use
yii\base\Model
;
/**
* @codeCoverageIgnore
*/
class
FakedValidationModel
extends
Model
{
private
$attr
=
array
();
public
function
__get
(
$name
)
{
if
(
stripos
(
$name
,
'attr'
)
===
0
)
{
return
isset
(
$this
->
attr
[
$name
])
?
$this
->
attr
[
$name
]
:
null
;
}
return
parent
::
__get
(
$name
);
}
public
function
__set
(
$name
,
$value
)
{
if
(
stripos
(
$name
,
'attr'
)
===
0
)
{
$this
->
attr
[
$name
]
=
$value
;
}
else
{
parent
::
__set
(
$name
,
$value
);
}
}
}
\ No newline at end of file
tests/unit/framework/validators/UrlValidatorTest.php
0 → 100644
View file @
1c57661e
<?php
namespace
yiiunit\framework\validators
;
use
yiiunit\framework\validators\FakedValidationModel
;
use
yii\validators\UrlValidator
;
use
yiiunit\TestCase
;
require_once
__DIR__
.
'/FakedValidationModel.php'
;
/**
* UrlValidatorTest
*/
class
UrlValidatorTest
extends
TestCase
{
public
function
testValidateValue
()
{
$val
=
new
UrlValidator
;
$this
->
assertFalse
(
$val
->
validateValue
(
'google.de'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'http://google.de'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'https://google.de'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'htp://yiiframework.com'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'https://www.google.de/search?q=yii+framework&ie=utf-8&oe=utf-8'
.
'&rls=org.mozilla:de:official&client=firefox-a&gws_rd=cr'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'ftp://ftp.ruhr-uni-bochum.de/'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'http://invalid,domain'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'http://äüö?=!"§$%&/()=}][{³²€.edu'
));
}
public
function
testValidateValueWithDefaultScheme
()
{
$val
=
new
UrlValidator
(
array
(
'defaultScheme'
=>
'https'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'yiiframework.com'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'http://yiiframework.com'
));
}
public
function
testValidateWithCustomScheme
()
{
$val
=
new
UrlValidator
(
array
(
'validSchemes'
=>
array
(
'http'
,
'https'
,
'ftp'
,
'ftps'
),
'defaultScheme'
=>
'http'
,
));
$this
->
assertTrue
(
$val
->
validateValue
(
'ftp://ftp.ruhr-uni-bochum.de/'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'google.de'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'http://google.de'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'https://google.de'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'htp://yiiframework.com'
));
// relative urls not supported
$this
->
assertFalse
(
$val
->
validateValue
(
'//yiiframework.com'
));
}
public
function
testValidateWithIdn
()
{
if
(
!
function_exists
(
'idn_to_ascii'
))
{
$this
->
markTestSkipped
(
'intl package required'
);
return
;
}
$val
=
new
UrlValidator
(
array
(
'enableIDN'
=>
true
,
));
$this
->
assertTrue
(
$val
->
validateValue
(
'http://äüößìà.de'
));
// converted via http://mct.verisign-grs.com/convertServlet
$this
->
assertTrue
(
$val
->
validateValue
(
'http://xn--zcack7ayc9a.de'
));
}
public
function
testValidateLength
()
{
$url
=
'http://'
.
str_pad
(
'base'
,
2000
,
'url'
)
.
'.de'
;
$val
=
new
UrlValidator
;
$this
->
assertFalse
(
$val
->
validateValue
(
$url
));
}
public
function
testValidateAttributeAndError
()
{
$obj
=
new
FakedValidationModel
;
$obj
->
attr_url
=
'http://google.de'
;
$val
=
new
UrlValidator
;
$val
->
validateAttribute
(
$obj
,
'attr_url'
);
$this
->
assertFalse
(
$obj
->
hasErrors
(
'attr_url'
));
$this
->
assertSame
(
'http://google.de'
,
$obj
->
attr_url
);
$obj
=
new
FakedValidationModel
;
$val
->
defaultScheme
=
'http'
;
$obj
->
attr_url
=
'google.de'
;
$val
->
validateAttribute
(
$obj
,
'attr_url'
);
$this
->
assertFalse
(
$obj
->
hasErrors
(
'attr_url'
));
$this
->
assertTrue
(
stripos
(
$obj
->
attr_url
,
'http'
)
!==
false
);
$obj
=
new
FakedValidationModel
;
$obj
->
attr_url
=
'gttp;/invalid string'
;
$val
->
validateAttribute
(
$obj
,
'attr_url'
);
$this
->
assertTrue
(
$obj
->
hasErrors
(
'attr_url'
));
}
}
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