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 testFromList() |
224
|
|
|
{ |
225
|
|
|
$table = TableNode::fromList(array( |
226
|
|
|
'everzet', |
227
|
|
|
'antono' |
228
|
|
|
)); |
229
|
|
|
|
230
|
|
|
$expected = new TableNode(array( |
231
|
|
|
array('everzet'), |
232
|
|
|
array('antono'), |
233
|
|
|
)); |
234
|
|
|
$this->assertEquals($expected, $table); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @expectedException \Behat\Gherkin\Exception\NodeException |
239
|
|
|
*/ |
240
|
|
|
public function testGetTableFromListWithMultidimensionalArrayArgument() |
241
|
|
|
{ |
242
|
|
|
TableNode::fromList(array( |
243
|
|
|
array(1, 2, 3), |
244
|
|
|
array(4, 5, 6) |
245
|
|
|
)); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
} |
249
|
|
|
|