Skip to content

Commit

Permalink
MDL-75724 tool_brickfield: Ensuring correct table headers pass checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichPound authored and learningtechnologyservices committed Sep 11, 2024
1 parent d3749a8 commit 4f79c3a
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function check(): void {
foreach ($tr->childNodes as $th) {
if ($this->property_is_equal($th, 'tagName', 'th')) {
break 3;
} else {
} else if ($th->nodeName != '#text') {
$this->add_report($table);
break 3;
}
Expand All @@ -57,7 +57,7 @@ public function check(): void {
foreach ($child->childNodes as $th) {
if ($this->property_is_equal($th, 'tagName', 'th')) {
break 2;
} else {
} else if ($th->nodeName != '#text') {
$this->add_report($table);
break 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

/**
* Class table_data_should_have_th_test
*
* @covers \tool_brickfield\local\htmlchecker\common\checks\table_data_should_have_th
*/
class table_data_should_have_th_test extends all_checks {
/** @var string Check type */
Expand Down Expand Up @@ -113,6 +115,117 @@ class table_data_should_have_th_test extends all_checks {
</table>
</body>
</html>
EOD;

/** @var string HTML that should not get flagged. */
private $htmlpass3 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table should have at least one th - pass</title>
</head>
<body>
<table>
<thead>
<tr>
<th>
This is table heading
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
This is a tables data
</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;

/** @var string HTML that should not get flagged. */
private $htmlpass4 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table should have at least one th - pass</title>
</head>
<body>
<table>
<tr>
<th>
This is table heading
</th>
</tr>
<tr>
<td>
This is a tables data
</td>
</tr>
</table>
</body>
</html>
EOD;

/** @var string HTML that should not get flagged. */
private $htmlpass5 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table should have at least one th - pass</title>
</head>
<body>
<table>
<thead>
<tr>
<th>
This is table heading
</th>
</tr>
</thead>
<tbody>
<tr>
<th>
This is a table heading in table data
</th>
</tr>
<tr>
<td>
This is a tables data
</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;

/** @var string HTML that should not get flagged. */
private $htmlpass6 = <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Table should have at least one th - pass</title>
</head>
<body>
<table>
<tbody>
<tr>
<th>
This is a table heading in table data
</th>
</tr>
<tr>
<td>
This is a tables data
</td>
</tr>
</tbody>
</table>
</body>
</html>
EOD;
/**
* Test that th does not exist
Expand All @@ -134,5 +247,17 @@ public function test_check_pass() {

$results = $this->get_checker_results($this->htmlpass2);
$this->assertEmpty($results);

$results = $this->get_checker_results($this->htmlpass3);
$this->assertEmpty($results);

$results = $this->get_checker_results($this->htmlpass4);
$this->assertEmpty($results);

$results = $this->get_checker_results($this->htmlpass5);
$this->assertEmpty($results);

$results = $this->get_checker_results($this->htmlpass6);
$this->assertEmpty($results);
}
}

0 comments on commit 4f79c3a

Please sign in to comment.