1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin\Node; |
4
|
|
|
|
5
|
|
|
use Behat\Gherkin\Node\TableNode; |
6
|
|
|
|
7
|
|
|
class TableNodeTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @expectedException \Behat\Gherkin\Exception\NodeException |
11
|
|
|
*/ |
12
|
|
|
public function testConstructorExpectsSameNumberOfColumnsInEachRow() |
13
|
|
|
{ |
14
|
|
|
new TableNode(array( |
15
|
|
|
array('username', 'password'), |
16
|
|
|
array('everzet'), |
17
|
|
|
array('antono', 'pa$sword') |
18
|
|
|
)); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testHashTable() |
22
|
|
|
{ |
23
|
|
|
$table = new TableNode(array( |
24
|
|
|
array('username', 'password'), |
25
|
|
|
array('everzet', 'qwerty'), |
26
|
|
|
array('antono', 'pa$sword') |
27
|
|
|
)); |
28
|
|
|
|
29
|
|
|
$this->assertEquals( |
30
|
|
|
array( |
31
|
|
|
array('username' => 'everzet', 'password' => 'qwerty') |
32
|
|
|
, array('username' => 'antono', 'password' => 'pa$sword') |
33
|
|
|
), |
34
|
|
|
$table->getHash() |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$table = new TableNode(array( |
38
|
|
|
array('username', 'password'), |
39
|
|
|
array('', 'qwerty'), |
40
|
|
|
array('antono', ''), |
41
|
|
|
array('', '') |
42
|
|
|
)); |
43
|
|
|
|
44
|
|
|
$this->assertEquals( |
45
|
|
|
array( |
46
|
|
|
array('username' => '', 'password' => 'qwerty'), |
47
|
|
|
array('username' => 'antono', 'password' => ''), |
48
|
|
|
array('username' => '', 'password' => ''), |
49
|
|
|
), |
50
|
|
|
$table->getHash() |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testIterator() |
55
|
|
|
{ |
56
|
|
|
$table = new TableNode(array( |
57
|
|
|
array('username', 'password'), |
58
|
|
|
array('', 'qwerty'), |
59
|
|
|
array('antono', ''), |
60
|
|
|
array('', ''), |
61
|
|
|
)); |
62
|
|
|
|
63
|
|
|
$this->assertEquals( |
64
|
|
|
array( |
65
|
|
|
array('username' => '', 'password' => 'qwerty'), |
66
|
|
|
array('username' => 'antono', 'password' => ''), |
67
|
|
|
array('username' => '', 'password' => ''), |
68
|
|
|
), |
69
|
|
|
iterator_to_array($table) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testRowsHashTable() |
74
|
|
|
{ |
75
|
|
|
$table = new TableNode(array( |
76
|
|
|
array('username', 'everzet'), |
77
|
|
|
array('password', 'qwerty'), |
78
|
|
|
array('uid', '35'), |
79
|
|
|
)); |
80
|
|
|
|
81
|
|
|
$this->assertEquals( |
82
|
|
|
array('username' => 'everzet', 'password' => 'qwerty', 'uid' => '35'), |
83
|
|
|
$table->getRowsHash() |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testLongRowsHashTable() |
88
|
|
|
{ |
89
|
|
|
$table = new TableNode(array( |
90
|
|
|
array('username', 'everzet', 'marcello'), |
91
|
|
|
array('password', 'qwerty', '12345'), |
92
|
|
|
array('uid', '35', '22') |
93
|
|
|
)); |
94
|
|
|
|
95
|
|
|
$this->assertEquals(array( |
96
|
|
|
'username' => array('everzet', 'marcello'), |
97
|
|
|
'password' => array('qwerty', '12345'), |
98
|
|
|
'uid' => array('35', '22') |
99
|
|
|
), $table->getRowsHash()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testGetRows() |
103
|
|
|
{ |
104
|
|
|
$table = new TableNode(array( |
105
|
|
|
array('username', 'password'), |
106
|
|
|
array('everzet', 'qwerty'), |
107
|
|
|
array('antono', 'pa$sword') |
108
|
|
|
)); |
109
|
|
|
|
110
|
|
|
$this->assertEquals(array( |
111
|
|
|
array('username', 'password'), |
112
|
|
|
array('everzet', 'qwerty'), |
113
|
|
|
array('antono', 'pa$sword') |
114
|
|
|
), $table->getRows()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testGetLines() |
118
|
|
|
{ |
119
|
|
|
$table = new TableNode(array( |
120
|
|
|
5 => array('username', 'password'), |
121
|
|
|
10 => array('everzet', 'qwerty'), |
122
|
|
|
13 => array('antono', 'pa$sword') |
123
|
|
|
)); |
124
|
|
|
|
125
|
|
|
$this->assertEquals(array(5, 10, 13), $table->getLines()); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testGetRow() |
129
|
|
|
{ |
130
|
|
|
$table = new TableNode(array( |
131
|
|
|
array('username', 'password'), |
132
|
|
|
array('everzet', 'qwerty'), |
133
|
|
|
array('antono', 'pa$sword') |
134
|
|
|
)); |
135
|
|
|
|
136
|
|
|
$this->assertEquals(array('username', 'password'), $table->getRow(0)); |
137
|
|
|
$this->assertEquals(array('antono', 'pa$sword'), $table->getRow(2)); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testGetColumn() |
141
|
|
|
{ |
142
|
|
|
$table = new TableNode(array( |
143
|
|
|
array('username', 'password'), |
144
|
|
|
array('everzet', 'qwerty'), |
145
|
|
|
array('antono', 'pa$sword') |
146
|
|
|
)); |
147
|
|
|
|
148
|
|
|
$this->assertEquals(array('username', 'everzet', 'antono'), $table->getColumn(0)); |
149
|
|
|
$this->assertEquals(array('password', 'qwerty', 'pa$sword'), $table->getColumn(1)); |
150
|
|
|
|
151
|
|
|
$table = new TableNode(array( |
152
|
|
|
array('username'), |
153
|
|
|
array('everzet'), |
154
|
|
|
array('antono') |
155
|
|
|
)); |
156
|
|
|
|
157
|
|
|
$this->assertEquals(array('username', 'everzet', 'antono'), $table->getColumn(0)); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function testGetRowWithLineNumbers() |
161
|
|
|
{ |
162
|
|
|
$table = new TableNode(array( |
163
|
|
|
5 => array('username', 'password'), |
164
|
|
|
10 => array('everzet', 'qwerty'), |
165
|
|
|
13 => array('antono', 'pa$sword') |
166
|
|
|
)); |
167
|
|
|
|
168
|
|
|
$this->assertEquals(array('username', 'password'), $table->getRow(0)); |
169
|
|
|
$this->assertEquals(array('antono', 'pa$sword'), $table->getRow(2)); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function testGetTable() |
173
|
|
|
{ |
174
|
|
|
$table = new TableNode($a = array( |
175
|
|
|
5 => array('username', 'password'), |
176
|
|
|
10 => array('everzet', 'qwerty'), |
177
|
|
|
13 => array('antono', 'pa$sword') |
178
|
|
|
)); |
179
|
|
|
|
180
|
|
|
$this->assertEquals($a, $table->getTable()); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function testGetRowLine() |
184
|
|
|
{ |
185
|
|
|
$table = new TableNode(array( |
186
|
|
|
5 => array('username', 'password'), |
187
|
|
|
10 => array('everzet', 'qwerty'), |
188
|
|
|
13 => array('antono', 'pa$sword') |
189
|
|
|
)); |
190
|
|
|
|
191
|
|
|
$this->assertEquals(5, $table->getRowLine(0)); |
192
|
|
|
$this->assertEquals(13, $table->getRowLine(2)); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function testGetRowAsString() |
196
|
|
|
{ |
197
|
|
|
$table = new TableNode(array( |
198
|
|
|
5 => array('username', 'password'), |
199
|
|
|
10 => array('everzet', 'qwerty'), |
200
|
|
|
13 => array('antono', 'pa$sword') |
201
|
|
|
)); |
202
|
|
|
|
203
|
|
|
$this->assertEquals('| username | password |', $table->getRowAsString(0)); |
204
|
|
|
$this->assertEquals('| antono | pa$sword |', $table->getRowAsString(2)); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function testGetTableAsString() |
208
|
|
|
{ |
209
|
|
|
$table = new TableNode(array( |
210
|
|
|
5 => array('id', 'username', 'password'), |
211
|
|
|
10 => array('42', 'everzet', 'qwerty'), |
212
|
|
|
13 => array('2', 'antono', 'pa$sword') |
213
|
|
|
)); |
214
|
|
|
|
215
|
|
|
$expected = <<<TABLE |
216
|
|
|
| id | username | password | |
217
|
|
|
| 42 | everzet | qwerty | |
218
|
|
|
| 2 | antono | pa\$sword | |
219
|
|
|
TABLE; |
220
|
|
|
$this->assertEquals($expected, $table->getTableAsString()); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function testMergeRowsFromTablePassSeveralTablesShouldBeMerged() |
224
|
|
|
{ |
225
|
|
|
$table = new TableNode(array( |
226
|
|
|
5 => array('id', 'username', 'password'), |
227
|
|
|
10 => array('42', 'everzet', 'qwerty'), |
228
|
|
|
13 => array('2', 'antono', 'pa$sword') |
229
|
|
|
)); |
230
|
|
|
|
231
|
|
|
$new = new TableNode(array( |
232
|
|
|
25 => array('id', 'username', 'password'), |
233
|
|
|
210 => array('242', '2everzet', '2qwerty'), |
234
|
|
|
213 => array('22', '2antono', '2pa$sword') |
235
|
|
|
)); |
236
|
|
|
|
237
|
|
|
$new2 = new TableNode(array( |
238
|
|
|
35 => array('id', 'username', 'password'), |
239
|
|
|
310 => array('342', '3everzet', '3qwerty'), |
240
|
|
|
313 => array('32', '3antono', '3pa$sword') |
241
|
|
|
)); |
242
|
|
|
|
243
|
|
|
$table->mergeRowsFromTable($new); |
|
|
|
|
244
|
|
|
$table->mergeRowsFromTable($new2); |
|
|
|
|
245
|
|
|
|
246
|
|
|
$this->assertEquals(array('id', 'username', 'password'), $table->getRow(0)); |
247
|
|
|
$this->assertEquals(array('2', 'antono', 'pa$sword'), $table->getRow(2)); |
248
|
|
|
$this->assertEquals(array('242', '2everzet', '2qwerty'), $table->getRow(3)); |
249
|
|
|
$this->assertEquals(array('32', '3antono', '3pa$sword'), $table->getRow(6)); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @expectedException \Behat\Gherkin\Exception\NodeException |
254
|
|
|
*/ |
255
|
|
|
public function testMergeRowsFromTableWrongHeaderNameExceptionThrown() |
256
|
|
|
{ |
257
|
|
|
$table = new TableNode(array( |
258
|
|
|
5 => array('id', 'username', 'password'), |
259
|
|
|
10 => array('42', 'everzet', 'qwerty'), |
260
|
|
|
13 => array('2', 'antono', 'pa$sword') |
261
|
|
|
)); |
262
|
|
|
|
263
|
|
|
$new = new TableNode(array( |
264
|
|
|
25 => array('id', 'QWE', 'password'), |
265
|
|
|
210 => array('242', '2everzet', '2qwerty') |
266
|
|
|
)); |
267
|
|
|
|
268
|
|
|
$table->mergeRowsFromTable($new); |
|
|
|
|
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @expectedException \Behat\Gherkin\Exception\NodeException |
273
|
|
|
*/ |
274
|
|
|
public function testMergeRowsFromTableWrongHeaderOrderExceptionThrown() |
275
|
|
|
{ |
276
|
|
|
$table = new TableNode(array( |
277
|
|
|
5 => array('id', 'username', 'password'), |
278
|
|
|
10 => array('42', 'everzet', 'qwerty'), |
279
|
|
|
13 => array('2', 'antono', 'pa$sword') |
280
|
|
|
)); |
281
|
|
|
|
282
|
|
|
$new = new TableNode(array( |
283
|
|
|
25 => array('id', 'password', 'username'), |
284
|
|
|
210 => array('242', '2everzet', '2qwerty') |
285
|
|
|
)); |
286
|
|
|
|
287
|
|
|
$table->mergeRowsFromTable($new); |
|
|
|
|
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @expectedException \Behat\Gherkin\Exception\NodeException |
292
|
|
|
*/ |
293
|
|
|
public function testMergeRowsFromTableWrongHeaderSizeExceptionThrown() |
294
|
|
|
{ |
295
|
|
|
$table = new TableNode(array( |
296
|
|
|
5 => array('id', 'username', 'password'), |
297
|
|
|
10 => array('42', 'everzet', 'qwerty'), |
298
|
|
|
13 => array('2', 'antono', 'pa$sword') |
299
|
|
|
)); |
300
|
|
|
|
301
|
|
|
$new = new TableNode(array( |
302
|
|
|
25 => array('id', 'username'), |
303
|
|
|
210 => array('242', '2everzet') |
304
|
|
|
)); |
305
|
|
|
|
306
|
|
|
$table->mergeRowsFromTable($new); |
|
|
|
|
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.