Skip to content

Commit

Permalink
Generic HTML Table also working with thead, tbody structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
lievenjanssen committed Sep 18, 2011
1 parent 944d1d2 commit dac46f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions model/resources/strategies/HTMLTable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function onCall($package,$resource){

$domxpath = new DOMXPath( $html );
$tablerows = $domxpath->query($xpath . "/tr" );
if ($tablerows->length == 0) {
//table has thead and tbody
$tablerows = $domxpath->query($xpath . "/*/tr" );
}

$rowIndex = 1;
foreach ($tablerows as $tr) {
Expand All @@ -86,6 +90,10 @@ public function onCall($package,$resource){
$domxpath = new DOMXPath( $newDom );
if ($rowIndex == 1) {
$tablecols = $domxpath->query("td");
if ($tablecols->length == 0) {
//thead row has th instead of td
$tablecols = $domxpath->query("th" );
}
$columnIndex = 1;
foreach($tablecols as $td) {
$fieldhash[ $td->nodeValue ] = $columnIndex;
Expand Down
12 changes: 8 additions & 4 deletions unittests/temp/person.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<html>
<table>
<tr><td>name<td>age</td><td>city</td></tr>
<tr><td>Jan<td>22</td><td>Veridian City</td></tr>
<tr><td>Pieter</td><td>22</td><td>Pallet Town</td></tr>
<tr><td>Ash</td><td>21</td><td>Pallet Town</td></tr>
<thead>
<tr><th>name<th>age</th><th>city</th></tr>
</thead>
<tbody>
<tr><td>Jan<td>22</td><td>Veridian City</td></tr>
<tr><td>Pieter</td><td>22</td><td>Pallet Town</td></tr>
<tr><td>Ash</td><td>21</td><td>Pallet Town</td></tr>
</tbody>
</table>
</html>
3 changes: 1 addition & 2 deletions unittests/tests/APITestGenericHTMLTable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class APITestGenericHTMLTable extends TDTUnitTest{

//private $location = "http://www.nieuws.be/";
//private $xpath = "//table[@id='htmlGrid_a119d7e2-e979-436a-8cad-765d37fc0fdd']";
private $location = "/unittests/temp/person.html";
private $location = "unittests/temp/person.html";
private $xpath = "//table";
private $install_as = "htmltablepackage/person/";
private $generic_type = "HTMLTable";
Expand Down Expand Up @@ -56,7 +56,6 @@ function testGetHTMLTable() {
if($request->http_code != 200 && $request->result)
$this->debug($request->result);
}

function testDeleteHTMLTable() {
$url = Config::$HOSTNAME . Config::$SUBDIR . $this->install_as;
$request = new REST($url, array(), "DELETE");
Expand Down

0 comments on commit dac46f4

Please sign in to comment.