diff --git a/src/Rule/CssTextStyleEmphasize.php b/src/Rule/CssTextStyleEmphasize.php index faf7416..250a269 100644 --- a/src/Rule/CssTextStyleEmphasize.php +++ b/src/Rule/CssTextStyleEmphasize.php @@ -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; diff --git a/src/Rule/ObjectMustContainText.php b/src/Rule/ObjectMustContainText.php index 43f9db8..7b23fb5 100644 --- a/src/Rule/ObjectMustContainText.php +++ b/src/Rule/ObjectMustContainText.php @@ -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); + } + } } \ No newline at end of file diff --git a/tests/ObjectMustContainTextTest.php b/tests/ObjectMustContainTextTest.php index 29aeebe..d6017e4 100644 --- a/tests/ObjectMustContainTextTest.php +++ b/tests/ObjectMustContainTextTest.php @@ -32,4 +32,24 @@ public function testCheckFalse() $this->assertEquals(1, $rule->check(), 'Object Must Contain Text should have one issue.'); } + + public function testCheckAriaLabel() + { + $html = '
';; + $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 = '';; + $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'); + } } \ No newline at end of file