Skip to content

Commit

Permalink
[!!!][TASK] Rename LinkTextBlacklisted to LinkTextDenylist
Browse files Browse the repository at this point in the history
  • Loading branch information
derhansen committed Sep 26, 2023
1 parent d35cfbe commit d5d70ae
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 38 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/CodeQuality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
strategy:
matrix:
env:
- { php: 7.4 }
- { php: 8.0 }
- { php: 8.1 }

env: ${{ matrix.env }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
/**
* Class LinkNameBlacklistedTest
*/
class LinkTextBlacklistedTest extends AbstractTest
class LinkTextDenylistTest extends AbstractTest
{
protected string $id = 'link-name-blacklisted';
protected string $id = 'link-name-denylist';
protected string $helpUrl = '';
protected int $impact = Result\Impact::MODERATE;
protected array $blacklist = [];
protected array $denylist = [];

/**
* LinkTextBlacklistedTest constructor.
Expand All @@ -26,18 +26,18 @@ public function __construct(array $configuration)
{
parent::__construct($configuration);

$blacklist = $configuration['blacklist'] ?? [];
$this->blacklist = $this->initBlacklist($blacklist);
$denylist = $configuration['denylist'] ?? [];
$this->denylist = $this->initDenylist($denylist);

$this->help .= '"' . implode('", "', $this->blacklist) . '"';
$this->help .= '"' . implode('", "', $this->denylist) . '"';
}

/**
* Initializes the blacklist end ensures text is lowercase
* Initializes the denylist end ensures text is lowercase
*/
protected function initBlacklist(array $blacklist): array
protected function initDenylist(array $denylist): array
{
return array_map('mb_strtolower', $blacklist);
return array_map('mb_strtolower', $denylist);
}

/**
Expand All @@ -52,11 +52,11 @@ public function run(string $html, int $fallbackElementUid): Result

/** @var \DOMElement $element */
foreach ($elements as $element) {
$checkResult = (LinkUtility::linkTextNotBlacklisted($element, $this->blacklist) &&
SharedUtility::elementAttributeValueNotBlacklisted($element, 'title', $this->blacklist) &&
SharedUtility::elementAttributeValueNotBlacklisted($element, 'aria-label', $this->blacklist) &&
LinkUtility::linkImageAttributeNotBlacklisted($element, 'alt', $this->blacklist) &&
LinkUtility::linkImageAttributeNotBlacklisted($element, 'title', $this->blacklist)) ||
$checkResult = (LinkUtility::linkTextAllowed($element, $this->denylist) &&
SharedUtility::elementAttributeValueAllowed($element, 'title', $this->denylist) &&
SharedUtility::elementAttributeValueAllowed($element, 'aria-label', $this->denylist) &&
LinkUtility::linkImageAttributeAllowed($element, 'alt', $this->denylist) &&
LinkUtility::linkImageAttributeAllowed($element, 'title', $this->denylist)) ||
SharedUtility::elementHasRolePresentation($element) ||
SharedUtility::elementHasRoleNone($element);

Expand Down
14 changes: 7 additions & 7 deletions Classes/Utility/Tests/LinkUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ public static function linkHasImageWithAlt(\DOMElement $element): bool
return $result;
}

public static function linkTextNotBlacklisted(\DOMElement $element, array $blacklist): bool
public static function linkTextAllowed(\DOMElement $element, array $allowlist): bool
{
if (empty($blacklist) || StringUtility::stripNewLines($element->textContent) === '') {
if (empty($allowlist) || StringUtility::stripNewLines($element->textContent) === '') {
return true;
}
$content = StringUtility::clearString($element->textContent);

return in_array(strtolower($content), $blacklist, true) === false;
return in_array(strtolower($content), $allowlist, true) === false;
}

public static function linkImageAttributeNotBlacklisted(
public static function linkImageAttributeAllowed(
\DOMElement $element,
string $attribute,
array $blacklist
array $allowlist
): bool {
if (empty($blacklist) || $attribute === '') {
if (empty($allowlist) || $attribute === '') {
return true;
}

Expand All @@ -56,7 +56,7 @@ public static function linkImageAttributeNotBlacklisted(

/** @var \DOMElement $image */
foreach ($images as $image) {
if (!SharedUtility::elementAttributeValueNotBlacklisted($image, $attribute, $blacklist)) {
if (!SharedUtility::elementAttributeValueAllowed($image, $attribute, $allowlist)) {
return false;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions Classes/Utility/Tests/SharedUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ public static function elementTitleNotRedundant(\DOMElement $element): bool
return mb_strtolower($content) !== mb_strtolower($element->getAttribute('title'));
}

public static function elementAttributeValueNotBlacklisted(
public static function elementAttributeValueAllowed(
\DOMElement $element,
string $attribute,
array $blacklist
array $allowlist
): bool {
if (!$element->hasAttribute($attribute)) {
return true;
}

$content = StringUtility::clearString($element->getAttribute($attribute));

return in_array(strtolower($content), $blacklist, true) === false;
return in_array(strtolower($content), $allowlist, true) === false;
}
}
4 changes: 2 additions & 2 deletions Configuration/A11y/Default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ presets:
testSuite:
id: "internalTests"
tests:
linkTextBlacklisted:
linkTextDenylist:
configuration:
blacklist: ['mehr', 'details', 'hier']
denylist: ['mehr', 'details', 'hier']
headingOrder:
configuration:
limitToColPos: [0]
Expand Down
2 changes: 1 addition & 1 deletion Configuration/A11y/Includes/TestSuites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ testSuites:
imageAltTest: { name: "Image-Alt", className: "UniWue\\UwA11yCheck\\Tests\\Internal\\ImageAltTest", configuration: {} }
redundantTitle: { name: "Redundant-Title", className: "UniWue\\UwA11yCheck\\Tests\\Internal\\RedundantTitleTest", configuration: {} }
redundantLink: { name: "Redundant-Link", className: "UniWue\\UwA11yCheck\\Tests\\Internal\\RedundantLinkTest", configuration: {} }
linkTextBlacklisted: { name: "Link-Text-Blacklisted", className: "UniWue\\UwA11yCheck\\Tests\\Internal\\LinkTextBlacklistedTest", configuration: {} }
linkTextDenylist: { name: "Link-Text-Denylist", className: "UniWue\\UwA11yCheck\\Tests\\Internal\\LinkTextDenylistTest", configuration: {} }
headingOrder: { name: "Heading-Order", className: "UniWue\\UwA11yCheck\\Tests\\Internal\\HeadingOrderTest", configuration: {} }
4 changes: 2 additions & 2 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@
<target>Links müssen einen erkennbaren Text haben</target>
</trans-unit>

<trans-unit id="link-name-blacklisted.description" xml:space="preserve">
<trans-unit id="link-name-denylist.description" xml:space="preserve">
<source>Ensures a link name or linked image alt/title attribute does not equal a blacklisted word</source>
<target>Stellt sicher, dass der Linkname, der Bild alternative Text oder der Bildtitel nicht zugelassen ist</target>
</trans-unit>
<trans-unit id="link-name-blacklisted.help" xml:space="preserve">
<trans-unit id="link-name-denylist.help" xml:space="preserve">
<source>The link name or the title/alt of a linked image equals a blacklisted word. Current Blacklist: </source>
<target>Der Linkname, der Bild alternative Text oder der Bildtitel ist nicht zugelassen. Aktuell nicht zugelassene Wörter: </target>
</trans-unit>
Expand Down
8 changes: 4 additions & 4 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
<source>Links must have discernible text</source>
</trans-unit>

<trans-unit id="link-name-blacklisted.description" xml:space="preserve">
<source>Ensures a link name or linked image alt/title attribute does not equal a blacklisted word</source>
<trans-unit id="link-name-denylist.description" xml:space="preserve">
<source>Ensures a link name or linked image alt/title attribute does not equal a denied word</source>
</trans-unit>
<trans-unit id="link-name-blacklisted.help" xml:space="preserve">
<source>The link name or the title/alt of a linked image equals a blacklisted word. Current Blacklist: </source>
<trans-unit id="link-name-denylist.help" xml:space="preserve">
<source>The link name or the title/alt of a linked image equals a blacklisted word. Current denylist: </source>
</trans-unit>

<trans-unit id="redundant-title.description" xml:space="preserve">
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Tests/Utility/Tests/LinkUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function linkTextNotBlacklistedTests(string $html, array $blacklist, bool

/** @var \DOMElement $element */
$element = $doc->getElementsByTagName('a')->item(0);
$result = LinkUtility::linkTextNotBlacklisted($element, $blacklist);
$result = LinkUtility::linkTextAllowed($element, $blacklist);

self::assertEquals($expected, $result);
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public function linkImageAttributeNotBlacklistedTests(

/** @var \DOMElement $element */
$element = $doc->getElementsByTagName('a')->item(0);
$result = LinkUtility::linkImageAttributeNotBlacklisted($element, $attribute, $blacklist);
$result = LinkUtility::linkImageAttributeAllowed($element, $attribute, $blacklist);

self::assertEquals($expected, $result);
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Tests/Utility/Tests/SharedUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function elementAttributeValueNotBlacklistedTests(

/** @var \DOMElement $element */
$element = $doc->getElementsByTagName('a')->item(0);
$result = SharedUtility::elementAttributeValueNotBlacklisted($element, $attribute, $blacklist);
$result = SharedUtility::elementAttributeValueAllowed($element, $attribute, $blacklist);

self::assertEquals($expected, $result);
}
Expand Down

0 comments on commit d5d70ae

Please sign in to comment.