|
52 | 52 | // basic usage with thead and tbody |
53 | 53 | $table = "<table id=\"test-table\"><thead><tr><th>First Name</th><th>Last Name</th><th>Points</th></tr></thead><tbody><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
54 | 54 | $helper = new HTMLTable2JSON(); |
55 | | -$code_output = $helper->tableToJSON('', false, null, null, null, null, null, true, null, $table); |
| 55 | +$code_output = $helper->tableToJSON('', false, null, null, null, null, null, true, null, null, $table); |
56 | 56 | $test_output = "[{\"First Name\":\"Jill\", \"Last Name\":\"Smith\", \"Points\":\"50\"},{\"First Name\":\"Eve\", \"Last Name\":\"Jackson\", \"Points\":\"94\"},{\"First Name\":\"John\", \"Last Name\":\"Doe\", \"Points\":\"80\"}]"; |
57 | 57 | if($code_output == $test_output) |
58 | 58 | $passed++; |
|
67 | 67 | // Tests: basic usage without thead or tbody |
68 | 68 | $table = "<table id=\"test-table\"><tr><th>First Name</th><th>Last Name</th><th>Points</th></tr><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
69 | 69 | $helper = new HTMLTable2JSON(); |
70 | | -$code_output = $helper->tableToJSON('', false, null, null, null, null, null, true, null, $table); |
| 70 | +$code_output = $helper->tableToJSON('', false, null, null, null, null, null, true, null, null, $table); |
71 | 71 | $test_output = "[{\"First Name\":\"Jill\", \"Last Name\":\"Smith\", \"Points\":\"50\"},{\"First Name\":\"Eve\", \"Last Name\":\"Jackson\", \"Points\":\"94\"},{\"First Name\":\"John\", \"Last Name\":\"Doe\", \"Points\":\"80\"}]"; |
72 | 72 | if($code_output == $test_output) |
73 | 73 | $passed++; |
|
87 | 87 | // Tests: ignore column 0 |
88 | 88 | $table = "<table id=\"test-table\"><thead><tr><th>First Name</th><th>Last Name</th><th>Points</th></tr></thead><tbody><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
89 | 89 | $helper = new HTMLTable2JSON(); |
90 | | -$code_output = $helper->tableToJSON('', false, null, array(0), null, null, null, true, null, $table); |
| 90 | +$code_output = $helper->tableToJSON('', false, null, array(0), null, null, null, true, null, null, $table); |
91 | 91 | $test_output = "[{\"Last Name\":\"Smith\", \"Points\":\"50\"},{\"Last Name\":\"Jackson\", \"Points\":\"94\"},{\"Last Name\":\"Doe\", \"Points\":\"80\"}]"; |
92 | 92 | if($code_output == $test_output) |
93 | 93 | $passed++; |
|
101 | 101 | // Tests: Ignore hidden row |
102 | 102 | $table = "<table id=\"test-table\"><thead><tr><th>First Name</th><th>Last Name</th><th>Points</th></tr></thead><tbody><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr style=\"display: none;\"><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
103 | 103 | $helper = new HTMLTable2JSON(); |
104 | | -$code_output = $helper->tableToJSON('', false, null, array(0), null, null, null, true, true, $table); |
| 104 | +$code_output = $helper->tableToJSON('', false, null, array(0), null, null, null, true, true, null, $table); |
105 | 105 | $test_output = "[{\"Last Name\":\"Smith\", \"Points\":\"50\"},{\"Last Name\":\"Jackson\", \"Points\":\"94\"}]"; |
106 | 106 |
|
107 | 107 | if($code_output == $test_output) |
|
115 | 115 | // Tests: Include hidden row |
116 | 116 | $table = "<table id=\"test-table\"><thead><tr><th>First Name</th><th>Last Name</th><th>Points</th></tr></thead><tbody><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr style=\"display: none;\"><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
117 | 117 | $helper = new HTMLTable2JSON(); |
118 | | -$code_output = $helper->tableToJSON(' ', false, null, array(0), null, null, null, true, false, $table); |
119 | | -$another_output = $helper->tableToJSON(' ', false, null, array(0), null, null, null, true, null, $table); |
| 118 | +$code_output = $helper->tableToJSON(' ', false, null, array(0), null, null, null, true, false, null, $table); |
| 119 | +$another_output = $helper->tableToJSON(' ', false, null, array(0), null, null, null, true, null, null, $table); |
120 | 120 | $test_output = "[{\"Last Name\":\"Smith\", \"Points\":\"50\"},{\"Last Name\":\"Jackson\", \"Points\":\"94\"},{\"Last Name\":\"Doe\", \"Points\":\"80\"}]"; |
121 | 121 | if($code_output == $test_output && $test_output == $another_output) |
122 | 122 | $passed++; |
|
129 | 129 | // Tests: Treat first row as column headers regardless of tags |
130 | 130 | $table = "<table id=\"test-table\"><tr><td>First Name</td><td>Last Name</td><td>Points</td></tr><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
131 | 131 | $helper = new HTMLTable2JSON(); |
132 | | -$code_output = $helper->tableToJSON(' ', false, null, null, null, null, null, true, null, $table); |
| 132 | +$code_output = $helper->tableToJSON(' ', false, null, null, null, null, null, true, null, null, $table); |
133 | 133 | $test_output = "[{\"First Name\":\"Jill\", \"Last Name\":\"Smith\", \"Points\":\"50\"},{\"First Name\":\"Eve\", \"Last Name\":\"Jackson\", \"Points\":\"94\"},{\"First Name\":\"John\", \"Last Name\":\"Doe\", \"Points\":\"80\"}]"; |
134 | 134 | if($code_output == $test_output) |
135 | 135 | $passed++; |
|
142 | 142 | // Tests: onlyColumns option - only columns 1 $ 2 (ignores column 0) |
143 | 143 | $table = "<table id=\"test-table\"><thead><tr><th>First Name</th><th>Last Name</th><th>Points</th></tr></thead><tbody><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
144 | 144 | $helper = new HTMLTable2JSON(); |
145 | | -$code_output = $helper->tableToJSON('', false, null, null, null, null, array(1, 2), true, null, $table); |
| 145 | +$code_output = $helper->tableToJSON('', false, null, null, null, null, array(1, 2), true, null, null, $table); |
146 | 146 | $test_output = "[{\"Last Name\":\"Smith\", \"Points\":\"50\"},{\"Last Name\":\"Jackson\", \"Points\":\"94\"},{\"Last Name\":\"Doe\", \"Points\":\"80\"}]"; |
147 | 147 | if($code_output == $test_output) |
148 | 148 | $passed++; |
|
156 | 156 | // Test uses only columns 1 & 2, ignore column 1 (should ignore column 0) |
157 | 157 | $table = "<table id=\"test-table\"><thead><tr><th>First Name</th><th>Last Name</th><th>Points</th></tr></thead><tbody><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
158 | 158 | $helper = new HTMLTable2JSON(); |
159 | | -$code_output = $helper->tableToJSON('', false, null, array(1), null, null, array(1, 2), true, null, $table); |
| 159 | +$code_output = $helper->tableToJSON('', false, null, array(1), null, null, array(1, 2), true, null, null, $table); |
160 | 160 | $test_output = "[{\"Last Name\":\"Smith\", \"Points\":\"50\"},{\"Last Name\":\"Jackson\", \"Points\":\"94\"},{\"Last Name\":\"Doe\", \"Points\":\"80\"}]"; |
161 | 161 | if($code_output == $test_output) |
162 | 162 | $passed++; |
|
171 | 171 | // Tests: include hidden row |
172 | 172 | $table = "<table id=\"test-table\"><tr><th>First Name</th><th>Last Name</th><th>Points</th></tr><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
173 | 173 | $helper = new HTMLTable2JSON(); |
174 | | -$code_output = $helper->tableToJSON(' ', false, null, null, array(2 => 'Score'), null, null, true, null, $table); |
| 174 | +$code_output = $helper->tableToJSON(' ', false, null, null, array(2 => 'Score'), null, null, true, null, null, $table); |
175 | 175 | $test_output = "[{\"First Name\":\"Jill\", \"Last Name\":\"Smith\", \"Score\":\"50\"},{\"First Name\":\"Eve\", \"Last Name\":\"Jackson\", \"Score\":\"94\"},{\"First Name\":\"John\", \"Last Name\":\"Doe\", \"Score\":\"80\"}]"; |
176 | 176 | if($code_output == $test_output) |
177 | 177 | $passed++; |
|
185 | 185 | // Note: You MUST set firstRowIsData to TRUE if there is not a header row in the table. |
186 | 186 | $table = "<table id=\"test-table\"><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
187 | 187 | $helper = new HTMLTable2JSON(); |
188 | | -$code_output = $helper->tableToJSON(' ', false, null, null, array(0 => 'First Name', 1 => 'Last Name', 2 => 'Score'), TRUE, null, true, null, $table); |
| 188 | +$code_output = $helper->tableToJSON(' ', false, null, null, array(0 => 'First Name', 1 => 'Last Name', 2 => 'Score'), TRUE, null, true, null, null, $table); |
189 | 189 | $test_output = "[{\"First Name\":\"Jill\", \"Last Name\":\"Smith\", \"Score\":\"50\"},{\"First Name\":\"Eve\", \"Last Name\":\"Jackson\", \"Score\":\"94\"},{\"First Name\":\"John\", \"Last Name\":\"Doe\", \"Score\":\"80\"}]"; |
190 | 190 | if($code_output == $test_output) |
191 | 191 | $passed++; |
|
197 | 197 |
|
198 | 198 | // Tests: test when headers are not provided by the table, and are not provided as an argument |
199 | 199 | $table = "<table id=\"test-table\"><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
200 | | -$code_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, null, true, null, $table); |
| 200 | +$code_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, null, true, null, null, $table); |
201 | 201 | $table = "<table id=\"test-table\"><tr><th>Jill</th><th>Smith</th><th>50</th></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
202 | | -$another_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, null, true, null, $table); |
| 202 | +$another_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, null, true, null, null, $table); |
203 | 203 | $table = "<table id=\"test-table\"><thead><tr><th>Jill</th><th>Smith</th><th>50</th></tr></thead><tbody><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
204 | | -$third_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, null, true, null, $table); |
| 204 | +$third_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, null, true, null, null, $table); |
205 | 205 | $test_output = "[{\"Column 0\":\"Jill\", \"Column 1\":\"Smith\", \"Column 2\":\"50\"},{\"Column 0\":\"Eve\", \"Column 1\":\"Jackson\", \"Column 2\":\"94\"},{\"Column 0\":\"John\", \"Column 1\":\"Doe\", \"Column 2\":\"80\"}]"; |
206 | 206 | if($code_output == $test_output && $test_output == $another_output && $test_output == $third_output) |
207 | 207 | $passed++; |
|
213 | 213 |
|
214 | 214 | // Tests: Interaction with ignoresColumns |
215 | 215 | $table = "<table id=\"test-table\"><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
216 | | -$code_output = $helper->tableToJSON(' ', false, null, array(0), null, TRUE, null, true, null, $table); |
| 216 | +$code_output = $helper->tableToJSON(' ', false, null, array(0), null, TRUE, null, true, null, null, $table); |
217 | 217 | $table = "<table id=\"test-table\"><tr><th>Jill</th><th>Smith</th><th>50</th></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
218 | | -$another_output = $helper->tableToJSON(' ', false, null, array(0), null, TRUE, null, true, null, $table); |
| 218 | +$another_output = $helper->tableToJSON(' ', false, null, array(0), null, TRUE, null, true, null, null, $table); |
219 | 219 | $table = "<table id=\"test-table\"><thead><tr><th>Jill</th><th>Smith</th><th>50</th></tr></thead><tbody><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
220 | | -$third_output = $helper->tableToJSON(' ', false, null, array(0), null, TRUE, null, true, null, $table); |
| 220 | +$third_output = $helper->tableToJSON(' ', false, null, array(0), null, TRUE, null, true, null, null, $table); |
221 | 221 | $test_output = "[{\"Column 1\":\"Smith\", \"Column 2\":\"50\"},{\"Column 1\":\"Jackson\", \"Column 2\":\"94\"},{\"Column 1\":\"Doe\", \"Column 2\":\"80\"}]"; |
222 | 222 | if($code_output == $test_output && $test_output == $another_output && $test_output == $third_output) |
223 | 223 | $passed++; |
|
229 | 229 |
|
230 | 230 | // Tests: Interaction with onlyColumns |
231 | 231 | $table = "<table id=\"test-table\"><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
232 | | -$code_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, array(1, 2), true, null, $table); |
| 232 | +$code_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, array(1, 2), true, null, null, $table); |
233 | 233 | $table = "<table id=\"test-table\"><tr><th>Jill</th><th>Smith</th><th>50</th></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>"; |
234 | | -$another_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, array(1, 2), true, null, $table); |
| 234 | +$another_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, array(1, 2), true, null, null, $table); |
235 | 235 | $table = "<table id=\"test-table\"><thead><tr><th>Jill</th><th>Smith</th><th>50</th></tr></thead><tbody><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></tbody></table>"; |
236 | | -$third_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, array(1, 2), true, null, $table); |
| 236 | +$third_output = $helper->tableToJSON(' ', false, null, null, null, TRUE, array(1, 2), true, null, null, $table); |
237 | 237 | $test_output = "[{\"Column 1\":\"Smith\", \"Column 2\":\"50\"},{\"Column 1\":\"Jackson\", \"Column 2\":\"94\"},{\"Column 1\":\"Doe\", \"Column 2\":\"80\"}]"; |
238 | 238 | if($code_output == $test_output && $test_output == $another_output && $test_output == $third_output) |
239 | 239 | $passed++; |
|
0 commit comments