Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
feat(v4.0.0): 175 WCAG 2.2 & ARIA rules, VPAT 2.5, 11 presets, PolicyEngine, inline suppressions, cache, CI generator, PHPUnit assertions, and open-source YakNet identity
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Analytics;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Analytics\HistoryTracker;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class HistoryTrackerTest extends TestCase
|
||||
{
|
||||
public function testRecordsSnapshotsAndComputesImprovingTrend(): void
|
||||
{
|
||||
$historyFile = sys_get_temp_dir() . '/yaknet_history_' . uniqid() . '.json';
|
||||
$tracker = new HistoryTracker();
|
||||
|
||||
try {
|
||||
$tracker->record([
|
||||
new Violation('WCAG_1_1_1_ALT', 'Missing alt', Severity::ERROR, WCAGStandard::A),
|
||||
new Violation('WCAG_4_1_2_BUTTON', 'Empty button', Severity::ERROR, WCAGStandard::A),
|
||||
], $historyFile, 'views', 'wcag22-aa');
|
||||
|
||||
$tracker->record([
|
||||
new Violation('WCAG_1_1_1_ALT', 'Missing alt', Severity::ERROR, WCAGStandard::A),
|
||||
], $historyFile, 'views', 'wcag22-aa');
|
||||
|
||||
$entries = $tracker->load($historyFile);
|
||||
$this->assertCount(2, $entries);
|
||||
|
||||
$trend = $tracker->computeTrend($entries);
|
||||
$this->assertSame(2, $trend['runs']);
|
||||
$this->assertSame('improving', $trend['trend']);
|
||||
$this->assertGreaterThan(0, $trend['score_delta']);
|
||||
} finally {
|
||||
@unlink($historyFile);
|
||||
}
|
||||
}
|
||||
|
||||
public function testComparesTwoReportsForRegressionsAndResolutions(): void
|
||||
{
|
||||
$tracker = new HistoryTracker();
|
||||
|
||||
$before = [
|
||||
['ruleId' => 'WCAG_1_1_1_ALT', 'severity' => 'error', 'htmlSnippet' => '<img src="1.png">', 'location' => ['file' => 'a.html', 'line' => 5]],
|
||||
['ruleId' => 'WCAG_2_4_4_LINK_TEXT', 'severity' => 'error', 'htmlSnippet' => '<a href="/"></a>', 'location' => ['file' => 'a.html', 'line' => 9]],
|
||||
];
|
||||
|
||||
$after = [
|
||||
['ruleId' => 'WCAG_1_1_1_ALT', 'severity' => 'error', 'htmlSnippet' => '<img src="1.png">', 'location' => ['file' => 'a.html', 'line' => 5]],
|
||||
['ruleId' => 'WCAG_3_2_2_BUTTON_TYPE', 'severity' => 'warning', 'htmlSnippet' => '<button>Go</button>', 'location' => ['file' => 'b.html', 'line' => 12]],
|
||||
];
|
||||
|
||||
$diff = $tracker->compareReports($before, $after);
|
||||
|
||||
$this->assertSame(1, $diff['unchanged_count']);
|
||||
$this->assertCount(1, $diff['new_violations']);
|
||||
$this->assertCount(1, $diff['resolved_violations']);
|
||||
$this->assertSame('WCAG_3_2_2_BUTTON_TYPE', $diff['new_violations'][0]['ruleId']);
|
||||
$this->assertSame('WCAG_2_4_4_LINK_TEXT', $diff['resolved_violations'][0]['ruleId']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Compliance;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Compliance\VpatReportGenerator;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class VpatReportGeneratorTest extends TestCase
|
||||
{
|
||||
public function testGeneratesVpatDataAndAllFormats(): void
|
||||
{
|
||||
$violations = [
|
||||
new Violation('WCAG_1_1_1_ALT', 'Missing alt', Severity::ERROR, WCAGStandard::A),
|
||||
new Violation('WCAG_2_5_8_TARGET_SIZE', 'Small target', Severity::WARNING, WCAGStandard::AA),
|
||||
];
|
||||
|
||||
$generator = new VpatReportGenerator();
|
||||
$data = $generator->buildReportData($violations, 'YakNet Portal', '2.0.0', 'YakNet QA');
|
||||
|
||||
$this->assertSame('YakNet Portal', $data['product_name']);
|
||||
$this->assertSame('Does Not Support', $data['criteria']['1.1.1']['conformance']);
|
||||
$this->assertSame('Partially Supports', $data['criteria']['2.5.8']['conformance']);
|
||||
$this->assertSame('Supports', $data['criteria']['3.1.1']['conformance']);
|
||||
$this->assertSame('Not Evaluated', $data['criteria']['1.4.10']['conformance']);
|
||||
|
||||
$markdown = $generator->renderMarkdown($violations, 'YakNet Portal', '2.0.0');
|
||||
$this->assertStringContainsString('# Accessibility Conformance Report (VPAT 2.5)', $markdown);
|
||||
$this->assertStringContainsString('Does Not Support', $markdown);
|
||||
$this->assertStringContainsString('YakNet Accessibility Console', $markdown);
|
||||
|
||||
$html = $generator->renderHtml($violations, 'YakNet Portal', '2.0.0');
|
||||
$this->assertStringContainsString('<title>VPAT 2.5 Accessibility Conformance Report', $html);
|
||||
$this->assertStringContainsString('Partially Supports', $html);
|
||||
|
||||
$json = $generator->renderJson($violations, 'YakNet Portal', '2.0.0');
|
||||
$decoded = json_decode($json, true);
|
||||
$this->assertIsArray($decoded);
|
||||
$this->assertSame(2, $decoded['total_violations']);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ class RulesCommandTest extends TestCase
|
||||
$this->assertSame(0, $exitCode);
|
||||
$output = $tester->getDisplay();
|
||||
$this->assertStringContainsString('Accessibility Console - Available Rules', $output);
|
||||
$this->assertStringContainsString('Total rules available: 130', $output);
|
||||
$this->assertStringContainsString('Total rules available: 175', $output);
|
||||
}
|
||||
|
||||
public function testFilterRulesBySearch(): void
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Console;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use YakNet\AccessibilityConsole\Console\Command\CompareCommand;
|
||||
use YakNet\AccessibilityConsole\Console\Command\DoctorCommand;
|
||||
use YakNet\AccessibilityConsole\Console\Command\ExplainCommand;
|
||||
use YakNet\AccessibilityConsole\Console\Command\PresetsCommand;
|
||||
use YakNet\AccessibilityConsole\Console\Command\RulesCommand;
|
||||
use YakNet\AccessibilityConsole\Console\Command\VpatCommand;
|
||||
|
||||
class V4CommandsTest extends TestCase
|
||||
{
|
||||
public function testDoctorCommandPasses(): void
|
||||
{
|
||||
$tester = new CommandTester(new DoctorCommand());
|
||||
$exitCode = $tester->execute([]);
|
||||
|
||||
$this->assertSame(0, $exitCode);
|
||||
$output = $tester->getDisplay();
|
||||
$this->assertStringContainsString('175 rules registered', $output);
|
||||
$this->assertStringContainsString('VALID (0 conflicts)', $output);
|
||||
$this->assertStringContainsString('11 profiles available', $output);
|
||||
}
|
||||
|
||||
public function testExplainCommandDisplaysRuleAndWcagGuidance(): void
|
||||
{
|
||||
$tester = new CommandTester(new ExplainCommand());
|
||||
$exitCode = $tester->execute(['rule' => 'WCAG_4_1_2_ARIA_TABLIST']);
|
||||
|
||||
$this->assertSame(0, $exitCode);
|
||||
$output = $tester->getDisplay();
|
||||
$this->assertStringContainsString('WCAG_4_1_2_ARIA_TABLIST', $output);
|
||||
$this->assertStringContainsString('W3C WCAG Guidance', $output);
|
||||
$this->assertStringContainsString('Non-Compliant Example', $output);
|
||||
}
|
||||
|
||||
public function testPresetsCommandListsAllElevenPresets(): void
|
||||
{
|
||||
$tester = new CommandTester(new PresetsCommand());
|
||||
$exitCode = $tester->execute([]);
|
||||
|
||||
$this->assertSame(0, $exitCode);
|
||||
$output = $tester->getDisplay();
|
||||
$this->assertStringContainsString('wcag22-aa', $output);
|
||||
$this->assertStringContainsString('eaa2025', $output);
|
||||
$this->assertStringContainsString('government', $output);
|
||||
$this->assertStringContainsString('Total compliance presets available: 11', $output);
|
||||
}
|
||||
|
||||
public function testRulesCommandHealableAndPrincipleFilters(): void
|
||||
{
|
||||
$tester = new CommandTester(new RulesCommand());
|
||||
$exitCode = $tester->execute(['--healable' => true]);
|
||||
|
||||
$this->assertSame(0, $exitCode);
|
||||
$output = $tester->getDisplay();
|
||||
$this->assertStringContainsString('WCAG_3_2_2_BUTTON_TYPE', $output);
|
||||
$this->assertStringContainsString('Showing', $output);
|
||||
|
||||
$exitCode2 = $tester->execute(['--principle' => 'Operable']);
|
||||
$this->assertSame(0, $exitCode2);
|
||||
$this->assertStringContainsString('WCAG_2_', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testVpatCommandOutputsMarkdownReport(): void
|
||||
{
|
||||
$tmpHtml = sys_get_temp_dir() . '/yaknet_vpat_' . uniqid() . '.html';
|
||||
file_put_contents($tmpHtml, '<!DOCTYPE html><html lang="en"><head><title>Demo</title></head><body><main><h1>Hello</h1><img src="x.png"></main></body></html>');
|
||||
|
||||
try {
|
||||
$tester = new CommandTester(new VpatCommand());
|
||||
$exitCode = $tester->execute([
|
||||
'target' => $tmpHtml,
|
||||
'--format' => 'markdown',
|
||||
'--product' => 'YakNet Demo',
|
||||
]);
|
||||
|
||||
$this->assertSame(0, $exitCode);
|
||||
$output = $tester->getDisplay();
|
||||
$this->assertStringContainsString('# Accessibility Conformance Report (VPAT 2.5)', $output);
|
||||
$this->assertStringContainsString('YakNet Demo', $output);
|
||||
} finally {
|
||||
@unlink($tmpHtml);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCompareCommandDetectsRegressionAndFailsWhenRequested(): void
|
||||
{
|
||||
$beforeFile = sys_get_temp_dir() . '/yaknet_before_' . uniqid() . '.json';
|
||||
$afterFile = sys_get_temp_dir() . '/yaknet_after_' . uniqid() . '.json';
|
||||
|
||||
file_put_contents($beforeFile, json_encode([]));
|
||||
file_put_contents($afterFile, json_encode([
|
||||
['ruleId' => 'WCAG_1_1_1_ALT', 'message' => 'Missing alt', 'severity' => 'error', 'htmlSnippet' => '<img src="new.png">', 'location' => ['file' => 'index.html', 'line' => 10]],
|
||||
]));
|
||||
|
||||
try {
|
||||
$tester = new CommandTester(new CompareCommand());
|
||||
$exitCode = $tester->execute([
|
||||
'before' => $beforeFile,
|
||||
'after' => $afterFile,
|
||||
'--fail-on-regression' => true,
|
||||
]);
|
||||
|
||||
$this->assertSame(1, $exitCode);
|
||||
$this->assertStringContainsString('REGRESSION', $tester->getDisplay());
|
||||
$this->assertStringContainsString('WCAG_1_1_1_ALT', $tester->getDisplay());
|
||||
} finally {
|
||||
@unlink($beforeFile);
|
||||
@unlink($afterFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Core;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Core\Analyser;
|
||||
use YakNet\AccessibilityConsole\Core\BaselineManager;
|
||||
use YakNet\AccessibilityConsole\Core\Config;
|
||||
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||
use YakNet\AccessibilityConsole\Core\Suppression\InlineSuppressionParser;
|
||||
use YakNet\AccessibilityConsole\Rules\ImgAltText;
|
||||
|
||||
class InlineSuppressionParserTest extends TestCase
|
||||
{
|
||||
public function testParsesNextLineBlockAndFileDirectivesWithReasons(): void
|
||||
{
|
||||
$parser = new InlineSuppressionParser();
|
||||
$html = <<<HTML
|
||||
<div>
|
||||
<!-- a11y-disable-next-line WCAG_1_1_1_ALT -- Decorative hero sprite -->
|
||||
<img src="hero.png">
|
||||
<!-- a11y-disable WCAG_1_4_3_CONTRAST -- Brand theme -->
|
||||
<p style="color:#aaa;background:#fff;">Muted</p>
|
||||
<!-- a11y-enable WCAG_1_4_3_CONTRAST -->
|
||||
<p>Normal</p>
|
||||
</div>
|
||||
HTML;
|
||||
|
||||
$parsed = $parser->parse($html);
|
||||
|
||||
$this->assertSame('Decorative hero sprite', $parser->getSuppressionReason($parsed, 'WCAG_1_1_1_ALT', 3));
|
||||
$this->assertNull($parser->getSuppressionReason($parsed, 'WCAG_1_1_1_ALT', 4));
|
||||
$this->assertSame('Brand theme', $parser->getSuppressionReason($parsed, 'WCAG_1_4_3_CONTRAST', 5));
|
||||
$this->assertNull($parser->getSuppressionReason($parsed, 'WCAG_1_4_3_CONTRAST', 7));
|
||||
}
|
||||
|
||||
public function testAnalyserHonorsInlineSuppressionAndLogsAuditTrail(): void
|
||||
{
|
||||
$tmpFile = sys_get_temp_dir() . '/yaknet_suppression_' . uniqid() . '.html';
|
||||
file_put_contents($tmpFile, "<div>\n<!-- a11y-disable-next-line WCAG_1_1_1_ALT -- Approved decorative -->\n<img src=\"a.png\">\n<img src=\"b.png\">\n</div>");
|
||||
|
||||
try {
|
||||
$scanner = new Scanner();
|
||||
$scanner->addRule(new ImgAltText());
|
||||
$analyser = new Analyser(new Config(), $scanner, new BaselineManager());
|
||||
|
||||
$result = $analyser->analyse([$tmpFile]);
|
||||
$this->assertCount(1, $result['violations']);
|
||||
|
||||
$auditLog = $analyser->getSuppressedAuditLog();
|
||||
$this->assertCount(1, $auditLog);
|
||||
$this->assertSame('WCAG_1_1_1_ALT', $auditLog[0]['ruleId']);
|
||||
$this->assertSame('Approved decorative', $auditLog[0]['reason']);
|
||||
} finally {
|
||||
@unlink($tmpFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Notifications;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Middleware;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Notifications\GenericWebhookNotifier;
|
||||
use YakNet\AccessibilityConsole\Notifications\MicrosoftTeamsNotifier;
|
||||
use YakNet\AccessibilityConsole\Notifications\NotificationPayload;
|
||||
|
||||
class ExpandedNotifiersTest extends TestCase
|
||||
{
|
||||
public function testMicrosoftTeamsNotifierPostsMessageCard(): void
|
||||
{
|
||||
$container = [];
|
||||
$history = Middleware::history($container);
|
||||
$mock = new MockHandler([new Response(200, [], '1')]);
|
||||
$stack = HandlerStack::create($mock);
|
||||
$stack->push($history);
|
||||
$client = new Client(['handler' => $stack]);
|
||||
|
||||
$notifier = new MicrosoftTeamsNotifier('https://teams.example.test/webhook', $client);
|
||||
$payload = new NotificationPayload('views/', 94, 2, 0, 2);
|
||||
|
||||
$this->assertTrue($notifier->send($payload));
|
||||
$this->assertCount(1, $container);
|
||||
$body = (string)$container[0]['request']->getBody();
|
||||
$this->assertStringContainsString('MessageCard', $body);
|
||||
$this->assertStringContainsString('YakNet Accessibility Console', $body);
|
||||
}
|
||||
|
||||
public function testGenericWebhookNotifierSignsPayloadWithHmacSha256(): void
|
||||
{
|
||||
$container = [];
|
||||
$history = Middleware::history($container);
|
||||
$mock = new MockHandler([new Response(202, [], '{"ok":true}')]);
|
||||
$stack = HandlerStack::create($mock);
|
||||
$stack->push($history);
|
||||
$client = new Client(['handler' => $stack]);
|
||||
|
||||
$notifier = new GenericWebhookNotifier('https://hooks.example.test/a11y', 'super-secret-key', $client);
|
||||
$payload = new NotificationPayload('templates/', 88, 3, 1, 2);
|
||||
|
||||
$this->assertTrue($notifier->send($payload));
|
||||
$this->assertCount(1, $container);
|
||||
$sigHeader = $container[0]['request']->getHeaderLine('X-YakNet-Signature-256');
|
||||
$this->assertStringStartsWith('sha256=', $sigHeader);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Parser;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||
use YakNet\AccessibilityConsole\Parser\JsxParser;
|
||||
use YakNet\AccessibilityConsole\Parser\TemplatePreprocessor;
|
||||
use YakNet\AccessibilityConsole\Parser\VueParser;
|
||||
use YakNet\AccessibilityConsole\Rules\ClickHandlerKeyboard;
|
||||
use YakNet\AccessibilityConsole\Rules\ImgAltText;
|
||||
|
||||
class ModernTemplateParsersTest extends TestCase
|
||||
{
|
||||
public function testVueParserExtractsTemplateAndPreservesLineNumbers(): void
|
||||
{
|
||||
$vue = <<<'VUE'
|
||||
<script setup>
|
||||
const title = "YakNet";
|
||||
</script>
|
||||
<template>
|
||||
<div @click="openModal()">
|
||||
<img src="banner.png">
|
||||
<span>{{ title }}</span>
|
||||
</div>
|
||||
</template>
|
||||
VUE;
|
||||
|
||||
$parser = new VueParser();
|
||||
$html = $parser->parse($vue);
|
||||
|
||||
$this->assertStringContainsString('onclick="openModal()"', $html);
|
||||
$this->assertStringContainsString('VueExpression', $html);
|
||||
|
||||
$scanner = new Scanner();
|
||||
$scanner->addRule(new ImgAltText());
|
||||
$scanner->addRule(new ClickHandlerKeyboard());
|
||||
$violations = $scanner->scan($html);
|
||||
|
||||
$ruleIds = array_map(static fn($v): string => $v->ruleId, $violations);
|
||||
$this->assertContains('WCAG_1_1_1_ALT', $ruleIds);
|
||||
$this->assertContains('WCAG_2_1_1_CLICK_KEYBOARD', $ruleIds);
|
||||
}
|
||||
|
||||
public function testJsxParserNormalizesReactAttributes(): void
|
||||
{
|
||||
$tsx = <<<'TSX'
|
||||
export function Card() {
|
||||
return (
|
||||
<div className="card" onClick={() => handleClick()}>
|
||||
<img src="cover.jpg" />
|
||||
<label htmlFor="email">Email</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
TSX;
|
||||
|
||||
$preprocessor = new TemplatePreprocessor();
|
||||
$html = $preprocessor->preprocess($tsx, 'Card.tsx');
|
||||
|
||||
$this->assertStringContainsString('class="card"', $html);
|
||||
$this->assertStringContainsString('for="email"', $html);
|
||||
$this->assertStringContainsString('onclick="jsxHandler()"', $html);
|
||||
|
||||
$scanner = new Scanner();
|
||||
$scanner->addRule(new ImgAltText());
|
||||
$violations = $scanner->scan($html);
|
||||
$this->assertCount(1, $violations);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Policy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
use YakNet\AccessibilityConsole\Policy\PolicyEngine;
|
||||
|
||||
class PolicyEngineTest extends TestCase
|
||||
{
|
||||
public function testPolicyPassesWhenWithinThresholds(): void
|
||||
{
|
||||
$engine = new PolicyEngine([
|
||||
'min_score' => 90,
|
||||
'max_errors' => 0,
|
||||
'max_warnings' => 2,
|
||||
'required_standards' => ['A'],
|
||||
]);
|
||||
|
||||
$violations = [
|
||||
new Violation('WCAG_2_5_8_TARGET_SIZE', 'Small button', Severity::WARNING, WCAGStandard::AA),
|
||||
];
|
||||
|
||||
$result = $engine->evaluate($violations);
|
||||
$this->assertTrue($result->passed);
|
||||
$this->assertEmpty($result->failures);
|
||||
}
|
||||
|
||||
public function testPolicyEnforcesAllGovernanceGatesAndSeverityOverrides(): void
|
||||
{
|
||||
$engine = new PolicyEngine([
|
||||
'min_score' => 95,
|
||||
'max_critical' => 0,
|
||||
'required_standards' => ['AA'],
|
||||
'banned_rules' => ['WCAG_1_1_1_ALT'],
|
||||
'principle_limits' => ['Perceivable' => 0],
|
||||
'severity_overrides' => [
|
||||
'WCAG_2_5_8_TARGET_SIZE' => 'critical',
|
||||
],
|
||||
]);
|
||||
|
||||
$v1 = new Violation('WCAG_1_1_1_ALT', 'Missing alt', Severity::ERROR, WCAGStandard::A);
|
||||
$v2 = new Violation('WCAG_2_5_8_TARGET_SIZE', 'Small target', Severity::WARNING, WCAGStandard::AA);
|
||||
|
||||
$result = $engine->evaluate([$v1, $v2]);
|
||||
|
||||
$this->assertFalse($result->passed);
|
||||
$this->assertSame(Severity::CRITICAL, $v2->severity);
|
||||
$this->assertGreaterThanOrEqual(4, count($result->failures));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Presets;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Core\SelfHealing\LocalHealer;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
use YakNet\AccessibilityConsole\Presets\PresetRegistry;
|
||||
|
||||
class PresetsExpandedTest extends TestCase
|
||||
{
|
||||
public function testAllElevenPresetsAreRegistered(): void
|
||||
{
|
||||
$registry = new PresetRegistry();
|
||||
$all = $registry->all();
|
||||
|
||||
$this->assertCount(11, $all);
|
||||
foreach (['section508', 'en301549', 'ecommerce', 'wcag22-aa', 'wcag22-aaa', 'eaa2025', 'bitv2', 'government', 'healthcare', 'banking', 'education'] as $name) {
|
||||
$this->assertNotNull($registry->get($name), "Expected preset '{$name}' to be registered.");
|
||||
}
|
||||
}
|
||||
|
||||
public function testGlobalHelpersWorkEndToEnd(): void
|
||||
{
|
||||
$html = '<html lang="en"><head><title>App</title></head><body><main><h1>Hi</h1><img src="x.png"></main></body></html>';
|
||||
|
||||
$violations = \a11y_scan_preset($html, 'government');
|
||||
$this->assertNotEmpty($violations);
|
||||
|
||||
$vpat = \a11y_vpat($html, 'markdown', 'YakNet Portal');
|
||||
$this->assertStringContainsString('VPAT 2.5', $vpat);
|
||||
$this->assertStringContainsString('YakNet Portal', $vpat);
|
||||
|
||||
$matrix = \a11y_compliance_matrix($html);
|
||||
$this->assertArrayHasKey('overall_compliance_percentage', $matrix);
|
||||
$this->assertArrayHasKey('principles', $matrix);
|
||||
}
|
||||
|
||||
public function testExpandedLocalHealerFixesNewRulesDeterministically(): void
|
||||
{
|
||||
$healer = new LocalHealer();
|
||||
|
||||
$btnFix = $healer->heal(new Violation('WCAG_3_2_2_BUTTON_TYPE', 'Missing type', Severity::WARNING, WCAGStandard::A, '<button>Click</button>'));
|
||||
$this->assertNotNull($btnFix);
|
||||
$this->assertStringContainsString('<button type="button">Click</button>', $btnFix);
|
||||
|
||||
$svgFix = $healer->heal(new Violation('WCAG_1_1_1_SVG_FOCUSABLE', 'Missing focusable', Severity::WARNING, WCAGStandard::A, '<svg aria-hidden="true"></svg>'));
|
||||
$this->assertNotNull($svgFix);
|
||||
$this->assertStringContainsString('focusable="false"', $svgFix);
|
||||
|
||||
$modalFix = $healer->heal(new Violation('WCAG_4_1_2_ARIA_MODAL', 'Missing aria-modal', Severity::WARNING, WCAGStandard::A, '<div role="dialog" aria-label="Info">Hi</div>'));
|
||||
$this->assertNotNull($modalFix);
|
||||
$this->assertStringContainsString('aria-modal="true"', $modalFix);
|
||||
|
||||
$this->assertGreaterThanOrEqual(30, count(LocalHealer::getSupportedRuleIds()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Reporting;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
use YakNet\AccessibilityConsole\Reporting\CheckstyleFormatter;
|
||||
|
||||
class CheckstyleFormatterTest extends TestCase
|
||||
{
|
||||
public function testRendersValidCheckstyleXml(): void
|
||||
{
|
||||
$formatter = new CheckstyleFormatter();
|
||||
$violations = [
|
||||
new Violation(
|
||||
ruleId: 'WCAG_1_1_1_ALT',
|
||||
message: 'Image missing alt attribute',
|
||||
severity: Severity::ERROR,
|
||||
standard: WCAGStandard::A,
|
||||
htmlSnippet: '<img src="a.png">',
|
||||
location: ['file' => 'views/home.blade.php', 'line' => 14, 'column' => 5]
|
||||
),
|
||||
new Violation(
|
||||
ruleId: 'WCAG_2_5_8_TARGET_SIZE',
|
||||
message: 'Button too small',
|
||||
severity: Severity::WARNING,
|
||||
standard: WCAGStandard::AA,
|
||||
htmlSnippet: '<button>X</button>',
|
||||
location: ['file' => 'views/home.blade.php', 'line' => 22, 'column' => 3]
|
||||
),
|
||||
];
|
||||
|
||||
$xml = $formatter->render($violations);
|
||||
|
||||
$this->assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $xml);
|
||||
$this->assertStringContainsString('<checkstyle version="4.0.0">', $xml);
|
||||
$this->assertStringContainsString('<file name="views/home.blade.php">', $xml);
|
||||
$this->assertStringContainsString('source="YakNet.Accessibility.WCAG_1_1_1_ALT"', $xml);
|
||||
$this->assertStringContainsString('severity="warning"', $xml);
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
$this->assertTrue($dom->loadXML($xml));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests\Rules;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Core\RuleRegistry;
|
||||
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||
use YakNet\AccessibilityConsole\Rules\AbbreviationExpansion;
|
||||
use YakNet\AccessibilityConsole\Rules\AllCapsLongText;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaActivedescendantValid;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaBreadcrumbPattern;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaComboboxPattern;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaDeprecatedRoles;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaLivePoliteMisuse;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaMenuPattern;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaModalBackdrop;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaOwnsValidTarget;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaSliderAttributes;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaSwitchState;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaTablistPattern;
|
||||
use YakNet\AccessibilityConsole\Rules\AriaTreePattern;
|
||||
use YakNet\AccessibilityConsole\Rules\ArticleAccessibleHeading;
|
||||
use YakNet\AccessibilityConsole\Rules\BlockquoteCiteValid;
|
||||
use YakNet\AccessibilityConsole\Rules\ButtonTypeExplicit;
|
||||
use YakNet\AccessibilityConsole\Rules\CharacterKeyShortcuts;
|
||||
use YakNet\AccessibilityConsole\Rules\CheckboxGroupFieldset;
|
||||
use YakNet\AccessibilityConsole\Rules\ColorContrastAAA;
|
||||
use YakNet\AccessibilityConsole\Rules\ConsistentHelp;
|
||||
use YakNet\AccessibilityConsole\Rules\DocumentHasH1;
|
||||
use YakNet\AccessibilityConsole\Rules\FlashingContentBanned;
|
||||
use YakNet\AccessibilityConsole\Rules\FocusAppearance;
|
||||
use YakNet\AccessibilityConsole\Rules\FontSizeMinimum;
|
||||
use YakNet\AccessibilityConsole\Rules\FormErrorSummary;
|
||||
use YakNet\AccessibilityConsole\Rules\HeaderMainNestedInvalid;
|
||||
use YakNet\AccessibilityConsole\Rules\HeadingLengthConcise;
|
||||
use YakNet\AccessibilityConsole\Rules\HoverFocusContentDismissible;
|
||||
use YakNet\AccessibilityConsole\Rules\IframeSandboxAccessibility;
|
||||
use YakNet\AccessibilityConsole\Rules\InputTypeValidation;
|
||||
use YakNet\AccessibilityConsole\Rules\JustifiedTextBanned;
|
||||
use YakNet\AccessibilityConsole\Rules\LinkDownloadContext;
|
||||
use YakNet\AccessibilityConsole\Rules\MotionAnimationReduced;
|
||||
use YakNet\AccessibilityConsole\Rules\NavAccessibleName;
|
||||
use YakNet\AccessibilityConsole\Rules\OrientationLockBanned;
|
||||
use YakNet\AccessibilityConsole\Rules\OutputForValid;
|
||||
use YakNet\AccessibilityConsole\Rules\PointerCancellation;
|
||||
use YakNet\AccessibilityConsole\Rules\RuleLevels;
|
||||
use YakNet\AccessibilityConsole\Rules\SectionAccessibleName;
|
||||
use YakNet\AccessibilityConsole\Rules\SelectOptionNotEmpty;
|
||||
use YakNet\AccessibilityConsole\Rules\SvgFocusableIeEdge;
|
||||
use YakNet\AccessibilityConsole\Rules\TargetSpacingMinimum;
|
||||
use YakNet\AccessibilityConsole\Rules\TextareaAccessibleName;
|
||||
use YakNet\AccessibilityConsole\Rules\TimeDatetimeValid;
|
||||
use YakNet\AccessibilityConsole\Rules\TimeoutWarning;
|
||||
|
||||
class V4NewRulesTest extends TestCase
|
||||
{
|
||||
public function testAll175RulesPassRegistryValidationWithUniqueIds(): void
|
||||
{
|
||||
$rules = RuleLevels::getRulesForLevel(9);
|
||||
$validation = RuleRegistry::validate($rules);
|
||||
|
||||
$this->assertTrue($validation['valid'], implode("\n", $validation['errors']));
|
||||
$this->assertSame(175, $validation['count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: class-string, 1: string, 2: string}>
|
||||
*/
|
||||
public static function newRulesProvider(): array
|
||||
{
|
||||
return [
|
||||
'FocusAppearance' => [
|
||||
FocusAppearance::class,
|
||||
'<style>a:focus { outline: 1px solid #999; }</style>',
|
||||
'<style>a:focus { outline: 2px solid #005fcc; }</style>',
|
||||
],
|
||||
'ConsistentHelp' => [
|
||||
ConsistentHelp::class,
|
||||
'<html><body><header><nav><a href="/">Home</a></nav></header><form><input type="text"></form></body></html>',
|
||||
'<html><body><header><nav><a href="/">Home</a><a href="/help">Help</a></nav></header><form><input type="text"></form></body></html>',
|
||||
],
|
||||
'MotionAnimationReduced' => [
|
||||
MotionAnimationReduced::class,
|
||||
'<style>@keyframes bounce { 0% { top: 0; } 100% { top: 10px; } }</style>',
|
||||
'<style>@keyframes bounce { 0% { top: 0; } 100% { top: 10px; } } @media (prefers-reduced-motion: reduce) { * { animation: none; } }</style>',
|
||||
],
|
||||
'OrientationLockBanned' => [
|
||||
OrientationLockBanned::class,
|
||||
'<style>@media (orientation: landscape) { body { display: none; } }</style>',
|
||||
'<style>@media (min-width: 768px) { .grid { display: grid; } }</style>',
|
||||
],
|
||||
'HoverFocusContentDismissible' => [
|
||||
HoverFocusContentDismissible::class,
|
||||
'<span data-tooltip="Help text">?</span>',
|
||||
'<button type="button" aria-describedby="tip1">?</button><div id="tip1" role="tooltip">Help text</div>',
|
||||
],
|
||||
'CharacterKeyShortcuts' => [
|
||||
CharacterKeyShortcuts::class,
|
||||
'<button aria-keyshortcuts="s">Save</button>',
|
||||
'<button aria-keyshortcuts="Control+S">Save</button>',
|
||||
],
|
||||
'PointerCancellation' => [
|
||||
PointerCancellation::class,
|
||||
'<button onmousedown="submitOrder()">Pay</button>',
|
||||
'<button onclick="submitOrder()">Pay</button>',
|
||||
],
|
||||
'TimeoutWarning' => [
|
||||
TimeoutWarning::class,
|
||||
'<div class="session-timeout" data-timeout="300">Expiring soon</div>',
|
||||
'<div role="timer" aria-live="polite" class="session-timeout" data-timeout="300">Expiring soon <button type="button">Extend</button></div>',
|
||||
],
|
||||
'FlashingContentBanned' => [
|
||||
FlashingContentBanned::class,
|
||||
'<div style="animation: flash 0.1s infinite;">Warning</div>',
|
||||
'<div style="animation: fade 1s ease-in;">Warning</div>',
|
||||
],
|
||||
'TargetSpacingMinimum' => [
|
||||
TargetSpacingMinimum::class,
|
||||
'<a href="/a" style="margin-left: -6px;">Link</a>',
|
||||
'<a href="/a" style="margin-left: 8px; padding: 8px;">Link</a>',
|
||||
],
|
||||
'AriaTablistPattern' => [
|
||||
AriaTablistPattern::class,
|
||||
'<div role="tablist"><button role="tab">Overview</button></div>',
|
||||
'<div role="tablist"><button id="t1" role="tab" aria-selected="true" aria-controls="p1">Overview</button></div><div id="p1" role="tabpanel" aria-labelledby="t1">Content</div>',
|
||||
],
|
||||
'AriaComboboxPattern' => [
|
||||
AriaComboboxPattern::class,
|
||||
'<input role="combobox">',
|
||||
'<input role="combobox" aria-expanded="false" aria-controls="list1" aria-label="Search country">',
|
||||
],
|
||||
'AriaSwitchState' => [
|
||||
AriaSwitchState::class,
|
||||
'<div role="switch">Dark mode</div>',
|
||||
'<button role="switch" aria-checked="false">Dark mode</button>',
|
||||
],
|
||||
'AriaSliderAttributes' => [
|
||||
AriaSliderAttributes::class,
|
||||
'<div role="slider"></div>',
|
||||
'<div role="slider" aria-valuemin="0" aria-valuemax="100" aria-valuenow="50" aria-label="Volume" tabindex="0"></div>',
|
||||
],
|
||||
'AriaMenuPattern' => [
|
||||
AriaMenuPattern::class,
|
||||
'<ul role="menu"><li><a href="/">Home</a></li></ul>',
|
||||
'<ul role="menu"><li role="none"><a role="menuitem" href="/">Home</a></li></ul>',
|
||||
],
|
||||
'AriaTreePattern' => [
|
||||
AriaTreePattern::class,
|
||||
'<ul role="tree"><li role="treeitem">Folder<ul role="group"><li role="treeitem">File</li></ul></li></ul>',
|
||||
'<ul role="tree" aria-label="Files"><li role="treeitem" aria-expanded="true">Folder<ul role="group"><li role="treeitem">File</li></ul></li></ul>',
|
||||
],
|
||||
'AriaBreadcrumbPattern' => [
|
||||
AriaBreadcrumbPattern::class,
|
||||
'<nav class="breadcrumb"><ol><li><a href="/">Home</a></li><li>Docs</li></ol></nav>',
|
||||
'<nav aria-label="Breadcrumb" class="breadcrumb"><ol><li><a href="/">Home</a></li><li aria-current="page">Docs</li></ol></nav>',
|
||||
],
|
||||
'AriaModalBackdrop' => [
|
||||
AriaModalBackdrop::class,
|
||||
'<div role="dialog" aria-label="Confirm">Are you sure?</div>',
|
||||
'<div role="dialog" aria-modal="true" aria-label="Confirm">Are you sure?</div>',
|
||||
],
|
||||
'AriaLivePoliteMisuse' => [
|
||||
AriaLivePoliteMisuse::class,
|
||||
'<main aria-live="assertive"><p>Page body</p></main>',
|
||||
'<main><div role="status" aria-live="polite">Saved</div></main>',
|
||||
],
|
||||
'AriaOwnsValidTarget' => [
|
||||
AriaOwnsValidTarget::class,
|
||||
'<div aria-owns="nonexistent-node">Menu</div>',
|
||||
'<div aria-owns="child-node">Menu</div><ul id="child-node"><li>Item</li></ul>',
|
||||
],
|
||||
'AriaActivedescendantValid' => [
|
||||
AriaActivedescendantValid::class,
|
||||
'<div role="listbox" aria-activedescendant="missing-opt"></div>',
|
||||
'<div role="listbox" tabindex="0" aria-activedescendant="opt1"><div id="opt1" role="option">One</div></div>',
|
||||
],
|
||||
'AriaDeprecatedRoles' => [
|
||||
AriaDeprecatedRoles::class,
|
||||
'<ul role="directory"><li>Item</li></ul>',
|
||||
'<ul role="list"><li>Item</li></ul>',
|
||||
],
|
||||
'ArticleAccessibleHeading' => [
|
||||
ArticleAccessibleHeading::class,
|
||||
'<article><p>Body text without heading</p></article>',
|
||||
'<article><h2>News Title</h2><p>Body text</p></article>',
|
||||
],
|
||||
'SectionAccessibleName' => [
|
||||
SectionAccessibleName::class,
|
||||
'<section role="region"><p>Content</p></section>',
|
||||
'<section role="region" aria-label="Statistics"><p>Content</p></section>',
|
||||
],
|
||||
'NavAccessibleName' => [
|
||||
NavAccessibleName::class,
|
||||
'<nav><a href="/">Home</a></nav><nav><a href="/about">About</a></nav>',
|
||||
'<nav aria-label="Primary"><a href="/">Home</a></nav><nav aria-label="Footer"><a href="/about">About</a></nav>',
|
||||
],
|
||||
'HeaderMainNestedInvalid' => [
|
||||
HeaderMainNestedInvalid::class,
|
||||
'<article><main><p>Invalid nesting</p></main></article>',
|
||||
'<main><article><h2>Valid nesting</h2></article></main>',
|
||||
],
|
||||
'HeadingLengthConcise' => [
|
||||
HeadingLengthConcise::class,
|
||||
'<h2>' . str_repeat('Very long heading content ', 10) . '</h2>',
|
||||
'<h2>Concise Section Heading</h2>',
|
||||
],
|
||||
'AbbreviationExpansion' => [
|
||||
AbbreviationExpansion::class,
|
||||
'<p><abbr>WCAG</abbr> standard</p>',
|
||||
'<p><abbr title="Web Content Accessibility Guidelines">WCAG</abbr> standard</p>',
|
||||
],
|
||||
'BlockquoteCiteValid' => [
|
||||
BlockquoteCiteValid::class,
|
||||
'<blockquote cite="">Quoted sentence</blockquote>',
|
||||
'<blockquote cite="https://www.w3.org">Quoted sentence</blockquote>',
|
||||
],
|
||||
'TimeDatetimeValid' => [
|
||||
TimeDatetimeValid::class,
|
||||
'<time datetime="yesterday">Yesterday</time>',
|
||||
'<time datetime="2026-11-21">21 Nov 2026</time>',
|
||||
],
|
||||
'IframeSandboxAccessibility' => [
|
||||
IframeSandboxAccessibility::class,
|
||||
'<iframe src="/embed" title="Widget" tabindex="-1"></iframe>',
|
||||
'<iframe src="/embed" title="Widget"></iframe>',
|
||||
],
|
||||
'DocumentHasH1' => [
|
||||
DocumentHasH1::class,
|
||||
'<html><body><main><h2>Subtitle only</h2></main></body></html>',
|
||||
'<html><body><main><h1>Main Title</h1><h2>Subtitle</h2></main></body></html>',
|
||||
],
|
||||
'InputTypeValidation' => [
|
||||
InputTypeValidation::class,
|
||||
'<input type="text" name="email" id="email">',
|
||||
'<input type="email" name="email" id="email">',
|
||||
],
|
||||
'FormErrorSummary' => [
|
||||
FormErrorSummary::class,
|
||||
'<input type="email" aria-invalid="true">',
|
||||
'<input type="email" aria-invalid="true" aria-describedby="email-err"><span id="email-err">Invalid email</span>',
|
||||
],
|
||||
'CheckboxGroupFieldset' => [
|
||||
CheckboxGroupFieldset::class,
|
||||
'<form><input type="checkbox" name="topics[]" value="a"><input type="checkbox" name="topics[]" value="b"></form>',
|
||||
'<form><fieldset><legend>Topics</legend><input type="checkbox" name="topics[]" value="a"><input type="checkbox" name="topics[]" value="b"></fieldset></form>',
|
||||
],
|
||||
'SelectOptionNotEmpty' => [
|
||||
SelectOptionNotEmpty::class,
|
||||
'<select aria-label="Country"><option value="tr"></option></select>',
|
||||
'<select aria-label="Country"><option value="tr">Türkiye</option></select>',
|
||||
],
|
||||
'TextareaAccessibleName' => [
|
||||
TextareaAccessibleName::class,
|
||||
'<textarea name="comments"></textarea>',
|
||||
'<label for="comments">Comments</label><textarea id="comments" name="comments"></textarea>',
|
||||
],
|
||||
'OutputForValid' => [
|
||||
OutputForValid::class,
|
||||
'<output for="missing_input">0</output>',
|
||||
'<input id="a" type="number"><output for="a">0</output>',
|
||||
],
|
||||
'ButtonTypeExplicit' => [
|
||||
ButtonTypeExplicit::class,
|
||||
'<form><button>Toggle</button></form>',
|
||||
'<form><button type="button">Toggle</button></form>',
|
||||
],
|
||||
'LinkDownloadContext' => [
|
||||
LinkDownloadContext::class,
|
||||
'<a href="/files/report.pdf">Annual Report</a>',
|
||||
'<a href="/files/report.pdf">Annual Report (PDF)</a>',
|
||||
],
|
||||
'ColorContrastAAA' => [
|
||||
ColorContrastAAA::class,
|
||||
'<p style="color: #767676; background-color: #ffffff;">Medium contrast text</p>',
|
||||
'<p style="color: #111111; background-color: #ffffff;">High contrast text</p>',
|
||||
],
|
||||
'FontSizeMinimum' => [
|
||||
FontSizeMinimum::class,
|
||||
'<p style="font-size: 8px;">Tiny legal text</p>',
|
||||
'<p style="font-size: 16px;">Readable text</p>',
|
||||
],
|
||||
'AllCapsLongText' => [
|
||||
AllCapsLongText::class,
|
||||
'<p style="text-transform: uppercase;">' . str_repeat('This is a long uppercase paragraph. ', 5) . '</p>',
|
||||
'<p style="text-transform: uppercase;">SHORT BADGE</p>',
|
||||
],
|
||||
'JustifiedTextBanned' => [
|
||||
JustifiedTextBanned::class,
|
||||
'<p style="text-align: justify;">Justified text block</p>',
|
||||
'<p style="text-align: start;">Aligned text block</p>',
|
||||
],
|
||||
'SvgFocusableIeEdge' => [
|
||||
SvgFocusableIeEdge::class,
|
||||
'<svg aria-hidden="true"><circle cx="5" cy="5" r="5"></circle></svg>',
|
||||
'<svg aria-hidden="true" focusable="false"><circle cx="5" cy="5" r="5"></circle></svg>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $ruleClass
|
||||
*/
|
||||
#[DataProvider('newRulesProvider')]
|
||||
public function testRuleDetectsViolationAndPassesCompliantMarkup(string $ruleClass, string $badHtml, string $goodHtml): void
|
||||
{
|
||||
$scanner = new Scanner();
|
||||
$scanner->addRule(new $ruleClass());
|
||||
|
||||
$badViolations = $scanner->scan($badHtml);
|
||||
$this->assertNotEmpty($badViolations, "Expected {$ruleClass} to report violation for bad HTML.");
|
||||
|
||||
$goodViolations = $scanner->scan($goodHtml);
|
||||
$this->assertEmpty($goodViolations, "Expected {$ruleClass} to report 0 violations for compliant HTML.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YakNet\AccessibilityConsole\Cache\ScanCache;
|
||||
use YakNet\AccessibilityConsole\CI\CiWorkflowGenerator;
|
||||
use YakNet\AccessibilityConsole\Core\Analyser;
|
||||
use YakNet\AccessibilityConsole\Core\BaselineManager;
|
||||
use YakNet\AccessibilityConsole\Core\Config;
|
||||
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||
use YakNet\AccessibilityConsole\Rules\ImgAltText;
|
||||
use YakNet\AccessibilityConsole\Testing\AccessibilityAssertions;
|
||||
|
||||
class V4SymmetryModulesTest extends TestCase
|
||||
{
|
||||
use AccessibilityAssertions;
|
||||
|
||||
public function testScanCacheStoresAndServesHits(): void
|
||||
{
|
||||
$cacheFile = sys_get_temp_dir() . '/yaknet_cache_' . uniqid() . '.json';
|
||||
$htmlFile = sys_get_temp_dir() . '/yaknet_cached_page_' . uniqid() . '.html';
|
||||
file_put_contents($htmlFile, '<main><img src="a.png"></main>');
|
||||
|
||||
try {
|
||||
$scanner = new Scanner();
|
||||
$scanner->addRule(new ImgAltText());
|
||||
|
||||
// First run: cache miss & populate
|
||||
$cache1 = new ScanCache($cacheFile, 'sig-v1');
|
||||
$analyser1 = new Analyser(new Config(), $scanner, new BaselineManager(), null, null, null, $cache1);
|
||||
$res1 = $analyser1->analyse([$htmlFile]);
|
||||
$this->assertCount(1, $res1['violations']);
|
||||
$this->assertSame(0, $cache1->getStats()['hits']);
|
||||
$this->assertSame(1, $cache1->getStats()['misses']);
|
||||
|
||||
// Second run: cache hit!
|
||||
$cache2 = new ScanCache($cacheFile, 'sig-v1');
|
||||
$cache2->load();
|
||||
$analyser2 = new Analyser(new Config(), $scanner, new BaselineManager(), null, null, null, $cache2);
|
||||
$res2 = $analyser2->analyse([$htmlFile]);
|
||||
$this->assertCount(1, $res2['violations']);
|
||||
$this->assertSame(1, $cache2->getStats()['hits']);
|
||||
$this->assertSame(100.0, $cache2->getStats()['hit_rate']);
|
||||
} finally {
|
||||
@unlink($cacheFile);
|
||||
@unlink($htmlFile);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCiWorkflowGeneratorSupportsAllFourPlatforms(): void
|
||||
{
|
||||
$generator = new CiWorkflowGenerator();
|
||||
|
||||
foreach (CiWorkflowGenerator::getSupportedPlatforms() as $platform) {
|
||||
$yaml = $generator->generate($platform, 'wcag22-aa', 95, 'templates');
|
||||
$this->assertStringContainsString('vendor/bin/a11y', $yaml);
|
||||
$this->assertStringContainsString('--preset=wcag22-aa', $yaml);
|
||||
$this->assertNotEmpty(CiWorkflowGenerator::getDefaultPath($platform));
|
||||
}
|
||||
}
|
||||
|
||||
public function testAccessibilityAssertionsTraitValidatesCleanHtml(): void
|
||||
{
|
||||
$cleanHtml = '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>YakNet</title></head><body><main><h1>Welcome</h1><p>Accessible page.</p></main></body></html>';
|
||||
|
||||
$this->assertHtmlAccessible($cleanHtml, level: 4);
|
||||
$this->assertAccessibilityScoreAtLeast($cleanHtml, minScore: 95, level: 4);
|
||||
$this->assertMeetsAccessibilityPreset($cleanHtml, 'wcag22-aa');
|
||||
$this->assertNoAccessibilityRuleViolation($cleanHtml, 'WCAG_1_1_1_ALT');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user