-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSdkConfigBuilderTest.php
More file actions
481 lines (430 loc) · 17.7 KB
/
SdkConfigBuilderTest.php
File metadata and controls
481 lines (430 loc) · 17.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<?php
namespace Yoti\Test\DocScan\Session\Create;
use Yoti\DocScan\Constants;
use Yoti\DocScan\Exception\DocScanException;
use Yoti\DocScan\Session\Create\SdkConfigBuilder;
use Yoti\Test\TestCase;
/**
* @coversDefaultClass \Yoti\DocScan\Session\Create\SdkConfigBuilder
*/
class SdkConfigBuilderTest extends TestCase
{
private const SOME_CAPTURE_METHOD = 'someCaptureMethod';
private const SOME_PRIMARY_COLOUR = 'somePrimaryColour';
private const SOME_SECONDARY_COLOUR = 'someSecondaryColour';
private const SOME_FONT_COLOUR = 'someFontColour';
private const SOME_LOCALE = 'someLocale';
private const SOME_PRESET_ISSUING_COUNTRY = 'somePresetIssuingCountry';
private const SOME_SUCCESS_URL = 'someSuccessUrl';
private const SOME_ERROR_URL = 'someErrorUrl';
private const SOME_PRIVACY_POLICY_URL = 'somePrivacyPolicyUrl';
private const SOME_CATEGORY = 'someCategory';
private const SOME_NUMBER_RETRIES = 5;
private const SOME_BIOMETRIC_CONSENT_FLOW = 'someBiometricConsentFlow';
private const SOME_DARK_MODE = 'someDarkMode';
private const SOME_PRIMARY_COLOUR_DARK_MODE = 'somePrimaryColourDarkMode';
private const SOME_BRAND_ID = 'someBrandId';
/**
* @test
* @covers ::build
* @covers ::withAllowedCaptureMethod
* @covers ::withPrimaryColour
* @covers ::withSecondaryColour
* @covers ::withFontColour
* @covers ::withLocale
* @covers ::withPresetIssuingCountry
* @covers ::withSuccessUrl
* @covers ::withErrorUrl
* @covers ::withPrivacyPolicyUrl
* @covers ::withAllowHandoff
* @covers ::withBrandId
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAllowedCaptureMethods
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getPrimaryColour
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getSecondaryColour
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getFontColour
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getLocale
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getPresetIssuingCountry
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getSuccessUrl
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getErrorUrl
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getPrivacyPolicyUrl
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAllowHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getDarkMode
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getPrimaryColourDarkMode
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getBrandId
*/
public function shouldCorrectlyBuildSdkConfig()
{
$result = (new SdkConfigBuilder())
->withAllowedCaptureMethod(self::SOME_CAPTURE_METHOD)
->withPrimaryColour(self::SOME_PRIMARY_COLOUR)
->withSecondaryColour(self::SOME_SECONDARY_COLOUR)
->withFontColour(self::SOME_FONT_COLOUR)
->withLocale(self::SOME_LOCALE)
->withPresetIssuingCountry(self::SOME_PRESET_ISSUING_COUNTRY)
->withSuccessUrl(self::SOME_SUCCESS_URL)
->withErrorUrl(self::SOME_ERROR_URL)
->withPrivacyPolicyUrl(self::SOME_PRIVACY_POLICY_URL)
->withAllowHandoff(true)
->withBiometricConsentFlow(self::SOME_BIOMETRIC_CONSENT_FLOW)
->withDarkMode(self::SOME_DARK_MODE)
->withPrimaryColourDarkMode(self::SOME_PRIMARY_COLOUR_DARK_MODE)
->withBrandId(self::SOME_BRAND_ID)
->build();
$this->assertEquals(self::SOME_CAPTURE_METHOD, $result->getAllowedCaptureMethods());
$this->assertEquals(self::SOME_PRIMARY_COLOUR, $result->getPrimaryColour());
$this->assertEquals(self::SOME_SECONDARY_COLOUR, $result->getSecondaryColour());
$this->assertEquals(self::SOME_FONT_COLOUR, $result->getFontColour());
$this->assertEquals(self::SOME_LOCALE, $result->getLocale());
$this->assertEquals(self::SOME_PRESET_ISSUING_COUNTRY, $result->getPresetIssuingCountry());
$this->assertEquals(self::SOME_SUCCESS_URL, $result->getSuccessUrl());
$this->assertEquals(self::SOME_ERROR_URL, $result->getErrorUrl());
$this->assertEquals(self::SOME_PRIVACY_POLICY_URL, $result->getPrivacyPolicyUrl());
$this->assertEquals(self::SOME_BIOMETRIC_CONSENT_FLOW, $result->getBiometricConsentFlow());
$this->assertTrue($result->getAllowHandoff());
$this->assertEquals(self::SOME_DARK_MODE, $result->getDarkMode());
$this->assertEquals(self::SOME_PRIMARY_COLOUR_DARK_MODE, $result->getPrimaryColourDarkMode());
$this->assertEquals(self::SOME_BRAND_ID, $result->getBrandId());
}
/**
* @test
* @covers ::withAllowsCamera
*/
public function shouldSetCorrectValueWithAllowsCamera()
{
$result = (new SdkConfigBuilder())
->withAllowsCamera()
->build();
$this->assertEquals('CAMERA', $result->getAllowedCaptureMethods());
}
/**
* @test
* @covers ::withAllowsCameraAndUpload
*/
public function shouldSetCorrectValuesWithAllowsCameraAndUpload()
{
$result = (new SdkConfigBuilder())
->withAllowsCameraAndUpload()
->build();
$this->assertEquals('CAMERA_AND_UPLOAD', $result->getAllowedCaptureMethods());
}
/**
* @test
* @covers \Yoti\DocScan\Session\Create\SdkConfig::jsonSerialize
*/
public function shouldProduceTheCorrectJsonString()
{
$result = (new SdkConfigBuilder())
->withAllowedCaptureMethod(self::SOME_CAPTURE_METHOD)
->withPrimaryColour(self::SOME_PRIMARY_COLOUR)
->withSecondaryColour(self::SOME_SECONDARY_COLOUR)
->withFontColour(self::SOME_FONT_COLOUR)
->withLocale(self::SOME_LOCALE)
->withPresetIssuingCountry(self::SOME_PRESET_ISSUING_COUNTRY)
->withSuccessUrl(self::SOME_SUCCESS_URL)
->withErrorUrl(self::SOME_ERROR_URL)
->withPrivacyPolicyUrl(self::SOME_PRIVACY_POLICY_URL)
->withAllowHandoff(true)
->withBiometricConsentFlow(self::SOME_BIOMETRIC_CONSENT_FLOW)
->withPrimaryColourDarkMode(self::SOME_PRIMARY_COLOUR_DARK_MODE)
->withDarkMode(self::SOME_DARK_MODE)
->build();
$expected = [
'allowed_capture_methods' => self::SOME_CAPTURE_METHOD,
'primary_colour' => self::SOME_PRIMARY_COLOUR,
'secondary_colour' => self::SOME_SECONDARY_COLOUR,
'font_colour' => self::SOME_FONT_COLOUR,
'locale' => self::SOME_LOCALE,
'preset_issuing_country' => self::SOME_PRESET_ISSUING_COUNTRY,
'success_url' => self::SOME_SUCCESS_URL,
'error_url' => self::SOME_ERROR_URL,
'privacy_policy_url' => self::SOME_PRIVACY_POLICY_URL,
'allow_handoff' => true,
'biometric_consent_flow' => self::SOME_BIOMETRIC_CONSENT_FLOW,
'dark_mode' => self::SOME_DARK_MODE,
'primary_colour_dark_mode' => self::SOME_PRIMARY_COLOUR_DARK_MODE
];
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($result));
}
/**
* @test
* @covers \Yoti\DocScan\Session\Create\SdkConfig::jsonSerialize
*/
public function shouldSerializeToEmptyObjectWithNoValuesSet()
{
$result = (new SdkConfigBuilder())->build();
$this->assertJsonStringEqualsJsonString('{}', json_encode($result));
}
/**
* @test
* @covers \Yoti\DocScan\Session\Create\SdkConfigBuilder::build
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAllowHandoff
*/
public function allowHandoffShouldBeNullWhenItIsNotSet()
{
$result = (new SdkConfigBuilder())
->withAllowedCaptureMethod(self::SOME_CAPTURE_METHOD)
->withPrimaryColour(self::SOME_PRIMARY_COLOUR)
->withSecondaryColour(self::SOME_SECONDARY_COLOUR)
->withFontColour(self::SOME_FONT_COLOUR)
->withLocale(self::SOME_LOCALE)
->withPresetIssuingCountry(self::SOME_PRESET_ISSUING_COUNTRY)
->build();
$this->assertNull($result->getAllowHandoff());
}
/**
* @test
* @covers ::build
* @covers ::withIdDocumentTextExtractionCategoryRetries
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAttemptsConfiguration
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::__construct
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::getIdDocumentTextDataExtraction
*/
public function shouldBuildWithIdDocumentTextExtractionCategoryRetries(): void
{
$data = [
self::SOME_CATEGORY => self::SOME_NUMBER_RETRIES
];
$sdkConfig = (new SdkConfigBuilder())
->withIdDocumentTextExtractionCategoryRetries(self::SOME_CATEGORY, self::SOME_NUMBER_RETRIES)
->build();
$this->assertEquals($data, $sdkConfig->getAttemptsConfiguration()->getIdDocumentTextDataExtraction());
}
/**
* @test
* @covers ::build
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAttemptsConfiguration
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
*/
public function attemptsConfigurationShouldBeNullIfNotSet(): void
{
$sdkConfig = (new SdkConfigBuilder())
->build();
$this->assertNull($sdkConfig->getAttemptsConfiguration());
}
/**
* @test
* @covers ::build
* @covers ::withIdDocumentTextExtractionCategoryRetries
* @covers ::withIdDocumentTextExtractionReclassificationRetries
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAttemptsConfiguration
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::__construct
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::getIdDocumentTextDataExtraction
*/
public function attemptsConfigurationShouldResetSameValueWithRepeatedCalls(): void
{
$data = [
Constants::RECLASSIFICATION => 4
];
$sdkConfig = (new SdkConfigBuilder())
->withIdDocumentTextExtractionReclassificationRetries(2)
->withIdDocumentTextExtractionReclassificationRetries(3)
->withIdDocumentTextExtractionReclassificationRetries(4)
->build();
$this->assertCount(1, $sdkConfig->getAttemptsConfiguration()->getIdDocumentTextDataExtraction());
$this->assertEquals($data, $sdkConfig->getAttemptsConfiguration()->getIdDocumentTextDataExtraction());
$this->assertArrayHasKey(
Constants::ID_DOCUMENT_TEXT_DATA_EXTRACTION,
(array)$sdkConfig->getAttemptsConfiguration()
);
}
/**
* @test
* @covers ::build
* @covers ::withIdDocumentTextExtractionCategoryRetries
* @covers ::withIdDocumentTextExtractionReclassificationRetries
* @covers ::withIdDocumentTextExtractionGenericAttempts
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAttemptsConfiguration
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::__construct
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::getIdDocumentTextDataExtraction
*/
public function attemptsConfigurationShouldAllowMultipleCategories(): void
{
$numberOfGenericRetries = 3;
$numberOfReclassificationRetries = 1;
$sdkConfig = (new SdkConfigBuilder())
->withIdDocumentTextExtractionReclassificationRetries($numberOfReclassificationRetries)
->withIdDocumentTextExtractionGenericAttempts($numberOfGenericRetries)
->withIdDocumentTextExtractionCategoryRetries(self::SOME_CATEGORY, self::SOME_NUMBER_RETRIES)
->build();
$this->assertCount(3, $sdkConfig->getAttemptsConfiguration()->getIdDocumentTextDataExtraction());
$this->assertArrayHasKey(
Constants::RECLASSIFICATION,
$sdkConfig->getAttemptsConfiguration()
->getIdDocumentTextDataExtraction()
);
$this->assertArrayHasKey(
Constants::GENERIC,
$sdkConfig->getAttemptsConfiguration()
->getIdDocumentTextDataExtraction()
);
$this->assertArrayHasKey(
self::SOME_CATEGORY,
$sdkConfig->getAttemptsConfiguration()
->getIdDocumentTextDataExtraction()
);
$this->assertContains(
$numberOfGenericRetries,
$sdkConfig->getAttemptsConfiguration()
->getIdDocumentTextDataExtraction()
);
$this->assertContains(
$numberOfReclassificationRetries,
$sdkConfig->getAttemptsConfiguration()
->getIdDocumentTextDataExtraction()
);
$this->assertContains(
self::SOME_NUMBER_RETRIES,
$sdkConfig->getAttemptsConfiguration()
->getIdDocumentTextDataExtraction()
);
}
/**
* @test
* @covers ::withDarkModeAuto
*/
public function shouldSetCorrectValueWithDarkModeAuto()
{
$result = (new SdkConfigBuilder())
->withDarkModeAuto()
->build();
$this->assertEquals('AUTO', $result->getDarkMode());
}
/**
* @test
* @covers ::withDarkModeOn
*/
public function shouldSetCorrectValueWithDarkModeOn()
{
$result = (new SdkConfigBuilder())
->withDarkModeOn()
->build();
$this->assertEquals('ON', $result->getDarkMode());
}
/**
* @test
* @covers ::withDarkModeOff
*/
public function shouldSetCorrectValueWithDarkModeOff()
{
$result = (new SdkConfigBuilder())
->withDarkModeOff()
->build();
$this->assertEquals('OFF', $result->getDarkMode());
}
/**
* @test
* @covers ::withEnforceHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getEnforceHandoff
*/
public function shouldSetEnforceHandoffToTrue()
{
$result = (new SdkConfigBuilder())
->withEnforceHandoff(true)
->build();
$this->assertTrue($result->getEnforceHandoff());
}
/**
* @test
* @covers ::withEnforceHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getEnforceHandoff
*/
public function shouldSetEnforceHandoffToFalse()
{
$result = (new SdkConfigBuilder())
->withEnforceHandoff(false)
->build();
$this->assertFalse($result->getEnforceHandoff());
}
/**
* @test
* @covers \Yoti\DocScan\Session\Create\SdkConfigBuilder::build
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getEnforceHandoff
*/
public function enforceHandoffShouldBeNullWhenItIsNotSet()
{
$result = (new SdkConfigBuilder())
->withAllowedCaptureMethod(self::SOME_CAPTURE_METHOD)
->build();
$this->assertNull($result->getEnforceHandoff());
}
/**
* @test
* @covers ::withEnforceHandoff
* @covers ::withAllowHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getEnforceHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAllowHandoff
*/
public function shouldSetBothEnforceHandoffAndAllowHandoffToTrue()
{
$result = (new SdkConfigBuilder())
->withAllowHandoff(true)
->withEnforceHandoff(true)
->build();
$this->assertTrue($result->getAllowHandoff());
$this->assertTrue($result->getEnforceHandoff());
}
/**
* @test
* @covers ::withEnforceHandoff
* @covers ::withAllowHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
*/
public function shouldThrowExceptionWhenEnforceHandoffTrueAndAllowHandoffFalse()
{
$this->expectException(DocScanException::class);
$this->expectExceptionMessage('enforce_handoff cannot be set to true when allow_handoff is false');
(new SdkConfigBuilder())
->withAllowHandoff(false)
->withEnforceHandoff(true)
->build();
}
/**
* @test
* @covers ::withEnforceHandoff
* @covers ::withAllowHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getEnforceHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAllowHandoff
*/
public function shouldAllowEnforceHandoffFalseWhenAllowHandoffFalse()
{
$result = (new SdkConfigBuilder())
->withAllowHandoff(false)
->withEnforceHandoff(false)
->build();
$this->assertFalse($result->getAllowHandoff());
$this->assertFalse($result->getEnforceHandoff());
}
/**
* @test
* @covers ::withEnforceHandoff
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getEnforceHandoff
*/
public function shouldAllowEnforceHandoffTrueWhenAllowHandoffIsNull()
{
$result = (new SdkConfigBuilder())
->withEnforceHandoff(true)
->build();
$this->assertNull($result->getAllowHandoff());
$this->assertTrue($result->getEnforceHandoff());
}
/**
* @test
* @covers \Yoti\DocScan\Session\Create\SdkConfig::jsonSerialize
*/
public function shouldIncludeEnforceHandoffInJsonSerialization()
{
$result = (new SdkConfigBuilder())
->withAllowHandoff(true)
->withEnforceHandoff(true)
->build();
$expected = [
'allow_handoff' => true,
'enforce_handoff' => true
];
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($result));
}
}