See Release Notes
Long Term Support Release
Differences Between: [Versions 311 and 401] [Versions 400 and 401]
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 * Class test_css_text_has_contrast 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 test_css_text_has_contrast_test 33 */ 34 class css_text_has_contrast_test extends all_checks { 35 /** @var string The check type. */ 36 protected $checktype = 'css_text_has_contrast'; 37 38 /** @var string HTML that should get flagged. */ 39 private $htmlfail1 = <<<EOD 40 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 41 <html lang="en"> 42 <head> 43 <title>OAC Testfile - Check #6 - Positive</title> 44 </head> 45 <body> 46 <p style="color:#333333; background-color:#000000; font-weight: bold;">This is not contrasty enough.</p> 47 </body> 48 </html> 49 EOD; 50 51 /** @var string HTML that should get flagged. */ 52 private $htmlfail2 = <<<EOD 53 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 54 <html lang="en"> 55 <head> 56 <title>OAC Testfile - Check #6 - Positive</title> 57 </head> 58 <body> 59 <p style="color:#333333; background-color:#000000; font-size: 18px;">This is not contrasty enough.</p> 60 </body> 61 </html> 62 EOD; 63 64 /** @var string HTML that should get flagged. */ 65 private $htmlfail3 = <<<EOD 66 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 67 <html lang="en"> 68 <head> 69 <title>OAC Testfile - Check #6 - Positive</title> 70 </head> 71 <body> 72 <p style="color:#333333; background-color:#000000; font-size: 18%;">This is not contrasty enough.</p> 73 </body> 74 </html> 75 EOD; 76 77 /** @var string HTML that should get flagged. */ 78 private $htmlfail4 = <<<EOD 79 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 80 <html lang="en"> 81 <head> 82 <title>OAC Testfile - Check #6 - Positive</title> 83 </head> 84 <body> 85 <p style="color:#333333; background-color:#000000; font-size: 18em;">This is not contrasty enough.</p> 86 </body> 87 </html> 88 EOD; 89 90 /** @var string HTML that should get flagged. */ 91 private $htmlfail5 = <<<EOD 92 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 93 <html lang="en"> 94 <head> 95 <title>OAC Testfile - Check #6 - Positive</title> 96 </head> 97 <body> 98 <p style="color:#333333; background-color:#000000; font-size: 18ex;">This is not contrasty enough.</p> 99 </body> 100 </html> 101 EOD; 102 103 /** @var string HTML that should get flagged. */ 104 private $htmlfail6 = <<<EOD 105 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 106 <html lang="en"> 107 <head> 108 <title>OAC Testfile - Check #6 - Positive</title> 109 </head> 110 <body> 111 <p style="color:#333333; background-color:#000000;">This is not contrasty enough.</p> 112 </body> 113 </html> 114 EOD; 115 116 /** @var string HTML that should not get flagged. */ 117 private $htmlpass = <<<EOD 118 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 119 <html lang="en"> 120 <head> 121 <title>OAC Testfile - Check #6 - Positive</title> 122 </head> 123 <body> 124 <p style="color:#333333; background-color:#ffffff;">This is contrasty enough.</p> 125 </body> 126 </html> 127 EOD; 128 129 /** @var string HTML that should get flagged. */ 130 private $namecolours = <<<EOD 131 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 132 <html lang="en"> 133 <head> 134 <title>OAC Testfile - Check #6 - Positive</title> 135 </head> 136 <body> 137 <p style="color: red; background-color: blue;">This is not contrasty enough.</p> 138 </body> 139 </html> 140 EOD; 141 142 /** @var string HTML with invalid colour names. */ 143 private $invalidcolours = <<<EOD 144 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 145 <html lang="en"> 146 <head> 147 <title>OAC Testfile - Check #6 - Positive</title> 148 </head> 149 <body> 150 <p style="color: grog; background-color: numpi;">This is not contrasty enough.</p> 151 </body> 152 </html> 153 EOD; 154 155 /** @var string HTML with invalid colour numeric values. */ 156 private $invalidvalue = <<<EOD 157 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 158 <html lang="en"> 159 <head> 160 <title>OAC Testfile - Check #6 - Positive</title> 161 </head> 162 <body> 163 <p style="color: 10000500; background-color: -10234;">This is not contrasty enough.</p> 164 </body> 165 </html> 166 EOD; 167 168 /** @var string HTML with empty colour values. */ 169 private $emptyvalue = <<<EOD 170 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd"> 171 <html lang="en"> 172 <head> 173 <title>OAC Testfile - Check #6 - Positive</title> 174 </head> 175 <body> 176 <p style="color:; background-color:;">This is not contrasty enough.</p> 177 </body> 178 </html> 179 EOD; 180 181 /** @var string HTML with px18 fail colour values. */ 182 private $px18 = <<<EOD 183 <body><p style="color:#EF0000; background-color:white; font-size: 18px"> 184 This is not contrasty enough.</p></body> 185 EOD; 186 187 /** @var string HTML with px19bold pass colour values. */ 188 private $px19bold = <<<EOD 189 <body><p style="color:#EF0000; background-color:white; font-size: 19px; font-weight: bold;"> 190 This is contrasty enough.</p></body> 191 EOD; 192 193 /** @var string HTML with px18 pass colour values. */ 194 private $px18pass = <<<EOD 195 <body><p style="color:#E60000; background-color:white; font-size: 18px"> 196 This is contrasty enough.</p></body> 197 EOD; 198 199 /** @var string HTML with medium size colour values. */ 200 private $mediumfail = <<<EOD 201 <body><p style="color:#EF0000; background-color:white; font-size: medium"> 202 This is not contrasty enough.</p></body> 203 EOD; 204 205 /** @var string HTML with px18 colour values. */ 206 private $mediumpass = <<<EOD 207 <body><p style="color:#E60000; background-color:white; font-size: medium"> 208 This is contrasty enough.</p></body> 209 EOD; 210 211 /** @var string HTML with larger fail colour values. */ 212 private $largerfail = <<<EOD 213 <body><p style="color:#FF6161; background-color:white; font-size: larger"> 214 This is not contrasty enough.</p></body> 215 EOD; 216 217 /** @var string HTML with px18 colour values. */ 218 private $largerpass = <<<EOD 219 <body><p style="color:#FF5C5C; background-color:white; font-size: larger;"> 220 This is contrasty enough.</p></body> 221 EOD; 222 223 /** @var string HTML with px18 colour values. */ 224 private $largerboldpass = <<<EOD 225 <body><p style="color:#FF5C5C; background-color:white; font-size: larger; font-weight: bold;"> 226 This is contrasty enough.</p></body> 227 EOD; 228 229 /** 230 * Test for the area assign intro 231 */ 232 public function test_check() { 233 $results = $this->get_checker_results($this->htmlfail1); 234 $this->assertTrue($results[0]->element->tagName == 'p'); 235 236 $results = $this->get_checker_results($this->htmlfail2); 237 $this->assertTrue($results[0]->element->tagName == 'p'); 238 239 $results = $this->get_checker_results($this->htmlfail3); 240 $this->assertTrue($results[0]->element->tagName == 'p'); 241 242 $results = $this->get_checker_results($this->htmlfail4); 243 $this->assertTrue($results[0]->element->tagName == 'p'); 244 245 $results = $this->get_checker_results($this->htmlfail5); 246 $this->assertTrue($results[0]->element->tagName == 'p'); 247 248 $results = $this->get_checker_results($this->htmlfail6); 249 $this->assertTrue($results[0]->element->tagName == 'p'); 250 251 $results = $this->get_checker_results($this->htmlpass); 252 $this->assertEmpty($results); 253 } 254 255 /** 256 * Test with valid colour names. 257 */ 258 public function test_check_for_namedcolours() { 259 $results = $this->get_checker_results($this->namecolours); 260 $this->assertTrue($results[0]->element->tagName == 'p'); 261 } 262 263 /** 264 * Test with invalid colour names. 265 */ 266 public function test_check_for_invalidcolours() { 267 $results = $this->get_checker_results($this->invalidcolours); 268 $this->assertTrue($results[0]->element->tagName == 'p'); 269 } 270 271 /** 272 * Test with invalid colour numeric values. 273 */ 274 public function test_check_for_invalidvalues() { 275 $results = $this->get_checker_results($this->invalidvalue); 276 $this->assertTrue($results[0]->element->tagName == 'p'); 277 } 278 279 /** 280 * Test with empty colour values. 281 */ 282 public function test_check_for_emptyvalues() { 283 $results = $this->get_checker_results($this->emptyvalue); 284 $this->assertEmpty($results); 285 } 286 287 /** 288 * Test for text px18 with insufficient contrast of 4.49. 289 */ 290 public function test_check_for_px18_fail() { 291 $results = $this->get_checker_results($this->px18); 292 $this->assertTrue($results[0]->element->tagName == 'p'); 293 } 294 295 /** 296 * Test for text px19 bold with sufficient contrast of 4.49. 297 */ 298 public function test_check_for_px19bold_pass() { 299 $results = $this->get_checker_results($this->px19bold); 300 $this->assertEmpty($results); 301 } 302 303 /** 304 * Test for text px18 with sufficient contrast of 4.81. 305 */ 306 public function test_check_for_px18_pass() { 307 $results = $this->get_checker_results($this->px18pass); 308 $this->assertEmpty($results); 309 } 310 311 /** 312 * Test for medium (12pt) text with insufficient contrast of 4.49. 313 */ 314 public function test_check_for_medium_fail() { 315 $results = $this->get_checker_results($this->mediumfail); 316 $this->assertTrue($results[0]->element->tagName == 'p'); 317 } 318 319 /** 320 * Test for medium (12pt) text with sufficient contrast of 4.81. 321 */ 322 public function test_check_for_medium_pass() { 323 $results = $this->get_checker_results($this->mediumpass); 324 $this->assertEmpty($results); 325 } 326 327 /** 328 * Test for larger (14pt) text with insufficient contrast of 2.94. 329 */ 330 public function test_check_for_larger_fail() { 331 $results = $this->get_checker_results($this->largerfail); 332 $this->assertTrue($results[0]->element->tagName == 'p'); 333 } 334 335 /** 336 * Test for larger (14pt) text with insufficient contrast of 3.02. 337 */ 338 public function test_check_for_larger_pass() { 339 $results = $this->get_checker_results($this->largerpass); 340 $this->assertTrue($results[0]->element->tagName == 'p'); 341 } 342 343 /** 344 * Test for larger (14pt) bold text with sufficient contrast of 3.02. 345 */ 346 public function test_check_for_largerbold_pass() { 347 $results = $this->get_checker_results($this->largerboldpass); 348 $this->assertEmpty($results); 349 } 350 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body