1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin\Keywords; |
4
|
|
|
|
5
|
|
|
use Behat\Gherkin\Keywords\ArrayKeywords; |
6
|
|
|
use Behat\Gherkin\Keywords\KeywordsDumper; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class KeywordsDumperTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
private $keywords; |
12
|
|
|
|
13
|
|
|
protected function setUp() |
14
|
|
|
{ |
15
|
|
|
$this->keywords = new ArrayKeywords(array( |
16
|
|
|
'en' => array( |
17
|
|
|
'feature' => 'Feature', |
18
|
|
|
'background' => 'Background', |
19
|
|
|
'scenario' => 'Scenario', |
20
|
|
|
'scenario_outline' => 'Scenario Outline|Scenario Template', |
21
|
|
|
'examples' => 'Examples|Scenarios', |
22
|
|
|
'given' => 'Given', |
23
|
|
|
'when' => 'When', |
24
|
|
|
'then' => 'Then', |
25
|
|
|
'and' => 'And', |
26
|
|
|
'but' => 'But' |
27
|
|
|
), |
28
|
|
|
'ru' => array( |
29
|
|
|
'feature' => 'Функционал|Фича', |
30
|
|
|
'background' => 'Предыстория|Бэкграунд', |
31
|
|
|
'scenario' => 'Сценарий|История', |
32
|
|
|
'scenario_outline' => 'Структура сценария|Аутлайн', |
33
|
|
|
'examples' => 'Примеры', |
34
|
|
|
'given' => 'Допустим', |
35
|
|
|
'when' => 'Если|@', |
36
|
|
|
'then' => 'То', |
37
|
|
|
'and' => 'И', |
38
|
|
|
'but' => 'Но' |
39
|
|
|
) |
40
|
|
|
)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testEnKeywordsDumper() |
44
|
|
|
{ |
45
|
|
|
$dumper = new KeywordsDumper($this->keywords); |
46
|
|
|
|
47
|
|
|
$dumped = $dumper->dump('en'); |
48
|
|
|
$etalon = <<<GHERKIN |
49
|
|
|
Feature: Internal operations |
50
|
|
|
In order to stay secret |
51
|
|
|
As a secret organization |
52
|
|
|
We need to be able to erase past agents' memory |
53
|
|
|
|
54
|
|
|
Background: |
55
|
|
|
Given there is agent A |
56
|
|
|
And there is agent B |
57
|
|
|
|
58
|
|
|
Scenario: Erasing agent memory |
59
|
|
|
Given there is agent J |
60
|
|
|
And there is agent K |
61
|
|
|
When I erase agent K's memory |
62
|
|
|
Then there should be agent J |
63
|
|
|
But there should not be agent K |
64
|
|
|
|
65
|
|
|
(Scenario Outline|Scenario Template): Erasing other agents' memory |
66
|
|
|
Given there is agent <agent1> |
67
|
|
|
And there is agent <agent2> |
68
|
|
|
When I erase agent <agent2>'s memory |
69
|
|
|
Then there should be agent <agent1> |
70
|
|
|
But there should not be agent <agent2> |
71
|
|
|
|
72
|
|
|
(Examples|Scenarios): |
73
|
|
|
| agent1 | agent2 | |
74
|
|
|
| D | M | |
75
|
|
|
GHERKIN; |
76
|
|
|
|
77
|
|
|
$this->assertEquals($etalon, $dumped); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testRuKeywordsDumper() |
81
|
|
|
{ |
82
|
|
|
$dumper = new KeywordsDumper($this->keywords); |
83
|
|
|
|
84
|
|
|
$dumped = $dumper->dump('ru'); |
85
|
|
|
$etalon = <<<GHERKIN |
86
|
|
|
# language: ru |
87
|
|
|
(Функционал|Фича): Internal operations |
88
|
|
|
In order to stay secret |
89
|
|
|
As a secret organization |
90
|
|
|
We need to be able to erase past agents' memory |
91
|
|
|
|
92
|
|
|
(Предыстория|Бэкграунд): |
93
|
|
|
Допустим there is agent A |
94
|
|
|
И there is agent B |
95
|
|
|
|
96
|
|
|
(Сценарий|История): Erasing agent memory |
97
|
|
|
Допустим there is agent J |
98
|
|
|
И there is agent K |
99
|
|
|
(Если|@) I erase agent K's memory |
100
|
|
|
То there should be agent J |
101
|
|
|
Но there should not be agent K |
102
|
|
|
|
103
|
|
|
(Структура сценария|Аутлайн): Erasing other agents' memory |
104
|
|
|
Допустим there is agent <agent1> |
105
|
|
|
И there is agent <agent2> |
106
|
|
|
(Если|@) I erase agent <agent2>'s memory |
107
|
|
|
То there should be agent <agent1> |
108
|
|
|
Но there should not be agent <agent2> |
109
|
|
|
|
110
|
|
|
Примеры: |
111
|
|
|
| agent1 | agent2 | |
112
|
|
|
| D | M | |
113
|
|
|
GHERKIN; |
114
|
|
|
|
115
|
|
|
$this->assertEquals($etalon, $dumped); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function testRuKeywordsCustomKeywordsDumper() |
119
|
|
|
{ |
120
|
|
|
$dumper = new KeywordsDumper($this->keywords); |
121
|
|
|
$dumper->setKeywordsDumperFunction(function ($keywords) { |
122
|
|
|
return '<keyword>'.implode(', ', $keywords).'</keyword>'; |
123
|
|
|
}); |
124
|
|
|
|
125
|
|
|
$dumped = $dumper->dump('ru'); |
126
|
|
|
$etalon = <<<GHERKIN |
127
|
|
|
# language: ru |
128
|
|
|
<keyword>Функционал, Фича</keyword>: Internal operations |
129
|
|
|
In order to stay secret |
130
|
|
|
As a secret organization |
131
|
|
|
We need to be able to erase past agents' memory |
132
|
|
|
|
133
|
|
|
<keyword>Предыстория, Бэкграунд</keyword>: |
134
|
|
|
<keyword>Допустим</keyword> there is agent A |
135
|
|
|
<keyword>И</keyword> there is agent B |
136
|
|
|
|
137
|
|
|
<keyword>Сценарий, История</keyword>: Erasing agent memory |
138
|
|
|
<keyword>Допустим</keyword> there is agent J |
139
|
|
|
<keyword>И</keyword> there is agent K |
140
|
|
|
<keyword>Если, @</keyword> I erase agent K's memory |
141
|
|
|
<keyword>То</keyword> there should be agent J |
142
|
|
|
<keyword>Но</keyword> there should not be agent K |
143
|
|
|
|
144
|
|
|
<keyword>Структура сценария, Аутлайн</keyword>: Erasing other agents' memory |
145
|
|
|
<keyword>Допустим</keyword> there is agent <agent1> |
146
|
|
|
<keyword>И</keyword> there is agent <agent2> |
147
|
|
|
<keyword>Если, @</keyword> I erase agent <agent2>'s memory |
148
|
|
|
<keyword>То</keyword> there should be agent <agent1> |
149
|
|
|
<keyword>Но</keyword> there should not be agent <agent2> |
150
|
|
|
|
151
|
|
|
<keyword>Примеры</keyword>: |
152
|
|
|
| agent1 | agent2 | |
153
|
|
|
| D | M | |
154
|
|
|
GHERKIN; |
155
|
|
|
|
156
|
|
|
$this->assertEquals($etalon, $dumped); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testExtendedVersionDumper() |
160
|
|
|
{ |
161
|
|
|
$dumper = new KeywordsDumper($this->keywords); |
162
|
|
|
|
163
|
|
|
$dumped = $dumper->dump('ru', false); |
164
|
|
|
$etalon = array( |
165
|
|
|
<<<GHERKIN |
166
|
|
|
# language: ru |
167
|
|
|
Функционал: Internal operations |
168
|
|
|
In order to stay secret |
169
|
|
|
As a secret organization |
170
|
|
|
We need to be able to erase past agents' memory |
171
|
|
|
|
172
|
|
|
Предыстория: |
173
|
|
|
Допустим there is agent A |
174
|
|
|
И there is agent B |
175
|
|
|
|
176
|
|
|
Сценарий: Erasing agent memory |
177
|
|
|
Допустим there is agent J |
178
|
|
|
И there is agent K |
179
|
|
|
Если I erase agent K's memory |
180
|
|
|
@ I erase agent K's memory |
181
|
|
|
То there should be agent J |
182
|
|
|
Но there should not be agent K |
183
|
|
|
|
184
|
|
|
История: Erasing agent memory |
185
|
|
|
Допустим there is agent J |
186
|
|
|
И there is agent K |
187
|
|
|
Если I erase agent K's memory |
188
|
|
|
@ I erase agent K's memory |
189
|
|
|
То there should be agent J |
190
|
|
|
Но there should not be agent K |
191
|
|
|
|
192
|
|
|
Структура сценария: Erasing other agents' memory |
193
|
|
|
Допустим there is agent <agent1> |
194
|
|
|
И there is agent <agent2> |
195
|
|
|
Если I erase agent <agent2>'s memory |
196
|
|
|
@ I erase agent <agent2>'s memory |
197
|
|
|
То there should be agent <agent1> |
198
|
|
|
Но there should not be agent <agent2> |
199
|
|
|
|
200
|
|
|
Примеры: |
201
|
|
|
| agent1 | agent2 | |
202
|
|
|
| D | M | |
203
|
|
|
|
204
|
|
|
Аутлайн: Erasing other agents' memory |
205
|
|
|
Допустим there is agent <agent1> |
206
|
|
|
И there is agent <agent2> |
207
|
|
|
Если I erase agent <agent2>'s memory |
208
|
|
|
@ I erase agent <agent2>'s memory |
209
|
|
|
То there should be agent <agent1> |
210
|
|
|
Но there should not be agent <agent2> |
211
|
|
|
|
212
|
|
|
Примеры: |
213
|
|
|
| agent1 | agent2 | |
214
|
|
|
| D | M | |
215
|
|
|
GHERKIN |
216
|
|
|
, <<<GHERKIN |
217
|
|
|
# language: ru |
218
|
|
|
Фича: Internal operations |
219
|
|
|
In order to stay secret |
220
|
|
|
As a secret organization |
221
|
|
|
We need to be able to erase past agents' memory |
222
|
|
|
|
223
|
|
|
Предыстория: |
224
|
|
|
Допустим there is agent A |
225
|
|
|
И there is agent B |
226
|
|
|
|
227
|
|
|
Сценарий: Erasing agent memory |
228
|
|
|
Допустим there is agent J |
229
|
|
|
И there is agent K |
230
|
|
|
Если I erase agent K's memory |
231
|
|
|
@ I erase agent K's memory |
232
|
|
|
То there should be agent J |
233
|
|
|
Но there should not be agent K |
234
|
|
|
|
235
|
|
|
История: Erasing agent memory |
236
|
|
|
Допустим there is agent J |
237
|
|
|
И there is agent K |
238
|
|
|
Если I erase agent K's memory |
239
|
|
|
@ I erase agent K's memory |
240
|
|
|
То there should be agent J |
241
|
|
|
Но there should not be agent K |
242
|
|
|
|
243
|
|
|
Структура сценария: Erasing other agents' memory |
244
|
|
|
Допустим there is agent <agent1> |
245
|
|
|
И there is agent <agent2> |
246
|
|
|
Если I erase agent <agent2>'s memory |
247
|
|
|
@ I erase agent <agent2>'s memory |
248
|
|
|
То there should be agent <agent1> |
249
|
|
|
Но there should not be agent <agent2> |
250
|
|
|
|
251
|
|
|
Примеры: |
252
|
|
|
| agent1 | agent2 | |
253
|
|
|
| D | M | |
254
|
|
|
|
255
|
|
|
Аутлайн: Erasing other agents' memory |
256
|
|
|
Допустим there is agent <agent1> |
257
|
|
|
И there is agent <agent2> |
258
|
|
|
Если I erase agent <agent2>'s memory |
259
|
|
|
@ I erase agent <agent2>'s memory |
260
|
|
|
То there should be agent <agent1> |
261
|
|
|
Но there should not be agent <agent2> |
262
|
|
|
|
263
|
|
|
Примеры: |
264
|
|
|
| agent1 | agent2 | |
265
|
|
|
| D | M | |
266
|
|
|
GHERKIN |
267
|
|
|
); |
268
|
|
|
|
269
|
|
|
$this->assertEquals($etalon, $dumped); |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|