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
06682d0b
Commit
06682d0b
authored
Aug 24, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coverage improvements
parent
c189e5ad
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
6 deletions
+49
-6
sqlite.sql
tests/unit/data/sqlite.sql
+4
-6
CompareValidatorTest.php
tests/unit/framework/validators/CompareValidatorTest.php
+6
-0
FileValidatorTest.php
tests/unit/framework/validators/FileValidatorTest.php
+17
-0
RequiredValidatorTest.php
tests/unit/framework/validators/RequiredValidatorTest.php
+21
-0
UniqueValidatorTest.php
tests/unit/framework/validators/UniqueValidatorTest.php
+1
-0
No files found.
tests/unit/data/sqlite.sql
View file @
06682d0b
...
...
@@ -95,16 +95,14 @@ DROP TABLE IF EXISTS tbl_validator_main;
DROP
TABLE
IF
EXISTS
tbl_validator_ref
;
CREATE
TABLE
tbl_validator_main
(
id
INT
(
11
)
NOT
NULL
,
field1
VARCHAR
(
255
),
PRIMARY
KEY
(
id
)
id
INTEGER
PRIMARY
KEY
,
field1
VARCHAR
(
255
)
);
CREATE
TABLE
tbl_validator_ref
(
id
INT
(
11
)
NOT
NULL
,
id
INT
EGER
PRIMARY
KEY
,
a_field
VARCHAR
(
255
),
ref
INT
(
11
),
PRIMARY
KEY
(
id
)
ref
INT
(
11
)
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
...
...
tests/unit/framework/validators/CompareValidatorTest.php
View file @
06682d0b
...
...
@@ -128,6 +128,12 @@ class CompareValidatorTest extends TestCase
$val
->
validateAttribute
(
$model
,
'attr_test'
);
$this
->
assertTrue
(
$model
->
hasErrors
(
'attr_test'
));
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_test_repeat'
));
// not existing op
$val
=
new
CompareValidator
();
$val
->
operator
=
'<>'
;
$model
=
FakedValidationModel
::
createWithAttributes
(
array
(
'attr_o'
=>
5
,
'attr_o_repeat'
=>
5
));
$val
->
validateAttribute
(
$model
,
'attr_o'
);
$this
->
assertTrue
(
$model
->
hasErrors
(
'attr_o'
));
}
public
function
testValidateAttributeOperators
()
...
...
tests/unit/framework/validators/FileValidatorTest.php
View file @
06682d0b
...
...
@@ -205,6 +205,23 @@ class FileValidatorTest extends TestCase
$this
->
assertSame
(
FileValidator
::
className
()
.
'::validateFile'
,
$log
[
'messages'
][
0
][
2
]);
}
public
function
testValidateAttributeType
()
{
$val
=
new
FileValidator
(
array
(
'types'
=>
'jpeg, jpg'
));
$m
=
FakedValidationModel
::
createWithAttributes
(
array
(
'attr_jpg'
=>
$this
->
createTestFiles
(
array
(
array
(
'name'
=>
'one.jpeg'
))),
'attr_exe'
=>
$this
->
createTestFiles
(
array
(
array
(
'name'
=>
'bad.exe'
))),
)
);
$val
->
validateAttribute
(
$m
,
'attr_jpg'
);
$this
->
assertFalse
(
$m
->
hasErrors
(
'attr_jpg'
));
$val
->
validateAttribute
(
$m
,
'attr_exe'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'attr_exe'
));
$this
->
assertTrue
(
stripos
(
current
(
$m
->
getErrors
(
'attr_exe'
)),
'Only files with these extensions '
)
!==
false
);
}
protected
function
createModelForAttributeTest
()
{
return
FakedValidationModel
::
createWithAttributes
(
...
...
tests/unit/framework/validators/RequiredValidatorTest.php
View file @
06682d0b
...
...
@@ -3,6 +3,7 @@ namespace yiiunit\framework\validators;
use
yii\validators\RequiredValidator
;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
class
RequiredValidatorTest
extends
TestCase
...
...
@@ -31,4 +32,23 @@ class RequiredValidatorTest extends TestCase
$this
->
assertFalse
(
$val
->
validateValue
(
"should fail"
));
$this
->
assertFalse
(
$val
->
validateValue
(
true
));
}
public
function
testValidateAttribute
()
{
// empty req-value
$val
=
new
RequiredValidator
();
$m
=
FakedValidationModel
::
createWithAttributes
(
array
(
'attr_val'
=>
null
));
$val
->
validateAttribute
(
$m
,
'attr_val'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'attr_val'
));
$this
->
assertTrue
(
stripos
(
current
(
$m
->
getErrors
(
'attr_val'
)),
'blank'
)
!==
false
);
$val
=
new
RequiredValidator
(
array
(
'requiredValue'
=>
55
));
$m
=
FakedValidationModel
::
createWithAttributes
(
array
(
'attr_val'
=>
56
));
$val
->
validateAttribute
(
$m
,
'attr_val'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'attr_val'
));
$this
->
assertTrue
(
stripos
(
current
(
$m
->
getErrors
(
'attr_val'
)),
'must be'
)
!==
false
);
$val
=
new
RequiredValidator
(
array
(
'requiredValue'
=>
55
));
$m
=
FakedValidationModel
::
createWithAttributes
(
array
(
'attr_val'
=>
55
));
$val
->
validateAttribute
(
$m
,
'attr_val'
);
$this
->
assertFalse
(
$m
->
hasErrors
(
'attr_val'
));
}
}
\ No newline at end of file
tests/unit/framework/validators/UniqueValidatorTest.php
View file @
06682d0b
...
...
@@ -44,6 +44,7 @@ class UniqueValidatorTest extends DatabaseTestCase
$val
->
validateAttribute
(
$m
,
'ref'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'ref'
));
$m
=
new
ValidatorTestRefModel
();
$m
->
id
=
7
;
$m
->
ref
=
12121
;
$val
->
validateAttribute
(
$m
,
'ref'
);
$this
->
assertFalse
(
$m
->
hasErrors
(
'ref'
));
...
...
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