Skip to content

Commit 17b6021

Browse files
authored
SDK-2185 Support for expired documents at session creation (#303)
1 parent 7dd8a43 commit 17b6021

File tree

6 files changed

+272
-7
lines changed

6 files changed

+272
-7
lines changed

src/DocScan/Session/Create/Filters/Document/DocumentRestrictionsFilter.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@ class DocumentRestrictionsFilter extends DocumentFilter implements \JsonSerializ
2525
*/
2626
private $allowNonLatinDocuments;
2727

28+
/**
29+
* @var bool|null
30+
*/
31+
private $allowExpiredDocuments;
32+
2833
/**
2934
* @param string $inclusion
30-
* @param DocumentRestriction[] $documents
35+
* @param array $documents
3136
* @param bool|null $allowNonLatinDocuments
37+
* @param bool|null $allowExpiredDocuments
3238
*/
33-
public function __construct(string $inclusion, array $documents, ?bool $allowNonLatinDocuments)
34-
{
39+
public function __construct(
40+
string $inclusion,
41+
array $documents,
42+
?bool $allowNonLatinDocuments,
43+
?bool $allowExpiredDocuments
44+
) {
3545
parent::__construct(Constants::DOCUMENT_RESTRICTIONS);
3646

3747
Validation::notEmptyString($inclusion, 'inclusion');
@@ -41,6 +51,7 @@ public function __construct(string $inclusion, array $documents, ?bool $allowNon
4151
Validation::isArrayOfType($documents, [DocumentRestriction::class], 'documents');
4252
$this->documents = $documents;
4353
$this->allowNonLatinDocuments = $allowNonLatinDocuments;
54+
$this->allowExpiredDocuments = $allowExpiredDocuments;
4455
}
4556

4657
/**
@@ -56,6 +67,10 @@ public function jsonSerialize(): \stdClass
5667
$jsonData->allow_non_latin_documents = $this->allowNonLatinDocuments;
5768
}
5869

70+
if (isset($this->allowExpiredDocuments)) {
71+
$jsonData->allow_expired_documents = $this->allowExpiredDocuments;
72+
}
73+
5974
return $jsonData;
6075
}
6176

@@ -66,4 +81,12 @@ public function isAllowNonLatinDocuments(): ?bool
6681
{
6782
return $this->allowNonLatinDocuments;
6883
}
84+
85+
/**
86+
* @return bool|null
87+
*/
88+
public function isAllowExpiredDocuments(): ?bool
89+
{
90+
return $this->allowExpiredDocuments;
91+
}
6992
}

src/DocScan/Session/Create/Filters/Document/DocumentRestrictionsFilterBuilder.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class DocumentRestrictionsFilterBuilder
2525
*/
2626
private $allowNonLatinDocuments;
2727

28+
/**
29+
* @var bool|null
30+
*/
31+
private $allowExpiredDocuments;
32+
2833
/**
2934
* @return $this
3035
*/
@@ -63,6 +68,24 @@ public function withAllowNonLatinDocuments(): self
6368
return $this;
6469
}
6570

71+
/**
72+
* @return $this
73+
*/
74+
public function withAllowExpiredDocuments(): self
75+
{
76+
$this->allowExpiredDocuments = true;
77+
return $this;
78+
}
79+
80+
/**
81+
* @return $this
82+
*/
83+
public function withDenyExpiredDocuments(): self
84+
{
85+
$this->allowExpiredDocuments = false;
86+
return $this;
87+
}
88+
6689
/**
6790
* @return DocumentRestrictionsFilter
6891
*/
@@ -72,7 +95,8 @@ public function build(): DocumentFilter
7295
return new DocumentRestrictionsFilter(
7396
$this->inclusion,
7497
$this->documents,
75-
$this->allowNonLatinDocuments
98+
$this->allowNonLatinDocuments,
99+
$this->allowExpiredDocuments
76100
);
77101
}
78102
}

src/DocScan/Session/Create/Filters/Orthogonal/OrthogonalRestrictionsFilter.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,28 @@ class OrthogonalRestrictionsFilter extends DocumentFilter
2424
*/
2525
private $allowNonLatinDocuments;
2626

27+
/**
28+
* @var bool|null
29+
*/
30+
private $allowExpiredDocuments;
31+
2732
/**
2833
* @param CountryRestriction|null $countryRestriction
2934
* @param TypeRestriction|null $typeRestriction
3035
* @param bool|null $allowNonLatinDocuments
36+
* @param bool|null $allowExpiredDocuments
3137
*/
3238
public function __construct(
3339
?CountryRestriction $countryRestriction,
3440
?TypeRestriction $typeRestriction,
35-
?bool $allowNonLatinDocuments
41+
?bool $allowNonLatinDocuments,
42+
?bool $allowExpiredDocuments
3643
) {
3744
parent::__construct(Constants::ORTHOGONAL_RESTRICTIONS);
38-
3945
$this->countryRestriction = $countryRestriction;
4046
$this->typeRestriction = $typeRestriction;
4147
$this->allowNonLatinDocuments = $allowNonLatinDocuments;
48+
$this->allowExpiredDocuments = $allowExpiredDocuments;
4249
}
4350

4451
/**
@@ -60,6 +67,10 @@ public function jsonSerialize(): \stdClass
6067
$jsonData->allow_non_latin_documents = $this->allowNonLatinDocuments;
6168
}
6269

70+
if (isset($this->allowExpiredDocuments)) {
71+
$jsonData->allow_expired_documents = $this->allowExpiredDocuments;
72+
}
73+
6374
return $jsonData;
6475
}
6576

@@ -70,4 +81,12 @@ public function isAllowNonLatinDocuments(): ?bool
7081
{
7182
return $this->allowNonLatinDocuments;
7283
}
84+
85+
/**
86+
* @return bool|null
87+
*/
88+
public function isAllowExpiredDocuments(): ?bool
89+
{
90+
return $this->allowExpiredDocuments;
91+
}
7392
}

src/DocScan/Session/Create/Filters/Orthogonal/OrthogonalRestrictionsFilterBuilder.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class OrthogonalRestrictionsFilterBuilder
2424
*/
2525
private $allowNonLatinDocuments;
2626

27+
/**
28+
* @var bool|null
29+
*/
30+
private $allowExpiredDocuments;
31+
2732
/**
2833
* @param string[] $countryCodes
2934
*
@@ -90,6 +95,24 @@ public function withAllowNonLatinDocuments(): OrthogonalRestrictionsFilterBuilde
9095
return $this;
9196
}
9297

98+
/**
99+
* @return $this
100+
*/
101+
public function withAllowExpiredDocuments(): OrthogonalRestrictionsFilterBuilder
102+
{
103+
$this->allowExpiredDocuments = true;
104+
return $this;
105+
}
106+
107+
/**
108+
* @return $this
109+
*/
110+
public function withDenyExpiredDocuments(): OrthogonalRestrictionsFilterBuilder
111+
{
112+
$this->allowExpiredDocuments = false;
113+
return $this;
114+
}
115+
93116
/**
94117
* @return OrthogonalRestrictionsFilter
95118
*/
@@ -98,7 +121,8 @@ public function build(): DocumentFilter
98121
return new OrthogonalRestrictionsFilter(
99122
$this->countryRestriction,
100123
$this->typeRestriction,
101-
$this->allowNonLatinDocuments
124+
$this->allowNonLatinDocuments,
125+
$this->allowExpiredDocuments
102126
);
103127
}
104128
}

tests/DocScan/Session/Create/Filters/Document/DocumentRestrictionsFilterBuilderTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,68 @@ public function shouldBuildAndAllowNonLatinDocumentsEqualsNull(): void
153153

154154
$this->assertNull($filter->isAllowNonLatinDocuments());
155155
}
156+
157+
/**
158+
* @test
159+
*
160+
* @covers ::build
161+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::__construct
162+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::isAllowExpiredDocuments
163+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::jsonSerialize
164+
* @covers ::forBlacklist
165+
* @covers ::withAllowExpiredDocuments
166+
* @covers ::withDocumentRestriction
167+
*/
168+
public function shouldBuildWithAllowExpiredDocuments(): void
169+
{
170+
$filter = (new DocumentRestrictionsFilterBuilder())
171+
->forBlacklist()
172+
->withDocumentRestriction($this->documentRestrictionMock)
173+
->withAllowExpiredDocuments()
174+
->build();
175+
176+
$this->assertTrue($filter->isAllowExpiredDocuments());
177+
}
178+
179+
/**
180+
* @test
181+
*
182+
* @covers ::build
183+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::__construct
184+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::isAllowExpiredDocuments
185+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::jsonSerialize
186+
* @covers ::forBlacklist
187+
* @covers ::withDenyExpiredDocuments
188+
* @covers ::withDocumentRestriction
189+
*/
190+
public function shouldBuildWithDenyExpiredDocuments(): void
191+
{
192+
$filter = (new DocumentRestrictionsFilterBuilder())
193+
->forBlacklist()
194+
->withDocumentRestriction($this->documentRestrictionMock)
195+
->withDenyExpiredDocuments()
196+
->build();
197+
198+
$this->assertFalse($filter->isAllowExpiredDocuments());
199+
}
200+
201+
/**
202+
* @test
203+
*
204+
* @covers ::build
205+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::__construct
206+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::isAllowExpiredDocuments
207+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::jsonSerialize
208+
* @covers ::forBlacklist
209+
* @covers ::withDocumentRestriction
210+
*/
211+
public function shouldBuildAndAllowExpiredDocumentsEqualsNull(): void
212+
{
213+
$filter = (new DocumentRestrictionsFilterBuilder())
214+
->forBlacklist()
215+
->withDocumentRestriction($this->documentRestrictionMock)
216+
->build();
217+
218+
$this->assertNull($filter->isAllowExpiredDocuments());
219+
}
156220
}

tests/DocScan/Session/Create/Filters/Orthogonal/OrthogonalRestrictionsFilterBuilderTest.php

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,115 @@ public function shouldBuildAndAllowNonLatinDocumentsEqualsNull()
270270

271271
$this->assertNull($filter->isAllowNonLatinDocuments());
272272
}
273+
274+
/**
275+
* @test
276+
*
277+
* @covers ::withAllowExpiredDocuments
278+
* @covers ::build
279+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::__construct
280+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::jsonSerialize
281+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::isAllowExpiredDocuments
282+
*/
283+
public function shouldBuildWithAllowExpiredDocuments()
284+
{
285+
$filter = (new OrthogonalRestrictionsFilterBuilder())
286+
->withBlacklistedDocumentTypes([self::SOME_DOCUMENT_TYPE])
287+
->withBlacklistedCountries([self::SOME_COUNTRY_CODE])
288+
->withAllowExpiredDocuments()
289+
->build();
290+
291+
$this->assertJsonStringEqualsJsonString(
292+
json_encode(
293+
(object) [
294+
'type' => 'ORTHOGONAL_RESTRICTIONS',
295+
'allow_expired_documents' => true,
296+
'country_restriction' => (object) [
297+
'inclusion' => 'BLACKLIST',
298+
'country_codes' => [self::SOME_COUNTRY_CODE],
299+
],
300+
'type_restriction' => (object) [
301+
'inclusion' => 'BLACKLIST',
302+
'document_types' => [self::SOME_DOCUMENT_TYPE],
303+
],
304+
]
305+
),
306+
json_encode($filter)
307+
);
308+
309+
$this->assertTrue($filter->isAllowExpiredDocuments());
310+
}
311+
312+
/**
313+
* @test
314+
*
315+
* @covers ::withDenyExpiredDocuments
316+
* @covers ::build
317+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::__construct
318+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::jsonSerialize
319+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::isAllowExpiredDocuments
320+
*/
321+
public function shouldBuildWithDenyExpiredDocuments()
322+
{
323+
$filter = (new OrthogonalRestrictionsFilterBuilder())
324+
->withBlacklistedDocumentTypes([self::SOME_DOCUMENT_TYPE])
325+
->withBlacklistedCountries([self::SOME_COUNTRY_CODE])
326+
->withDenyExpiredDocuments()
327+
->build();
328+
329+
$this->assertJsonStringEqualsJsonString(
330+
json_encode(
331+
(object) [
332+
'type' => 'ORTHOGONAL_RESTRICTIONS',
333+
'allow_expired_documents' => false,
334+
'country_restriction' => (object) [
335+
'inclusion' => 'BLACKLIST',
336+
'country_codes' => [self::SOME_COUNTRY_CODE],
337+
],
338+
'type_restriction' => (object) [
339+
'inclusion' => 'BLACKLIST',
340+
'document_types' => [self::SOME_DOCUMENT_TYPE],
341+
],
342+
]
343+
),
344+
json_encode($filter)
345+
);
346+
347+
$this->assertFalse($filter->isAllowExpiredDocuments());
348+
}
349+
350+
/**
351+
* @test
352+
*
353+
* @covers ::build
354+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::__construct
355+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::jsonSerialize
356+
* @covers \Yoti\DocScan\Session\Create\Filters\Orthogonal\OrthogonalRestrictionsFilter::isAllowExpiredDocuments
357+
*/
358+
public function shouldBuildAndAllowExpiredDocumentsEqualsNull()
359+
{
360+
$filter = (new OrthogonalRestrictionsFilterBuilder())
361+
->withBlacklistedDocumentTypes([self::SOME_DOCUMENT_TYPE])
362+
->withBlacklistedCountries([self::SOME_COUNTRY_CODE])
363+
->build();
364+
365+
$this->assertJsonStringEqualsJsonString(
366+
json_encode(
367+
(object) [
368+
'type' => 'ORTHOGONAL_RESTRICTIONS',
369+
'country_restriction' => (object) [
370+
'inclusion' => 'BLACKLIST',
371+
'country_codes' => [self::SOME_COUNTRY_CODE],
372+
],
373+
'type_restriction' => (object) [
374+
'inclusion' => 'BLACKLIST',
375+
'document_types' => [self::SOME_DOCUMENT_TYPE],
376+
],
377+
]
378+
),
379+
json_encode($filter)
380+
);
381+
382+
$this->assertNull($filter->isAllowExpiredDocuments());
383+
}
273384
}

0 commit comments

Comments
 (0)