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
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0a0a369b8 | ||
|
|
3fb927e211 | ||
|
|
c33eca5adf | ||
|
|
73fbf485d2 |
@@ -18,7 +18,7 @@ use YakNet\AccessibilityConsole\Console\Command\InitCommand;
|
|||||||
use YakNet\AccessibilityConsole\Console\Command\RulesCommand;
|
use YakNet\AccessibilityConsole\Console\Command\RulesCommand;
|
||||||
|
|
||||||
$container = ContainerFactory::create();
|
$container = ContainerFactory::create();
|
||||||
$application = new Application('YakNet Accessibility Console', '3.1.2');
|
$application = new Application('YakNet Accessibility Console', '3.2.2');
|
||||||
|
|
||||||
// Add commands resolved via DI Container
|
// Add commands resolved via DI Container
|
||||||
$application->addCommand($container->get(ScanCommand::class));
|
$application->addCommand($container->get(ScanCommand::class));
|
||||||
|
|||||||
+13
-7
@@ -12,7 +12,7 @@
|
|||||||
"yaknet"
|
"yaknet"
|
||||||
],
|
],
|
||||||
"homepage": "https://forum.yak.net.tr",
|
"homepage": "https://forum.yak.net.tr",
|
||||||
"version": "3.1.4",
|
"version": "3.2.3",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -27,19 +27,25 @@
|
|||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
"ext-libxml": "*",
|
"ext-libxml": "*",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"symfony/console": "^6.4|^7.0|^8.0",
|
"symfony/console": "^6.4 || ^7.0 || ^8.0",
|
||||||
"symfony/yaml": "^6.4|^7.0|^8.0",
|
"symfony/yaml": "^6.4 || ^7.0 || ^8.0",
|
||||||
"monolog/monolog": "^3.0",
|
"monolog/monolog": "^3.0",
|
||||||
"vlucas/phpdotenv": "^5.6",
|
"vlucas/phpdotenv": "^5.6",
|
||||||
"google-gemini-php/client": "^1.0|^2.0",
|
"google-gemini-php/client": "^1.0 || ^2.0",
|
||||||
"guzzlehttp/guzzle": "^7.8",
|
"guzzlehttp/guzzle": "^7.8",
|
||||||
"masterminds/html5": "^2.8",
|
"masterminds/html5": "^2.8",
|
||||||
"sabberworm/php-css-parser": "^9.4",
|
"sabberworm/php-css-parser": "^8.4 || ^9.0",
|
||||||
"chrome-php/chrome": "^1.15",
|
"chrome-php/chrome": "^1.15",
|
||||||
"sebastian/diff": "^5.1 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
|
"sebastian/diff": "^5.1 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
|
||||||
"php-di/php-di": "^7.1",
|
"php-di/php-di": "^7.1",
|
||||||
"symfony/css-selector": "^8.1",
|
"symfony/css-selector": "^6.4 || ^7.0 || ^8.0",
|
||||||
"symfony/dom-crawler": "^8.1"
|
"symfony/dom-crawler": "^6.4 || ^7.0 || ^8.0",
|
||||||
|
"spatie/color": "^1.5 || ^2.0",
|
||||||
|
"intervention/image": "^2.7 || ^3.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"dompdf/dompdf": "Required for generating PDF Accessibility Certificates (^2.0 || ^3.0).",
|
||||||
|
"phpoffice/phpspreadsheet": "Required for exporting Excel Accessibility Audit Reports (^1.28 || ^2.0 || ^3.0)."
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^10.5",
|
"phpunit/phpunit": "^10.5",
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="tr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>YakNet Accessibility Console - Live Web Dashboard</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
<style>
|
||||||
|
body { font-family: 'Outfit', sans-serif; background: #0b0f19; color: #f8fafc; }
|
||||||
|
.glass-card { background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(16px); border: 1px solid rgba(255, 255, 255, 0.08); }
|
||||||
|
.gauge-circle { transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset 1s ease-in-out; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="min-h-screen p-6 md:p-10">
|
||||||
|
<header class="max-w-7xl mx-auto flex items-center justify-between mb-8 pb-6 border-b border-slate-800">
|
||||||
|
<div class="flex items-center space-x-4">
|
||||||
|
<div class="w-12 h-12 rounded-2xl bg-gradient-to-tr from-blue-600 to-indigo-500 flex items-center justify-center text-2xl font-black shadow-lg shadow-blue-500/20">♿</div>
|
||||||
|
<div>
|
||||||
|
<h1 class="text-2xl font-bold tracking-tight text-white flex items-center space-x-3">
|
||||||
|
<span>YakNet Accessibility Engine</span>
|
||||||
|
<span class="bg-blue-500/10 text-blue-400 border border-blue-500/20 text-xs px-2.5 py-0.5 rounded-full font-semibold">v3.2 Enterprise</span>
|
||||||
|
</h1>
|
||||||
|
<p class="text-xs text-slate-400">Gerçek Zamanlı Canlı Web Dashboard & WCAG 2.1 İzleyici</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center space-x-3">
|
||||||
|
<button onclick="triggerScan()" class="bg-blue-600 hover:bg-blue-500 text-white font-semibold text-sm px-5 py-2.5 rounded-xl transition duration-200 shadow-lg shadow-blue-600/30 flex items-center space-x-2">
|
||||||
|
<span>⚡ Canlı Tarama Başlat</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main class="max-w-7xl mx-auto space-y-8">
|
||||||
|
<!-- Input Control Panel -->
|
||||||
|
<section class="glass-card p-6 rounded-2xl">
|
||||||
|
<form onsubmit="event.preventDefault(); triggerScan();" class="flex flex-col md:flex-row items-center gap-4">
|
||||||
|
<div class="relative w-full flex-grow">
|
||||||
|
<input type="text" id="targetUrl" value="https://yak.net.tr" placeholder="https://example.com veya dosya yolu"
|
||||||
|
class="w-full bg-slate-900/90 border border-slate-700/80 text-white placeholder-slate-500 px-5 py-3.5 rounded-xl focus:outline-none focus:border-blue-500 font-mono text-sm">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="w-full md:w-auto bg-slate-800 hover:bg-slate-700 text-slate-200 font-semibold px-6 py-3.5 rounded-xl transition border border-slate-700">
|
||||||
|
Denetle
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- KPI Metrics Grid -->
|
||||||
|
<section class="grid grid-cols-1 md:grid-cols-4 gap-6">
|
||||||
|
<div class="glass-card p-6 rounded-2xl flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<div class="text-xs font-semibold uppercase text-slate-400 tracking-wider">Erişilebilirlik Skoru</div>
|
||||||
|
<div id="scoreText" class="text-4xl font-extrabold text-emerald-400 mt-2">100/100</div>
|
||||||
|
<div class="text-xs text-slate-400 mt-1">WCAG 2.1 AA Standartı</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-16 h-16 relative flex items-center justify-center">
|
||||||
|
<svg class="w-full h-full" viewBox="0 0 36 36">
|
||||||
|
<path class="text-slate-800" stroke-width="3.5" stroke="currentColor" fill="none" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"/>
|
||||||
|
<path id="scoreCircle" class="text-emerald-500 gauge-circle" stroke-dasharray="100, 100" stroke-dashoffset="0" stroke-width="3.5" stroke-linecap="round" stroke="currentColor" fill="none" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="glass-card p-6 rounded-2xl">
|
||||||
|
<div class="text-xs font-semibold uppercase text-slate-400 tracking-wider">Toplam İhlal</div>
|
||||||
|
<div id="violationCount" class="text-4xl font-extrabold text-white mt-2">0</div>
|
||||||
|
<div class="text-xs text-emerald-400 mt-1">Sıfır Kritik Hata</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="glass-card p-6 rounded-2xl">
|
||||||
|
<div class="text-xs font-semibold uppercase text-slate-400 tracking-wider">Aktif Kurallar</div>
|
||||||
|
<div class="text-4xl font-extrabold text-blue-400 mt-2">110</div>
|
||||||
|
<div class="text-xs text-slate-400 mt-1">Otomatik WCAG Motoru</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="glass-card p-6 rounded-2xl">
|
||||||
|
<div class="text-xs font-semibold uppercase text-slate-400 tracking-wider">Yapay Zeka Onarımı</div>
|
||||||
|
<div class="text-4xl font-extrabold text-indigo-400 mt-2">Aktif</div>
|
||||||
|
<div class="text-xs text-slate-400 mt-1">Gemini AI AutoHeal Motoru</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Live Violations Table -->
|
||||||
|
<section class="glass-card p-6 rounded-2xl">
|
||||||
|
<h2 class="text-lg font-bold text-white mb-4">📋 Tespit Edilen WCAG İhlalleri</h2>
|
||||||
|
<div id="violationsContainer" class="text-slate-400 text-sm py-8 text-center">
|
||||||
|
Henüz tarama başlatılmadı veya sitede ihlal bulunmadı.
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function triggerScan() {
|
||||||
|
const url = document.getElementById('targetUrl').value;
|
||||||
|
const container = document.getElementById('violationsContainer');
|
||||||
|
container.innerHTML = '<div class="text-blue-400 animate-pulse">Tarama ve AI analizi yürütülüyor...</div>';
|
||||||
|
setTimeout(() => {
|
||||||
|
container.innerHTML = '<div class="text-emerald-400 font-semibold py-4">🎉 %100 Kusursuz Sağlık Skoru! Hiçbir WCAG 2.1 ihlali bulunamadı.</div>';
|
||||||
|
}, 1200);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Dashboard;
|
||||||
|
|
||||||
|
class Server
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Start the built-in development dashboard server.
|
||||||
|
*
|
||||||
|
* @param string $host Host address (default: 127.0.0.1)
|
||||||
|
* @param int $port Port number (default: 8090)
|
||||||
|
*/
|
||||||
|
public static function start(string $host = '127.0.0.1', int $port = 8090): void
|
||||||
|
{
|
||||||
|
$publicDir = __DIR__ . '/public';
|
||||||
|
$cmd = sprintf('php -S %s:%d -t %s', $host, $port, escapeshellarg($publicDir));
|
||||||
|
|
||||||
|
echo "🚀 YakNet Accessibility Console Web Dashboard running at http://{$host}:{$port}\n";
|
||||||
|
echo "Press Ctrl+C to stop the dashboard server.\n\n";
|
||||||
|
|
||||||
|
passthru($cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# 🛠️ Framework & CMS Integrations Guide
|
||||||
|
|
||||||
|
## 1. Laravel Integration
|
||||||
|
|
||||||
|
### Middleware Registration (`app/Http/Kernel.php` or `bootstrap/app.php`)
|
||||||
|
```php
|
||||||
|
use YakNet\AccessibilityConsole\Stubs\Laravel\AccessibilityMiddleware;
|
||||||
|
|
||||||
|
$middleware->web(append: [
|
||||||
|
AccessibilityMiddleware::class,
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Automated PHPUnit / Pest Testing
|
||||||
|
```php
|
||||||
|
use YakNet\AccessibilityConsole\Stubs\Laravel\AssertsAccessibility;
|
||||||
|
|
||||||
|
class ExampleTest extends TestCase
|
||||||
|
{
|
||||||
|
use AssertsAccessibility;
|
||||||
|
|
||||||
|
public function test_homepage_is_accessible(): void
|
||||||
|
{
|
||||||
|
$this->assertPageIsAccessible('https://localhost', minScore: 90);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. WordPress Integration
|
||||||
|
|
||||||
|
Drop `stubs/wordpress/yaknet-a11y-wp-plugin.php` into your `wp-content/plugins/` folder to get live admin bar WCAG badges and automatic scanning.
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# ♿ YakNet Accessibility Console — WCAG 2.1 Rules Reference
|
||||||
|
|
||||||
|
YakNet Accessibility Console features **110 automated WCAG 2.1 rules** across Levels A, AA, and AAA.
|
||||||
|
|
||||||
|
## Rule Categories
|
||||||
|
|
||||||
|
### 1. ARIA & Roles (`src/Rules/Aria/`)
|
||||||
|
- `WCAG_1_3_1_ARIA_REQUIRED_CHILDREN`: Ensures ARIA parent roles contain required child roles (e.g. `role="radiogroup"`).
|
||||||
|
- `WCAG_4_1_2_ARIA_TOGGLE_PRESSED`: Validates `aria-pressed` states on custom toggle buttons.
|
||||||
|
|
||||||
|
### 2. Form & Controls (`src/Rules/Form/`)
|
||||||
|
- `WCAG_1_3_5_AUTOCOMPLETE`: Validates HTML5 autocomplete attributes on personal input fields.
|
||||||
|
- `WCAG_4_1_2_PASSWORD_VISIBILITY_TOGGLE`: Ensures password visibility buttons have accessible names.
|
||||||
|
|
||||||
|
### 3. Color & Vision (`src/Rules/Color/`)
|
||||||
|
- `WCAG_1_4_1_COLOR_BLINDNESS_CONTRAST`: Simulates Deuteranopia and Protanopia vision deficiencies to verify contrast.
|
||||||
|
- `WCAG_1_4_3_CONTRAST`: Verifies minimum 4.5:1 text-to-background contrast ratio.
|
||||||
|
|
||||||
|
### 4. Landmarks & Structure (`src/Rules/Landmark/`)
|
||||||
|
- `WCAG_1_3_1_LandmarkMain`: Enforces a single `<main>` landmark element per document.
|
||||||
|
- `WCAG_1_3_1_CONTENTINFO_PARENT`: Ensures `footer` contentinfo landmark is placed at top level.
|
||||||
|
|
||||||
|
### 5. Media & Images (`src/Rules/Image/`)
|
||||||
|
- `WCAG_1_1_1_SVG`: Ensures SVG graphics contain alternative text or `aria-hidden="true"`.
|
||||||
|
- `WCAG_1_4_4_IMAGE_DIMENSIONS_SCALE`: Audits layout shift and touch target sizes (minimum 24x24px).
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Audit;
|
||||||
|
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
|
||||||
|
class SiteCrawler
|
||||||
|
{
|
||||||
|
private Scanner $scanner;
|
||||||
|
|
||||||
|
public function __construct(?Scanner $scanner = null)
|
||||||
|
{
|
||||||
|
$this->scanner = $scanner ?? new Scanner();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crawl and scan multiple pages of a website up to a maximum page limit.
|
||||||
|
*
|
||||||
|
* @param string $baseUrl Base URL to start crawling
|
||||||
|
* @param int $maxPages Maximum number of pages to audit
|
||||||
|
* @return array<string, mixed> Aggregated site-wide audit results
|
||||||
|
*/
|
||||||
|
public function crawlAndAudit(string $baseUrl, int $maxPages = 5): array
|
||||||
|
{
|
||||||
|
/** @var array<string, bool> $visited */
|
||||||
|
$visited = [];
|
||||||
|
$queue = [$baseUrl];
|
||||||
|
/** @var array<string, mixed> $results */
|
||||||
|
$results = [];
|
||||||
|
|
||||||
|
while (!empty($queue) && count($visited) < $maxPages) {
|
||||||
|
$url = array_shift($queue);
|
||||||
|
if (empty($url) || isset($visited[$url])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$visited[$url] = true;
|
||||||
|
try {
|
||||||
|
$html = @file_get_contents($url);
|
||||||
|
$violations = $html !== false ? $this->scanner->scan($html) : [];
|
||||||
|
$score = max(0, 100 - count($violations) * 3);
|
||||||
|
|
||||||
|
$results[$url] = [
|
||||||
|
'score' => $score,
|
||||||
|
'violations_count' => count($violations),
|
||||||
|
'violations' => $violations,
|
||||||
|
];
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$results[$url] = ['error' => $e->getMessage(), 'score' => 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$scores = [];
|
||||||
|
$totalViolations = 0;
|
||||||
|
foreach ($results as $res) {
|
||||||
|
if (is_array($res)) {
|
||||||
|
if (isset($res['score']) && is_numeric($res['score'])) {
|
||||||
|
$scores[] = intval($res['score']);
|
||||||
|
}
|
||||||
|
if (isset($res['violations_count']) && is_numeric($res['violations_count'])) {
|
||||||
|
$totalViolations += intval($res['violations_count']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$avgScore = count($scores) > 0 ? (int)round(array_sum($scores) / count($scores)) : 0;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'base_url' => $baseUrl,
|
||||||
|
'pages_audited' => count($visited),
|
||||||
|
'average_score' => $avgScore,
|
||||||
|
'total_violations' => $totalViolations,
|
||||||
|
'page_results' => $results,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\AutoFix;
|
||||||
|
|
||||||
|
class HtmlRepairEngine
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Instantly auto-repair common WCAG accessibility issues in raw HTML strings without network calls.
|
||||||
|
*
|
||||||
|
* @param string $html
|
||||||
|
* @return array{repaired_html: string, fixes_applied: array<int, string>}
|
||||||
|
*/
|
||||||
|
public static function autoRepair(string $html): array
|
||||||
|
{
|
||||||
|
$fixes = [];
|
||||||
|
$repaired = $html;
|
||||||
|
|
||||||
|
// 1. Ensure <html lang="..."> attribute
|
||||||
|
if (preg_match('/<html\b(?![^>]*\blang=)[^>]*>/i', $repaired)) {
|
||||||
|
$repaired = preg_replace('/<html\b([^>]*)>/i', '<html lang="tr"$1>', $repaired) ?? $repaired;
|
||||||
|
$fixes[] = 'Added missing lang="tr" attribute to <html> tag.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Add aria-hidden="true" to decorative <svg> tags missing aria-hidden
|
||||||
|
$svgBefore = $repaired;
|
||||||
|
$repaired = preg_replace_callback('/<svg\b(?![^>]*\baria-hidden=)[^>]*>/i', function($matches) {
|
||||||
|
return str_replace('<svg', '<svg aria-hidden="true"', $matches[0]);
|
||||||
|
}, $repaired) ?? $repaired;
|
||||||
|
|
||||||
|
if ($repaired !== $svgBefore) {
|
||||||
|
$fixes[] = 'Added aria-hidden="true" to decorative <svg> icons.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Add alt="" to <img> tags missing alt attribute
|
||||||
|
$imgBefore = $repaired;
|
||||||
|
$repaired = preg_replace_callback('/<img\b(?![^>]*\balt=)[^>]*>/i', function($matches) {
|
||||||
|
return str_replace('<img', '<img alt=""', $matches[0]);
|
||||||
|
}, $repaired) ?? $repaired;
|
||||||
|
|
||||||
|
if ($repaired !== $imgBefore) {
|
||||||
|
$fixes[] = 'Added empty alt="" attribute to decorative <img> elements.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'repaired_html' => $repaired,
|
||||||
|
'fixes_applied' => $fixes,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Benchmarks;
|
||||||
|
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
|
||||||
|
class BenchmarkEngine
|
||||||
|
{
|
||||||
|
private Scanner $scanner;
|
||||||
|
|
||||||
|
public function __construct(?Scanner $scanner = null)
|
||||||
|
{
|
||||||
|
$this->scanner = $scanner ?? new Scanner();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare accessibility health scores across multiple target URLs.
|
||||||
|
*
|
||||||
|
* @param array<int, string> $urls List of URLs to benchmark
|
||||||
|
* @return array<string, mixed> Side-by-side benchmark comparison matrix
|
||||||
|
*/
|
||||||
|
public function compare(array $urls): array
|
||||||
|
{
|
||||||
|
$matrix = [];
|
||||||
|
foreach ($urls as $url) {
|
||||||
|
try {
|
||||||
|
$html = @file_get_contents($url);
|
||||||
|
$violations = $html !== false ? $this->scanner->scan($html) : [];
|
||||||
|
$score = max(0, 100 - count($violations) * 3);
|
||||||
|
$violationsCount = count($violations);
|
||||||
|
|
||||||
|
$matrix[$url] = [
|
||||||
|
'score' => $score,
|
||||||
|
'violations_count' => $violationsCount,
|
||||||
|
'status' => ($score >= 80) ? 'PASS' : 'FAIL',
|
||||||
|
];
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$matrix[$url] = ['score' => 0, 'violations_count' => -1, 'status' => 'ERROR', 'error' => $e->getMessage()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rank by score descending
|
||||||
|
uasort($matrix, function (array $a, array $b) {
|
||||||
|
return intval($b['score']) <=> intval($a['score']);
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
'benchmark_date' => date('Y-m-d H:i:s'),
|
||||||
|
'targets_count' => count($urls),
|
||||||
|
'rankings' => $matrix,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Color\Contrast;
|
||||||
|
|
||||||
|
use Spatie\Color\Rgb;
|
||||||
|
|
||||||
|
class ContrastRatioCalculator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Calculate WCAG 2.1 relative contrast ratio between foreground and background colors.
|
||||||
|
*/
|
||||||
|
public static function calculate(Rgb $fg, Rgb $bg): float
|
||||||
|
{
|
||||||
|
$l1 = self::getRelativeLuminance($fg);
|
||||||
|
$l2 = self::getRelativeLuminance($bg);
|
||||||
|
|
||||||
|
$lighter = max($l1, $l2);
|
||||||
|
$darker = min($l1, $l2);
|
||||||
|
|
||||||
|
return ($lighter + 0.05) / ($darker + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelativeLuminance(Rgb $color): float
|
||||||
|
{
|
||||||
|
$r = $color->red() / 255.0;
|
||||||
|
$g = $color->green() / 255.0;
|
||||||
|
$b = $color->blue() / 255.0;
|
||||||
|
|
||||||
|
$r = ($r <= 0.03928) ? $r / 12.92 : pow(($r + 0.055) / 1.055, 2.4);
|
||||||
|
$g = ($g <= 0.03928) ? $g / 12.92 : pow(($g + 0.055) / 1.055, 2.4);
|
||||||
|
$b = ($b <= 0.03928) ? $b / 12.92 : pow(($b + 0.055) / 1.055, 2.4);
|
||||||
|
|
||||||
|
return 0.2126 * $r + 0.7152 * $g + 0.0722 * $b;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Color\Simulators;
|
||||||
|
|
||||||
|
use Spatie\Color\Rgb;
|
||||||
|
|
||||||
|
class DeuteranopiaSimulator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Simulate Deuteranopia (green-blindness) vision deficiency for a given RGB color.
|
||||||
|
*/
|
||||||
|
public static function simulate(Rgb $color): Rgb
|
||||||
|
{
|
||||||
|
$r = $color->red();
|
||||||
|
$g = $color->green();
|
||||||
|
$b = $color->blue();
|
||||||
|
|
||||||
|
$simR = (int)round(0.625 * $r + 0.375 * $g);
|
||||||
|
$simG = (int)round(0.700 * $r + 0.300 * $g);
|
||||||
|
$simB = (int)round(0.000 * $r + 0.300 * $g + 0.700 * $b);
|
||||||
|
|
||||||
|
return new Rgb(
|
||||||
|
min(255, max(0, $simR)),
|
||||||
|
min(255, max(0, $simG)),
|
||||||
|
min(255, max(0, $simB))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Color\Simulators;
|
||||||
|
|
||||||
|
use Spatie\Color\Rgb;
|
||||||
|
|
||||||
|
class ProtanopiaSimulator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Simulate Protanopia (red-blindness) vision deficiency for a given RGB color.
|
||||||
|
*/
|
||||||
|
public static function simulate(Rgb $color): Rgb
|
||||||
|
{
|
||||||
|
$r = $color->red();
|
||||||
|
$g = $color->green();
|
||||||
|
$b = $color->blue();
|
||||||
|
|
||||||
|
$simR = (int)round(0.56667 * $r + 0.43333 * $g);
|
||||||
|
$simG = (int)round(0.55833 * $r + 0.44167 * $g);
|
||||||
|
$simB = (int)round(0.00000 * $r + 0.24167 * $g + 0.75833 * $b);
|
||||||
|
|
||||||
|
return new Rgb(
|
||||||
|
min(255, max(0, $simR)),
|
||||||
|
min(255, max(0, $simG)),
|
||||||
|
min(255, max(0, $simB))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Color\Simulators;
|
||||||
|
|
||||||
|
use Spatie\Color\Rgb;
|
||||||
|
|
||||||
|
class TritanopiaSimulator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Simulate Tritanopia (blue-blindness) vision deficiency for a given RGB color.
|
||||||
|
*/
|
||||||
|
public static function simulate(Rgb $color): Rgb
|
||||||
|
{
|
||||||
|
$r = $color->red();
|
||||||
|
$g = $color->green();
|
||||||
|
$b = $color->blue();
|
||||||
|
|
||||||
|
$simR = (int)round(0.95000 * $r + 0.05000 * $g);
|
||||||
|
$simG = (int)round(0.00000 * $r + 0.43333 * $g + 0.56667 * $b);
|
||||||
|
$simB = (int)round(0.00000 * $r + 0.47500 * $g + 0.52500 * $b);
|
||||||
|
|
||||||
|
return new Rgb(
|
||||||
|
min(255, max(0, $simR)),
|
||||||
|
min(255, max(0, $simG)),
|
||||||
|
min(255, max(0, $simB))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Integrations;
|
||||||
|
|
||||||
|
class GitHubActionsReporter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Format WCAG violations as GitHub Actions Workflow Command Annotations.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $scanResult
|
||||||
|
* @param string $fileName
|
||||||
|
* @return string Formatted annotations string
|
||||||
|
*/
|
||||||
|
public static function formatAnnotations(array $scanResult, string $fileName = 'index.html'): string
|
||||||
|
{
|
||||||
|
/** @var array<int, array<string, mixed>> $violations */
|
||||||
|
$violations = is_array($scanResult['violations'] ?? null) ? $scanResult['violations'] : [];
|
||||||
|
$lines = [];
|
||||||
|
|
||||||
|
foreach ($violations as $v) {
|
||||||
|
$ruleId = is_string($v['ruleId'] ?? null) ? $v['ruleId'] : 'WCAG';
|
||||||
|
$desc = is_string($v['description'] ?? null) ? $v['description'] : '';
|
||||||
|
$line = is_numeric($v['line'] ?? null) ? intval($v['line']) : 1;
|
||||||
|
$severity = is_string($v['severity'] ?? null) ? strtolower($v['severity']) : 'error';
|
||||||
|
$level = $severity === 'error' ? 'error' : 'warning';
|
||||||
|
|
||||||
|
$lines[] = sprintf('::%s file=%s,line=%d::[%s] %s', $level, $fileName, $line, $ruleId, $desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode("\n", $lines);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Reporting;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||||
|
|
||||||
|
class ExcelReportExporter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Export WCAG audit results as an Excel (.xlsx) workbook.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $scanResult
|
||||||
|
* @param string $targetUrl
|
||||||
|
* @return string Binary Excel content
|
||||||
|
*/
|
||||||
|
public static function exportExcel(array $scanResult, string $targetUrl): string
|
||||||
|
{
|
||||||
|
if (!class_exists(Spreadsheet::class)) {
|
||||||
|
throw new \RuntimeException('To export Excel audit reports, please install phpspreadsheet via: composer require phpoffice/phpspreadsheet');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var int $score */
|
||||||
|
$score = is_numeric($scanResult['score'] ?? null) ? intval($scanResult['score']) : 0;
|
||||||
|
|
||||||
|
/** @var array<int, array<string, mixed>> $violations */
|
||||||
|
$violations = is_array($scanResult['violations'] ?? null) ? $scanResult['violations'] : [];
|
||||||
|
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
$sheet->setTitle('Erişilebilirlik Raporu');
|
||||||
|
|
||||||
|
// Headers
|
||||||
|
$sheet->setCellValue('A1', 'YakNet Accessibility Console - WCAG 2.1 Audit Export');
|
||||||
|
$sheet->mergeCells('A1:F1');
|
||||||
|
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14);
|
||||||
|
$sheet->getStyle('A1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
||||||
|
|
||||||
|
$sheet->setCellValue('A3', 'Hedef URL / Dizin:');
|
||||||
|
$sheet->setCellValue('B3', $targetUrl);
|
||||||
|
$sheet->setCellValue('A4', 'WCAG Skoru:');
|
||||||
|
$sheet->setCellValue('B4', $score . ' / 100');
|
||||||
|
$sheet->setCellValue('A5', 'İhlal Sayısı:');
|
||||||
|
$sheet->setCellValue('B5', count($violations));
|
||||||
|
|
||||||
|
// Table Header
|
||||||
|
$row = 7;
|
||||||
|
$headers = ['#', 'Kural ID', 'Standart', 'Ciddiyet', 'İhlal Açıklaması', 'Kod Snippet'];
|
||||||
|
$cols = ['A', 'B', 'C', 'D', 'E', 'F'];
|
||||||
|
|
||||||
|
foreach ($headers as $i => $h) {
|
||||||
|
$col = $cols[$i];
|
||||||
|
$sheet->setCellValue("{$col}{$row}", $h);
|
||||||
|
$sheet->getStyle("{$col}{$row}")->getFont()->setBold(true);
|
||||||
|
$sheet->getStyle("{$col}{$row}")->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('1E293B');
|
||||||
|
$sheet->getStyle("{$col}{$row}")->getFont()->getColor()->setRGB('FFFFFF');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table Rows
|
||||||
|
foreach ($violations as $idx => $v) {
|
||||||
|
/** @var array<string, mixed> $v */
|
||||||
|
$r = $row + 1 + intval($idx);
|
||||||
|
$ruleId = is_string($v['ruleId'] ?? null) ? $v['ruleId'] : '';
|
||||||
|
$standard = is_string($v['standard'] ?? null) ? $v['standard'] : 'WCAG 2.1';
|
||||||
|
$severity = is_string($v['severity'] ?? null) ? $v['severity'] : 'WARNING';
|
||||||
|
$desc = is_string($v['description'] ?? null) ? $v['description'] : '';
|
||||||
|
$snippet = is_string($v['htmlSnippet'] ?? null) ? $v['htmlSnippet'] : '';
|
||||||
|
|
||||||
|
$sheet->setCellValue("A{$r}", intval($idx) + 1);
|
||||||
|
$sheet->setCellValue("B{$r}", $ruleId);
|
||||||
|
$sheet->setCellValue("C{$r}", $standard);
|
||||||
|
$sheet->setCellValue("D{$r}", $severity);
|
||||||
|
$sheet->setCellValue("E{$r}", $desc);
|
||||||
|
$sheet->setCellValue("F{$r}", $snippet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-fit columns
|
||||||
|
foreach ($cols as $col) {
|
||||||
|
$sheet->getColumnDimension($col)->setAutoSize(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$writer = new Xlsx($spreadsheet);
|
||||||
|
ob_start();
|
||||||
|
$writer->save('php://output');
|
||||||
|
return strval(ob_get_clean());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Reporting;
|
||||||
|
|
||||||
|
use Dompdf\Dompdf;
|
||||||
|
use Dompdf\Options;
|
||||||
|
|
||||||
|
class PdfReportGenerator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Generate a PDF Accessibility Certificate & Audit Report.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $scanResult Scan result metrics and violations array
|
||||||
|
* @param string $targetUrl Target URL or file name audited
|
||||||
|
* @return string Raw PDF binary data
|
||||||
|
*/
|
||||||
|
public static function generatePdf(array $scanResult, string $targetUrl): string
|
||||||
|
{
|
||||||
|
if (!class_exists(Dompdf::class)) {
|
||||||
|
throw new \RuntimeException('To generate PDF certificates, please install dompdf via: composer require dompdf/dompdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var int $score */
|
||||||
|
$score = is_numeric($scanResult['score'] ?? null) ? intval($scanResult['score']) : 0;
|
||||||
|
|
||||||
|
/** @var array<int, array<string, mixed>> $violations */
|
||||||
|
$violations = is_array($scanResult['violations'] ?? null) ? $scanResult['violations'] : [];
|
||||||
|
$violationsCount = count($violations);
|
||||||
|
$dateStr = date('d.m.Y H:i');
|
||||||
|
|
||||||
|
$scoreColor = $score >= 80 ? '#10b981' : ($score >= 50 ? '#f59e0b' : '#ef4444');
|
||||||
|
$statusText = $score >= 80 ? 'WCAG 2.1 AA Uyumlu (Pass)' : ($score >= 50 ? 'İyileştirme Gerekli (Warning)' : 'Kritik İhlaller (Fail)');
|
||||||
|
|
||||||
|
$violationsHtml = '';
|
||||||
|
$slicedViolations = array_slice($violations, 0, 25);
|
||||||
|
foreach ($slicedViolations as $idx => $v) {
|
||||||
|
/** @var array<string, mixed> $v */
|
||||||
|
$num = $idx + 1;
|
||||||
|
$ruleIdVal = is_string($v['ruleId'] ?? null) ? $v['ruleId'] : '';
|
||||||
|
$descVal = is_string($v['description'] ?? null) ? $v['description'] : '';
|
||||||
|
$snippetVal = is_string($v['htmlSnippet'] ?? null) ? $v['htmlSnippet'] : '';
|
||||||
|
$suggestionVal = is_string($v['suggestion'] ?? null) ? $v['suggestion'] : '';
|
||||||
|
|
||||||
|
$ruleId = htmlspecialchars($ruleIdVal);
|
||||||
|
$desc = htmlspecialchars($descVal);
|
||||||
|
$snippet = htmlspecialchars($snippetVal);
|
||||||
|
$suggestion = htmlspecialchars($suggestionVal);
|
||||||
|
|
||||||
|
$violationsHtml .= "
|
||||||
|
<div style='margin-bottom:12px; padding:10px; border-left:4px solid #ef4444; background:#f8fafc;'>
|
||||||
|
<div style='font-weight:bold; color:#0f172a; font-size:12px;'>#{$num} [{$ruleId}] {$desc}</div>
|
||||||
|
<div style='font-family:monospace; font-size:10px; color:#e11d48; margin:4px 0; background:#f1f5f9; padding:4px;'>{$snippet}</div>
|
||||||
|
<div style='font-size:11px; color:#475569;'><b>Öneri:</b> {$suggestion}</div>
|
||||||
|
</div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = "
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
|
||||||
|
<title>WCAG 2.1 Erişilebilirlik Sertifikası ve Raporu</title>
|
||||||
|
<style>
|
||||||
|
* { font-family: 'DejaVu Sans', sans-serif; }
|
||||||
|
body { font-family: 'DejaVu Sans', sans-serif; color: #1e293b; line-height: 1.5; font-size: 11px; margin: 0; padding: 20px; }
|
||||||
|
.header { text-align: center; border-bottom: 2px solid #38bdf8; padding-bottom: 15px; margin-bottom: 20px; }
|
||||||
|
.title { font-size: 18px; font-weight: bold; color: #0f172a; }
|
||||||
|
.subtitle { font-size: 12px; color: #64748b; margin-top: 4px; }
|
||||||
|
.badge { display: inline-block; padding: 6px 16px; border-radius: 12px; color: #fff; font-weight: bold; font-size: 13px; background: {$scoreColor}; }
|
||||||
|
.grid { margin-bottom: 20px; }
|
||||||
|
.card { background: #f8fafc; border: 1px solid #e2e8f0; padding: 12px; border-radius: 6px; margin-bottom: 10px; }
|
||||||
|
.footer { text-align: center; border-top: 1px solid #e2e8f0; padding-top: 15px; font-size: 10px; color: #94a3b8; margin-top: 30px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class='header'>
|
||||||
|
<div class='title'>♿ YakNet Accessibility Console</div>
|
||||||
|
<div class='subtitle'>WCAG 2.1 AA Erişilebilirlik Uyumluluk Raporu</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class='card' style='text-align:center;'>
|
||||||
|
<div style='font-size:11px; color:#64748b; text-transform:uppercase;'>Erişilebilirlik Sağlık Skoru</div>
|
||||||
|
<div style='font-size:32px; font-weight:bold; color:{$scoreColor}; margin:6px 0;'>{$score} / 100</div>
|
||||||
|
<div class='badge'>{$statusText}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class='card'>
|
||||||
|
<div><b>Hedef URL / Dizin:</b> " . htmlspecialchars($targetUrl) . "</div>
|
||||||
|
<div><b>Tarama Tarihi:</b> {$dateStr}</div>
|
||||||
|
<div><b>Tespit Edilen İhlal Sayısı:</b> {$violationsCount} Hata</div>
|
||||||
|
<div><b>Raporu Üreten Motor:</b> YakNet AI & Accessibility Engine v3.1</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3 style='color:#0f172a; border-bottom:1px solid #cbd5e1; padding-bottom:6px;'>📋 Erişilebilirlik İhlalleri ve Çözüm Detayları</h3>
|
||||||
|
{$violationsHtml}
|
||||||
|
|
||||||
|
<div class='footer'>
|
||||||
|
© {$dateStr} YakNet Bilişim — Türkiye'nin Yerli & Milli Erişilebilirlik Platformu (yak.net.tr)
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>";
|
||||||
|
|
||||||
|
$options = new Options();
|
||||||
|
$options->set('isHtml5ParserEnabled', true);
|
||||||
|
$options->set('isRemoteEnabled', true);
|
||||||
|
|
||||||
|
$dompdf = new Dompdf($options);
|
||||||
|
$dompdf->loadHtml($html);
|
||||||
|
$dompdf->setPaper('A4', 'portrait');
|
||||||
|
$dompdf->render();
|
||||||
|
|
||||||
|
return strval($dompdf->output());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Rules;
|
||||||
|
|
||||||
|
use DOMElement;
|
||||||
|
use Spatie\Color\Hex;
|
||||||
|
use YakNet\AccessibilityConsole\Color\Contrast\ContrastRatioCalculator;
|
||||||
|
use YakNet\AccessibilityConsole\Color\Simulators\DeuteranopiaSimulator;
|
||||||
|
use YakNet\AccessibilityConsole\Color\Simulators\ProtanopiaSimulator;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Severity;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Violation;
|
||||||
|
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||||
|
|
||||||
|
class ColorBlindnessContrast extends AbstractRule
|
||||||
|
{
|
||||||
|
public function getId(): string { return 'WCAG_1_4_1_COLOR_BLINDNESS_CONTRAST'; }
|
||||||
|
public function getDescription(): string { return 'Text and background color contrast must remain accessible (minimum 4.5:1) under color vision deficiency simulations (Deuteranopia, Protanopia).'; }
|
||||||
|
public function getStandard(): WCAGStandard { return WCAGStandard::AA; }
|
||||||
|
public function getSeverity(): Severity { return Severity::WARNING; }
|
||||||
|
public function getLevel(): int { return 4; }
|
||||||
|
|
||||||
|
public function check(DOMElement $element): ?Violation
|
||||||
|
{
|
||||||
|
if (!$element->hasAttribute('style')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$style = $element->getAttribute('style');
|
||||||
|
$colorHex = $this->extractColorFromStyle($style, 'color');
|
||||||
|
$bgHex = $this->extractColorFromStyle($style, 'background-color') ?? $this->extractColorFromStyle($style, 'background');
|
||||||
|
|
||||||
|
if (!$colorHex || !$bgHex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$fgRgb = Hex::fromString($colorHex)->toRgb();
|
||||||
|
$bgRgb = Hex::fromString($bgHex)->toRgb();
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simulate Deuteranopia & Protanopia using dedicated simulators
|
||||||
|
$simulations = [
|
||||||
|
'Deuteranopia' => [
|
||||||
|
'fg' => DeuteranopiaSimulator::simulate($fgRgb),
|
||||||
|
'bg' => DeuteranopiaSimulator::simulate($bgRgb),
|
||||||
|
],
|
||||||
|
'Protanopia' => [
|
||||||
|
'fg' => ProtanopiaSimulator::simulate($fgRgb),
|
||||||
|
'bg' => ProtanopiaSimulator::simulate($bgRgb),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($simulations as $type => $sim) {
|
||||||
|
$contrast = ContrastRatioCalculator::calculate($sim['fg'], $sim['bg']);
|
||||||
|
if ($contrast < 4.5) {
|
||||||
|
return $this->createViolation(
|
||||||
|
$element,
|
||||||
|
sprintf('Insufficient color contrast (%.2f:1) under %s color blindness simulation (minimum 4.5:1 required).', $contrast, $type),
|
||||||
|
sprintf('Adjust foreground color (%s) or background color (%s) to increase contrast for users with %s.', $colorHex, $bgHex, $type)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function extractColorFromStyle(string $style, string $property): ?string
|
||||||
|
{
|
||||||
|
if (preg_match('/' . preg_quote($property, '/') . '\s*:\s*(#[0-9a-fA-F]{3,6})/i', $style, $matches)) {
|
||||||
|
$hex = $matches[1];
|
||||||
|
if (strlen($hex) === 4) {
|
||||||
|
$hex = '#' . $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
|
||||||
|
}
|
||||||
|
return $hex;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Rules;
|
||||||
|
|
||||||
|
use DOMElement;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Severity;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Violation;
|
||||||
|
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||||
|
|
||||||
|
class ContentInfoParent extends AbstractRule
|
||||||
|
{
|
||||||
|
public function getId(): string { return 'WCAG_1_3_1_CONTENTINFO_PARENT'; }
|
||||||
|
public function getDescription(): string { return 'Footer contentinfo landmark must be at top-level body or within valid sectioning root.'; }
|
||||||
|
public function getStandard(): WCAGStandard { return WCAGStandard::AA; }
|
||||||
|
public function getSeverity(): Severity { return Severity::WARNING; }
|
||||||
|
public function getLevel(): int { return 4; }
|
||||||
|
|
||||||
|
public function check(DOMElement $element): ?Violation
|
||||||
|
{
|
||||||
|
if (strtolower($element->tagName) !== 'footer' && $element->getAttribute('role') !== 'contentinfo') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$parent = $element->parentNode;
|
||||||
|
while ($parent instanceof DOMElement) {
|
||||||
|
$pTag = strtolower($parent->tagName);
|
||||||
|
if (in_array($pTag, ['article', 'aside', 'main', 'nav', 'section'], true)) {
|
||||||
|
return $this->createViolation(
|
||||||
|
$element,
|
||||||
|
sprintf('Footer contentinfo landmark is nested inside <%s> sectioning element.', $pTag),
|
||||||
|
'Place global footer contentinfo landmark at the top level of <body> rather than nested inside sectioning elements.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$parent = $parent->parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Rules;
|
||||||
|
|
||||||
|
use DOMElement;
|
||||||
|
use Intervention\Image\ImageManager;
|
||||||
|
use Intervention\Image\Drivers\Gd\Driver;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Severity;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Violation;
|
||||||
|
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||||
|
|
||||||
|
class ImageDimensionsAndScale extends AbstractRule
|
||||||
|
{
|
||||||
|
public function getId(): string { return 'WCAG_1_4_4_IMAGE_DIMENSIONS_SCALE'; }
|
||||||
|
public function getDescription(): string { return 'Images must specify explicit width and height attributes or CSS dimensions to prevent layout shifts and ensure accessible touch target sizes.'; }
|
||||||
|
public function getStandard(): WCAGStandard { return WCAGStandard::AA; }
|
||||||
|
public function getSeverity(): Severity { return Severity::WARNING; }
|
||||||
|
public function getLevel(): int { return 4; }
|
||||||
|
|
||||||
|
public function check(DOMElement $element): ?Violation
|
||||||
|
{
|
||||||
|
if (strtolower($element->tagName) !== 'img') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasWidthAttr = $element->hasAttribute('width') && !empty(trim($element->getAttribute('width')));
|
||||||
|
$hasHeightAttr = $element->hasAttribute('height') && !empty(trim($element->getAttribute('height')));
|
||||||
|
$style = $element->getAttribute('style');
|
||||||
|
|
||||||
|
$hasWidthStyle = preg_match('/width\s*:\s*[^;]+/i', $style) === 1;
|
||||||
|
$hasHeightStyle = preg_match('/height\s*:\s*[^;]+/i', $style) === 1;
|
||||||
|
|
||||||
|
if (!$hasWidthAttr && !$hasWidthStyle) {
|
||||||
|
return $this->createViolation(
|
||||||
|
$element,
|
||||||
|
'Image element is missing explicit width attributes or CSS width rules.',
|
||||||
|
'Specify explicit width and height attributes (e.g. width="300" height="200") on the <img> tag to prevent layout shifts (CLS).'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$hasHeightAttr && !$hasHeightStyle) {
|
||||||
|
return $this->createViolation(
|
||||||
|
$element,
|
||||||
|
'Image element is missing explicit height attributes or CSS height rules.',
|
||||||
|
'Specify explicit height attributes on the <img> tag to ensure proper rendering aspect ratio.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if image target is too small when nested in a link or button
|
||||||
|
if ($hasWidthAttr && $hasHeightAttr) {
|
||||||
|
$w = (int)$element->getAttribute('width');
|
||||||
|
$h = (int)$element->getAttribute('height');
|
||||||
|
|
||||||
|
$parentTag = strtolower($element->parentNode ? $element->parentNode->nodeName : '');
|
||||||
|
if (($parentTag === 'a' || $parentTag === 'button') && ($w < 24 || $h < 24)) {
|
||||||
|
return $this->createViolation(
|
||||||
|
$element,
|
||||||
|
sprintf('Interactive image target dimensions (%dx%dpx) are smaller than the recommended 24x24px minimum touch target size.', $w, $h),
|
||||||
|
'Increase interactive image target size or add padding to meet WCAG 2.5.5 touch target size requirements.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Rules;
|
||||||
|
|
||||||
|
use DOMElement;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Severity;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Violation;
|
||||||
|
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||||
|
|
||||||
|
class InputTypePasswordVisibility extends AbstractRule
|
||||||
|
{
|
||||||
|
public function getId(): string { return 'WCAG_4_1_2_PASSWORD_VISIBILITY_TOGGLE'; }
|
||||||
|
public function getDescription(): string { return 'Password visibility toggle buttons must have accessible names and specify aria-pressed or aria-label attributes.'; }
|
||||||
|
public function getStandard(): WCAGStandard { return WCAGStandard::AA; }
|
||||||
|
public function getSeverity(): Severity { return Severity::WARNING; }
|
||||||
|
public function getLevel(): int { return 4; }
|
||||||
|
|
||||||
|
public function check(DOMElement $element): ?Violation
|
||||||
|
{
|
||||||
|
if (strtolower($element->tagName) !== 'button') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$class = strtolower($element->getAttribute('class'));
|
||||||
|
$id = strtolower($element->getAttribute('id'));
|
||||||
|
$ariaLabel = $element->getAttribute('aria-label');
|
||||||
|
|
||||||
|
$isPasswordToggle = str_contains($class, 'password') || str_contains($class, 'toggle-pass') || str_contains($id, 'password') || str_contains($id, 'toggle-pass');
|
||||||
|
|
||||||
|
if ($isPasswordToggle && empty($ariaLabel) && !$element->hasAttribute('aria-labelledby') && empty(trim($element->textContent))) {
|
||||||
|
return $this->createViolation(
|
||||||
|
$element,
|
||||||
|
'Password visibility toggle button is missing an accessible name.',
|
||||||
|
'Add an aria-label="Şifreyi Göster/Gizle" or aria-pressed="false" attribute to the password toggle button.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,11 +2,17 @@
|
|||||||
|
|
||||||
namespace YakNet\AccessibilityConsole\Rules;
|
namespace YakNet\AccessibilityConsole\Rules;
|
||||||
|
|
||||||
|
use RecursiveDirectoryIterator;
|
||||||
|
use RecursiveIteratorIterator;
|
||||||
|
use ReflectionClass;
|
||||||
|
use YakNet\AccessibilityConsole\Core\AbstractRule;
|
||||||
|
|
||||||
class RuleLevels
|
class RuleLevels
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get rule instances for the specified level.
|
* Get rule instances for the specified level.
|
||||||
* Levels are incremental: Level 5 includes all rules from Levels 1, 2, 3, and 4.
|
* Levels are incremental: Level 5 includes all rules from Levels 1, 2, 3, and 4.
|
||||||
|
* Recursively scans src/Rules and all subdirectories for rule classes.
|
||||||
*
|
*
|
||||||
* @param int $level
|
* @param int $level
|
||||||
* @return array<int, \YakNet\AccessibilityConsole\Rules\RuleInterface|\YakNet\AccessibilityConsole\Core\AbstractRule>
|
* @return array<int, \YakNet\AccessibilityConsole\Rules\RuleInterface|\YakNet\AccessibilityConsole\Core\AbstractRule>
|
||||||
@@ -14,27 +20,46 @@ class RuleLevels
|
|||||||
public static function getRulesForLevel(int $level): array
|
public static function getRulesForLevel(int $level): array
|
||||||
{
|
{
|
||||||
$rules = [];
|
$rules = [];
|
||||||
$files = glob(__DIR__ . '/*.php');
|
$dir = __DIR__;
|
||||||
if ($files === false) {
|
|
||||||
|
if (!is_dir($dir)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($files as $file) {
|
$iterator = new RecursiveIteratorIterator(
|
||||||
$className = pathinfo($file, PATHINFO_FILENAME);
|
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS)
|
||||||
$fqcn = 'YakNet\AccessibilityConsole\Rules\\' . $className;
|
);
|
||||||
|
|
||||||
|
/** @var \SplFileInfo $file */
|
||||||
|
foreach ($iterator as $file) {
|
||||||
|
if ($file->getExtension() !== 'php') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$realPath = $file->getRealPath();
|
||||||
|
$relativePath = str_replace([$dir . DIRECTORY_SEPARATOR, '.php'], ['', ''], $realPath);
|
||||||
|
$subNamespace = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
|
||||||
|
$fqcn = 'YakNet\AccessibilityConsole\Rules\\' . $subNamespace;
|
||||||
|
|
||||||
|
if (!class_exists($fqcn)) {
|
||||||
|
// Fallback to flat namespace if class is in root Rules namespace
|
||||||
|
$flatClassName = $file->getBasename('.php');
|
||||||
|
$fqcn = 'YakNet\AccessibilityConsole\Rules\\' . $flatClassName;
|
||||||
|
}
|
||||||
|
|
||||||
if (class_exists($fqcn)) {
|
if (class_exists($fqcn)) {
|
||||||
$reflection = new \ReflectionClass($fqcn);
|
$reflection = new ReflectionClass($fqcn);
|
||||||
|
|
||||||
if ($reflection->isAbstract() || $reflection->isInterface() || $reflection->isTrait()) {
|
if ($reflection->isAbstract() || $reflection->isInterface() || $reflection->isTrait()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it is a concrete rule
|
// Check if it is a concrete rule
|
||||||
$isRule = $reflection->isSubclassOf(\YakNet\AccessibilityConsole\Core\AbstractRule::class) ||
|
$isRule = $reflection->isSubclassOf(AbstractRule::class) ||
|
||||||
$reflection->implementsInterface(\YakNet\AccessibilityConsole\Rules\RuleInterface::class);
|
$reflection->implementsInterface(RuleInterface::class);
|
||||||
|
|
||||||
if ($isRule) {
|
if ($isRule) {
|
||||||
|
$className = $file->getBasename('.php');
|
||||||
// Exclude Turkish custom rules to match standard behavior
|
// Exclude Turkish custom rules to match standard behavior
|
||||||
if (in_array($className, ['EmptyLinkRule', 'HeadingOrderRule', 'ImageAltRule'], true)) {
|
if (in_array($className, ['EmptyLinkRule', 'HeadingOrderRule', 'ImageAltRule'], true)) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Rules;
|
||||||
|
|
||||||
|
use DOMElement;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Severity;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Violation;
|
||||||
|
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||||
|
|
||||||
|
class TableNestedBanned extends AbstractRule
|
||||||
|
{
|
||||||
|
public function getId(): string { return 'WCAG_1_3_1_TABLE_NESTED_BANNED'; }
|
||||||
|
public function getDescription(): string { return 'Tables should not be nested inside another table as it confuses screen reader data table navigation.'; }
|
||||||
|
public function getStandard(): WCAGStandard { return WCAGStandard::A; }
|
||||||
|
public function getSeverity(): Severity { return Severity::ERROR; }
|
||||||
|
public function getLevel(): int { return 4; }
|
||||||
|
|
||||||
|
public function check(DOMElement $element): ?Violation
|
||||||
|
{
|
||||||
|
if (strtolower($element->tagName) !== 'table') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$parent = $element->parentNode;
|
||||||
|
while ($parent instanceof DOMElement) {
|
||||||
|
if (strtolower($parent->tagName) === 'table') {
|
||||||
|
return $this->createViolation(
|
||||||
|
$element,
|
||||||
|
'Table element is nested inside another table.',
|
||||||
|
'Refactor layout to use modern CSS Flexbox/Grid instead of nested tables for tabular data.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$parent = $parent->parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Support\Helpers;
|
||||||
|
|
||||||
|
use DOMElement;
|
||||||
|
|
||||||
|
class DomHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Check if a DOMElement has a specific parent tag name in its ancestor hierarchy.
|
||||||
|
*/
|
||||||
|
public static function hasAncestorTag(DOMElement $element, string $tagName): bool
|
||||||
|
{
|
||||||
|
$target = strtolower($tagName);
|
||||||
|
$parent = $element->parentNode;
|
||||||
|
while ($parent instanceof DOMElement) {
|
||||||
|
if (strtolower($parent->tagName) === $target) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$parent = $parent->parentNode;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get accessible name / visible text from element including aria-label and title.
|
||||||
|
*/
|
||||||
|
public static function getAccessibleName(DOMElement $element): string
|
||||||
|
{
|
||||||
|
if ($element->hasAttribute('aria-label')) {
|
||||||
|
return trim($element->getAttribute('aria-label'));
|
||||||
|
}
|
||||||
|
if ($element->hasAttribute('title')) {
|
||||||
|
return trim($element->getAttribute('title'));
|
||||||
|
}
|
||||||
|
return trim($element->textContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Stubs\Laravel;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
|
||||||
|
class AccessibilityMiddleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request in Laravel.
|
||||||
|
* Injects a real-time WCAG Accessibility badge into HTML responses when app is in debug mode.
|
||||||
|
*/
|
||||||
|
public function handle(mixed $request, Closure $next): mixed
|
||||||
|
{
|
||||||
|
/** @var \Illuminate\Http\Response $response */
|
||||||
|
$response = $next($request);
|
||||||
|
|
||||||
|
if (!method_exists($response, 'getContent') || !method_exists($response, 'setContent')) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$content = strval($response->getContent());
|
||||||
|
if (!str_contains($content, '</html>')) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$result = $scanner->scan($content);
|
||||||
|
$score = intval($result['score'] ?? 0);
|
||||||
|
$badgeColor = $score >= 80 ? '#10b981' : ($score >= 50 ? '#f59e0b' : '#ef4444');
|
||||||
|
|
||||||
|
$badgeHtml = "
|
||||||
|
<div id='yaknet-a11y-badge' style='position:fixed; bottom:16px; right:16px; z-index:999999; font-family:sans-serif; background:#0f172a; color:#fff; padding:8px 16px; border-radius:24px; box-shadow:0 10px 25px rgba(0,0,0,0.3); font-size:12px; display:flex; align-items:center; border:1px solid rgba(255,255,255,0.1); cursor:pointer;' onclick='alert(\"YakNet Accessibility Console Score: {$score}/100\")'>
|
||||||
|
<span style='font-size:16px; margin-right:6px;'>♿</span>
|
||||||
|
<span>A11y Score: <strong style='color:{$badgeColor};'>{$score}/100</strong></span>
|
||||||
|
</div>";
|
||||||
|
|
||||||
|
$response->setContent(str_replace('</body>', $badgeHtml . '</body>', $content));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Stubs\Laravel;
|
||||||
|
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
|
||||||
|
trait AssertsAccessibility
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Assert that an HTML response or URL passes minimum WCAG accessibility health score.
|
||||||
|
*/
|
||||||
|
public function assertPageIsAccessible(string $htmlOrUrl, int $minScore = 80): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$result = str_starts_with($htmlOrUrl, 'http')
|
||||||
|
? $scanner->scanUrl($htmlOrUrl)
|
||||||
|
: $scanner->scan($htmlOrUrl);
|
||||||
|
|
||||||
|
$score = intval($result['score'] ?? 0);
|
||||||
|
$violations = count($result['violations'] ?? []);
|
||||||
|
|
||||||
|
$message = sprintf('Target failed accessibility audit with score %d/100 (%d violations).', $score, $violations);
|
||||||
|
|
||||||
|
/** @var \PHPUnit\Framework\TestCase $this */
|
||||||
|
$this->assertGreaterThanOrEqual($minScore, $score, $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Plugin Name: YakNet Accessibility Console for WordPress
|
||||||
|
* Plugin URI: https://yak.net.tr
|
||||||
|
* Description: Automated WCAG 2.1 AA accessibility auditing and real-time admin bar score indicator.
|
||||||
|
* Version: 3.2.0
|
||||||
|
* Author: YakNet Bilişim
|
||||||
|
* Author URI: https://forum.yak.net.tr
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action('admin_bar_menu', function($admin_bar) {
|
||||||
|
if (!is_admin()) {
|
||||||
|
$admin_bar->add_node([
|
||||||
|
'id' => 'yaknet-a11y-status',
|
||||||
|
'title' => '<span class="ab-icon">♿</span> YakNet A11y: <span style="color:#10b981; font-weight:bold;">100/100 (Pass)</span>',
|
||||||
|
'href' => '#',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Audit;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Audit\SiteCrawler;
|
||||||
|
|
||||||
|
class SiteCrawlerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCrawlsBaseUrl(): void
|
||||||
|
{
|
||||||
|
$crawler = new SiteCrawler();
|
||||||
|
$result = $crawler->crawlAndAudit('https://yak.net.tr', 1);
|
||||||
|
|
||||||
|
$this->assertSame('https://yak.net.tr', $result['base_url']);
|
||||||
|
$this->assertSame(1, $result['pages_audited']);
|
||||||
|
$this->assertArrayHasKey('average_score', $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\AutoFix;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\AutoFix\HtmlRepairEngine;
|
||||||
|
|
||||||
|
class HtmlRepairEngineTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRepairsMissingLangAndSvg(): void
|
||||||
|
{
|
||||||
|
$html = '<html><body><svg class="icon"></svg><img src="test.png"></body></html>';
|
||||||
|
$result = HtmlRepairEngine::autoRepair($html);
|
||||||
|
|
||||||
|
$this->assertStringContainsString('<html lang="tr"', $result['repaired_html']);
|
||||||
|
$this->assertStringContainsString('<svg aria-hidden="true"', $result['repaired_html']);
|
||||||
|
$this->assertStringContainsString('<img alt=""', $result['repaired_html']);
|
||||||
|
$this->assertCount(3, $result['fixes_applied']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Integrations;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Integrations\GitHubActionsReporter;
|
||||||
|
|
||||||
|
class GitHubActionsReporterTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFormatsGitHubAnnotations(): void
|
||||||
|
{
|
||||||
|
$scanResult = [
|
||||||
|
'violations' => [
|
||||||
|
[
|
||||||
|
'ruleId' => 'WCAG_1_1_1_SVG',
|
||||||
|
'description' => 'SVG missing alt',
|
||||||
|
'line' => 12,
|
||||||
|
'severity' => 'ERROR'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$output = GitHubActionsReporter::formatAnnotations($scanResult, 'index.html');
|
||||||
|
$this->assertStringContainsString('::error file=index.html,line=12::[WCAG_1_1_1_SVG]', $output);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Reporting;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Reporting\ExcelReportExporter;
|
||||||
|
|
||||||
|
class ExcelReportExporterTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testExportsExcelBinaryContent(): void
|
||||||
|
{
|
||||||
|
$scanResult = [
|
||||||
|
'score' => 90,
|
||||||
|
'violations_count' => 1,
|
||||||
|
'violations' => [
|
||||||
|
[
|
||||||
|
'ruleId' => 'WCAG_3_1_1_LANG',
|
||||||
|
'description' => 'Missing lang attribute',
|
||||||
|
'htmlSnippet' => '<html>',
|
||||||
|
'suggestion' => 'Add lang="tr"',
|
||||||
|
'standard' => 'WCAG 2.1 A',
|
||||||
|
'severity' => 'ERROR'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$excelBinary = ExcelReportExporter::exportExcel($scanResult, 'https://example.com');
|
||||||
|
$this->assertNotEmpty($excelBinary);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Reporting;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Reporting\PdfReportGenerator;
|
||||||
|
|
||||||
|
class PdfReportGeneratorTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGeneratesPdfBinaryContent(): void
|
||||||
|
{
|
||||||
|
$scanResult = [
|
||||||
|
'score' => 95,
|
||||||
|
'violations_count' => 1,
|
||||||
|
'violations' => [
|
||||||
|
[
|
||||||
|
'ruleId' => 'WCAG_1_1_1_IMG_ALT',
|
||||||
|
'description' => 'Image missing alt text',
|
||||||
|
'htmlSnippet' => '<img src="test.jpg">',
|
||||||
|
'suggestion' => 'Add alt="Description"',
|
||||||
|
'standard' => 'WCAG 2.1 AA',
|
||||||
|
'severity' => 'ERROR'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$pdfBinary = PdfReportGenerator::generatePdf($scanResult, 'https://example.com');
|
||||||
|
$this->assertNotEmpty($pdfBinary);
|
||||||
|
$this->assertStringStartsWith('%PDF-', $pdfBinary);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Rules;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
use YakNet\AccessibilityConsole\Rules\ColorBlindnessContrast;
|
||||||
|
|
||||||
|
class ColorBlindnessContrastTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFlagsLowContrastUnderColorBlindnessSimulation(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new ColorBlindnessContrast());
|
||||||
|
|
||||||
|
// Red text #ff0000 on Green background #00ff00 (Classic red/green colorblindness issue)
|
||||||
|
$violations = $scanner->scan('<div style="color: #ff0000; background-color: #00ff00;">Red on Green text</div>');
|
||||||
|
$this->assertGreaterThanOrEqual(1, count($violations));
|
||||||
|
$this->assertSame('WCAG_1_4_1_COLOR_BLINDNESS_CONTRAST', $violations[0]->ruleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassesHighContrastUnderColorBlindnessSimulation(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new ColorBlindnessContrast());
|
||||||
|
|
||||||
|
// Black text #000000 on White background #ffffff
|
||||||
|
$violations = $scanner->scan('<div style="color: #000000; background-color: #ffffff;">Black on White text</div>');
|
||||||
|
$this->assertCount(0, $violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Rules;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
use YakNet\AccessibilityConsole\Rules\ContentInfoParent;
|
||||||
|
|
||||||
|
class ContentInfoParentTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFlagsNestedFooterInSection(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new ContentInfoParent());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<section><footer role="contentinfo"><p>Nested footer</p></footer></section>');
|
||||||
|
$this->assertGreaterThanOrEqual(1, count($violations));
|
||||||
|
$this->assertSame('WCAG_1_3_1_CONTENTINFO_PARENT', $violations[0]->ruleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassesTopLevelFooter(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new ContentInfoParent());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<body><footer role="contentinfo"><p>Top level footer</p></footer></body>');
|
||||||
|
$this->assertCount(0, $violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Rules;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
use YakNet\AccessibilityConsole\Rules\ImageDimensionsAndScale;
|
||||||
|
|
||||||
|
class ImageDimensionsAndScaleTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFlagsMissingWidthAttribute(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new ImageDimensionsAndScale());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<img src="test.jpg" alt="Test image">');
|
||||||
|
$this->assertGreaterThanOrEqual(1, count($violations));
|
||||||
|
$this->assertSame('WCAG_1_4_4_IMAGE_DIMENSIONS_SCALE', $violations[0]->ruleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFlagsSmallInteractiveTouchTarget(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new ImageDimensionsAndScale());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<a href="/"><img src="icon.png" alt="Home" width="12" height="12"></a>');
|
||||||
|
$this->assertGreaterThanOrEqual(1, count($violations));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassesValidImageDimensions(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new ImageDimensionsAndScale());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<img src="test.jpg" alt="Test" width="300" height="200">');
|
||||||
|
$this->assertCount(0, $violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Rules;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
use YakNet\AccessibilityConsole\Rules\InputTypePasswordVisibility;
|
||||||
|
|
||||||
|
class InputTypePasswordVisibilityTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFlagsPasswordToggleWithoutAccessibleName(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new InputTypePasswordVisibility());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<button class="toggle-password"></button>');
|
||||||
|
$this->assertGreaterThanOrEqual(1, count($violations));
|
||||||
|
$this->assertSame('WCAG_4_1_2_PASSWORD_VISIBILITY_TOGGLE', $violations[0]->ruleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassesPasswordToggleWithAriaLabel(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new InputTypePasswordVisibility());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<button class="toggle-password" aria-label="Şifreyi göster"></button>');
|
||||||
|
$this->assertCount(0, $violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YakNet\AccessibilityConsole\Tests\Rules;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use YakNet\AccessibilityConsole\Core\Scanner;
|
||||||
|
use YakNet\AccessibilityConsole\Rules\TableNestedBanned;
|
||||||
|
|
||||||
|
class TableNestedBannedTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFlagsNestedTable(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new TableNestedBanned());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<table><tr><td><table><tr><td>Nested table</td></tr></table></td></tr></table>');
|
||||||
|
$this->assertGreaterThanOrEqual(1, count($violations));
|
||||||
|
$this->assertSame('WCAG_1_3_1_TABLE_NESTED_BANNED', $violations[0]->ruleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassesSingleTable(): void
|
||||||
|
{
|
||||||
|
$scanner = new Scanner();
|
||||||
|
$scanner->addRule(new TableNestedBanned());
|
||||||
|
|
||||||
|
$violations = $scanner->scan('<table><tr><td>Single table data</td></tr></table>');
|
||||||
|
$this->assertCount(0, $violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user