Skip to content

Commit 98e009f

Browse files
LuborRodRodion Liuborets
andauthored
SDK-2050 Add non-latin to DocumentRestrictionsFilter (#261)
Co-authored-by: Rodion Liuborets <[email protected]>
1 parent 83e14d1 commit 98e009f

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ class DocumentRestrictionsFilter extends DocumentFilter implements \JsonSerializ
2020
*/
2121
private $documents;
2222

23+
/**
24+
* @var bool|null
25+
*/
26+
private $allowNonLatinDocuments;
27+
2328
/**
2429
* @param string $inclusion
2530
* @param DocumentRestriction[] $documents
31+
* @param bool|null $allowNonLatinDocuments
2632
*/
27-
public function __construct(string $inclusion, array $documents)
33+
public function __construct(string $inclusion, array $documents, ?bool $allowNonLatinDocuments)
2834
{
2935
parent::__construct(Constants::DOCUMENT_RESTRICTIONS);
3036

@@ -34,6 +40,7 @@ public function __construct(string $inclusion, array $documents)
3440
Validation::notEmptyArray($documents, 'documents');
3541
Validation::isArrayOfType($documents, [DocumentRestriction::class], 'documents');
3642
$this->documents = $documents;
43+
$this->allowNonLatinDocuments = $allowNonLatinDocuments;
3744
}
3845

3946
/**
@@ -44,6 +51,19 @@ public function jsonSerialize(): \stdClass
4451
$jsonData = parent::jsonSerialize();
4552
$jsonData->inclusion = $this->inclusion;
4653
$jsonData->documents = $this->documents;
54+
55+
if (isset($this->allowNonLatinDocuments)) {
56+
$jsonData->allow_non_latin_documents = $this->allowNonLatinDocuments;
57+
}
58+
4759
return $jsonData;
4860
}
61+
62+
/**
63+
* @return bool|null
64+
*/
65+
public function isAllowNonLatinDocuments(): ?bool
66+
{
67+
return $this->allowNonLatinDocuments;
68+
}
4969
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class DocumentRestrictionsFilterBuilder
2020
*/
2121
private $documents = [];
2222

23+
/**
24+
* @var bool|null
25+
*/
26+
private $allowNonLatinDocuments;
27+
2328
/**
2429
* @return $this
2530
*/
@@ -49,12 +54,25 @@ public function withDocumentRestriction(DocumentRestriction $documentRestriction
4954
return $this;
5055
}
5156

57+
/**
58+
* @return $this
59+
*/
60+
public function withAllowNonLatinDocuments(): self
61+
{
62+
$this->allowNonLatinDocuments = true;
63+
return $this;
64+
}
65+
5266
/**
5367
* @return DocumentRestrictionsFilter
5468
*/
5569
public function build(): DocumentFilter
5670
{
5771
Validation::notEmptyString($this->inclusion, 'inclusion');
58-
return new DocumentRestrictionsFilter($this->inclusion, $this->documents);
72+
return new DocumentRestrictionsFilter(
73+
$this->inclusion,
74+
$this->documents,
75+
$this->allowNonLatinDocuments
76+
);
5977
}
6078
}

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ public function shouldBuildDocumentRestrictionsFilterForBlacklist()
6666
$filter = (new DocumentRestrictionsFilterBuilder())
6767
->forBlacklist()
6868
->withDocumentRestriction($this->documentRestrictionMock)
69+
->withAllowNonLatinDocuments()
6970
->build();
7071

7172
$this->assertJsonStringEqualsJsonString(
7273
json_encode(
7374
(object) [
7475
'type' => 'DOCUMENT_RESTRICTIONS',
76+
'allow_non_latin_documents' => true,
7577
'inclusion' => 'BLACKLIST',
7678
'documents' => [ $this->documentRestrictionMock ],
7779
]
@@ -109,4 +111,46 @@ public function shouldThrowExceptionWithoutDocumentRestriction()
109111
->forWhitelist()
110112
->build();
111113
}
114+
115+
/**
116+
* @test
117+
*
118+
* @covers ::build
119+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::__construct
120+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::isAllowNonLatinDocuments
121+
* @covers ::forBlacklist
122+
* @covers ::withAllowNonLatinDocuments
123+
* @covers ::withDocumentRestriction
124+
* @covers ::build
125+
*/
126+
public function shouldBuildWithAllowNonLatinDocuments(): void
127+
{
128+
$filter = (new DocumentRestrictionsFilterBuilder())
129+
->forBlacklist()
130+
->withDocumentRestriction($this->documentRestrictionMock)
131+
->withAllowNonLatinDocuments()
132+
->build();
133+
134+
$this->assertTrue($filter->isAllowNonLatinDocuments());
135+
}
136+
137+
/**
138+
* @test
139+
*
140+
* @covers ::build
141+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::__construct
142+
* @covers \Yoti\DocScan\Session\Create\Filters\Document\DocumentRestrictionsFilter::isAllowNonLatinDocuments
143+
* @covers ::forBlacklist
144+
* @covers ::withDocumentRestriction
145+
* @covers ::build
146+
*/
147+
public function shouldBuildAndAllowNonLatinDocumentsEqualsNull(): void
148+
{
149+
$filter = (new DocumentRestrictionsFilterBuilder())
150+
->forBlacklist()
151+
->withDocumentRestriction($this->documentRestrictionMock)
152+
->build();
153+
154+
$this->assertNull($filter->isAllowNonLatinDocuments());
155+
}
112156
}

0 commit comments

Comments
 (0)