1 | <?php |
||
7 | class TableNodeTest extends \PHPUnit_Framework_TestCase |
||
8 | { |
||
9 | /** |
||
10 | * @expectedException \Behat\Gherkin\Exception\NodeException |
||
11 | */ |
||
12 | public function testConstructorExpectsSameNumberOfColumnsInEachRow() |
||
20 | |||
21 | public function testHashTable() |
||
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() |
||
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() |
||
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() |
||
182 | |||
183 | public function testGetRowLine() |
||
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() |
||
236 | |||
237 | /** |
||
238 | * @expectedException \Behat\Gherkin\Exception\NodeException |
||
239 | */ |
||
240 | public function testGetTableFromListWithMultidimensionalArrayArgument() |
||
247 | |||
248 | } |
||
249 |