Skip to content

Commit

Permalink
Merge pull request #21 from cidilabs/scottcooper/php-ally-track-number
Browse files Browse the repository at this point in the history
Make changes for IssueCount and TestCount
  • Loading branch information
cidilabs authored Nov 19, 2021
2 parents 9858425 + efbcc04 commit 73171a7
Show file tree
Hide file tree
Showing 41 changed files with 104 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/PhpAlly.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions src/PhpAllyReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class PhpAllyReport implements \JsonSerializable {
protected $issues = [];
protected $errors = [];
protected $html = '';
protected $issueCounts = [];

public function __construct()
{
Expand All @@ -16,6 +17,7 @@ public function toArray()
return [
'issues' => $this->getIssues(),
'errors' => $this->getErrors(),
'issueCounts' => $this->getIssueCounts(),
];
}

Expand Down Expand Up @@ -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);
}

}
1 change: 1 addition & 0 deletions src/Rule/AnchorLinksToMultiMediaRequireTranscript.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function check()
$this->setIssue($a);
}
}
$this->totalTests++;
}

return count($this->issues);
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/AnchorLinksToSoundFilesNeedTranscripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function check()
$this->setIssue($a);
}
}
}
$this->totalTests++;
}

return count($this->issues);
}
Expand Down
1 change: 1 addition & 0 deletions src/Rule/AnchorMustContainText.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function check()
if (!$this->elementContainsReadableText($a) && ($a->hasAttribute('href'))) {
$this->setIssue($a);
}
$this->totalTests++;
}

return count($this->issues);
Expand Down
1 change: 1 addition & 0 deletions src/Rule/AnchorSuspiciousLinkText.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Rule/BaseFontIsNotUsed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function check()
{
foreach ($this->getAllElements('basefont') as $b) {
$this->setIssue($b);
$this->totalTests++;
}

return count($this->issues);
Expand Down
14 changes: 12 additions & 2 deletions src/Rule/BaseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BaseRule implements PhpAllyRuleInterface {
protected $altTextLengthLimit;
protected $minDocLengthForHeaders;
protected $maxWordCount;
protected $totalTests = 0;

public function __construct(DOMDocument $dom, $options = [])
{
Expand Down Expand Up @@ -217,8 +218,6 @@ private function walkUpTreeForInheritance($element, $style) {
}




public function elementContainsReadableText($element)
{
if (is_a($element, 'DOMText')) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -323,4 +331,6 @@ function propertyIsEqual($object, $property, $value, $trim = false, $lower = fal
}
return ($property_value == $value);
}


}
1 change: 1 addition & 0 deletions src/Rule/BlinkIsNotUsed.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function check()
{
foreach ($this->getAllElements('blink') as $b) {
$this->setIssue($b);
$this->totalTests++;
}

return count($this->issues);
Expand Down
1 change: 1 addition & 0 deletions src/Rule/BrokenLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function check()
if ($href) {
$links[$href] = $a;
}
$this->totalTests++;
}
$this->checkLink($links);

Expand Down
1 change: 1 addition & 0 deletions src/Rule/ContentTooLong.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function check()
if($text != null){
$pageText = $pageText . $text;
}
$this->totalTests++;
}
$wordCount = str_word_count($pageText);

Expand Down
1 change: 1 addition & 0 deletions src/Rule/CssTextHasContrast.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public function check()
}
}
}
$this->totalTests++;
}

return count($this->issues);
Expand Down
1 change: 1 addition & 0 deletions src/Rule/CssTextStyleEmphasize.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function check()
}

$this->setIssue($element);
$this->totalTests++;
}

return count($this->issues);
Expand Down
1 change: 1 addition & 0 deletions src/Rule/DocumentReadingDirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function check()
if ($element->getAttribute('dir') != 'rtl')
$this->setIssue($element);
}
$this->totalTests++;
}

return count($this->issues);
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/EmbedHasAssociatedNoEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function check()
&& !$this->propertyIsEqual($embed->nextSibling, 'tagName', 'noembed')) {
$this->setIssue($embed);
}

$this->totalTests++;
}

return count($this->issues);
Expand Down
1 change: 1 addition & 0 deletions src/Rule/EmbedTagDetected.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function check()
{
foreach ($this->getAllElements('embed') as $object) {
$this->setIssue($object);
$this->totalTests++;
}

return count($this->issues);
Expand Down
1 change: 1 addition & 0 deletions src/Rule/FontIsNotUsed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function check()
{
foreach ($this->getAllElements('font') as $b) {
$this->setIssue($b);
$this->totalTests++;
}

return count($this->issues);
Expand Down
1 change: 1 addition & 0 deletions src/Rule/HeadersHaveText.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function check()
if (!$this->elementContainsReadableText($header)) {
$this->setIssue($header);
}
$this->totalTests++;
}

return count($this->issues);
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/HeadingsInOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function check()
}

$previousLevel = $currentLevel;
$this->totalTests++;
}

return count($this->issues);
}
}
4 changes: 3 additions & 1 deletion src/Rule/ImageAltIsDifferent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/ImageAltIsTooLong.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/ImageAltNotEmptyInAnchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function check()
$this->setIssue($child);
}
}
}
$this->totalTests++;
}

return count($this->issues);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/ImageAltNotPlaceholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function check()
}
}
}
}
$this->totalTests++;
}

return count($this->issues);
}
Expand Down
1 change: 1 addition & 0 deletions src/Rule/ImageHasAlt.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function check()
$this->setIssue($img);
}
}
$this->totalTests++;
}

return count($this->issues);
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/ImageHasAltDecorative.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function check()
&& trim($img->getAttribute('alt') != '')) {
$this->setIssue($img);
}
}
$this->totalTests++;
}

return count($this->issues);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Rule/ImageHasLongDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function check()
$this->setIssue($img);
}
}
}
$this->totalTests++;

}

return count($this->issues);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Rule/InputImageNotDecorative.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Rule/MarqueeIsNotUsed.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function check()
{
foreach ($this->getAllElements('marquee') as $m) {
$this->setIssue($m);
}
$this->totalTests++;

}

return count($this->issues);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Rule/NoHeadings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function check()
$this->setIssue($this->dom->documentElement);
}
}

$this->totalTests++;


return count($this->issues);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Rule/ObjectInterfaceIsAccessible.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public function check()
{
foreach ($this->getAllElements('object') as $object) {
$this->setIssue($object);
}

$this->totalTests++;

}

return count($this->issues);
}
Expand Down
1 change: 1 addition & 0 deletions src/Rule/ObjectMustContainText.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function check()
&& (!$object->hasAttribute('alt') || trim($object->getAttribute('alt')) == '')){
$this->setIssue($object);
}
$this->totalTests++;

return count($this->issues);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/ObjectShouldHaveLongDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public function check()
{
foreach ($this->getAllElements('object') as $object) {
$this->setIssue($object);
}
$this->totalTests++;
}

return count($this->issues);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Rule/ObjectTagDetected.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function check()
{
foreach ($this->getAllElements('object') as $object) {
$this->setIssue($object);
}
$this->totalTests++;

}

return count($this->issues);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Rule/ParagraphNotUsedAsHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function check()
}
}
}
}
$this->totalTests++;

}

return count($this->issues);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/PreShouldNotBeUsedForTabularValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Rule/RedirectedLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function check()
if ($href) {
$links[$href] = $a;
}
}
$this->totalTests++;

}
$this->checkLink($links);

return count($this->issues);
Expand Down
Loading

0 comments on commit 73171a7

Please sign in to comment.