Skip to content

Commit 8a4c617

Browse files
authored
Merge pull request #700 from equalizedigital/release/1.14.3
Release v1.14.3
2 parents 36c590d + 9a10bd4 commit 8a4c617

5 files changed

Lines changed: 132 additions & 11 deletions

File tree

accessibility-checker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Plugin Name: Accessibility Checker
1111
* Plugin URI: https://a11ychecker.com
1212
* Description: Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance.
13-
* Version: 1.14.2
13+
* Version: 1.14.3
1414
* Author: Equalize Digital
1515
* Author URI: https://equalizedigital.com
1616
* License: GPL-2.0+
@@ -35,7 +35,7 @@
3535

3636
// Current plugin version.
3737
if ( ! defined( 'EDAC_VERSION' ) ) {
38-
define( 'EDAC_VERSION', '1.14.2' );
38+
define( 'EDAC_VERSION', '1.14.3' );
3939
}
4040

4141
// Current database version.

includes/rules/empty_link.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,32 @@ function edac_rule_empty_link( $content, $post ) { // phpcs:ignore -- $post is r
4545
// does not have a name.
4646

4747
$image = $link->find( 'img' );
48-
if ( ! $error && isset( $input[0] ) && empty( trim( $image[0]->getAttribute( 'alt' ) ) ) ) {
48+
$input = $link->find( 'input' );
49+
$i = $link->find( 'i' );
50+
51+
// If there's no image, input or i tag it's just an empty link and should be flagged.
52+
if ( empty( $image ) && empty( $input ) && empty( $i ) ) {
53+
$error = $a_tag_code;
54+
}
55+
56+
if ( ! $error && isset( $image[0] ) && empty( trim( $image[0]->getAttribute( 'alt' ) ) ) ) {
4957

5058
// The first image inside the link does not have an alt.
5159
// Throw error.
5260
$error = $a_tag_code;
5361
}
5462

55-
$input = $link->find( 'input' );
56-
if ( ! $error && isset( $input[0] ) && empty( trim( $image[0]->getAttribute( 'value' ) ) ) ) {
63+
if ( ! $error && isset( $input[0] ) && empty( trim( $input[0]->getAttribute( 'value' ) ) ) ) {
5764

5865
// The first input inside the link does not have a value.
5966
// Throw error.
6067
$error = $a_tag_code;
6168
}
6269

63-
$i = $link->find( 'i' );
64-
if ( ! $error && isset( $input[0] ) &&
65-
empty( trim( $i[0]->getAttribute( 'title' ) ) ) &&
66-
empty( trim( $i[0]->getAttribute( 'aria-label' ) ) )
70+
if ( ! $error &&
71+
isset( $i[0] ) &&
72+
empty( trim( $i[0]->getAttribute( 'title' ) ) ) &&
73+
empty( trim( $i[0]->getAttribute( 'aria-label' ) ) )
6774
) {
6875

6976
// The first i inside the link does not have a title &

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "accessibility-checker",
3-
"version": "1.14.2",
3+
"version": "1.14.3",
44
"description": "Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance.",
55
"author": "Equalize Digital",
66
"license": "GPL-2.0+",

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: equalizedigital, alh0319, stevejonesdev
33
Tags: accessibility, accessible, wcag, ada, WP accessibility
44
Requires at least: 6.2
55
Tested up to: 6.5.5
6-
Stable tag: 1.14.0
6+
Stable tag: 1.14.3
77
License: GPLv2 or later
88
License URI: http://www.gnu.org/licenses/gpl-2.0.html
99

@@ -171,6 +171,9 @@ No, Accessibility Checker runs completely on your server and does not require yo
171171

172172
== Changelog ==
173173

174+
= 1.14.3 =
175+
* Fixed: Allow empty_link rule to detect actually empty links
176+
174177
= 1.14.2 =
175178
* Enhancement: Reduce false positives for underlined text check
176179
* Fixed: Frontend highlighter could not be moved to the right side of the window on mobile
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Tests the empty_link rule.
4+
*
5+
* @package Accessibility_Checker
6+
*/
7+
8+
/**
9+
* Some test cases for the empty_link rule.
10+
*
11+
* @group rules
12+
*/
13+
class EmptyLinkTest extends WP_UnitTestCase {
14+
15+
/**
16+
* Test that a link with no content, no aria-label, no title, no id, no name, and no alt text throws an error.
17+
*/
18+
public function test_empty_link() {
19+
20+
$expected_error = '<a href="http://example.com"></a>';
21+
22+
$not_expected_error = '<a href="http://example.com">Some content</a>';
23+
24+
25+
$dom = new EDAC_Dom();
26+
$dom->load( $expected_error . PHP_EOL . $not_expected_error );
27+
28+
$errors = edac_rule_empty_link( [ 'html' => $dom ], null );
29+
30+
$this->assertContains( $expected_error, $errors );
31+
$this->assertNotContains( $not_expected_error, $errors );
32+
}
33+
34+
/**
35+
* Test that a link with no content, no aria-label, no title, no id, no name, and no alt text throws an error.
36+
*/
37+
public function test_empty_link_with_img() {
38+
$expected_errors = [
39+
'<a href="http://example.com"><img src="http://example.com/image.jpg" alt=""></a>',
40+
'<a href="http://example.com"><img src="http://example.com/image.jpg" alt=" "></a>',
41+
];
42+
43+
$not_expected_error = '<a href="http://example.com"><img src="http://example.com/image.jpg" alt="A filled alt"></a>';
44+
45+
$dom = new EDAC_Dom();
46+
$dom->load( implode( PHP_EOL, $expected_errors ) . PHP_EOL . $not_expected_error );
47+
48+
$errors = edac_rule_empty_link( [ 'html' => $dom ], null );
49+
50+
foreach ( $expected_errors as $expected_error ) {
51+
$this->assertContains( $expected_error, $errors );
52+
}
53+
54+
$this->assertNotContains( $not_expected_error, $errors );
55+
}
56+
57+
/**
58+
* Test that a link with no content, no aria-label, no title, no id, no name, and no alt text throws an error.
59+
*/
60+
public function test_empty_link_with_input() {
61+
62+
$expected_errors = [
63+
'<a href="http://example.com"><input type="text"></a>',
64+
'<a href="http://example.com"><input type="text" value=""></a>',
65+
'<a href="http://example.com"><input type="text" value=" "></a>', // whitespace should be stripped, this is still empty.
66+
];
67+
68+
$not_expected_error = '<a href="http://example.com"><input type="text" value="Some value"></a>';
69+
70+
$dom = new EDAC_Dom();
71+
$dom->load( implode( PHP_EOL, $expected_errors ) . PHP_EOL . $not_expected_error );
72+
73+
$errors = edac_rule_empty_link( [ 'html' => $dom ], null );
74+
75+
foreach ( $expected_errors as $expected_error ) {
76+
$this->assertContains( $expected_error, $errors );
77+
}
78+
$this->assertNotContains( $not_expected_error, $errors );
79+
}
80+
81+
/**
82+
* Test that a link with no content, no aria-label, no title, no id, no name, and no alt text throws an error.
83+
*/
84+
public function test_empty_link_with_i() {
85+
$expected_errors = [
86+
'<a href="http://example.com"><i></i></a>',
87+
'<a href="http://example.com"><i title=""></i></a>',
88+
'<a href="http://example.com"><i aria-label=""></i></a>',
89+
'<a href="http://example.com"><i title=" "></i></a>', // whitespace should be stripped, this is still empty.
90+
'<a href="http://example.com"><i aria-label=" "></i></a>', // whitespace should be stripped, this is still empty.
91+
];
92+
93+
$not_expected_errors = [
94+
'<a href="http://example.com"><i title="Some title"></i></a>',
95+
'<a href="http://example.com"><i aria-label="A label"></i></a>',
96+
'<a href="http://example.com"><i title="Some title" aria-label="A label"></i></a>',
97+
];
98+
99+
$dom = new EDAC_Dom();
100+
$dom->load( implode( PHP_EOL, $expected_errors ) . PHP_EOL . implode( PHP_EOL, $not_expected_errors ) );
101+
102+
$errors = edac_rule_empty_link( [ 'html' => $dom ], null );
103+
104+
foreach ( $expected_errors as $expected_error ) {
105+
$this->assertContains( $expected_error, $errors );
106+
}
107+
foreach ( $not_expected_errors as $not_expected_error ) {
108+
$this->assertNotContains( $not_expected_error, $errors );
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)