Skip to content

Commit

Permalink
Merge pull request #815 from equalizedigital/release/1.16.3
Browse files Browse the repository at this point in the history
Release v1.16.3
  • Loading branch information
pattonwebz authored Nov 18, 2024
2 parents 7443360 + a670251 commit 0c1949e
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 6 deletions.
4 changes: 2 additions & 2 deletions accessibility-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Accessibility Checker
* Plugin URI: https://a11ychecker.com
* Description: Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance.
* Version: 1.16.2
* Version: 1.16.3
* Author: Equalize Digital
* Author URI: https://equalizedigital.com
* License: GPL-2.0+
Expand All @@ -35,7 +35,7 @@

// Current plugin version.
if ( ! defined( 'EDAC_VERSION' ) ) {
define( 'EDAC_VERSION', '1.16.2' );
define( 'EDAC_VERSION', '1.16.3' );
}

// Current database version.
Expand Down
18 changes: 18 additions & 0 deletions admin/site-health/class-free.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace EDAC\Admin\SiteHealth;

use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager;

/**
* Loads free information into Site Health
*
Expand All @@ -28,6 +30,18 @@ public function __construct() {
* @return array
*/
public function get() {
// Get only the non-pro fixes.
$fixes = array_filter(
FixesManager::get_instance()->get_fixes_settings(),
function ( $fix ) {
return ! $fix['is_pro'];
}
);
// remove the is_pro flag, this isn't needed in the output.
foreach ( $fixes as $key => $fix ) {
unset( $fixes[ $key ]['is_pro'] );
}

return [
'label' => __( 'Accessibility Checker — Free', 'accessibility-checker' ),
'fields' => [
Expand Down Expand Up @@ -87,6 +101,10 @@ public function get() {
'label' => 'DB Table Count',
'value' => absint( edac_database_table_count( 'accessibility_checker' ) ),
],
'fixes' => [
'label' => 'Fixes',
'value' => esc_html( wp_json_encode( $fixes ) ),
],
],
];
}
Expand Down
19 changes: 19 additions & 0 deletions admin/site-health/class-pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace EDAC\Admin\SiteHealth;

use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager;

/**
* Loads pro information into Site Health
*
Expand All @@ -28,6 +30,19 @@ public function __construct() {
* @return array
*/
public function get() {

// Get only the pro fixes.
$fixes = array_filter(
FixesManager::get_instance()->get_fixes_settings(),
function ( $fix ) {
return $fix['is_pro'];
}
);
// remove the is_pro flag, this isn't needed in the output.
foreach ( $fixes as $key => $fix ) {
unset( $fixes[ $key ]['is_pro'] );
}

return [
'label' => __( 'Accessibility Checker — Pro', 'accessibility-checker' ),
'fields' => [
Expand Down Expand Up @@ -71,6 +86,10 @@ public function get() {
'label' => 'Ignores DB Table Count',
'value' => absint( edac_database_table_count( 'accessibility_checker_global_ignores' ) ),
],
'fixes' => [
'label' => 'Fixes',
'value' => esc_html( wp_json_encode( $fixes ) ),
],
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function get_slug(): string {
* @return string
*/
public static function get_nicename(): string {
return __( 'Add Size & Type To File Links', 'accessibility-checker' );
return __( 'Add Labels to Unlabelled Form Fields', 'accessibility-checker' );
}

/**
Expand Down
24 changes: 24 additions & 0 deletions includes/classes/Fixes/FixesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,30 @@ public function get_fix( $slug ) {
return isset( $this->fixes[ $slug ] ) ? $this->fixes[ $slug ] : null;
}

/**
* Get the fixes settings.
*
* Returns an array of all the fix settings and their values along with a pro or not flag.
*
* @return array
*/
public function get_fixes_settings() {
$fixes_array = [];
foreach ( $this->fixes as $fix ) {

$fields = [];
foreach ( $fix->get_fields_array() as $field_slug => $field ) {
$fields[ $field_slug ] = get_option( $field_slug, $field['default'] ?? 0 );
}

$fixes_array[ $fix::get_slug() ] = [
'fields' => $fields,
'is_pro' => isset( $fix->is_pro ) ? $fix->is_pro : false,
];
}
return $fixes_array;
}

/**
* Register the fixes.
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "accessibility-checker",
"version": "1.16.2",
"version": "1.16.3",
"description": "Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance.",
"author": "Equalize Digital",
"license": "GPL-2.0+",
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: equalizedigital, alh0319, stevejonesdev
Tags: accessibility, accessible, wcag, ada, WP accessibility
Requires at least: 6.2
Tested up to: 6.7.0
Stable tag: 1.16.2
Stable tag: 1.16.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -171,8 +171,11 @@ No, Accessibility Checker runs completely on your server and does not require yo

== Changelog ==

= 1.16.2 =
= 1.16.3 =
* Enhancement: Add Fix settings to site health info panels.
* Fixed: Corrected a string that was misplaced in a fix.

= 1.16.2 =
* Enhancement: Use better names for fix modal titles.
* Enhancement: Improve the link_pdf rule to detect more accurately.
* Enhancement: Improve the link_ms_office_doc rule to detect more accurately.
Expand Down
118 changes: 118 additions & 0 deletions tests/phpunit/includes/classes/Fixes/FixesManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* Test class for FixesManager.
*
* @package accessibility-checker
*/

use PHPUnit\Framework\TestCase;
use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager;
use EqualizeDigital\AccessibilityChecker\Fixes\FixInterface;

/**
* Unit tests for the FixesManager class.
*/
class FixesManagerTest extends WP_UnitTestCase {

/**
* Setup the test environment by resetting the instance before each test.
*
* @return void
*/
public function setUp(): void {
parent::setUp();
// Reset the instance before each test.
$reflection = new ReflectionClass( FixesManager::class );
$instance = $reflection->getProperty( 'instance' );
$instance->setAccessible( true );
$instance->setValue( null, null );
}

/**
* Tear down the test environment by closing Mockery.
*
* @return void
*/
public function tearDown(): void {
Mockery::close();
}

/**
* Test that the instance retuns an empty array when no fixes are registered.
*
* @return void
*/
public function test_get_fixes_settings_returns_empty_array_when_no_fixes() {
$fixes_manager = FixesManager::get_instance();
$this->assertEmpty( $fixes_manager->get_fixes_settings() );
}

/**
* Test that the instance returns the correct structure when fixes are registered.
*
* @return void
*/
public function test_get_fixes_settings_returns_correct_structure() {
$fix_mock = Mockery::mock( 'EqualizeDigital\AccessibilityChecker\Fixes\Fix\AddFileSizeAndTypeToLinkedFilesFix' );
$fix_mock->shouldReceive( 'get_slug' )->andReturn( 'mock_fix' );
$fix_mock->shouldReceive( 'get_fields_array' )->andReturn(
[
'field1' => [ 'default' => 'value1' ],
'field2' => [ 'default' => 'value2' ],
]
);
$fix_mock->is_pro = true;

$fixes_manager = FixesManager::get_instance();
$reflection = new ReflectionClass( $fixes_manager );
$fixes_property = $reflection->getProperty( 'fixes' );
$fixes_property->setAccessible( true );
$fixes_property->setValue( $fixes_manager, [ 'mock_fix' => $fix_mock ] );

$expected = [
'mock_fix' => [
'fields' => [
'field1' => 'value1',
'field2' => 'value2',
],
'is_pro' => true,
],
];

$this->assertEquals( $expected, $fixes_manager->get_fixes_settings() );
}

/**
* Test that the instance returns the default values when options aren't set.
*
* @return void
*/
public function test_get_fixes_settings_uses_default_values() {
$fix_mock = Mockery::mock( 'EqualizeDigital\AccessibilityChecker\Fixes\Fix\AddFileSizeAndTypeToLinkedFilesFix' );
$fix_mock->shouldReceive( 'get_slug' )->andReturn( 'mock_fix' );
$fix_mock->shouldReceive( 'get_fields_array' )->andReturn(
[
'field1' => [ 'default' => 'default_value1' ],
'field2' => [ 'default' => 'default_value2' ],
]
);

$fixes_manager = FixesManager::get_instance();
$reflection = new ReflectionClass( $fixes_manager );
$fixes_property = $reflection->getProperty( 'fixes' );
$fixes_property->setAccessible( true );
$fixes_property->setValue( $fixes_manager, [ 'mock_fix' => $fix_mock ] );

$expected = [
'mock_fix' => [
'fields' => [
'field1' => 'default_value1',
'field2' => 'default_value2',
],
'is_pro' => false,
],
];

$this->assertEquals( $expected, $fixes_manager->get_fixes_settings() );
}
}

0 comments on commit 0c1949e

Please sign in to comment.