|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hryvinskyi\QuoteAddressValidator\Test\Unit\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Hryvinskyi\QuoteAddressValidator\Model\Config; |
|
6
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
|
7
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
|
8
|
|
|
use Magento\Store\Model\ScopeInterface; |
|
9
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
|
|
|
|
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class ConfigTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Config |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $model; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var ScopeConfigInterface|MockObject |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $scopeConfigMock; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @inheritdoc |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function setUp(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) |
|
30
|
|
|
->setMethods(['getValue', 'isSetFlag']) |
|
31
|
|
|
->disableOriginalConstructor() |
|
32
|
|
|
->getMockForAbstractClass(); |
|
33
|
|
|
|
|
34
|
|
|
$objectManager = new ObjectManagerHelper($this); |
|
|
|
|
|
|
35
|
|
|
$this->model = $objectManager->getObject( |
|
36
|
|
|
Config::class, |
|
37
|
|
|
[ |
|
38
|
|
|
'scopeConfig' => $this->scopeConfigMock |
|
39
|
|
|
] |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Test isEnabled() |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
* @dataProvider isEnabledDataProvider |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testisEnabled($isSetFlag, $result): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
|
|
|
|
|
52
|
|
|
->method('isSetFlag') |
|
53
|
|
|
->with(Config::XML_CONF_ENABLED, ScopeInterface::SCOPE_STORE) |
|
54
|
|
|
->willReturn($isSetFlag); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertEquals($result, $this->model->isEnabled()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Data provider for isEnabled() |
|
61
|
|
|
* |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
|
|
public function isEnabledDataProvider(): array |
|
65
|
|
|
{ |
|
66
|
|
|
return [ |
|
67
|
|
|
[true, true], |
|
68
|
|
|
[false, false], |
|
69
|
|
|
[true, 1], |
|
70
|
|
|
[false, 0], |
|
71
|
|
|
[false, null], |
|
72
|
|
|
[false, ''] |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Test getValidationType() |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testGetValidationType(): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
84
|
|
|
->method('getValue') |
|
85
|
|
|
->with(Config::XML_CONF_VALIDATION_TYPE, ScopeInterface::SCOPE_STORE) |
|
86
|
|
|
->willReturn('1'); |
|
87
|
|
|
|
|
88
|
|
|
$this->assertEquals(1, $this->model->getValidationType()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Test isEnabledFirstname() |
|
93
|
|
|
* |
|
94
|
|
|
* @return void |
|
95
|
|
|
*/ |
|
96
|
|
|
public function testIsEnabledFirstname(): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
99
|
|
|
->method('isSetFlag') |
|
100
|
|
|
->with(Config::XML_CONF_ENABLED_FIRSTNAME, ScopeInterface::SCOPE_STORE) |
|
101
|
|
|
->willReturn(1); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertEquals(true, $this->model->isEnabledFirstname()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Test isEnabledLastname() |
|
108
|
|
|
* |
|
109
|
|
|
* @return void |
|
110
|
|
|
*/ |
|
111
|
|
|
public function testIsEnabledLastname(): void |
|
112
|
|
|
{ |
|
113
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
114
|
|
|
->method('isSetFlag') |
|
115
|
|
|
->with(Config::XML_CONF_ENABLED_LASTNAME, ScopeInterface::SCOPE_STORE) |
|
116
|
|
|
->willReturn(1); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertEquals(true, $this->model->isEnabledLastname()); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Test isEnabledStreet() |
|
123
|
|
|
* |
|
124
|
|
|
* @return void |
|
125
|
|
|
*/ |
|
126
|
|
|
public function testIsEnabledStreet(): void |
|
127
|
|
|
{ |
|
128
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
129
|
|
|
->method('isSetFlag') |
|
130
|
|
|
->with(Config::XML_CONF_ENABLED_STREET, ScopeInterface::SCOPE_STORE) |
|
131
|
|
|
->willReturn(1); |
|
132
|
|
|
|
|
133
|
|
|
$this->assertEquals(true, $this->model->isEnabledStreet()); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Test getFirstnameStopwords() |
|
138
|
|
|
* |
|
139
|
|
|
* @return void |
|
140
|
|
|
*/ |
|
141
|
|
|
public function testGetFirstnameStopwords(): void |
|
142
|
|
|
{ |
|
143
|
|
|
$stopwords = 'test,test,example,Example'; |
|
144
|
|
|
$expected = ['test', 'example', 'Example']; |
|
145
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
146
|
|
|
->method('getValue') |
|
147
|
|
|
->with(Config::XML_CONF_FIRSTNAME_STOPWORDS, ScopeInterface::SCOPE_STORE) |
|
148
|
|
|
->willReturn($stopwords); |
|
149
|
|
|
|
|
150
|
|
|
$this->assertEquals($expected, $this->model->getFirstnameStopwords()); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Test getLastnameStopwords() |
|
155
|
|
|
* |
|
156
|
|
|
* @return void |
|
157
|
|
|
*/ |
|
158
|
|
|
public function testGetLastnameStopwords(): void |
|
159
|
|
|
{ |
|
160
|
|
|
$stopwords = 'test,test, example, Example'; |
|
161
|
|
|
$expected = ['test', 'example', 'Example']; |
|
162
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
163
|
|
|
->method('getValue') |
|
164
|
|
|
->with(Config::XML_CONF_LASTNAME_STOPWORDS, ScopeInterface::SCOPE_STORE) |
|
165
|
|
|
->willReturn($stopwords); |
|
166
|
|
|
|
|
167
|
|
|
$this->assertEquals($expected, $this->model->getLastnameStopwords()); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Test getStreetStopwords() |
|
172
|
|
|
* |
|
173
|
|
|
* @return void |
|
174
|
|
|
*/ |
|
175
|
|
|
public function testGetStreetStopwords(): void |
|
176
|
|
|
{ |
|
177
|
|
|
$stopwords = 'test,test, example, Example'; |
|
178
|
|
|
$expected = ['test', 'example', 'Example']; |
|
179
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
180
|
|
|
->method('getValue') |
|
181
|
|
|
->with(Config::XML_CONF_STREET_STOPWORDS, ScopeInterface::SCOPE_STORE) |
|
182
|
|
|
->willReturn($stopwords); |
|
183
|
|
|
|
|
184
|
|
|
$this->assertEquals($expected, $this->model->getStreetStopwords()); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Test getFirstnameRegex() |
|
189
|
|
|
* |
|
190
|
|
|
* @return void |
|
191
|
|
|
*/ |
|
192
|
|
|
public function testGetFirstnameRegex(): void |
|
193
|
|
|
{ |
|
194
|
|
|
$regex = '/^[a-zA-Z]+$/'; |
|
195
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
196
|
|
|
->method('getValue') |
|
197
|
|
|
->with(Config::XML_CONF_FIRSTNAME_REGEX, ScopeInterface::SCOPE_STORE) |
|
198
|
|
|
->willReturn($regex); |
|
199
|
|
|
|
|
200
|
|
|
$this->assertEquals($regex, $this->model->getFirstnameRegex()); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Test getLastnameRegex() |
|
205
|
|
|
* |
|
206
|
|
|
* @return void |
|
207
|
|
|
*/ |
|
208
|
|
|
public function testGetLastnameRegex(): void |
|
209
|
|
|
{ |
|
210
|
|
|
$regex = '/^[a-zA-Z]+$/'; |
|
211
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
212
|
|
|
->method('getValue') |
|
213
|
|
|
->with(Config::XML_CONF_LASTNAME_REGEX, ScopeInterface::SCOPE_STORE) |
|
214
|
|
|
->willReturn($regex); |
|
215
|
|
|
|
|
216
|
|
|
$this->assertEquals($regex, $this->model->getLastnameRegex()); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Test getStreetRegex() |
|
221
|
|
|
* |
|
222
|
|
|
* @return void |
|
223
|
|
|
*/ |
|
224
|
|
|
public function testGetStreetRegex(): void |
|
225
|
|
|
{ |
|
226
|
|
|
$regex = '/^[a-zA-Z0-9\s]+$/'; |
|
227
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
228
|
|
|
->method('getValue') |
|
229
|
|
|
->with(Config::XML_CONF_STREET_REGEX, ScopeInterface::SCOPE_STORE) |
|
230
|
|
|
->willReturn($regex); |
|
231
|
|
|
|
|
232
|
|
|
$this->assertEquals($regex, $this->model->getStreetRegex()); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Test getFirstnameErrorMessage() |
|
237
|
|
|
* |
|
238
|
|
|
* @return void |
|
239
|
|
|
*/ |
|
240
|
|
|
public function testGetFirstnameErrorMessage(): void |
|
241
|
|
|
{ |
|
242
|
|
|
$errorMessage = 'Invalid firstname'; |
|
243
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
244
|
|
|
->method('getValue') |
|
245
|
|
|
->with(Config::XML_CONF_FIRSTNAME_ERROR_MESSAGE, ScopeInterface::SCOPE_STORE) |
|
246
|
|
|
->willReturn($errorMessage); |
|
247
|
|
|
|
|
248
|
|
|
$this->assertEquals($errorMessage, $this->model->getFirstnameErrorMessage()); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Test getLastnameErrorMessage() |
|
253
|
|
|
* |
|
254
|
|
|
* @return void |
|
255
|
|
|
*/ |
|
256
|
|
|
public function testGetLastnameErrorMessage(): void |
|
257
|
|
|
{ |
|
258
|
|
|
$errorMessage = 'Invalid lastname'; |
|
259
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
260
|
|
|
->method('getValue') |
|
261
|
|
|
->with(Config::XML_CONF_LASTNAME_ERROR_MESSAGE, ScopeInterface::SCOPE_STORE) |
|
262
|
|
|
->willReturn($errorMessage); |
|
263
|
|
|
|
|
264
|
|
|
$this->assertEquals($errorMessage, $this->model->getLastnameErrorMessage()); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* Test getStreetErrorMessage() |
|
269
|
|
|
* |
|
270
|
|
|
* @return void |
|
271
|
|
|
*/ |
|
272
|
|
|
public function testGetStreetErrorMessage(): void |
|
273
|
|
|
{ |
|
274
|
|
|
$errorMessage = 'Invalid street'; |
|
275
|
|
|
$this->scopeConfigMock->expects($this->once()) |
|
276
|
|
|
->method('getValue') |
|
277
|
|
|
->with(Config::XML_CONF_STREET_ERROR_MESSAGE, ScopeInterface::SCOPE_STORE) |
|
278
|
|
|
->willReturn($errorMessage); |
|
279
|
|
|
|
|
280
|
|
|
$this->assertEquals($errorMessage, $this->model->getStreetErrorMessage()); |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths