1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway; |
4
|
|
|
|
5
|
|
|
class ValidatorTest extends \PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
View Code Duplication |
public function testCheckCartItemName() |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
Validator::checkCartItemName('foo name'); |
11
|
|
|
|
12
|
|
|
try { |
13
|
|
|
Validator::checkCartItemName('very long long long cart item name'); |
14
|
|
|
$this->fail(); |
15
|
|
|
|
16
|
|
|
} catch (\InvalidArgumentException $e) { |
17
|
|
|
$this->assertSame('Cart item name can have maximum of 20 characters.', $e->getMessage()); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
try { |
21
|
|
|
Validator::checkCartItemName(' whitespace'); |
22
|
|
|
$this->fail(); |
23
|
|
|
|
24
|
|
|
} catch (\InvalidArgumentException $e) { |
25
|
|
|
$this->assertSame('Argument starts or ends with whitespace.', $e->getMessage()); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
View Code Duplication |
public function testCheckCartItemDescription() |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
Validator::checkCartItemDescription('foo description'); |
32
|
|
|
|
33
|
|
|
try { |
34
|
|
|
Validator::checkCartItemDescription('very long long long cart item description'); |
35
|
|
|
$this->fail(); |
36
|
|
|
|
37
|
|
|
} catch (\InvalidArgumentException $e) { |
38
|
|
|
$this->assertSame('Cart item description can have maximum of 40 characters.', $e->getMessage()); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
public function testCheckCartItemQuantity() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
Validator::checkCartItemQuantity(2); |
45
|
|
|
|
46
|
|
|
try { |
47
|
|
|
Validator::checkCartItemQuantity(0); |
48
|
|
|
$this->fail(); |
49
|
|
|
|
50
|
|
|
} catch (\InvalidArgumentException $e) { |
51
|
|
|
$this->assertSame('Quantity must be greater than 0. 0 given.', $e->getMessage()); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function testCheckOrderId() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
Validator::checkOrderId('123'); |
58
|
|
|
|
59
|
|
|
try { |
60
|
|
|
Validator::checkOrderId('123456789123456789'); |
61
|
|
|
$this->fail(); |
62
|
|
|
|
63
|
|
|
} catch (\InvalidArgumentException $e) { |
64
|
|
|
$this->assertSame('OrderId can have maximum of 10 characters.', $e->getMessage()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
try { |
68
|
|
|
Validator::checkOrderId('abc'); |
69
|
|
|
$this->fail(); |
70
|
|
|
|
71
|
|
|
} catch (\InvalidArgumentException $e) { |
72
|
|
|
$this->assertSame('OrderId must be numeric value. abc given.', $e->getMessage()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
View Code Duplication |
public function testCheckReturnUrl() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
Validator::checkReturnUrl('https://example.com'); |
79
|
|
|
|
80
|
|
|
try { |
81
|
|
|
Validator::checkReturnUrl('https://example.com/' . implode('-', array_fill(0, 100, 'long'))); |
82
|
|
|
$this->fail(); |
83
|
|
|
|
84
|
|
|
} catch (\InvalidArgumentException $e) { |
85
|
|
|
$this->assertSame('ReturnUrl can have maximum of 300 characters.', $e->getMessage()); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
View Code Duplication |
public function testDescription() |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
Validator::checkDescription('foo description'); |
92
|
|
|
|
93
|
|
|
try { |
94
|
|
|
Validator::checkDescription(implode(' ', array_fill(0, 60, 'very')) . ' long description'); |
95
|
|
|
$this->fail(); |
96
|
|
|
|
97
|
|
|
} catch (\InvalidArgumentException $e) { |
98
|
|
|
$this->assertSame('Description can have maximum of 255 characters.', $e->getMessage()); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
View Code Duplication |
public function testMerchantData() |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
Validator::checkMerchantData('foo merchant data'); |
105
|
|
|
|
106
|
|
|
try { |
107
|
|
|
Validator::checkMerchantData(implode(' ', array_fill(0, 60, 'very')) . ' long merchantData'); |
108
|
|
|
$this->fail(); |
109
|
|
|
|
110
|
|
|
} catch (\InvalidArgumentException $e) { |
111
|
|
|
$this->assertSame('MerchantData can have maximum of 255 characters in encoded state.', $e->getMessage()); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
View Code Duplication |
public function testCustomerId() |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
Validator::checkCustomerId('foo customerId'); |
118
|
|
|
|
119
|
|
|
try { |
120
|
|
|
Validator::checkCustomerId('very very very very very very very very long long long customerId'); |
121
|
|
|
$this->fail(); |
122
|
|
|
|
123
|
|
|
} catch (\InvalidArgumentException $e) { |
124
|
|
|
$this->assertSame('CustomerId can have maximum of 50 characters.', $e->getMessage()); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
View Code Duplication |
public function testPayId() |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
Validator::checkPayId('foo payId'); |
131
|
|
|
|
132
|
|
|
try { |
133
|
|
|
Validator::checkPayId('very long long payId'); |
134
|
|
|
$this->fail(); |
135
|
|
|
|
136
|
|
|
} catch (\InvalidArgumentException $e) { |
137
|
|
|
$this->assertSame('PayId can have maximum of 15 characters.', $e->getMessage()); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
View Code Duplication |
public function testTtlSec() |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
Validator::checkTtlSec(500); |
144
|
|
|
|
145
|
|
|
try { |
146
|
|
|
Validator::checkTtlSec(200); |
147
|
|
|
$this->fail(); |
148
|
|
|
|
149
|
|
|
} catch (\InvalidArgumentException $e) { |
150
|
|
|
$this->assertSame('TTL sec is out of range (300 - 1800). Current value is 200.', $e->getMessage()); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
try { |
154
|
|
|
Validator::checkTtlSec(3000); |
155
|
|
|
$this->fail(); |
156
|
|
|
|
157
|
|
|
} catch (\InvalidArgumentException $e) { |
158
|
|
|
$this->assertSame('TTL sec is out of range (300 - 1800). Current value is 3000.', $e->getMessage()); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
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.