|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Behat Gherkin. |
|
5
|
|
|
* (c) Konstantin Kudryashov <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Behat\Gherkin\Keywords; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Array initializable keywords holder. |
|
15
|
|
|
* |
|
16
|
|
|
* $keywords = new Behat\Gherkin\Keywords\ArrayKeywords(array( |
|
17
|
|
|
* 'en' => array( |
|
18
|
|
|
* 'feature' => 'Feature', |
|
19
|
|
|
* 'background' => 'Background', |
|
20
|
|
|
* 'scenario' => 'Scenario', |
|
21
|
|
|
* 'scenario_outline' => 'Scenario Outline|Scenario Template', |
|
22
|
|
|
* 'examples' => 'Examples|Scenarios', |
|
23
|
|
|
* 'given' => 'Given', |
|
24
|
|
|
* 'when' => 'When', |
|
25
|
|
|
* 'then' => 'Then', |
|
26
|
|
|
* 'and' => 'And', |
|
27
|
|
|
* 'but' => 'But' |
|
28
|
|
|
* ), |
|
29
|
|
|
* 'ru' => array( |
|
30
|
|
|
* 'feature' => 'Функционал', |
|
31
|
|
|
* 'background' => 'Предыстория', |
|
32
|
|
|
* 'scenario' => 'Сценарий', |
|
33
|
|
|
* 'scenario_outline' => 'Структура сценария', |
|
34
|
|
|
* 'examples' => 'Значения', |
|
35
|
|
|
* 'given' => 'Допустим', |
|
36
|
|
|
* 'when' => 'Если', |
|
37
|
|
|
* 'then' => 'То', |
|
38
|
|
|
* 'and' => 'И', |
|
39
|
|
|
* 'but' => 'Но' |
|
40
|
|
|
* ) |
|
41
|
|
|
* )); |
|
42
|
|
|
* |
|
43
|
|
|
* @author Konstantin Kudryashov <[email protected]> |
|
44
|
|
|
*/ |
|
45
|
|
|
class ArrayKeywords implements KeywordsInterface |
|
46
|
|
|
{ |
|
47
|
|
|
private $keywords = array(); |
|
48
|
|
|
private $keywordString = array(); |
|
49
|
|
|
private $language; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Initializes holder with keywords. |
|
53
|
|
|
* |
|
54
|
|
|
* @param array $keywords Keywords array |
|
55
|
|
|
*/ |
|
56
|
59 |
|
public function __construct(array $keywords) |
|
57
|
|
|
{ |
|
58
|
59 |
|
$this->keywords = $keywords; |
|
59
|
59 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Sets keywords holder language. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $language Language name |
|
65
|
|
|
*/ |
|
66
|
57 |
|
public function setLanguage($language) |
|
67
|
|
|
{ |
|
68
|
57 |
|
if (!isset($this->keywords[$language])) { |
|
69
|
|
|
$this->language = 'en'; |
|
70
|
|
|
} else { |
|
71
|
57 |
|
$this->language = $language; |
|
72
|
|
|
} |
|
73
|
57 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns Feature keywords (splitted by "|"). |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
57 |
|
public function getFeatureKeywords() |
|
81
|
|
|
{ |
|
82
|
57 |
|
return $this->keywords[$this->language]['feature']; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns Background keywords (splitted by "|"). |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
57 |
|
public function getBackgroundKeywords() |
|
91
|
|
|
{ |
|
92
|
57 |
|
return $this->keywords[$this->language]['background']; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns Scenario keywords (splitted by "|"). |
|
97
|
|
|
* |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
57 |
|
public function getScenarioKeywords() |
|
101
|
|
|
{ |
|
102
|
57 |
|
return $this->keywords[$this->language]['scenario']; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Returns Scenario Outline keywords (splitted by "|"). |
|
107
|
|
|
* |
|
108
|
|
|
* @return string |
|
109
|
|
|
*/ |
|
110
|
57 |
|
public function getOutlineKeywords() |
|
111
|
|
|
{ |
|
112
|
57 |
|
return $this->keywords[$this->language]['scenario_outline']; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Returns Examples keywords (splitted by "|"). |
|
117
|
|
|
* |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
57 |
|
public function getExamplesKeywords() |
|
121
|
|
|
{ |
|
122
|
57 |
|
return $this->keywords[$this->language]['examples']; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Returns Given keywords (splitted by "|"). |
|
127
|
|
|
* |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
48 |
|
public function getGivenKeywords() |
|
131
|
|
|
{ |
|
132
|
48 |
|
return $this->keywords[$this->language]['given']; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Returns When keywords (splitted by "|"). |
|
137
|
|
|
* |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
48 |
|
public function getWhenKeywords() |
|
141
|
|
|
{ |
|
142
|
48 |
|
return $this->keywords[$this->language]['when']; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Returns Then keywords (splitted by "|"). |
|
147
|
|
|
* |
|
148
|
|
|
* @return string |
|
149
|
|
|
*/ |
|
150
|
48 |
|
public function getThenKeywords() |
|
151
|
|
|
{ |
|
152
|
48 |
|
return $this->keywords[$this->language]['then']; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Returns And keywords (splitted by "|"). |
|
157
|
|
|
* |
|
158
|
|
|
* @return string |
|
159
|
|
|
*/ |
|
160
|
48 |
|
public function getAndKeywords() |
|
161
|
|
|
{ |
|
162
|
48 |
|
return $this->keywords[$this->language]['and']; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Returns But keywords (splitted by "|"). |
|
167
|
|
|
* |
|
168
|
|
|
* @return string |
|
169
|
|
|
*/ |
|
170
|
48 |
|
public function getButKeywords() |
|
171
|
|
|
{ |
|
172
|
48 |
|
return $this->keywords[$this->language]['but']; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Returns all step keywords (Given, When, Then, And, But). |
|
177
|
|
|
* |
|
178
|
|
|
* @return string |
|
179
|
|
|
*/ |
|
180
|
44 |
|
public function getStepKeywords() |
|
181
|
|
|
{ |
|
182
|
44 |
|
if (!isset($this->keywordString[$this->language])) { |
|
183
|
44 |
|
$keywords = array_merge( |
|
184
|
44 |
|
explode('|', $this->getGivenKeywords()), |
|
185
|
44 |
|
explode('|', $this->getWhenKeywords()), |
|
186
|
44 |
|
explode('|', $this->getThenKeywords()), |
|
187
|
44 |
|
explode('|', $this->getAndKeywords()), |
|
188
|
44 |
|
explode('|', $this->getButKeywords()) |
|
189
|
44 |
|
); |
|
190
|
|
|
|
|
191
|
44 |
|
usort($keywords, function ($keyword1, $keyword2) { |
|
192
|
44 |
|
return mb_strlen($keyword2, 'utf8') - mb_strlen($keyword1, 'utf8'); |
|
193
|
44 |
|
}); |
|
194
|
|
|
|
|
195
|
44 |
|
$this->keywordString[$this->language] = implode('|', $keywords); |
|
196
|
44 |
|
} |
|
197
|
|
|
|
|
198
|
44 |
|
return $this->keywordString[$this->language]; |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|