Skip to content

Add Site Health status checks - #1106

Merged
SteveJonesDev merged 10 commits into
developfrom
codex/add-wordpress-site-health-integration
Aug 5, 2025
Merged

Add Site Health status checks#1106
SteveJonesDev merged 10 commits into
developfrom
codex/add-wordpress-site-health-integration

Conversation

@SteveJonesDev

@SteveJonesDev SteveJonesDev commented Jul 24, 2025

Copy link
Copy Markdown
Member

Summary

  • show accessibility issues and scanning status in Site Health

Testing

  • composer lint
  • composer test (fails: Could not find /tmp/wordpress-tests-lib/includes/functions.php)

https://chatgpt.com/codex/tasks/task_e_6881acfdda4c8328a3c9cb0112999ad1

Summary by CodeRabbit

  • New Features
    • Added new accessibility checks to the WordPress Site Health tool, including tests to detect unresolved accessibility issues and to verify if any content has been scanned for accessibility.
    • Site Health now displays detailed results and action buttons for addressing accessibility issues or initiating scans directly from the Site Health interface.
    • Introduced configuration checks for post types enabled for accessibility scanning, with clear status indicators and quick access links for setup.

@coderabbitai

coderabbitai Bot commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

A new Checks class was introduced under the EDAC\Admin\SiteHealth namespace to provide WordPress Site Health integration for accessibility status. The admin initialization process was updated to instantiate this class and register its Site Health tests, allowing detection of accessibility issues and scanned content status within the Site Health interface. Comprehensive PHPUnit tests were added to verify the behavior of these Site Health checks.

Changes

Cohort / File(s) Change Summary
Admin Initialization Update
admin/class-admin.php
Added import, instantiation, and hook initialization for new Checks class in admin init process.
Site Health Accessibility Checks
admin/site-health/class-checks.php
Introduced Checks class with methods to register and implement Site Health tests for accessibility issues and scan status.
Unit Tests for Site Health Checks
tests/phpunit/Admin/SiteHealth/ChecksTest.php
Added PHPUnit test class verifying all aspects of the Checks class including hook registration, test results for various scenarios, and helper methods.

Sequence Diagram(s)

sequenceDiagram
    participant Admin
    participant Checks
    participant SiteHealth
    participant Scans_Stats

    Admin->>Checks: instantiate
    Admin->>Checks: init_hooks()
    Checks->>SiteHealth: add_filter('site_status_tests', register_tests)
    SiteHealth->>Checks: test_for_issues()
    Checks->>Scans_Stats: get_recent_stats()
    Checks-->>SiteHealth: return test result (issues status)
    SiteHealth->>Checks: test_content_scanned()
    Checks->>Scans_Stats: get_recent_stats()
    Checks-->>SiteHealth: return test result (scan status)
    SiteHealth->>Checks: test_post_types_configured()
    Checks-->>SiteHealth: return test result (post types status)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • pattonwebz

Poem

A bunny hops through code anew,
Site Health checks now in view!
Accessibility stats, so clear and bright,
Warn of issues, show what’s right.
With every scan and every test,
This fluffy coder’s done its best!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd0a9d0 and 3df2487.

📒 Files selected for processing (1)
  • tests/phpunit/Admin/SiteHealth/ChecksTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Integration Test: PHP 8.2 | WP latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.1 | WP latest (+ ms)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-wordpress-site-health-integration

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @SteveJonesDev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces new Site Health status checks to provide administrators with immediate insights into the accessibility status of their WordPress site. It integrates information about detected accessibility issues and the scanning progress of site content directly into the Site Health dashboard, making it easier to monitor and address accessibility concerns.

Highlights

  • Accessibility Issue Summary: A new check (edac_issues) reports the total number of accessibility errors and warnings found by the Accessibility Checker, providing a direct link to the issues page.
  • Content Scan Status: Another new check (edac_scanned) informs users whether any content has been scanned for accessibility, prompting them to initiate a full site scan if no content has been checked yet.
  • Dedicated Checks Class: A new class, EDACAdminSiteHealthChecks, has been introduced to encapsulate the logic for registering and performing these new Site Health tests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces new Site Health checks to display accessibility issues and scan status. The implementation is mostly correct, but there are a few areas for improvement regarding code style, efficiency, and readability. I've pointed out incorrect indentation and suggested a refactoring to avoid redundant operations.

Comment thread admin/class-admin.php Outdated
Comment thread admin/site-health/class-checks.php Outdated
Comment thread admin/site-health/class-checks.php Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
admin/site-health/class-checks.php (3)

54-84: Add error handling for Scans_Stats instantiation.

The method properly handles data sanitization and follows Site Health return format. However, consider adding error handling around the Scans_Stats instantiation in case it throws exceptions.

 public function test_for_issues(): array {
-    $stats  = ( new Scans_Stats( 60 * 5 ) )->summary();
+    try {
+        $stats = ( new Scans_Stats( 60 * 5 ) )->summary();
+    } catch ( Exception $e ) {
+        return [
+            'status'      => 'recommended',
+            'label'       => __( 'Unable to check accessibility issues', 'accessibility-checker' ),
+            'description' => __( 'There was an error retrieving accessibility scan statistics.', 'accessibility-checker' ),
+            'test'        => 'edac_issues',
+        ];
+    }

91-118: Add error handling for Scans_Stats instantiation.

The method properly uses pluralization with _n() and follows Site Health conventions. However, like the test_for_issues() method, consider adding error handling for the Scans_Stats instantiation.

 public function test_content_scanned(): array {
-    $stats = ( new Scans_Stats( 60 * 5 ) )->summary();
+    try {
+        $stats = ( new Scans_Stats( 60 * 5 ) )->summary();
+    } catch ( Exception $e ) {
+        return [
+            'status'      => 'recommended',
+            'label'       => __( 'Unable to check scan status', 'accessibility-checker' ),
+            'description' => __( 'There was an error retrieving scan statistics.', 'accessibility-checker' ),
+            'test'        => 'edac_scanned',
+        ];
+    }

55-55: Consider extracting the time window constant.

Both methods use the same 5-minute window (60 * 5). Consider extracting this as a class constant for better maintainability.

 class Checks {
+    /**
+     * Time window for recent scan statistics (5 minutes in seconds).
+     */
+    private const STATS_TIME_WINDOW = 300;

     // ... other methods ...

-    $stats  = ( new Scans_Stats( 60 * 5 ) )->summary();
+    $stats  = ( new Scans_Stats( self::STATS_TIME_WINDOW ) )->summary();

     // ... and in the other method ...

-    $stats = ( new Scans_Stats( 60 * 5 ) )->summary();
+    $stats = ( new Scans_Stats( self::STATS_TIME_WINDOW ) )->summary();

Also applies to: 92-92

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b686cdf and a6a277b.

📒 Files selected for processing (2)
  • admin/class-admin.php (2 hunks)
  • admin/site-health/class-checks.php (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#921
File: src/pageScanner/checks/linked-image-alt-present.js:43-50
Timestamp: 2025-04-15T02:30:38.897Z
Learning: In the Accessibility Checker plugin, accessibility rules are separated by specific concerns. For example, linked images have separate rules for checking: (1) missing alt attributes and (2) empty alt attributes. The rule `linked_image_alt_present` specifically checks for the presence of alt attributes on linked images, while a separate rule `img_linked_alt_empty` handles validation of empty alt attributes. Suggestions should respect this separation of concerns.
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#1088
File: includes/classes/Rules/Rule/EmptyParagraphTagRule.php:50-50
Timestamp: 2025-07-18T01:29:35.548Z
Learning: In the Accessibility Checker plugin, the 'wcag' field can use custom values like '0.1' to represent best practice rules and manual testing requirements that don't map directly to specific WCAG success criteria but are still important for accessibility compliance.
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#1088
File: includes/classes/Rules/Rule/VideoPresentRule.php:41-42
Timestamp: 2025-07-18T01:18:27.812Z
Learning: In the Accessibility Checker plugin, the 'wcag' field can use custom values like '0.3' to represent best practice rules and manual testing requirements that don't map directly to specific WCAG success criteria but are still important for accessibility compliance.
Learnt from: pattonwebz
PR: equalizedigital/accessibility-checker#1089
File: includes/classes/Fixes/Fix/AddSpacebarSupportToLinksWithButtonRoleFix.php:83-83
Timestamp: 2025-07-20T09:54:46.746Z
Learning: In the Accessibility Checker plugin, fix classes use a consistent pattern `isset( $this->is_pro ) && $this->is_pro ? false : true` for the upsell field in their settings arrays. The `is_pro` property is dynamically set and the `isset()` check prevents PHP notices when the property doesn't exist. This is the standard pattern used across all fix classes in the codebase.
Learnt from: pattonwebz
PR: equalizedigital/accessibility-checker#927
File: src/pageScanner/checks/img-alt-missing-check.js:35-37
Timestamp: 2025-04-18T14:27:18.140Z
Learning: In the Accessibility Checker plugin, the img_alt_missing rule specifically checks for missing alt attributes on images and image inputs, while empty alt attributes are handled by a separate rule. Each accessibility concern is deliberately separated into individual rules.
Learnt from: pattonwebz
PR: equalizedigital/accessibility-checker#927
File: src/pageScanner/checks/img-alt-missing-check.js:32-32
Timestamp: 2025-04-18T14:27:49.512Z
Learning: In the Accessibility Checker plugin, the img_alt_missing rule specifically checks for missing alt attributes (whether the attribute exists at all), while empty alt attributes (alt="") are handled by a separate rule. This separation of concerns is by design.
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#921
File: src/pageScanner/checks/linked-image-alt-present.js:43-50
Timestamp: 2025-04-15T02:30:38.897Z
Learning: In the Accessibility Checker plugin, there are separate rules for different aspects of image accessibility. The rule `linked_image_alt_present` specifically checks for the presence of alt attributes on linked images, while a separate rule handles validation of empty alt attributes.
admin/site-health/class-checks.php (1)

Learnt from: pattonwebz
PR: #1089
File: includes/classes/Fixes/Fix/AddSpacebarSupportToLinksWithButtonRoleFix.php:83-83
Timestamp: 2025-07-20T09:54:46.746Z
Learning: In the Accessibility Checker plugin, fix classes use a consistent pattern isset( $this->is_pro ) && $this->is_pro ? false : true for the upsell field in their settings arrays. The is_pro property is dynamically set and the isset() check prevents PHP notices when the property doesn't exist. This is the standard pattern used across all fix classes in the codebase.

🔇 Additional comments (4)
admin/class-admin.php (2)

11-11: LGTM: Proper import statement added.

The import follows the existing namespace pattern and is correctly placed with other use statements.


63-67: LGTM: Site Health integration properly implemented.

The instantiation and initialization of both Information and Checks classes follow the established pattern used throughout the init() method. The placement is logical, grouping related Site Health functionality together.

admin/site-health/class-checks.php (2)

1-27: LGTM: Well-structured class with proper WordPress integration.

The class follows WordPress coding standards with proper namespace, documentation, and hook initialization. The init_hooks() method correctly registers with the Site Health system.


35-47: LGTM: Proper Site Health test registration.

The test registration follows WordPress Site Health API conventions correctly, with appropriate labels and callback references for both direct tests.

Updated the method name from `get_badge` to `get_accessibility_badge` to better reflect its purpose and improve code readability.
This change enhances the user experience by providing a localized message indicating the number of posts scanned by the Accessibility Checker.

[PRO-165]
@pattonwebz

Copy link
Copy Markdown
Member

I added a badge of 'Accessibility' for our checks.
Screenshot from 2025-07-24 21-14-12

@pattonwebz pattonwebz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and it works, I fixed the CS issues and made some minor tweaks

@SteveJonesDev

Copy link
Copy Markdown
Member Author

Added number formatting and conditional to switch the button link based on if Pro is installed or not.

@SteveJonesDev

Copy link
Copy Markdown
Member Author

Also added a check for if no custom post types are set to scan.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (1)
tests/phpunit/Admin/SiteHealth/ChecksTest.php (1)

1-439: Add text domain verification for translatable strings.

Based on the coding guidelines, all user-facing text should use the 'accessibility-checker' text domain. However, this test file only verifies the structure, not the actual translatable strings.

Consider adding a test to verify that the actual Checks class methods use proper internationalization:

/**
 * Test that all user-facing strings are translatable.
 */
public function test_strings_are_translatable() {
    // This would require integration with the actual Checks class
    // to verify __() and _n() function usage with correct text domain
    $this->markTestIncomplete( 'Add verification of i18n text domain usage' );
}
🧹 Nitpick comments (1)
tests/phpunit/Admin/SiteHealth/ChecksTest.php (1)

90-125: Consider mocking the stats property instead of Scans_Stats class.

The test creates a mock of Scans_Stats but then uses reflection to set the stats property directly. This is inconsistent and the mock isn't actually used.

 public function test_test_for_issues_with_no_issues() {
-	// Mock Scans_Stats to return no issues.
-	$mock_stats = $this->getMockBuilder( Scans_Stats::class )
-		->disableOriginalConstructor()
-		->getMock();
-	
-	$mock_stats->method( 'summary' )
-		->willReturn(
-			[
-				'errors'   => 0,
-				'warnings' => 0,
-			] 
-		);
-
 	// Use reflection to set the private stats property.
 	$reflection     = new \ReflectionClass( $this->checks );
 	$stats_property = $reflection->getProperty( 'stats' );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 347dae9 and bd0a9d0.

📒 Files selected for processing (1)
  • tests/phpunit/Admin/SiteHealth/ChecksTest.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.php

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.php: Follow WordPress coding standards (WPCS) in all PHP files
Use PSR-4 autoloading with EqualizeDigital\AccessibilityChecker namespace for new classes
Use WordPress hooks and filters appropriately
Use edac_ prefix for custom hooks and filters
Minimum PHP 7.4 compatibility
Use type hints where appropriate in PHP code
Follow WordPress security best practices (sanitization, validation, nonces)
Use WordPress database API (wpdb) for database operations
Prefix all functions and classes with edac_ when in global namespace
Use WordPress hooks (actions/filters) for extensibility
Use WordPress transients for caching
Sanitize all user inputs
Validate and escape all outputs
Use WordPress nonces for form submissions
Implement proper capability checks
Provide appropriate hooks for extensibility when adding new functionality
Use descriptive hook names with edac_ prefix
Document all custom hooks in docblocks
Document custom hooks and filters with clear descriptions and parameter types
Use PHPDoc for all public classes, methods, and properties
Escape all output, especially in admin screens and user-generated content
Use WordPress error handling functions (e.g., WP_Error) for PHP errors

Files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
**/[A-Z]*.php

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/[A-Z]*.php: Class names use CamelCase (ClassNameConvention) for new classes
File names use ClassNameConvention.php for new classes (CamelCase)
Classes: ClassName.php

Files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
**/*.{php,js}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.{php,js}: Follow WordPress internationalization (i18n) practices and use accessibility-checker text domain
All user-facing text must be translatable
Add inline comments for complex accessibility logic or non-obvious code
Use semantic HTML structure
ARIA attributes used correctly
Keyboard navigation supported
Images have descriptive alt text
Heading hierarchy logical
Screen reader compatibility
Forms are accessible and labeled

Files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
tests/phpunit/**/*.php

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

tests/phpunit/**/*.php: Write unit tests for new PHP functions and classes
Add integration tests for major features and accessibility rules

Files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Applies to **/*.{php,js} : Follow WordPress internationalization (i18n) practices and use accessibility-checker text domain
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#1088
File: includes/classes/Rules/Rule/VideoPresentRule.php:41-42
Timestamp: 2025-07-18T01:18:27.812Z
Learning: In the Accessibility Checker plugin, the 'wcag' field can use custom values like '0.3' to represent best practice rules and manual testing requirements that don't map directly to specific WCAG success criteria but are still important for accessibility compliance.
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#1088
File: includes/classes/Rules/Rule/EmptyParagraphTagRule.php:50-50
Timestamp: 2025-07-18T01:29:35.548Z
Learning: In the Accessibility Checker plugin, the 'wcag' field can use custom values like '0.1' to represent best practice rules and manual testing requirements that don't map directly to specific WCAG success criteria but are still important for accessibility compliance.
Learnt from: pattonwebz
PR: equalizedigital/accessibility-checker#1089
File: includes/classes/Fixes/Fix/AddSpacebarSupportToLinksWithButtonRoleFix.php:83-83
Timestamp: 2025-07-20T09:54:46.746Z
Learning: In the Accessibility Checker plugin, fix classes use a consistent pattern `isset( $this->is_pro ) && $this->is_pro ? false : true` for the upsell field in their settings arrays. The `is_pro` property is dynamically set and the `isset()` check prevents PHP notices when the property doesn't exist. This is the standard pattern used across all fix classes in the codebase.
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: No accessibility regressions introduced
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#921
File: src/pageScanner/checks/linked-image-alt-present.js:43-50
Timestamp: 2025-04-15T02:30:38.897Z
Learning: In the Accessibility Checker plugin, accessibility rules are separated by specific concerns. For example, linked images have separate rules for checking: (1) missing alt attributes and (2) empty alt attributes. The rule `linked_image_alt_present` specifically checks for the presence of alt attributes on linked images, while a separate rule `img_linked_alt_empty` handles validation of empty alt attributes. Suggestions should respect this separation of concerns.
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Applies to accessibility-checker.php : Implement proper activation/deactivation hooks
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Applies to tests/phpunit/**/*.php : Add integration tests for major features and accessibility rules
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Prioritize accessibility in UI/UX decisions and code reviews
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Applies to **/*.php : Use PSR-4 autoloading with EqualizeDigital\AccessibilityChecker namespace for new classes
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Use axe-core browser extension for manual accessibility checks
📚 Learning: applies to tests/phpunit/**/*.php : add integration tests for major features and accessibility rules...
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Applies to tests/phpunit/**/*.php : Add integration tests for major features and accessibility rules

Applied to files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
📚 Learning: applies to tests/phpunit/**/*.php : write unit tests for new php functions and classes...
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Applies to tests/phpunit/**/*.php : Write unit tests for new PHP functions and classes

Applied to files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
📚 Learning: in the accessibility checker plugin, fix classes use a consistent pattern `isset( $this->is_pro ) &&...
Learnt from: pattonwebz
PR: equalizedigital/accessibility-checker#1089
File: includes/classes/Fixes/Fix/AddSpacebarSupportToLinksWithButtonRoleFix.php:83-83
Timestamp: 2025-07-20T09:54:46.746Z
Learning: In the Accessibility Checker plugin, fix classes use a consistent pattern `isset( $this->is_pro ) && $this->is_pro ? false : true` for the upsell field in their settings arrays. The `is_pro` property is dynamically set and the `isset()` check prevents PHP notices when the property doesn't exist. This is the standard pattern used across all fix classes in the codebase.

Applied to files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
📚 Learning: applies to accessibility-checker.php : implement proper activation/deactivation hooks...
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Applies to accessibility-checker.php : Implement proper activation/deactivation hooks

Applied to files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
📚 Learning: applies to **/*.{php,js} : follow wordpress internationalization (i18n) practices and use accessibil...
Learnt from: CR
PR: equalizedigital/accessibility-checker#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-04T16:46:23.515Z
Learning: Applies to **/*.{php,js} : Follow WordPress internationalization (i18n) practices and use accessibility-checker text domain

Applied to files:

  • tests/phpunit/Admin/SiteHealth/ChecksTest.php
🪛 GitHub Actions: Test
tests/phpunit/Admin/SiteHealth/ChecksTest.php

[error] 42-42: PHPUnit test failure: Failed asserting that 10 is true in 'Init hooks adds filter' test.


[error] 178-178: PHPUnit test failure: Failed asserting that output contains 'accessibility_checker_issues' in 'Test for issues with pro version' test.


[error] 298-298: PHPUnit test failure: Failed asserting that 'Accessibility Checker is configured to scan 2 post types: post, page.' contains 'configured to scan 3 post types: post, page, product' in 'Test post types configured with multiple types' test.

🔇 Additional comments (5)
tests/phpunit/Admin/SiteHealth/ChecksTest.php (5)

8-13: LGTM! Proper namespace and imports.

The namespace follows PSR-4 conventions with the correct EqualizeDigital\AccessibilityChecker pattern, and all necessary imports are properly declared.


371-387: LGTM! Consistent number formatting test.

This test follows the same pattern as the issues formatting test and should work correctly if the implementation uses WordPress number formatting.


392-428: LGTM! Comprehensive validation of required keys.

This test ensures all Site Health test methods return the required array structure, which is essential for WordPress Site Health integration.


433-437: LGTM! Proper test cleanup.

The tearDown method correctly cleans up the options set during tests to prevent test pollution.


347-366: No action needed: WordPress number_format_i18n is used for formatting

The class-checks.php implementation calls number_format_i18n() for errors, warnings, scanned posts, and post‐type counts. The test’s expectation of commas in “1,234” and “5,678” is therefore correct.

Comment thread tests/phpunit/Admin/SiteHealth/ChecksTest.php
Comment on lines +156 to +180
public function test_test_for_issues_with_pro_version() {
if ( ! defined( 'EDACP_VERSION' ) ) {
define( 'EDACP_VERSION', '1.0.0' );
}
if ( ! defined( 'EDAC_KEY_VALID' ) ) {
define( 'EDAC_KEY_VALID', true );
}

// Mock stats with issues.
$reflection = new \ReflectionClass( $this->checks );
$stats_property = $reflection->getProperty( 'stats' );
$stats_property->setAccessible( true );
$stats_property->setValue(
$this->checks,
[
'errors' => 2,
'warnings' => 1,
]
);

$result = $this->checks->test_for_issues();

$this->assertStringContainsString( 'accessibility_checker_issues', $result['actions'] );
$this->assertStringContainsString( 'View Issues', $result['actions'] );
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Fix the Pro version test - verify actual method implementation.

The test is failing because it expects 'accessibility_checker_issues' in the actions but gets different content. This suggests the actual implementation differs from expectations.


🏁 Script executed:

#!/bin/bash
# Description: Check the actual implementation of get_issues_link method in the Checks class
# Expected: Find the method and see what URL/actions it generates for Pro version

ast-grep --pattern $'get_issues_link($_) {
  $$$
}'

# Also search for how Pro version affects the issues link
rg -A 10 -B 5 "EDACP_VERSION|EDAC_KEY_VALID" --type php

Length of output: 43240


🏁 Script executed:

#!/bin/bash
# Locate the implementation of test_for_issues in the Site Health Checks class
rg -n "function test_for_issues" -A 10 -B 5 admin/site-health/class-checks.php

Length of output: 628


🏁 Script executed:

#!/bin/bash
# Show full test_for_issues implementation to inspect 'actions' key construction
rg -n "public function test_for_issues" -A 40 -B 0 admin/site-health/class-checks.php

Length of output: 1617


🏁 Script executed:

#!/bin/bash
# Inspect get_stats implementation in admin/site-health/class-checks.php
rg -n "function get_stats" -A 30 -B 0 admin/site-health/class-checks.php

Length of output: 1109


Clarify and Enable the Pro-Branch Test

The implementation of get_issues_link() is correct (it returns an admin_url for “accessibility_checker_issues” and the text “View Issues” when Pro constants are true), so the test is failing not because of site-health logic but because EDAC_KEY_VALID is defined unconditionally at plugin load and cannot be redefined in PHPUnit. To allow your test to hit the Pro branch you can:

• In accessibility-checker.php, wrap the EDAC_KEY_VALID definition so tests can override it:

if ( ! defined( 'EDAC_KEY_VALID' ) ) {
    define( 'EDAC_KEY_VALID', 'valid' === get_option( 'edacp_license_status' ) );
}

(and similarly guard EDACP_VERSION)

• Or in admin/site-health/class-checks.php, extract the license check into a protected is_pro_active() method that get_issues_link() calls—tests can then subclass or mock that method.

• Update the PHPUnit bootstrap or the test itself to define EDAC_KEY_VALID before the plugin file is loaded (so the guarded define won’t override it), ensuring your assertStringContainsString('accessibility_checker_issues', …) and 'View Issues' both pass.

🧰 Tools
🪛 GitHub Actions: Test

[error] 178-178: PHPUnit test failure: Failed asserting that output contains 'accessibility_checker_issues' in 'Test for issues with pro version' test.

🤖 Prompt for AI Agents
In tests/phpunit/Admin/SiteHealth/ChecksTest.php around lines 156 to 180, the
test for the Pro version branch fails because EDAC_KEY_VALID is defined
unconditionally at plugin load and cannot be redefined in PHPUnit. To fix this,
modify accessibility-checker.php to wrap the EDAC_KEY_VALID and EDACP_VERSION
definitions with checks using if (!defined(...)) so they can be overridden in
tests. Alternatively, refactor the license check into a protected method in
admin/site-health/class-checks.php that can be mocked or subclassed in tests.
Also, ensure EDAC_KEY_VALID is defined before the plugin loads in the PHPUnit
bootstrap or test setup to allow the test assertions for
'accessibility_checker_issues' and 'View Issues' to pass.

Comment thread tests/phpunit/Admin/SiteHealth/ChecksTest.php
@SteveJonesDev
SteveJonesDev merged commit f50d865 into develop Aug 5, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants