diff --git a/src/PhpAlly.php b/src/PhpAlly.php index 686642e..93cba87 100644 --- a/src/PhpAlly.php +++ b/src/PhpAlly.php @@ -33,8 +33,9 @@ public function checkMany($content, $ruleIds = [], $options = []) } $rule = new $className($document, $options); - $rule->check(); + $issueCount = $rule->check(); + $report->setIssueCounts($ruleId, $issueCount, $rule->getTotalTests()); $report->setIssues($rule->getIssues()); $report->setErrors($rule->getErrors()); } catch (\Exception $e) { diff --git a/src/PhpAllyReport.php b/src/PhpAllyReport.php index 5905c2c..defca61 100644 --- a/src/PhpAllyReport.php +++ b/src/PhpAllyReport.php @@ -6,6 +6,7 @@ class PhpAllyReport implements \JsonSerializable { protected $issues = []; protected $errors = []; protected $html = ''; + protected $issueCounts = []; public function __construct() { @@ -16,6 +17,7 @@ public function toArray() return [ 'issues' => $this->getIssues(), 'errors' => $this->getErrors(), + 'issueCounts' => $this->getIssueCounts(), ]; } @@ -59,4 +61,14 @@ public function setErrors($errors) $this->errors = array_merge($this->errors, $errors); } + public function getIssueCounts() + { + return $this->issueCounts; + } + + public function setIssueCounts($ruleId, $issueCount, $total) { + $ruleId = str_replace(['CidiLabs\\PhpAlly\\Rule\\','App\\Rule\\'], '', $ruleId); + $this->issueCounts[$ruleId] = array('issueCount' => $issueCount, "totalCount" => $total); + } + } \ No newline at end of file diff --git a/src/Rule/AnchorLinksToMultiMediaRequireTranscript.php b/src/Rule/AnchorLinksToMultiMediaRequireTranscript.php index 7760b5f..a627991 100644 --- a/src/Rule/AnchorLinksToMultiMediaRequireTranscript.php +++ b/src/Rule/AnchorLinksToMultiMediaRequireTranscript.php @@ -32,6 +32,7 @@ public function check() $this->setIssue($a); } } + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/AnchorLinksToSoundFilesNeedTranscripts.php b/src/Rule/AnchorLinksToSoundFilesNeedTranscripts.php index 4be0169..0495bae 100644 --- a/src/Rule/AnchorLinksToSoundFilesNeedTranscripts.php +++ b/src/Rule/AnchorLinksToSoundFilesNeedTranscripts.php @@ -34,7 +34,8 @@ public function check() $this->setIssue($a); } } - } + $this->totalTests++; + } return count($this->issues); } diff --git a/src/Rule/AnchorMustContainText.php b/src/Rule/AnchorMustContainText.php index 89df01e..e38b22e 100644 --- a/src/Rule/AnchorMustContainText.php +++ b/src/Rule/AnchorMustContainText.php @@ -25,6 +25,7 @@ public function check() if (!$this->elementContainsReadableText($a) && ($a->hasAttribute('href'))) { $this->setIssue($a); } + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/AnchorSuspiciousLinkText.php b/src/Rule/AnchorSuspiciousLinkText.php index 5faee2d..56e53bf 100644 --- a/src/Rule/AnchorSuspiciousLinkText.php +++ b/src/Rule/AnchorSuspiciousLinkText.php @@ -25,6 +25,7 @@ public function check() foreach ($this->getAllElements('a') as $a) { if (in_array(strtolower(trim($a->nodeValue)), $this->translation()) || $a->nodeValue == $a->getAttribute('href')) $this->setIssue($a); + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/BaseFontIsNotUsed.php b/src/Rule/BaseFontIsNotUsed.php index 27e193f..f03c485 100644 --- a/src/Rule/BaseFontIsNotUsed.php +++ b/src/Rule/BaseFontIsNotUsed.php @@ -20,6 +20,7 @@ public function check() { foreach ($this->getAllElements('basefont') as $b) { $this->setIssue($b); + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/BaseRule.php b/src/Rule/BaseRule.php index cadab99..3c38365 100644 --- a/src/Rule/BaseRule.php +++ b/src/Rule/BaseRule.php @@ -25,6 +25,7 @@ class BaseRule implements PhpAllyRuleInterface { protected $altTextLengthLimit; protected $minDocLengthForHeaders; protected $maxWordCount; + protected $totalTests = 0; public function __construct(DOMDocument $dom, $options = []) { @@ -217,8 +218,6 @@ private function walkUpTreeForInheritance($element, $style) { } - - public function elementContainsReadableText($element) { if (is_a($element, 'DOMText')) { @@ -266,6 +265,15 @@ public function getIssues() return $this->issues; } + public function getTotalTests() + { + return $this->totalTests; + } + public function IncrementTotalTests() + { + return $this->totalTests++; + } + public function setError($errorMsg) { $this->errors[] = $errorMsg; @@ -323,4 +331,6 @@ function propertyIsEqual($object, $property, $value, $trim = false, $lower = fal } return ($property_value == $value); } + + } \ No newline at end of file diff --git a/src/Rule/BlinkIsNotUsed.php b/src/Rule/BlinkIsNotUsed.php index dce34b0..2215bbf 100644 --- a/src/Rule/BlinkIsNotUsed.php +++ b/src/Rule/BlinkIsNotUsed.php @@ -21,6 +21,7 @@ public function check() { foreach ($this->getAllElements('blink') as $b) { $this->setIssue($b); + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/BrokenLink.php b/src/Rule/BrokenLink.php index c0c0475..2169a70 100644 --- a/src/Rule/BrokenLink.php +++ b/src/Rule/BrokenLink.php @@ -25,6 +25,7 @@ public function check() if ($href) { $links[$href] = $a; } + $this->totalTests++; } $this->checkLink($links); diff --git a/src/Rule/ContentTooLong.php b/src/Rule/ContentTooLong.php index aab1a75..08cd663 100644 --- a/src/Rule/ContentTooLong.php +++ b/src/Rule/ContentTooLong.php @@ -28,6 +28,7 @@ public function check() if($text != null){ $pageText = $pageText . $text; } + $this->totalTests++; } $wordCount = str_word_count($pageText); diff --git a/src/Rule/CssTextHasContrast.php b/src/Rule/CssTextHasContrast.php index c0ea96f..5439020 100644 --- a/src/Rule/CssTextHasContrast.php +++ b/src/Rule/CssTextHasContrast.php @@ -287,6 +287,7 @@ public function check() } } } + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/CssTextStyleEmphasize.php b/src/Rule/CssTextStyleEmphasize.php index b24a7c9..0cc39aa 100644 --- a/src/Rule/CssTextStyleEmphasize.php +++ b/src/Rule/CssTextStyleEmphasize.php @@ -89,6 +89,7 @@ public function check() } $this->setIssue($element); + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/DocumentReadingDirection.php b/src/Rule/DocumentReadingDirection.php index 82a7e8c..48ba1a8 100644 --- a/src/Rule/DocumentReadingDirection.php +++ b/src/Rule/DocumentReadingDirection.php @@ -31,6 +31,7 @@ public function check() if ($element->getAttribute('dir') != 'rtl') $this->setIssue($element); } + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/EmbedHasAssociatedNoEmbed.php b/src/Rule/EmbedHasAssociatedNoEmbed.php index 8d46d30..bef684a 100644 --- a/src/Rule/EmbedHasAssociatedNoEmbed.php +++ b/src/Rule/EmbedHasAssociatedNoEmbed.php @@ -24,7 +24,7 @@ public function check() && !$this->propertyIsEqual($embed->nextSibling, 'tagName', 'noembed')) { $this->setIssue($embed); } - + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/EmbedTagDetected.php b/src/Rule/EmbedTagDetected.php index b9f46a2..b3b09d5 100644 --- a/src/Rule/EmbedTagDetected.php +++ b/src/Rule/EmbedTagDetected.php @@ -19,6 +19,7 @@ public function check() { foreach ($this->getAllElements('embed') as $object) { $this->setIssue($object); + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/FontIsNotUsed.php b/src/Rule/FontIsNotUsed.php index 94920c0..ebace0c 100644 --- a/src/Rule/FontIsNotUsed.php +++ b/src/Rule/FontIsNotUsed.php @@ -20,6 +20,7 @@ public function check() { foreach ($this->getAllElements('font') as $b) { $this->setIssue($b); + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/HeadersHaveText.php b/src/Rule/HeadersHaveText.php index 36ea7cd..8301bfc 100644 --- a/src/Rule/HeadersHaveText.php +++ b/src/Rule/HeadersHaveText.php @@ -22,6 +22,7 @@ public function check() if (!$this->elementContainsReadableText($header)) { $this->setIssue($header); } + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/HeadingsInOrder.php b/src/Rule/HeadingsInOrder.php index d56c9a4..49f245f 100644 --- a/src/Rule/HeadingsInOrder.php +++ b/src/Rule/HeadingsInOrder.php @@ -37,8 +37,8 @@ public function check() } $previousLevel = $currentLevel; + $this->totalTests++; } - return count($this->issues); } } diff --git a/src/Rule/ImageAltIsDifferent.php b/src/Rule/ImageAltIsDifferent.php index 0449417..ddcbf8d 100644 --- a/src/Rule/ImageAltIsDifferent.php +++ b/src/Rule/ImageAltIsDifferent.php @@ -25,7 +25,9 @@ public function check() $this->setIssue($img); else if ( preg_match("/\.jpg|\.JPG|\.png|\.PNG|\.gif|\.GIF|\.jpeg|\.JPEG$/", trim($img->getAttribute('alt'))) ) $this->setIssue($img); - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/ImageAltIsTooLong.php b/src/Rule/ImageAltIsTooLong.php index c27cbf9..b031575 100644 --- a/src/Rule/ImageAltIsTooLong.php +++ b/src/Rule/ImageAltIsTooLong.php @@ -24,7 +24,8 @@ public function check() if ($img->hasAttribute('alt') && (strlen($img->getAttribute('alt')) > $this->altTextLengthLimit)) { $this->setIssue($img); } - } + $this->totalTests++; + } return count($this->issues); } diff --git a/src/Rule/ImageAltNotEmptyInAnchor.php b/src/Rule/ImageAltNotEmptyInAnchor.php index b8d8d3b..f15dc55 100644 --- a/src/Rule/ImageAltNotEmptyInAnchor.php +++ b/src/Rule/ImageAltNotEmptyInAnchor.php @@ -28,7 +28,8 @@ public function check() $this->setIssue($child); } } - } + $this->totalTests++; + } return count($this->issues); } diff --git a/src/Rule/ImageAltNotPlaceholder.php b/src/Rule/ImageAltNotPlaceholder.php index 10b384e..a999cb2 100644 --- a/src/Rule/ImageAltNotPlaceholder.php +++ b/src/Rule/ImageAltNotPlaceholder.php @@ -34,7 +34,8 @@ public function check() } } } - } + $this->totalTests++; + } return count($this->issues); } diff --git a/src/Rule/ImageHasAlt.php b/src/Rule/ImageHasAlt.php index 61fecf4..95c7a6b 100644 --- a/src/Rule/ImageHasAlt.php +++ b/src/Rule/ImageHasAlt.php @@ -26,6 +26,7 @@ public function check() $this->setIssue($img); } } + $this->totalTests++; } return count($this->issues); diff --git a/src/Rule/ImageHasAltDecorative.php b/src/Rule/ImageHasAltDecorative.php index e484cf1..1ece532 100644 --- a/src/Rule/ImageHasAltDecorative.php +++ b/src/Rule/ImageHasAltDecorative.php @@ -32,7 +32,8 @@ public function check() && trim($img->getAttribute('alt') != '')) { $this->setIssue($img); } - } + $this->totalTests++; + } return count($this->issues); } diff --git a/src/Rule/ImageHasLongDescription.php b/src/Rule/ImageHasLongDescription.php index a17d95d..e185f99 100644 --- a/src/Rule/ImageHasLongDescription.php +++ b/src/Rule/ImageHasLongDescription.php @@ -27,7 +27,9 @@ public function check() $this->setIssue($img); } } - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/InputImageNotDecorative.php b/src/Rule/InputImageNotDecorative.php index 18d4761..f667186 100644 --- a/src/Rule/InputImageNotDecorative.php +++ b/src/Rule/InputImageNotDecorative.php @@ -23,7 +23,9 @@ public function check() foreach ($this->getAllElements('input') as $input) { if ($input->getAttribute('type') == 'image') $this->setIssue($input); - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/MarqueeIsNotUsed.php b/src/Rule/MarqueeIsNotUsed.php index 5b9f140..06d4553 100644 --- a/src/Rule/MarqueeIsNotUsed.php +++ b/src/Rule/MarqueeIsNotUsed.php @@ -21,7 +21,9 @@ public function check() { foreach ($this->getAllElements('marquee') as $m) { $this->setIssue($m); - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/NoHeadings.php b/src/Rule/NoHeadings.php index 4b9b020..6b764c1 100644 --- a/src/Rule/NoHeadings.php +++ b/src/Rule/NoHeadings.php @@ -32,7 +32,9 @@ public function check() $this->setIssue($this->dom->documentElement); } } - + $this->totalTests++; + + return count($this->issues); } diff --git a/src/Rule/ObjectInterfaceIsAccessible.php b/src/Rule/ObjectInterfaceIsAccessible.php index 478d4b8..b7ac8bf 100644 --- a/src/Rule/ObjectInterfaceIsAccessible.php +++ b/src/Rule/ObjectInterfaceIsAccessible.php @@ -21,7 +21,10 @@ public function check() { foreach ($this->getAllElements('object') as $object) { $this->setIssue($object); - } + + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/ObjectMustContainText.php b/src/Rule/ObjectMustContainText.php index 7b23fb5..0d57f21 100644 --- a/src/Rule/ObjectMustContainText.php +++ b/src/Rule/ObjectMustContainText.php @@ -32,6 +32,7 @@ function check() && (!$object->hasAttribute('alt') || trim($object->getAttribute('alt')) == '')){ $this->setIssue($object); } + $this->totalTests++; return count($this->issues); } diff --git a/src/Rule/ObjectShouldHaveLongDescription.php b/src/Rule/ObjectShouldHaveLongDescription.php index 0702eb9..67ac77b 100644 --- a/src/Rule/ObjectShouldHaveLongDescription.php +++ b/src/Rule/ObjectShouldHaveLongDescription.php @@ -21,7 +21,8 @@ public function check() { foreach ($this->getAllElements('object') as $object) { $this->setIssue($object); - } + $this->totalTests++; + } return count($this->issues); } diff --git a/src/Rule/ObjectTagDetected.php b/src/Rule/ObjectTagDetected.php index 3aa922a..87b6a48 100644 --- a/src/Rule/ObjectTagDetected.php +++ b/src/Rule/ObjectTagDetected.php @@ -21,7 +21,9 @@ public function check() { foreach ($this->getAllElements('object') as $object) { $this->setIssue($object); - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/ParagraphNotUsedAsHeader.php b/src/Rule/ParagraphNotUsedAsHeader.php index b2a5efb..b262506 100644 --- a/src/Rule/ParagraphNotUsedAsHeader.php +++ b/src/Rule/ParagraphNotUsedAsHeader.php @@ -44,7 +44,9 @@ public function check() } } } - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/PreShouldNotBeUsedForTabularValues.php b/src/Rule/PreShouldNotBeUsedForTabularValues.php index caa5bd2..a3cdafd 100644 --- a/src/Rule/PreShouldNotBeUsedForTabularValues.php +++ b/src/Rule/PreShouldNotBeUsedForTabularValues.php @@ -23,7 +23,8 @@ public function check() $rows = preg_split('/[\n\r]+/', $pre->nodeValue); if (count($rows) > 1) $this->setIssue($pre); - } + $this->totalTests++; + } return count($this->issues); } diff --git a/src/Rule/RedirectedLink.php b/src/Rule/RedirectedLink.php index 63e493c..5aa5cc3 100644 --- a/src/Rule/RedirectedLink.php +++ b/src/Rule/RedirectedLink.php @@ -25,7 +25,9 @@ public function check() if ($href) { $links[$href] = $a; } - } + $this->totalTests++; + + } $this->checkLink($links); return count($this->issues); diff --git a/src/Rule/TableDataShouldHaveTableHeader.php b/src/Rule/TableDataShouldHaveTableHeader.php index db57df6..d674f4a 100644 --- a/src/Rule/TableDataShouldHaveTableHeader.php +++ b/src/Rule/TableDataShouldHaveTableHeader.php @@ -51,7 +51,9 @@ public function check() } } } - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/TableHeaderShouldHaveScope.php b/src/Rule/TableHeaderShouldHaveScope.php index 7acf13d..ce95ca7 100644 --- a/src/Rule/TableHeaderShouldHaveScope.php +++ b/src/Rule/TableHeaderShouldHaveScope.php @@ -41,6 +41,8 @@ public function check() $this->setIssue($table); $this->setPreviewElement($table); } + $this->totalTests++; + } return count($this->issues); diff --git a/src/Rule/VideoEmbedCheck.php b/src/Rule/VideoEmbedCheck.php index 5431d6a..2522a28 100644 --- a/src/Rule/VideoEmbedCheck.php +++ b/src/Rule/VideoEmbedCheck.php @@ -24,19 +24,25 @@ public function check() if (preg_match($search, $iframe->getAttribute('src'))) { $this->setIssue($iframe); } - } + $this->totalTests++; + + } foreach ($this->getAllElements('a') as $link) { if (preg_match($search, $link->getAttribute('href'))) { $this->setIssue($link); } - } + $this->totalTests++; + + } foreach ($this->getAllElements('object') as $object) { if (preg_match($search, $object->getAttribute('data'))) { $this->setIssue($object); } - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/VideoProvidesCaptions.php b/src/Rule/VideoProvidesCaptions.php index 96e6910..1429ad3 100644 --- a/src/Rule/VideoProvidesCaptions.php +++ b/src/Rule/VideoProvidesCaptions.php @@ -22,7 +22,9 @@ public function check() if (!$this->elementHasChild($video, 'track')) { $this->setIssue($video); } - } + $this->totalTests++; + + } return count($this->issues); } diff --git a/src/Rule/VideoScan.php b/src/Rule/VideoScan.php index e01ac3c..aa95aee 100644 --- a/src/Rule/VideoScan.php +++ b/src/Rule/VideoScan.php @@ -51,6 +51,8 @@ public function check() $this->checkCaptionsLanguage($captions, $provider, $video); $this->checkCaptionsAutoGenerated($captions, $provider, $video); } + $this->totalTests++; + } return count($this->issues);