From 0ddb18f55cdc70330b32aa3641c9a6695d34a656 Mon Sep 17 00:00:00 2001 From: Michael Pound Date: Wed, 17 Jul 2024 16:35:45 +0100 Subject: [PATCH] MDL-75724 tool_brickfield: Ensuring correct table headers pass checks. --- .../checks/table_data_should_have_th.php | 4 +- .../checks/table_data_should_have_th_test.php | 125 ++++++++++++++++++ 2 files changed, 127 insertions(+), 2 deletions(-) diff --git a/admin/tool/brickfield/classes/local/htmlchecker/common/checks/table_data_should_have_th.php b/admin/tool/brickfield/classes/local/htmlchecker/common/checks/table_data_should_have_th.php index 4d77cb3d42391..cddef948e483f 100644 --- a/admin/tool/brickfield/classes/local/htmlchecker/common/checks/table_data_should_have_th.php +++ b/admin/tool/brickfield/classes/local/htmlchecker/common/checks/table_data_should_have_th.php @@ -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; } @@ -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; } diff --git a/admin/tool/brickfield/tests/local/htmlchecker/common/checks/table_data_should_have_th_test.php b/admin/tool/brickfield/tests/local/htmlchecker/common/checks/table_data_should_have_th_test.php index ba703684ff82b..1abde5de1ce57 100644 --- a/admin/tool/brickfield/tests/local/htmlchecker/common/checks/table_data_should_have_th_test.php +++ b/admin/tool/brickfield/tests/local/htmlchecker/common/checks/table_data_should_have_th_test.php @@ -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 */ @@ -113,6 +115,117 @@ class table_data_should_have_th_test extends all_checks { +EOD; + + /** @var string HTML that should not get flagged. */ + private $htmlpass3 = << + + + Table should have at least one th - pass + + + + + + + + + + + + + +
+ This is table heading +
+ This is a tables data +
+ + +EOD; + + /** @var string HTML that should not get flagged. */ + private $htmlpass4 = << + + + Table should have at least one th - pass + + + + + + + + + +
+ This is table heading +
+ This is a tables data +
+ + +EOD; + + /** @var string HTML that should not get flagged. */ + private $htmlpass5 = << + + + Table should have at least one th - pass + + + + + + + + + + + + + + + + +
+ This is table heading +
+ This is a table heading in table data +
+ This is a tables data +
+ + +EOD; + + /** @var string HTML that should not get flagged. */ + private $htmlpass6 = << + + + Table should have at least one th - pass + + + + + + + + + + + +
+ This is a table heading in table data +
+ This is a tables data +
+ + EOD; /** * Test that th does not exist @@ -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); } }