1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * tool_brickfield check test. 19 * 20 * @package tool_brickfield 21 * @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace tool_brickfield\local\htmlchecker\common\checks; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 require_once ('all_checks.php'); 30 31 /** 32 * Class table_th_should_have_scope_test 33 */ 34 class table_th_should_have_scope_test extends all_checks { 35 /** @var string Check type */ 36 public $checktype = 'table_th_should_have_scope'; 37 38 /** @var string Html fail 1 */ 39 private $htmlfail1 = <<<EOD 40 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 41 <html> 42 <head> 43 <title>Scope exists whilst specifying "col" - fail</title> 44 </head> 45 <body> 46 <table> 47 <thead> 48 <tr> 49 <th></th> 50 <th scope="col">1</th> 51 <th></th> 52 </tr> 53 </thead> 54 <tbody> 55 <tr> 56 <td>2</td> 57 <td>3</td> 58 </tr> 59 <tr> 60 <td>4</td> 61 <td>5</td> 62 </tr> 63 </tbody> 64 </table> 65 </body> 66 </html> 67 EOD; 68 69 /** @var string Html fail 2 */ 70 private $htmlfail2 = <<<EOD 71 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 72 <html> 73 <head> 74 <title>Scope exists whilst specifying "row" - fail</title> 75 </head> 76 <body> 77 <table> 78 <thead> 79 <tr> 80 <th scope="col">1</th> 81 <th scope="col">2</th> 82 <th scope="col">3</th> 83 </tr> 84 </thead> 85 <tbody> 86 <tr> 87 <td>2</td> 88 <td>3</td> 89 <th>4</th> 90 </tr> 91 <tr> 92 <td>4</td> 93 <td>5</td> 94 </tr> 95 </tbody> 96 </table> 97 </body> 98 </html> 99 EOD; 100 101 /** @var string Html pass 1 */ 102 private $htmlpass1 = <<<EOD 103 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 104 <html> 105 <head> 106 <title>Scope exists whilst specifying something that isn't "col" or "row" - pass</title> 107 </head> 108 <body> 109 <table> 110 <thead> 111 <tr> 112 <th scope="col">1</th> 113 <th scope="col">2</th> 114 <th scope="col">3</th> 115 </tr> 116 </thead> 117 <tbody> 118 <tr> 119 <td>2</td> 120 <td>3</td> 121 </tr> 122 <tr> 123 <td>4</td> 124 <td>5</td> 125 </tr> 126 </tbody> 127 </table> 128 </body> 129 </html> 130 EOD; 131 132 /** @var string Html pass 2 */ 133 private $htmlpass2 = <<<EOD 134 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 135 <html> 136 <head> 137 <title>Scope is not specified - pass</title> 138 </head> 139 <body> 140 <table> 141 <thead> 142 <tr> 143 <th scope="col">1</th> 144 <th scope="col">2</th> 145 <th scope="col">3</th> 146 </tr> 147 </thead> 148 <tbody> 149 <tr> 150 <td>2</td> 151 <td>3</td> 152 <th scope="row">4</th> 153 </tr> 154 <tr> 155 <td>4</td> 156 <td>5</td> 157 </tr> 158 </tbody> 159 </table> 160 </body> 161 </html> 162 EOD; 163 /** 164 * Test that th has scope that is equal to col or row 165 */ 166 public function test_check_fail() { 167 $results = $this->get_checker_results($this->htmlfail1); 168 $this->assertEquals(2, count($results)); 169 $this->assertTrue($results[0]->element->tagName == 'th'); 170 $this->assertTrue($results[1]->element->tagName == 'th'); 171 172 $results = $this->get_checker_results($this->htmlfail2); 173 $this->assertEquals(1, count($results)); 174 $this->assertTrue($results[0]->element->tagName == 'th'); 175 } 176 177 /** 178 * Test that th has scope but != col || row. Test that th has no scope 179 */ 180 public function test_check_pass() { 181 $results = $this->get_checker_results($this->htmlpass1); 182 $this->assertEmpty($results); 183 184 $results = $this->get_checker_results($this->htmlpass2); 185 $this->assertEmpty($results); 186 } 187 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body