1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiiviet/yii2-validator |
4
|
|
|
* @copyright Copyright (c) 2018 Yii Viet |
5
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yiiviet\tests\unit\validator; |
9
|
|
|
|
10
|
|
|
use yii\base\DynamicModel; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Lớp IdNumValidatorTest |
14
|
|
|
* |
15
|
|
|
* @author Vuong Minh <[email protected]> |
16
|
|
|
* @since 1.0 |
17
|
|
|
*/ |
18
|
|
|
class IdNumValidatorTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @dataProvider idNumValidProvider |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
public function testValidIdNum($idOld, $idNew, $cId) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$model = DynamicModel::validateData([ |
26
|
|
|
'idOld' => $idOld, |
27
|
|
|
'idNew' => $idNew, |
28
|
|
|
'cId' => $cId |
29
|
|
|
], [ |
30
|
|
|
[['idOld', 'idNew', 'cId'], 'idnumvn'] |
31
|
|
|
]); |
32
|
|
|
|
33
|
|
|
$this->assertFalse($model->hasErrors()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider idNumValidProvider |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function testValidIdNumExceptCID($idOld, $idNew, $cId) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$model = DynamicModel::validateData([ |
42
|
|
|
'idOld' => $idOld, |
43
|
|
|
'idNew' => $idNew, |
44
|
|
|
'cId' => $cId |
45
|
|
|
], [ |
46
|
|
|
[['idOld', 'idNew', 'cId'], 'idnumvn', 'onlyId' => true] |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$this->assertTrue($model->hasErrors()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @dataProvider idNumInvalidProvider |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function testInValidIdNum($idOld, $idNew, $cId) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$model = DynamicModel::validateData([ |
58
|
|
|
'idOld' => $idOld, |
59
|
|
|
'idNew' => $idNew, |
60
|
|
|
'cId' => $cId |
61
|
|
|
], [ |
62
|
|
|
[['idOld', 'idNew', 'cId'], 'idnumvn'] |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
$this->assertTrue($model->hasErrors()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function idNumValidProvider() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
['293422825', '001089000098', '405071000030'], |
72
|
|
|
['025478996', '036087000067', '526099003096'], |
73
|
|
|
['017351686', '016509820190', '722099000144'], |
74
|
|
|
['293422825', '079301000099', '836200003212'], |
75
|
|
|
['293422825', '2934228250', '961302004651'], |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function idNumInvalidProvider() |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
|
|
['79a7sd9a7', '331089000098a', '415071000030'], |
83
|
|
|
['987845687', '836087000067e', '506099003096'], |
84
|
|
|
['465879754', '216509820190f', '782099000144'], |
85
|
|
|
['39979800e', '079301000099e', '816200003212'], |
86
|
|
|
['554979964', '2934228250fe', '981302004651'], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.