Skip to content

Commit

Permalink
Merge pull request #7 from cidilabs/objectMustContainTextAriaLabel
Browse files Browse the repository at this point in the history
Object must contain text aria label
  • Loading branch information
cidilabs authored Oct 6, 2021
2 parents f13326d + 46d2540 commit f781dc5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/Rule/CssTextStyleEmphasize.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,11 @@ public function check()
* @param object $element A DOMElement object
*/
function isHeading($element) {
if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3'
|| $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6') {
return true;
if (property_exists($element, 'tagName')) {
if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3'
|| $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6') {
return true;
}
}

return false;
Expand Down
29 changes: 18 additions & 11 deletions src/Rule/ObjectMustContainText.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ public function id()
return self::class;
}

public function check()
{
foreach ($this->getAllElements('object') as $object) {
if ((!$object->nodeValue || trim($object->nodeValue) == '') && (!$object->hasAttribute('alt') || trim($object->getAttribute('alt')) == ''))
{
$this->setIssue($object);
}
}

return count($this->issues);
}
/**
* All objects contain a text equivalent of the object.
* object element must contain a text equivalent for the object in case the object can't be rendered.
* @link http://quail-lib.org/test-info/objectMustContainText
*/
function check()
{
foreach ($this->getAllElements('object') as $object) {
if ((!$object->nodeValue || trim($object->nodeValue) == '')
&& !($object->hasAttribute('aria-label') && strlen($object->getAttribute('aria-label')) > 0)
&& !($object->hasAttribute('aria-labelledby') && strlen($object->getAttribute('aria-labelledby')) > 0)
&& (!$object->hasAttribute('alt') || trim($object->getAttribute('alt')) == '')){
$this->setIssue($object);
}

return count($this->issues);
}
}

}
20 changes: 20 additions & 0 deletions tests/ObjectMustContainTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,24 @@ public function testCheckFalse()

$this->assertEquals(1, $rule->check(), 'Object Must Contain Text should have one issue.');
}

public function testCheckAriaLabel()
{
$html = '<div><object aria-label="label" type="application/pdf"data="/media/examples/In-CC0.pdf"width="250"height="200"></object></div>';;
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML($html);
$rule = new ObjectMustContainText($dom);

$this->assertEquals(0, $rule->check(), 'Object Must Contain Text should have no issues');
}

public function testCheckAriaLabeledBy()
{
$html = '<div><object aria-labelledby="label" type="application/pdf"data="/media/examples/In-CC0.pdf"width="250"height="200"></object></div>';;
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML($html);
$rule = new ObjectMustContainText($dom);

$this->assertEquals(0, $rule->check(), 'Object Must Contain Text should have no issues');
}
}

0 comments on commit f781dc5

Please sign in to comment.