Skip to content

Commit d571862

Browse files
committed
Merge pull request #87 from ucfcdl/UDOIT_issue14
Udoit Issue #7, #14, & #86
2 parents bbb6b00 + 0546932 commit d571862

File tree

17 files changed

+791
-166
lines changed

17 files changed

+791
-166
lines changed

config/localConfig.template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
$db_reports_table = 'reports';
2727
$dsn = "{$db_type}:host={$db_host};port={$db_port};dbname={$db_name}";
2828

29-
$debug = false;
29+
$debug = false;

config/tests.php

100644100755
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,17 @@
225225
<pre><code>'. htmlspecialchars('<h1>Header 1</h1>') .'</code></pre>
226226
',
227227
],
228+
[
229+
'name' => 'cssTextStyleEmphasize',
230+
'title' => 'Avoid using color alone for emphasis',
231+
'desc' => '<p>When emphasizing text, you may use color with sufficient contrast as long as you also apply some other form of emphasis, such as bold or italics. This ensures that screen reader users are aware of the text\'s importance.</p>',
232+
'resources' => [
233+
'<a href="https://www.w3.org/TR/WCAG20-TECHS/H49.html">Resource Link</a>'
234+
],
235+
'example' => '
236+
<p>This example shows how to use the em and strong elements to emphasize text. The em and strong elements were designed to indicate structural emphasis that may be rendered in a variety of ways (font style changes, speech inflection changes, etc.).</p>
237+
<pre><code>...What she <em>really</em> meant to say was, &quot;This is not ok, it is <strong>excellent</strong>&quot;!...</code></pre>
238+
',
239+
],
228240
],
229241
];

lib/Ufixit.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ public function fixAltText($error_html, $new_content, $submitting_again = false)
128128
* @param array $error_colors - The color(s) that need to be replaced
129129
* @param string $error_html - The bad html that needs to be fixed
130130
* @param string|array $new_content - The new CSS color(s) from the user
131+
* @param bool $bold - Boolean whether resulting text should be stylized bold
132+
* @param bool $italic - Boolean whether resulting text should be stylized italicised
131133
* @param bool $submitting_again - If the user is resubmitting their error fix
132134
* @return string $fixed_css - The html with corrected CSS
133135
*/
134-
public function fixCss($error_colors, $error_html, $new_content, $bold, $italic, $submitting_again = false)
136+
public function fixCssColor($error_colors, $error_html, $new_content, $bold, $italic, $submitting_again = false)
135137
{
136138
preg_match_all('/<(\w+)\s+\w+.*?>/s', $error_html, $matches);
137139

@@ -145,12 +147,43 @@ public function fixCss($error_colors, $error_html, $new_content, $bold, $italic,
145147

146148
$tag = $this->dom->getElementsByTagName( $matches[1][0] )->item(0);
147149

148-
if ($bold == 'bold') {
150+
if ($bold) {
149151
$tag->setAttribute('style', $tag->getAttribute('style').' font-weight: bold;');
150152

151153
}
152154

153-
if ($italic == 'italic') {
155+
if ($italic) {
156+
$tag->setAttribute('style', $tag->getAttribute('style').' font-style: italic;');
157+
}
158+
159+
$fixed_css = $this->dom->saveHTML($tag);
160+
161+
return $fixed_css;
162+
}
163+
164+
/**
165+
* Adds font styles to colored text for emphasis
166+
* @param string $error_html - The bad html that needs to be fixed
167+
* @param string|array $new_content - The new CSS color(s) from the user
168+
* @param bool $bold - Boolean whether resulting text should be stylized bold
169+
* @param bool $italic - Boolean whether resulting text should be stylized italicised
170+
* @param bool $submitting_again - If the user is resubmitting their error fix
171+
* @return string $fixed_css - The html with corrected CSS
172+
*/
173+
public function fixCssEmphasize($error_html, $new_content, $bold, $italic, $submitting_again = false)
174+
{
175+
preg_match_all('/<(\w+)\s+\w+.*?>/s', $error_html, $matches);
176+
177+
$this->dom->loadHTML('<?xml encoding="utf-8" ?>' . $error_html );
178+
179+
$tag = $this->dom->getElementsByTagName( $matches[1][0] )->item(0);
180+
181+
if ($bold) {
182+
$tag->setAttribute('style', $tag->getAttribute('style').' font-weight: bold;');
183+
184+
}
185+
186+
if ($italic) {
154187
$tag->setAttribute('style', $tag->getAttribute('style').' font-style: italic;');
155188
}
156189

lib/quail/quail/common/accessibility_tests.php

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,14 +1186,124 @@ function check()
11861186
}
11871187

11881188
$luminosity = $this->getLuminosity($style['color'], $background);
1189+
$font_size = 0;
1190+
$bold = false;
11891191

1190-
if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3' || $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6') {
1192+
if (isset($style['font-size'])) {
1193+
preg_match_all('!\d+!', $style['font-size'], $matches);
1194+
$font_size = $matches[0][0];
1195+
}
1196+
1197+
if (isset($style['font-weight'])) {
1198+
preg_match_all('!\d+!', $style['font-weight'], $matches);
1199+
1200+
if (count($matches) > 0) {
1201+
if ($matches >= 700) {
1202+
$bold = true;
1203+
} else {
1204+
if ($style['font-weight'] === 'bold' || $style['font-weight'] === 'bolder') {
1205+
$bold = true;
1206+
}
1207+
}
1208+
}
1209+
}
1210+
1211+
if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3' || $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6' || $font_size >= 18 || $font_size >= 14 && $bold) {
11911212
if ($luminosity < 3) {
1192-
$this->addReport($element, 'background: '. $background .' fore: '. $style['color'] . ' lum: '. $luminosity . 'type: heading');
1213+
$this->addReport($element, 'heading');
11931214
}
11941215
} else {
11951216
if ($luminosity < 4.5) {
1196-
$this->addReport($element, 'background: '. $background .' fore: '. $style['color'] . ' lum: '. $luminosity . 'type: text');
1217+
$this->addReport($element, 'text');
1218+
}
1219+
}
1220+
}
1221+
}
1222+
}
1223+
}
1224+
1225+
/**
1226+
* Checks that all color and background elements has stufficient contrast.
1227+
*
1228+
* @link http://quail-lib.org/test-info/cssTextHasContrast
1229+
*/
1230+
class cssTextStyleEmphasize extends quailColorTest
1231+
{
1232+
/**
1233+
* @var int $default_severity The default severity code for this test.
1234+
*/
1235+
var $default_severity = QUAIL_TEST_SUGGESTION;
1236+
1237+
/**
1238+
* @var string $default_background The default background color
1239+
*/
1240+
var $default_background = '#ffffff';
1241+
1242+
/**
1243+
* @var string $default_background The default background color
1244+
*/
1245+
var $default_color = '#000000';
1246+
1247+
/**
1248+
* The main check function. This is called by the parent class to actually check content
1249+
*/
1250+
function check()
1251+
{
1252+
if (isset($this->options['css_background'])) {
1253+
$this->default_background = $this->options['css_background'];
1254+
}
1255+
1256+
if (isset($this->options['css_foreground'])) {
1257+
$this->default_color = $this->options['css_foreground'];
1258+
}
1259+
1260+
$xpath = new DOMXPath($this->dom);
1261+
$entries = $xpath->query('//*');
1262+
1263+
foreach ($entries as $element) {
1264+
$style = $this->css->getStyle($element);
1265+
1266+
if (!isset($style['background-color'])) {
1267+
$style['background-color'] = $this->default_background;
1268+
}
1269+
1270+
if ((isset($style['background']) || isset($style['background-color'])) && isset($style['color']) && $element->nodeValue) {
1271+
$background = (isset($style['background-color'])) ? $style['background-color'] : $style['background'];
1272+
1273+
if (!$background || $this->options['css_only_use_default']) {
1274+
$background = $this->default_background;
1275+
}
1276+
1277+
$luminosity = $this->getLuminosity($style['color'], $background);
1278+
$font_size = 0;
1279+
$bold = false;
1280+
1281+
if (isset($style['font-size'])) {
1282+
preg_match_all('!\d+!', $style['font-size'], $matches);
1283+
$font_size = $matches[0][0];
1284+
}
1285+
1286+
if (isset($style['font-weight'])) {
1287+
preg_match_all('!\d+!', $style['font-weight'], $matches);
1288+
1289+
if (count($matches) > 0) {
1290+
if ($matches >= 700) {
1291+
$bold = true;
1292+
} else {
1293+
if ($style['font-weight'] === 'bold' || $style['font-weight'] === 'bolder') {
1294+
$bold = true;
1295+
}
1296+
}
1297+
}
1298+
}
1299+
1300+
if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3' || $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6' || $font_size >= 18 || $font_size >= 14 && $bold) {
1301+
if ($luminosity >= 3 && !$bold) {
1302+
$this->addReport($element, 'heading');
1303+
}
1304+
} else {
1305+
if ($luminosity >= 4.5 && !$bold) {
1306+
$this->addReport($element, 'text');
11971307
}
11981308
}
11991309
}

lib/quail/quail/guidelines/section508.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Section508Guideline extends quailGuideline{
8282
// 'passwordHasLabel',
8383
// 'checkboxHasLabel',
8484
'cssTextHasContrast',
85+
'cssTextStyleEmphasize',
8586
// 'fileHasLabel',
8687
// 'radioHasLabel',
8788
// 'frameIsNotUsed',

lib/quail/quail/guidelines/translations/en.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
"imgNonDecorativeHasAlt","Images should have a non-empty ""alt"" attribute","<p>Alternative Text (Alt Text) is an alternative (non-visual) way to describe the meaning of an image. Please provide a brief (under 100 characters) description of the image for a <a href='http://en.wikipedia.org/wiki/Screen_reader'>screen reader</a> user. Note: It should not be the image file name.</p>","2"
55
"imgImportantNoSpacerAlt","Images that are important should not have a purely white-space ""alt"" attribute","<p>Any image that is not used decoratively or which is purely for layout purposes cannot have an ""alt"" attribute that consists solely of white space (i.e. a space, or a new line). Alternative Text (Alt Text) is an alternative (non-visual) way to describe the meaning of an image. Please provide a brief (under 100 characters) description of the image for a <a href='http://en.wikipedia.org/wiki/Screen_reader'>screen reader</a> user. Note: It should not be the image file name.</p><h4>Example</h4><h5>Wrong</h5><p><code>&lt;img src=""dog.jpg"" alt="" ""&gt;</code></p><h5>Right</h5><p><code>&lt;img src=""dog.jpg"" alt=""A photograph of a dog""&gt;</code></p>","1"
66
"imgAltNotPlaceHolder","Images should not have a simple placeholder text as an ""alt"" attribute","<p>Any image that is not used decorativey or which is purely for layout purposes cannot have an ""alt"" attribute that consists solely of placeholders. Placeholders include:</p><ul><li>nbsp</li><li>&amp;nbsp;</li><li>spacer</li><li>image</li><li>img</li><li>photo</li></ul><h4>Example</h4><h5>Wrong</h5><p><code>&lt;img src=""dog.jpg"" alt=""image""&gt;</code></p><h5>Right</h5><p><code>&lt;img src=""dog.jpg"" alt=""A photograph of a dog""&gt;</code></p>","1"
7-
<<<<<<< HEAD
87
"imgAltNotEmptyInAnchor","Alt text for all img elements used as source anchors should not be empty","<p>Alternative Text (Alt Text) is an alternative (non-visual) way to describe the meaning of an image. Please provide a brief (under 100 characters) description of the image for a <a href='http://en.wikipedia.org/wiki/Screen_reader'>screen reader</a> user. Note: It should not be the image file name.</p>","1"
9-
=======
10-
"imgAltNotEmptyInAnchor","Alt text for all img elements used as source anchors should not be empty","<p>Alternative Text (Alt Text) is an alternative (non-visual) way to describe the meaning of an image. Please provide a brief (under 100 characters) description of the image for a <a href='http://en.wikipedia.org/wiki/Screen_reader'>screen reader</a> user. Note: It should not be the image file name.</p>","1"
11-
>>>>>>> c17ab2c797754d01bcc81741fd02db24f8bc8a11
128
"imgHasLongDesc","A ""longdesc"" attribute is required for any image where additional information not in the ""alt"" attribute is required","<p>Any image that has an ""alt"" attribute that does not fully convey the meaning of the image should have a ""longdesc"" attribute.</p><h4>Example</h4><h5>Wrong</h5><p><code>&lt;img src=""complexImage.png"" alt=""A complex image that cannot be described succinctly.""&gt;</code></p><h5>Right</h5><p><code>&lt;img src=""complexImage.png"" alt=""A complex image that cannot be described succinctly."" longdesc=""longer_description.html""&gt;</code></p>","1"
139
"imgNeedsLongDescWDlink","An image with a ""longdesc"" attribute should have a corresponding description link","<p>Any image that has a ""longdesc"" attribute should also have a corresponding ""d-link,"" or Description link. This should point to the same resource as the ""longdesc"" attribute and should only contain the text ""d"".</p><h4>Example</h4><h5>Wrong</h5><p><code>&lt;img src=""complexImage.png"" alt=""A complex image that cannot be described succinctly."" longdesc=""longer_description.html""&gt;</code></p><h5>Right</h5><p><code>&lt;img src=""complexImage.png"" alt=""A complex image that cannot be described succinctly."" longdesc=""longer_description.html""&gt;&lt;a href=""longer_description.html""&gt;d&lt;/a&gt;</code></p>","1"
1410
"imgGifNoFlicker","Avoid the use of animated GIF’s","<p>Animated GIFs may cause seizures if they flash more than 3 times per second. A recommendation is to use an alternative format to deliver the content.</p>","1"
@@ -236,7 +232,8 @@
236232
"documentReadingDirection","Changes in text decoration should be marked up","<p>Changes in text direction in inline content should be indicated using any HTML element (for example, <code>span</code>) with a ""dir"" attribute indicating left-to-right or right-to-left. For example, a Hebrew phrase within an english paragraph should have it's own text direction indicated.</p>","2"
237233
"formDeleteIsReversable","Deleting items using a form should be reversable","<p>Check that, if a form has the option to delete an item, that the user has a chance to either reverse the delete process, or is asked for confirmation before the item is deleted. This is not something that can be checked through automated testing and requires manual confirmation.</p>","3"
238234
"svgContainsTitle", "Inline SVG should use Title elements","<p>Any inline SVG image should have an embedded <code>title</code> element","1"
239-
"cssTextHasContrast","Insufficient text color contrast with the background","<p>Text color should be easily viewable and should not be the only indicator of meaning or function. Color balance should have at least a 4.5:1 ratio.</p>","1"
235+
"cssTextHasContrast","Insufficient text color contrast with the background","<p>Text color should be easily viewable and should not be the only indicator of meaning or function. Color balance should have at least a 4.5:1 ratio for small text and 3:1 ratio for large text.</p>","1"
236+
"cssTextStyleEmphasize","Avoid using color alone for emphasis","<p>When emphasizing text, you may use color with sufficient contrast as long as you also apply some other form of emphasis, such as bold or italics. This ensures that screen reader users are aware of the text's importance.</p>","1"
240237
"videoProvidesCaptions","All video tags should provide captions","<p>Videos used on online courses are required to have closed captioning. Unfortunately, automatic captioning (such as on YouTube videos) is not accurate enough for educational use. You have three options:</p><ul><li>Contact the creator of the video and request captions be added.</li><li>Create captions yourself using a service like Amara (http://amara.org/).</li><li>Find a different video that has closed captioning.</li></ul>","2"
241238
"videosEmbeddedOrLinkedNeedCaptions","Synchronized <a href='http://webaim.org/techniques/captions/'>captions</a> should be provided for prerecorded web-based video","<p>Captions should be included in the video to provide dialogue to users who are hearing impaired.</p>","1"
242239
"documentIsWrittenClearly","The document should be written to the target audience and read clearly","<p>If a document is beyond a 10th grade level, then a summary or other guide should also be provided to guide the user through the content.</p>","2"

lib/quail/quail/guidelines/wcag1aa.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class Wcag1aaGuideline extends quailGuideline{
123123
'documentTitleDescribesDocument',
124124
'svgContainsTitle',
125125
'cssTextHasContrast',
126+
'cssTextStyleEmphasize',
126127
'headersHaveText',
127128
);
128129
}

lib/quail/quail/guidelines/wcag1aaa.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class Wcag1aaaGuideline extends quailGuideline{
147147
'skipToContentLinkProvided',
148148
'svgContainsTitle',
149149
'cssTextHasContrast',
150+
'cssTextStyleEmphasize',
150151
'headersHaveText',
151152
);
152153

lib/quail/quail/guidelines/wcag2aa.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class Wcag2aaGuideline extends quailGuideline{
165165
'formDeleteIsReversable',
166166
'svgContainsTitle',
167167
'cssTextHasContrast',
168+
'cssTextStyleEmphasize',
168169
'headersHaveText',
169170
);
170171
}

lib/quail/quail/guidelines/wcag2aaa.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class Wcag2aaaGuideline extends quailGuideline
172172
// 'svgContainsTitle',
173173
// 'documentIsWrittenClearly',
174174
'cssTextHasContrast',
175+
'cssTextStyleEmphasize',
175176
'headersHaveText',
176177
'videoEmbedChecked',
177178
'videosEmbeddedOrLinkedNeedCaptions',

0 commit comments

Comments
 (0)