forked from getyoti/yoti-php-sdk-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeatureContext.php
221 lines (199 loc) · 7.19 KB
/
FeatureContext.php
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
<?php
namespace Yoti\Demo\Context;
use Behat\MinkExtension\Context\RawMinkContext;
use Yoti\Sandbox\DocScan\Request\Check\Report\SandboxBreakdownBuilder;
use Yoti\Sandbox\DocScan\Request\Check\Report\SandboxRecommendationBuilder;
use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentAuthenticityCheckBuilder;
use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentTextDataCheckBuilder;
use Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder;
use Yoti\Sandbox\DocScan\Request\SandboxResponseConfigBuilder;
use Yoti\Sandbox\DocScan\Request\SandboxTaskResultsBuilder;
use Yoti\Sandbox\DocScan\Request\Task\SandboxDocumentTextDataExtractionTaskBuilder;
use Yoti\Sandbox\DocScan\SandboxClient;
class FeatureContext extends RawMinkContext
{
/**
* @var SandboxClient
*/
private $sandboxClient;
/**
* @var array
*/
private $settings;
/**
* Initializes context.
*/
public function __construct($settings)
{
$this->sandboxClient = new SandboxClient(
$_ENV['YOTI_SANDBOX_CLIENT_SDK_ID'],
$_ENV['YOTI_KEY_FILE_PATH']
);
$this->settings = $settings;
}
/**
* @BeforeScenario
*/
public function setTimeouts()
{
if (isset($this->settings['timeouts'])) {
$this->getSession()->getDriver()->setTimeouts($this->settings['timeouts']);
}
}
/**
* @Given I configure the session response
*/
public function iConfigureTheSessionResponse()
{
$iframeUrl = $this->getSession()->getPage()->find('css', 'iframe')->getAttribute('src');
parse_str(parse_url($iframeUrl, PHP_URL_QUERY), $queryParams);
$sessionId = $queryParams['sessionID'];
$responseConfig = (new SandboxResponseConfigBuilder())
->withCheckReports(
(new SandboxCheckReportsBuilder())
->withAsyncReportDelay(5)
->withDocumentAuthenticityCheck(
(new SandboxDocumentAuthenticityCheckBuilder())
->withBreakdown(
(new SandboxBreakdownBuilder())
->withSubCheck('security_features')
->withResult('NOT_AVAILABLE')
->withDetail('some_detail', 'some_detail_value')
->build()
)
->withRecommendation(
(new SandboxRecommendationBuilder())
->withValue('NOT_AVAILABLE')
->withReason('PICTURE_TOO_DARK')
->withRecoverySuggestion('BETTER_LIGHTING')
->build()
)
->build()
)
->withDocumentTextDataCheck(
(new SandboxDocumentTextDataCheckBuilder())
->withBreakdown(
(new SandboxBreakdownBuilder())
->withSubCheck('document_in_date')
->withResult('PASS')
->build()
)
->withRecommendation(
(new SandboxRecommendationBuilder())
->withValue('APPROVE')
->build()
)
->withDocumentFields([
'full_name' => 'John Doe',
'nationality' => 'GBR',
'date_of_birth' => '1986-06-01',
'document_number' => '123456789',
])
->build()
)
->build()
)
->withTaskResults(
(new SandboxTaskResultsBuilder())
->withDocumentTextDataExtractionTask(
(new SandboxDocumentTextDataExtractionTaskBuilder())
->withDocumentFields([
'full_name' => 'John Doe',
'nationality' => 'GBR',
'date_of_birth' => '1986-06-01',
'document_number' => '123456789',
])
->build()
)
->build()
)
->build();
$this->sandboxClient->configureSessionResponse($sessionId, $responseConfig);
}
/**
* @Given I switch to the iframe
*/
public function iSwitchToTheIframe()
{
$this->getSession()->getDriver()->switchToIFrame(0);
}
/**
* @param string $selector
*/
private function clickOn($selector)
{
$this->getSession()->getPage()->find('css', $selector)->click();
}
/**
* @Given I choose :value
*/
public function iChoose($value)
{
$this->clickOn("input[value='{$value}']");
}
/**
* @Given I click on add photo button
*/
public function iClickOnAddPhotoButton()
{
$this->clickOn("*[data-qa='addPhotoButton']");
}
/**
* @Given I upload a document
*/
public function iUploadADocument()
{
$element = $this->getSession()->getPage()->find('css', "input[data-qa='change-photo']");
$element->attachFile($this->settings['image_path']);
}
/**
* @Given I click on finish button
*/
public function iClickOnFinishButton()
{
$this->clickOn("*[data-qa='finish-button']");
}
/**
* @Given I wait :seconds seconds
*/
public function iWaitSeconds($seconds)
{
sleep($seconds);
}
/**
* @param string $selector
* @param string $text
*/
private function assertElementContains($selector, $text)
{
$this->assertSession()->elementContains('css', $selector, $text);
}
/**
* @Then the authenticity check breakdown sub check should be :subCheck
*/
public function theAuthenticityCheckBreakdownSubCheckShouldBe($subCheck)
{
$this->assertElementContains("*[data-qa='authenticity-checks'] *[data-qa='sub-check']", $subCheck);
}
/**
* @Then the authenticity check breakdown result should be :result
*/
public function theAuthenticityCheckBreakdownResultShouldBe($result)
{
$this->assertElementContains("*[data-qa='authenticity-checks'] *[data-qa='result']", $result);
}
/**
* @Then the text data check breakdown sub check should be :subCheck
*/
public function theTextDataCheckBreakdownSubCheckShouldBe($subCheck)
{
$this->assertElementContains("*[data-qa='text-data-checks'] *[data-qa='sub-check']", $subCheck);
}
/**
* @Then the text data check breakdown result should be :result
*/
public function theTextDataCheckBreakdownResultShouldBe($result)
{
$this->assertElementContains("*[data-qa='text-data-checks'] *[data-qa='result']", $result);
}
}