1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MinMaxLengthValidationTest |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\SchemaBundle\Tests\ConstraintBuilder; |
7
|
|
|
|
8
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
13
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
14
|
|
|
* @link http://swisscom.ch |
15
|
|
|
*/ |
16
|
|
|
class MinMaxLengthValidationTest extends RestTestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* see if handling is ok when we send all correct |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function testMinMaxHandling() |
25
|
|
|
{ |
26
|
|
|
$entity = [ |
27
|
|
|
'minMaxField' => '123456', |
28
|
|
|
'maxRequiredField' => '12', |
29
|
|
|
'minLength' => '12' |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
$client = static::createRestClient(); |
33
|
|
|
$client->post('/testcase/minmaxlength/', (object) $entity); |
34
|
|
|
|
35
|
|
|
$this->assertEmpty($client->getResults()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* test lower bound limits of lengths |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function testMinMaxHandlingLower() |
44
|
|
|
{ |
45
|
|
|
$entity = [ |
46
|
|
|
'minMaxField' => 'aaaa', |
47
|
|
|
'maxRequiredField' => '', |
48
|
|
|
'minLength' => '' |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$client = static::createRestClient(); |
52
|
|
|
$client->post('/testcase/minmaxlength/', (object) $entity); |
53
|
|
|
|
54
|
|
|
$this->assertEquals( |
55
|
|
|
[ |
56
|
|
|
(object) [ |
57
|
|
|
'propertyPath' => 'minMaxField', |
58
|
|
|
'message' => 'Must be at least 5 characters long', |
59
|
|
|
], |
60
|
|
|
(object) [ |
61
|
|
|
'propertyPath' => 'maxRequiredField', |
62
|
|
|
'message' => 'Must be at least 1 characters long', |
63
|
|
|
], |
64
|
|
|
(object) [ |
65
|
|
|
'propertyPath' => 'minLength', |
66
|
|
|
'message' => 'Must be at least 1 characters long', |
67
|
|
|
] |
68
|
|
|
], |
69
|
|
|
$client->getResults() |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* test upper bound limits of lengths |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function testMinMaxHandlingUpper() |
79
|
|
|
{ |
80
|
|
|
$entity = [ |
81
|
|
|
'minMaxField' => '12345678900', |
82
|
|
|
'maxRequiredField' => '123', |
83
|
|
|
'minLength' => '12' |
84
|
|
|
]; |
85
|
|
|
|
86
|
|
|
$client = static::createRestClient(); |
87
|
|
|
$client->post('/testcase/minmaxlength/', (object) $entity); |
88
|
|
|
|
89
|
|
|
$this->assertEquals( |
90
|
|
|
[ |
91
|
|
|
(object) [ |
92
|
|
|
'propertyPath' => 'minMaxField', |
93
|
|
|
'message' => 'Must be at most 10 characters long', |
94
|
|
|
], |
95
|
|
|
(object) [ |
96
|
|
|
'propertyPath' => 'maxRequiredField', |
97
|
|
|
'message' => 'Must be at most 2 characters long', |
98
|
|
|
] |
99
|
|
|
], |
100
|
|
|
$client->getResults() |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|