Skip to content

Commit

Permalink
feat: add axe accessibility testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jackd248 committed Aug 6, 2024
1 parent 11635e7 commit a316cdf
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Xima\XimaTypo3Toolbox\ExpressionLanguage;

use TYPO3\CMS\Core\ExpressionLanguage\AbstractProvider;
use Xima\XimaTypo3Toolbox\TypoScript\AxeAccessibilityConditionFunctionsProvider;

class AxeAccessibilityTypoScriptConditionProvider extends AbstractProvider
{
public function __construct()
{
$this->expressionLanguageProviders = [
AxeAccessibilityConditionFunctionsProvider::class,
];
}
}
31 changes: 31 additions & 0 deletions Classes/TypoScript/AxeAccessibilityConditionFunctionsProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Xima\XimaTypo3Toolbox\TypoScript;

use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use TYPO3\CMS\Core\Core\Environment;
use Xima\XimaTypo3Toolbox\Configuration;

class AxeAccessibilityConditionFunctionsProvider implements ExpressionFunctionProviderInterface
{
public function getFunctions(): array
{
return [
$this->getWebserviceFunction(),
];
}

protected function getWebserviceFunction(): ExpressionFunction
{
return new ExpressionFunction(
'enableAxeAccessibility',
static fn () => null,
static function () {
return $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][Configuration::EXT_KEY]['axeAccessibility']['enable'] && in_array(Environment::getContext()->__toString(), $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][Configuration::EXT_KEY]['axeAccessibility']['enableForContexts']);
}
);
}
}
1 change: 1 addition & 0 deletions Configuration/ExpressionLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
'typoscript' => [
\Xima\XimaTypo3Toolbox\ExpressionLanguage\TechnicalContextTypoScriptConditionProvider::class,
\Xima\XimaTypo3Toolbox\ExpressionLanguage\FrontendEditingTypoScriptConditionProvider::class,
\Xima\XimaTypo3Toolbox\ExpressionLanguage\AxeAccessibilityTypoScriptConditionProvider::class,
],
];
12 changes: 12 additions & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
}
[GLOBAL]

[enableAxeAccessibility()]
page.includeJS {
axeAccessibility = EXT:xima_typo3_toolbox/Resources/Public/JavaScript/lib/axe.min.js
}
page.jsInline {
1722945503 = TEXT
1722945503.value (
window.onload = function () { axe.run().then(results => { if (results.violations.length) { console.warn('[XIMA TYPO3 Toolbox] Axe accessibility warnings:', results.violations); } }).catch(err => { console.error('Something bad happened:', err.message); });}
)
}
[GLOBAL]

lib.contentElement {
templateRootPaths.1722340760 = EXT:xima_typo3_toolbox/Resources/Private/Templates/
}
Expand Down
Binary file added Documentation/Images/axe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ __Features__:
- Application context endpoint
- Frontend editing link within content elements for editors
- Technical headline content element for e.g. styleguides or technical documentation
- Integration of axe accessibility testing engine
- Various collection of TYPO3 ViewHelpers

## Installation
Expand Down Expand Up @@ -90,6 +91,12 @@ The *technical headline* is a content element to structure e.g. your styleguide

![Technical Headline](./Documentation/Images/technicalHeadline.png)

### Axe

[Axe](https://www.deque.com/axe/) is an accessibility testing engine for websites. It will be automatically (regarding the configured application context) integrated into the TYPO3 frontend and display accessibility issues of your website within the browser console.

![Axe](./Documentation/Images/axe.png)

### ViewHelpers

See the [ViewHelpers documentation](./Documentation/ViewHelpers/CLASSES.md) for a complete list of available ViewHelpers.
Expand Down
4 changes: 3 additions & 1 deletion Resources/Private/Templates/TechnicalContextHint.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@
<div
class="technical-context"
data-context="{context}"
aria-hidden="true"
style="background-color:{color};"
title="This is part of the feature branch deployment and shows the actual site name of the website. This hint will not be displayed in production context."
>
{context}
<button
type="button"
class="technical-context__close"
tabindex="-1"
onclick="this.parentElement.remove()"
aria-label="Schließe Context"
aria-label="Close context hint"
></button>
</div>
12 changes: 12 additions & 0 deletions Resources/Public/JavaScript/lib/axe.min.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@

// Frontend Editing
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][Configuration::EXT_KEY]['frontendEditing']['enable'] = false;

// Axe Accessibility
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][Configuration::EXT_KEY]['axeAccessibility']['enable'] = true;
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][Configuration::EXT_KEY]['axeAccessibility']['enableForContexts'] = [
'Testing/Stage',
'Testing',
'Staging',
'Development/DDEV',
'Development',
];

0 comments on commit a316cdf

Please sign in to comment.