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
24e2f885
Commit
24e2f885
authored
Aug 23, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed validator test models to be less specific.
parent
7d5bb082
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
66 deletions
+75
-66
mysql.sql
tests/unit/data/mysql.sql
+15
-15
postgres.sql
tests/unit/data/postgres.sql
+16
-16
sqlite.sql
tests/unit/data/sqlite.sql
+16
-16
ValidatorTestMainModel.php
tests/unit/data/validators/models/ValidatorTestMainModel.php
+5
-3
ValidatorTestRefModel.php
tests/unit/data/validators/models/ValidatorTestRefModel.php
+5
-3
CompareValidatorTest.php
tests/unit/framework/validators/CompareValidatorTest.php
+5
-0
ExistValidatorTest.php
tests/unit/framework/validators/ExistValidatorTest.php
+13
-13
No files found.
tests/unit/data/mysql.sql
View file @
24e2f885
...
...
@@ -103,32 +103,32 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2,
/**
* (MySQL-)Database Schema for
ExistValidatorTest
* (MySQL-)Database Schema for
validator tests
*/
DROP
TABLE
IF
EXISTS
tbl_validator_
exist_
main
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_validator_
exist_
ref
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_validator_main
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_validator_ref
CASCADE
;
CREATE
TABLE
`tbl_validator_exist_main`
(
CREATE
TABLE
tbl_validator_main
(
`id`
INT
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`field1`
VARCHAR
(
255
),
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`tbl_validator_exist_ref`
(
CREATE
TABLE
tbl_validator_ref
(
`id`
INT
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`a_field`
VARCHAR
(
255
),
`ref`
INT
(
11
),
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
INSERT
INTO
tbl_validator_
exist_
main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_validator_
exist_
main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_validator_
exist_
main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_validator_
exist_
main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_validator_
exist_
ref
(
a_field
,
ref
)
VALUES
(
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_
exist_
ref
(
a_field
,
ref
)
VALUES
(
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_
exist_
ref
(
a_field
,
ref
)
VALUES
(
'ref_to_3'
,
3
);
INSERT
INTO
tbl_validator_
exist_
ref
(
a_field
,
ref
)
VALUES
(
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_
exist_
ref
(
a_field
,
ref
)
VALUES
(
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_
exist_
ref
(
a_field
,
ref
)
VALUES
(
'ref_to_5'
,
5
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_3'
,
3
);
INSERT
INTO
tbl_validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_5'
,
5
);
tests/unit/data/postgres.sql
View file @
24e2f885
...
...
@@ -94,30 +94,30 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3,
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
/**
* (Postgres-)Database Schema for
ExistValidatorTest
* (Postgres-)Database Schema for
validator tests
*/
DROP
TABLE
IF
EXISTS
tbl_validator_
exist_
main
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_validator_
exist_
ref
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_validator_main
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_validator_ref
CASCADE
;
CREATE
TABLE
tbl_validator_
exist_
main
(
CREATE
TABLE
tbl_validator_main
(
id
integer
not
null
primary
key
,
field1
VARCHAR
(
255
)
);
CREATE
TABLE
tbl_validator_
exist_
ref
(
CREATE
TABLE
tbl_validator_ref
(
id
integer
not
null
primary
key
,
a_field
VARCHAR
(
255
),
ref
integer
);
INSERT
INTO
tbl_validator_exist_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_validator_exist_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_validator_exist_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_validator_exist_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
1
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
2
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
\ No newline at end of file
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
1
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
2
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
\ No newline at end of file
tests/unit/data/sqlite.sql
View file @
24e2f885
...
...
@@ -88,32 +88,32 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3,
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
/**
* (SqLite-)Database Schema for
ExistValidatorTest
* (SqLite-)Database Schema for
validator tests
*/
DROP
TABLE
IF
EXISTS
tbl_validator_
exist_
main
;
DROP
TABLE
IF
EXISTS
tbl_validator_
exist_
ref
;
DROP
TABLE
IF
EXISTS
tbl_validator_main
;
DROP
TABLE
IF
EXISTS
tbl_validator_ref
;
CREATE
TABLE
tbl_validator_
exist_
main
(
CREATE
TABLE
tbl_validator_main
(
id
INT
(
11
)
NOT
NULL
,
field1
VARCHAR
(
255
),
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
tbl_validator_
exist_
ref
(
CREATE
TABLE
tbl_validator_ref
(
id
INT
(
11
)
NOT
NULL
,
a_field
VARCHAR
(
255
),
ref
INT
(
11
),
PRIMARY
KEY
(
id
)
);
INSERT
INTO
tbl_validator_exist_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_validator_exist_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_validator_exist_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_validator_exist_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
1
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
2
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_exist_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
\ No newline at end of file
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
1
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
2
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
\ No newline at end of file
tests/unit/data/validators/models/
ExistValidator
MainModel.php
→
tests/unit/data/validators/models/
ValidatorTest
MainModel.php
View file @
24e2f885
...
...
@@ -5,16 +5,17 @@ namespace yiiunit\data\validators\models;
use
yii\db\ActiveRecord
;
class
ExistValidator
MainModel
extends
ActiveRecord
class
ValidatorTest
MainModel
extends
ActiveRecord
{
public
$testMainVal
=
1
;
public
static
function
tableName
()
{
return
'tbl_validator_
exist_
main'
;
return
'tbl_validator_main'
;
}
public
function
getReferences
()
{
return
$this
->
hasMany
(
ExistValidator
RefModel
::
className
(),
array
(
'ref'
=>
'id'
));
return
$this
->
hasMany
(
ValidatorTest
RefModel
::
className
(),
array
(
'ref'
=>
'id'
));
}
}
\ No newline at end of file
tests/unit/data/validators/models/
ExistValidator
RefModel.php
→
tests/unit/data/validators/models/
ValidatorTest
RefModel.php
View file @
24e2f885
...
...
@@ -5,18 +5,19 @@ namespace yiiunit\data\validators\models;
use
yii\db\ActiveRecord
;
class
ExistValidator
RefModel
extends
ActiveRecord
class
ValidatorTest
RefModel
extends
ActiveRecord
{
public
$test_val
=
2
;
public
$test_val_fail
=
99
;
public
static
function
tableName
()
{
return
'tbl_validator_
exist_
ref'
;
return
'tbl_validator_ref'
;
}
public
function
getMain
()
{
return
$this
->
hasOne
(
ExistValidator
MainModel
::
className
(),
array
(
'id'
=>
'ref'
));
return
$this
->
hasOne
(
ValidatorTest
MainModel
::
className
(),
array
(
'id'
=>
'ref'
));
}
}
\ No newline at end of file
tests/unit/framework/validators/CompareValidatorTest.php
View file @
24e2f885
...
...
@@ -77,6 +77,11 @@ class CompareValidatorTest extends TestCase
array
(
$value
+
1
,
false
),
array
(
$value
-
1
,
true
),
),
//'non-op' => array(
// array($value, false),
// array($value + 1, false),
// array($value - 1, false),
//),
);
}
...
...
tests/unit/framework/validators/ExistValidatorTest.php
View file @
24e2f885
...
...
@@ -7,8 +7,8 @@ use Yii;
use
yii\base\Exception
;
use
yii\validators\ExistValidator
;
use
yiiunit\data\ar\ActiveRecord
;
use
yiiunit\data\validators\models\
ExistValidator
MainModel
;
use
yiiunit\data\validators\models\
ExistValidator
RefModel
;
use
yiiunit\data\validators\models\
ValidatorTest
MainModel
;
use
yiiunit\data\validators\models\
ValidatorTest
RefModel
;
use
yiiunit\framework\db\DatabaseTestCase
;
class
ExistValidatorTest
extends
DatabaseTestCase
...
...
@@ -39,7 +39,7 @@ class ExistValidatorTest extends DatabaseTestCase
}
// combine to save the time creating a new db-fixture set (likely ~5 sec)
try
{
$val
=
new
ExistValidator
(
array
(
'className'
=>
ExistValidator
MainModel
::
className
()));
$val
=
new
ExistValidator
(
array
(
'className'
=>
ValidatorTest
MainModel
::
className
()));
$val
->
validateValue
(
'ref'
);
$this
->
fail
(
'Exception should have been thrown at this time'
);
}
catch
(
Exception
$e
)
{
...
...
@@ -50,7 +50,7 @@ class ExistValidatorTest extends DatabaseTestCase
public
function
testValidateValue
()
{
$val
=
new
ExistValidator
(
array
(
'className'
=>
ExistValidator
RefModel
::
className
(),
'attributeName'
=>
'id'
));
$val
=
new
ExistValidator
(
array
(
'className'
=>
ValidatorTest
RefModel
::
className
(),
'attributeName'
=>
'id'
));
$this
->
assertTrue
(
$val
->
validateValue
(
2
));
$this
->
assertTrue
(
$val
->
validateValue
(
5
));
$this
->
assertFalse
(
$val
->
validateValue
(
99
));
...
...
@@ -60,39 +60,39 @@ class ExistValidatorTest extends DatabaseTestCase
public
function
testValidateAttribute
()
{
// existing value on different table
$val
=
new
ExistValidator
(
array
(
'className'
=>
ExistValidator
MainModel
::
className
(),
'attributeName'
=>
'id'
));
$m
=
ExistValidator
RefModel
::
find
(
array
(
'id'
=>
1
));
$val
=
new
ExistValidator
(
array
(
'className'
=>
ValidatorTest
MainModel
::
className
(),
'attributeName'
=>
'id'
));
$m
=
ValidatorTest
RefModel
::
find
(
array
(
'id'
=>
1
));
$val
->
validateAttribute
(
$m
,
'ref'
);
$this
->
assertFalse
(
$m
->
hasErrors
());
// non-existing value on different table
$val
=
new
ExistValidator
(
array
(
'className'
=>
ExistValidator
MainModel
::
className
(),
'attributeName'
=>
'id'
));
$m
=
ExistValidator
RefModel
::
find
(
array
(
'id'
=>
6
));
$val
=
new
ExistValidator
(
array
(
'className'
=>
ValidatorTest
MainModel
::
className
(),
'attributeName'
=>
'id'
));
$m
=
ValidatorTest
RefModel
::
find
(
array
(
'id'
=>
6
));
$val
->
validateAttribute
(
$m
,
'ref'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'ref'
));
// existing value on same table
$val
=
new
ExistValidator
(
array
(
'attributeName'
=>
'ref'
));
$m
=
ExistValidator
RefModel
::
find
(
array
(
'id'
=>
2
));
$m
=
ValidatorTest
RefModel
::
find
(
array
(
'id'
=>
2
));
$val
->
validateAttribute
(
$m
,
'test_val'
);
$this
->
assertFalse
(
$m
->
hasErrors
());
// non-existing value on same table
$val
=
new
ExistValidator
(
array
(
'attributeName'
=>
'ref'
));
$m
=
ExistValidator
RefModel
::
find
(
array
(
'id'
=>
5
));
$m
=
ValidatorTest
RefModel
::
find
(
array
(
'id'
=>
5
));
$val
->
validateAttribute
(
$m
,
'test_val_fail'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'test_val_fail'
));
// check for given value (true)
$val
=
new
ExistValidator
();
$m
=
ExistValidator
RefModel
::
find
(
array
(
'id'
=>
3
));
$m
=
ValidatorTest
RefModel
::
find
(
array
(
'id'
=>
3
));
$val
->
validateAttribute
(
$m
,
'ref'
);
$this
->
assertFalse
(
$m
->
hasErrors
());
// check for given defaults (false)
$val
=
new
ExistValidator
();
$m
=
ExistValidator
RefModel
::
find
(
array
(
'id'
=>
4
));
$m
=
ValidatorTest
RefModel
::
find
(
array
(
'id'
=>
4
));
$m
->
a_field
=
'some new value'
;
$val
->
validateAttribute
(
$m
,
'a_field'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'a_field'
));
// check array
$val
=
new
ExistValidator
(
array
(
'attributeName'
=>
'ref'
));
$m
=
ExistValidator
RefModel
::
find
(
array
(
'id'
=>
2
));
$m
=
ValidatorTest
RefModel
::
find
(
array
(
'id'
=>
2
));
$m
->
test_val
=
array
(
1
,
2
,
3
);
$val
->
validateAttribute
(
$m
,
'test_val'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'test_val'
));
...
...
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