themePath = storage_path('framework/testing/stylist-accessibility-'.uniqid());
mkdir($this->themePath.'/views', 0777, true);
}
protected function tearDown(): void
{
app(Filesystem::class)->deleteDirectory($this->themePath);
parent::tearDown();
}
public function test_blade_object_access_does_not_break_image_alt_detection(): void
{
file_put_contents(
$this->themePath.'/views/page.blade.php',
'
'
);
$this->assertSame([], $this->validate());
}
public function test_image_without_alt_is_reported(): void
{
file_put_contents(
$this->themePath.'/views/page.blade.php',
'
'
);
$issues = $this->validate();
$this->assertCount(1, $issues);
$this->assertSame('error', $issues[0]['severity']);
$this->assertSame('1 image(s) missing alt text.', $issues[0]['message']);
}
public function test_aria_labelled_icon_button_is_not_reported(): void
{
file_put_contents(
$this->themePath.'/views/page.blade.php',
''
);
$this->assertSame([], $this->validate());
}
public function test_button_with_visible_text_is_not_reported(): void
{
file_put_contents(
$this->themePath.'/views/page.blade.php',
''
);
$this->assertSame([], $this->validate());
}
public function test_empty_unlabelled_button_is_reported(): void
{
file_put_contents(
$this->themePath.'/views/page.blade.php',
''
);
$issues = $this->validate();
$this->assertCount(1, $issues);
$this->assertSame('warning', $issues[0]['severity']);
$this->assertSame('1 button(s) may lack an accessible name.', $issues[0]['message']);
}
/** @return array */
private function validate(): array
{
$theme = new Theme('test', 'Test', $this->themePath);
return app(ThemeAccessibilityValidator::class)->validate($theme);
}
}