Skip to content

added: plugin action links class to add Settings and Get Pro links - #1051

Merged
SteveJonesDev merged 14 commits into
developfrom
steve/pro-190-plugin-action-links-add-get-accessibility-checker-pro-and
Jul 8, 2025
Merged

added: plugin action links class to add Settings and Get Pro links#1051
SteveJonesDev merged 14 commits into
developfrom
steve/pro-190-plugin-action-links-add-get-accessibility-checker-pro-and

Conversation

@SteveJonesDev

@SteveJonesDev SteveJonesDev commented Jul 3, 2025

Copy link
Copy Markdown
Member

This pull request introduces functionality to add custom action links to the plugin list table, including a "Settings" link and a "Get Pro" link for non-pro users. It also includes related styling for these links. The most important changes are the addition of the Plugin_Action_Links class, integration of its hooks in the admin initialization, and styling updates for the "Get Pro" link.

Functional changes:

  • Added Plugin_Action_Links class: Implements the functionality to display custom plugin action links ("Settings" and "Get Pro") in the plugin list table.
  • Integrated Plugin_Action_Links hooks: Updated the admin/class-admin.php file to initialize the hooks for Plugin_Action_Links during admin initialization.

Styling changes:

  • Added styles for "Get Pro" link: Updated accessibility-checker-admin.scss to include bold red text and hover/focus effects for the "Get Pro" link.

Screenshot 2025-07-03 at 4 24 52 PM

Summary by CodeRabbit

  • New Features

    • Added "Settings" and "Get Pro" action links to the plugin list for easier access to the plugin's settings and upgrade options.
  • Style

    • Introduced new styles for the plugin action links, including a distinct appearance for the "Get Pro" link with enhanced color and emphasis on hover and focus.

@coderabbitai

coderabbitai Bot commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new class was added to handle plugin action links in the admin interface, including logic for "Settings" and "Get Pro" links. The admin initialization was updated to register this functionality. New SCSS styles were introduced to visually distinguish these action links, particularly the "Go Pro" link. The translation template was updated to include new strings and references related to these links. Additionally, a PHPUnit test suite was created to verify the behavior of the new plugin action links class.

Changes

File(s) Change Summary
admin/class-plugin-action-links.php Introduced Plugin_Action_Links class to manage and modify plugin action links in admin.
admin/class-admin.php Updated Admin::init() to instantiate and initialize Plugin_Action_Links.
src/admin/sass/accessibility-checker-admin.scss Added styles for .edac-plugin-action-links and emphasized .edac-plugin-action-links__go-pro.
languages/accessibility-checker.pot Updated translation template with new strings and references for plugin action links.
tests/phpunit/Admin/PluginActionLinksTest.php Added PHPUnit test class to verify Plugin_Action_Links functionality and behavior.

Sequence Diagram(s)

sequenceDiagram
    participant WP_Admin as WordPress Admin
    participant Admin as Admin
    participant PluginActionLinks as Plugin_Action_Links

    WP_Admin->>Admin: init()
    Admin->>PluginActionLinks: new Plugin_Action_Links()
    Admin->>PluginActionLinks: init_hooks()
    PluginActionLinks->>WP_Admin: Add filter for plugin_action_links
    WP_Admin->>PluginActionLinks: plugin_action_links($links)
    PluginActionLinks->>WP_Admin: Return modified $links (Settings, Get Pro)
Loading

Suggested reviewers

  • pattonwebz

Poem

In the admin’s warren, new links appear bright,
“Settings” and “Go Pro”—a delightful sight!
A dash of bold red, some styles to show,
Rabbits hop faster when features just flow.
With code and with CSS, we make plugins sing,
Hopping ahead—what joy new links bring! 🐇✨


📜 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 afa15f5 and f72d9ca.

📒 Files selected for processing (1)
  • admin/class-plugin-action-links.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • admin/class-plugin-action-links.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). (1)
  • GitHub Check: Integration Test: PHP 8.2 | WP latest (+ ms)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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 enhances the plugin's administrative interface by adding custom action links to its entry in the WordPress plugin list table. It provides quick access to plugin settings and prominently displays an option for non-pro users to upgrade, with accompanying styling to make the upgrade link stand out.

Highlights

  • New Feature: Plugin Action Links: Introduced a dedicated Plugin_Action_Links class to manage and display custom action links ('Settings' and 'Get Pro') directly on the WordPress plugin list table, enhancing user navigation and discoverability.
  • Admin Integration: The newly created Plugin_Action_Links functionality has been seamlessly integrated into the main admin initialization process, ensuring the custom links are properly registered and displayed when the admin interface loads.
  • Styling for 'Get Pro' Link: Custom SCSS has been added to visually distinguish the 'Get Pro' link. It is now styled with bold red text and includes appropriate hover/focus effects, aiming to improve its visibility and encourage user engagement for non-pro users.
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 is currently in preview and 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 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.

@github-actions

github-actions Bot commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

The POT file has changed. Please update the POT file in your PR to keep translations up to date.
The updated POT file is available in the artifacts of this workflow run: https://github.com/equalizedigital/accessibility-checker/actions/runs/16059913492

@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 a new Plugin_Action_Links class to add "Settings" and "Get Pro" links to the plugin's action links in the WordPress admin, along with corresponding styles. The implementation is solid, but I've identified a few areas for improvement, primarily concerning security and code quality. My main feedback points are escaping URLs and refining the SCSS to remove redundant properties.

Comment thread admin/class-plugin-action-links.php Outdated
Comment thread admin/class-plugin-action-links.php Outdated
Comment thread src/admin/sass/accessibility-checker-admin.scss

@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

🧹 Nitpick comments (1)
admin/class-admin.php (1)

51-52: Add use statement for Plugin_Action_Links class.

The class is instantiated but there's no corresponding use statement at the top of the file. For consistency with other classes in this file, add the use statement.

+use EDAC\Admin\Plugin_Action_Links;
 use EDAC\Admin\SiteHealth\Information;
 use EDAC\Admin\Purge_Post_Data;
 use EDAC\Admin\Post_Save;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d0c6d2 and f120582.

📒 Files selected for processing (3)
  • admin/class-admin.php (1 hunks)
  • admin/class-plugin-action-links.php (1 hunks)
  • src/admin/sass/accessibility-checker-admin.scss (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/admin/sass/accessibility-checker-admin.scss (3)
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: 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.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: make-pot
🔇 Additional comments (3)
src/admin/sass/accessibility-checker-admin.scss (1)

2005-2016: LGTM! Well-implemented CSS for plugin action links.

The styling follows best practices with proper SASS nesting, design system variables, and accessibility-friendly hover/focus states. The BEM naming convention is consistent with the codebase.

admin/class-plugin-action-links.php (2)

39-43: LGTM! Proper URL construction and escaping.

The Settings link is properly constructed with admin_url() and esc_html__() for security and internationalization.


52-56: Good accessibility implementation.

The aria-label provides excellent context for screen reader users, clearly indicating the link opens in a new window.

Comment thread admin/class-plugin-action-links.php Outdated
Comment thread admin/class-plugin-action-links.php Outdated
Comment thread admin/class-plugin-action-links.php Outdated
@github-actions

github-actions Bot commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

The POT file has changed. Please update the POT file in your PR to keep translations up to date.
The updated POT file is available in the artifacts of this workflow run: https://github.com/equalizedigital/accessibility-checker/actions/runs/16060299452

@SteveJonesDev SteveJonesDev changed the title added: plugin Action Links class and styles for admin interface added: plugin action links class to add Settings and Get Pro links Jul 3, 2025
@SteveJonesDev
SteveJonesDev requested a review from pattonwebz July 3, 2025 20:57
…ve/pro-190-plugin-action-links-add-get-accessibility-checker-pro-and

Update translation files (POT/JSON)

@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: 2

🧹 Nitpick comments (4)
tests/phpunit/Admin/PluginActionLinksTest.php (4)

32-47: Consider using more descriptive test names.

While method existence tests are useful, consider using more descriptive test names that indicate the expected behavior rather than just existence.

-	public function test_init_hooks_method_exists() {
+	public function test_init_hooks_method_is_callable() {
-	public function test_add_plugin_action_links_method_exists() {
+	public function test_add_plugin_action_links_method_is_callable() {

104-117: Remove unused parameter from mock function.

The mock function has an unused parameter that triggers static analysis warnings.

-		function edac_link_wrapper( $url, $source, $campaign, $unused ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
+		function edac_link_wrapper( $url, $source, $campaign ) {

99-101: Consider using dependency injection for better testability.

Directly defining constants in tests can lead to coupling and makes tests less maintainable. Consider using dependency injection or mocking frameworks.

-		// Define the constant as false for this test.
-		if ( ! defined( 'EDAC_KEY_VALID' ) ) {
-			define( 'EDAC_KEY_VALID', false );
-		}
+		// Mock the constant check in the actual class instead
+		// or use a test double that allows dependency injection

88-92: Enhance test assertions for better reliability.

Consider using more specific assertions and testing the actual URL structure rather than just string contains checks.

-		$this->assertStringContainsString( 'Settings', $first_link, 'Settings link not found' );
-		$this->assertStringContainsString( 'accessibility_checker_settings', $first_link, 'Settings link does not point to correct page' );
+		$this->assertStringContainsString( 'Settings', $first_link, 'Settings link text not found' );
+		$this->assertStringContainsString( 'page=accessibility_checker_settings', $first_link, 'Settings link does not point to correct admin page' );
+		$this->assertStringContainsString( 'admin.php', $first_link, 'Settings link does not point to admin area' );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c7f040d and ed55e76.

📒 Files selected for processing (1)
  • tests/phpunit/Admin/PluginActionLinksTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
tests/phpunit/Admin/PluginActionLinksTest.php (1)
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.
🪛 PHPMD (2.15.0)
tests/phpunit/Admin/PluginActionLinksTest.php

114-114: Avoid unused parameters such as '$unused'. (Unused Code Rules)

(UnusedFormalParameter)


177-177: Avoid unused parameters such as '$unused'. (Unused Code Rules)

(UnusedFormalParameter)

⏰ 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). (8)
  • GitHub Check: Integration Test: PHP 8.1 | WP latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.1 | WP latest
  • GitHub Check: Integration Test: PHP 8.2 | WP latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.1 | WP 6.2
  • GitHub Check: make-pot
  • GitHub Check: Integration Test: PHP 8.1 | WP latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.1 | WP latest
  • GitHub Check: Integration Test: PHP 8.2 | WP latest (+ ms)
🔇 Additional comments (4)
tests/phpunit/Admin/PluginActionLinksTest.php (4)

1-13: LGTM! Well-structured test class setup.

The file header, namespace usage, and class declaration follow PHPUnit best practices.


25-27: LGTM! Standard PHPUnit setUp method.

The setUp method properly initializes the class under test.


122-126: Good comprehensive testing of the pro link attributes.

The test thoroughly verifies various aspects of the pro link including text, target, CSS class, and accessibility attributes.


194-199: LGTM! Proper test cleanup.

The tearDown method properly cleans up filters to maintain test isolation.

Comment on lines +54 to +56
if ( ! defined( 'EDAC_PLUGIN_FILE' ) ) {
define( 'EDAC_PLUGIN_FILE', __FILE__ );
}

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.

🛠️ Refactor suggestion

Potential test isolation issues with constant definitions.

Defining constants conditionally can cause test isolation issues if tests run in different orders. Consider using a more robust approach for test constants.

-		if ( ! defined( 'EDAC_PLUGIN_FILE' ) ) {
-			define( 'EDAC_PLUGIN_FILE', __FILE__ );
-		}
+		// Use a test-specific constant or mock the dependency
+		if ( ! defined( 'EDAC_PLUGIN_FILE' ) ) {
+			define( 'EDAC_PLUGIN_FILE', dirname( __DIR__, 3 ) . '/accessibility-checker.php' );
+		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ( ! defined( 'EDAC_PLUGIN_FILE' ) ) {
define( 'EDAC_PLUGIN_FILE', __FILE__ );
}
// Use a test-specific constant or mock the dependency
if ( ! defined( 'EDAC_PLUGIN_FILE' ) ) {
define( 'EDAC_PLUGIN_FILE', dirname( __DIR__, 3 ) . '/accessibility-checker.php' );
}
🤖 Prompt for AI Agents
In tests/phpunit/Admin/PluginActionLinksTest.php around lines 54 to 56, defining
the constant EDAC_PLUGIN_FILE conditionally can cause test isolation issues when
tests run in different orders. To fix this, refactor the test setup to avoid
defining constants conditionally; instead, define the constant once in a
dedicated bootstrap or setup method that runs before all tests, or mock the
constant's usage to ensure consistent test isolation and prevent side effects
between tests.

Comment thread tests/phpunit/Admin/PluginActionLinksTest.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

♻️ Duplicate comments (2)
tests/phpunit/Admin/PluginActionLinksTest.php (2)

54-56: Potential test isolation issues with constant definitions.

Defining constants conditionally can cause test isolation issues if tests run in different orders. Consider using a more robust approach for test constants.


166-180: Eliminate duplicate mock function definition.

The edac_link_wrapper function is defined twice in the file, which is redundant and could cause issues. Consider extracting this to a shared setUp method or using a more robust mocking approach.

🧹 Nitpick comments (2)
tests/phpunit/Admin/PluginActionLinksTest.php (2)

104-117: Remove unused parameter from mock function.

The mock function has an unused parameter that should be removed to clean up the code.

-		if ( ! function_exists( 'edac_link_wrapper' ) ) {
-			/**
-			 * Mock the edac_link_wrapper function.
-			 *
-			 * @param string $url      The URL to wrap.
-			 * @param string $source   The source parameter.
-			 * @param string $campaign The campaign parameter.
-			 * @param bool   $unused   Unused parameter for compatibility.
-			 * @return string The wrapped URL.
-			 */
-			function edac_link_wrapper( $url, $source, $campaign, $unused ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
-				return $url . '?utm_source=' . $source . '&utm_campaign=' . $campaign;
-			}
-		}
+		if ( ! function_exists( 'edac_link_wrapper' ) ) {
+			/**
+			 * Mock the edac_link_wrapper function.
+			 *
+			 * @param string $url      The URL to wrap.
+			 * @param string $source   The source parameter.
+			 * @param string $campaign The campaign parameter.
+			 * @return string The wrapped URL.
+			 */
+			function edac_link_wrapper( $url, $source, $campaign ) {
+				return $url . '?utm_source=' . $source . '&utm_campaign=' . $campaign;
+			}
+		}

98-101: Consider centralizing constant definitions for better test isolation.

Multiple test methods define the same constants conditionally, which can lead to test order dependencies. Consider moving these to a shared setUp method.

 	protected function setUp(): void {
 		$this->plugin_action_links = new Plugin_Action_Links();
+		
+		// Define test constants if not already defined
+		if ( ! defined( 'EDAC_PLUGIN_FILE' ) ) {
+			define( 'EDAC_PLUGIN_FILE', dirname( __DIR__, 3 ) . '/accessibility-checker.php' );
+		}
+		if ( ! defined( 'EDAC_KEY_VALID' ) ) {
+			define( 'EDAC_KEY_VALID', false );
+		}
+		
+		// Mock the edac_link_wrapper function if it doesn't exist
+		if ( ! function_exists( 'edac_link_wrapper' ) ) {
+			/**
+			 * Mock the edac_link_wrapper function.
+			 *
+			 * @param string $url      The URL to wrap.
+			 * @param string $source   The source parameter.
+			 * @param string $campaign The campaign parameter.
+			 * @return string The wrapped URL.
+			 */
+			function edac_link_wrapper( $url, $source, $campaign ) {
+				return $url . '?utm_source=' . $source . '&utm_campaign=' . $campaign;
+			}
+		}
 	}

Also applies to: 162-164

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed55e76 and 4c4e8e7.

📒 Files selected for processing (1)
  • tests/phpunit/Admin/PluginActionLinksTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
tests/phpunit/Admin/PluginActionLinksTest.php (1)
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.
🪛 PHPMD (2.15.0)
tests/phpunit/Admin/PluginActionLinksTest.php

114-114: Avoid unused parameters such as '$unused'. (Unused Code Rules)

(UnusedFormalParameter)


177-177: Avoid unused parameters such as '$unused'. (Unused Code Rules)

(UnusedFormalParameter)

⏰ 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). (4)
  • GitHub Check: Integration Test: PHP 8.1 | WP latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.2 | WP latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.1 | WP 6.2
  • GitHub Check: make-pot
🔇 Additional comments (6)
tests/phpunit/Admin/PluginActionLinksTest.php (6)

1-27: Test structure and setup look good.

The test class follows WordPress testing conventions and properly extends WP_UnitTestCase. The setUp method correctly initializes the class under test.


32-47: Method existence tests are appropriate.

These tests ensure the required methods exist on the class, which is good for catching basic structural issues.


97-126: Pro link test logic is comprehensive.

The test properly validates the conditional logic for adding the "Get Pro" link and checks all the required attributes including CSS class, target, and text content.


131-155: Link preservation and URL escaping tests are solid.

These tests ensure that existing plugin action links are preserved and that URLs are properly escaped, which is important for security and functionality.


160-189: Accessibility test coverage is excellent.

The test properly validates that accessibility attributes like aria-label are included in the pro link, which aligns well with the accessibility focus of this plugin.


194-200: Proper cleanup in tearDown method.

The tearDown method correctly removes filters to prevent test pollution, which is good practice for test isolation.

@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: 2

♻️ Duplicate comments (1)
tests/phpunit/Admin/PluginActionLinksTest.php (1)

37-43: Address test isolation issues with constant definitions.

Defining constants conditionally in test methods can cause test isolation problems when tests run in different orders or when constants are already defined elsewhere in the test suite.

Consider using a more robust approach for test constants:

-		// Define constants if not already defined.
-		if ( ! defined( 'EDAC_PLUGIN_FILE' ) ) {
-			define( 'EDAC_PLUGIN_FILE', __FILE__ );
-		}
-		
-		if ( ! defined( 'EDAC_KEY_VALID' ) ) {
-			define( 'EDAC_KEY_VALID', false );
-		}
+		// Use a test-specific constant path
+		if ( ! defined( 'EDAC_PLUGIN_FILE' ) ) {
+			define( 'EDAC_PLUGIN_FILE', dirname( __DIR__, 3 ) . '/accessibility-checker.php' );
+		}
+		
+		if ( ! defined( 'EDAC_KEY_VALID' ) ) {
+			define( 'EDAC_KEY_VALID', false );
+		}
🧹 Nitpick comments (1)
tests/phpunit/Admin/PluginActionLinksTest.php (1)

46-59: Remove unused parameter from mock function.

The static analysis correctly identifies that the $unused parameter is not used in the mock function, which creates unnecessary complexity.

-		// Mock the edac_link_wrapper function if it doesn't exist.
-		if ( ! function_exists( 'edac_link_wrapper' ) ) {
-			/**
-			 * Mock the edac_link_wrapper function.
-			 *
-			 * @param string $url      The URL to wrap.
-			 * @param string $source   The source parameter.
-			 * @param string $campaign The campaign parameter.
-			 * @param bool   $unused   Unused parameter for compatibility.
-			 * @return string The wrapped URL.
-			 */
-			function edac_link_wrapper( $url, $source, $campaign, $unused ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
-				return $url . '?utm_source=' . $source . '&utm_campaign=' . $campaign;
-			}
-		}
+		// Mock the edac_link_wrapper function if it doesn't exist.
+		if ( ! function_exists( 'edac_link_wrapper' ) ) {
+			/**
+			 * Mock the edac_link_wrapper function.
+			 *
+			 * @param string $url      The URL to wrap.
+			 * @param string $source   The source parameter.
+			 * @param string $campaign The campaign parameter.
+			 * @return string The wrapped URL.
+			 */
+			function edac_link_wrapper( $url, $source, $campaign ) {
+				return $url . '?utm_source=' . $source . '&utm_campaign=' . $campaign;
+			}
+		}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c4e8e7 and 55b5ab7.

📒 Files selected for processing (1)
  • tests/phpunit/Admin/PluginActionLinksTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
tests/phpunit/Admin/PluginActionLinksTest.php (1)
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.
🪛 PHPMD (2.15.0)
tests/phpunit/Admin/PluginActionLinksTest.php

56-56: Avoid unused parameters such as '$unused'. (Unused Code Rules)

(UnusedFormalParameter)

⏰ 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). (8)
  • GitHub Check: Integration Test: PHP 8.1 | WP latest
  • GitHub Check: Integration Test: PHP 8.1 | WP 6.2
  • GitHub Check: Integration Test: PHP 8.1 | WP latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.2 | WP latest (+ ms)
  • GitHub Check: make-pot
  • GitHub Check: Integration Test: PHP 8.1 | WP latest
  • GitHub Check: Integration Test: PHP 8.1 | WP latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.1 | WP 6.2
🔇 Additional comments (2)
tests/phpunit/Admin/PluginActionLinksTest.php (2)

25-30: LGTM! Well-structured test setup.

The setUp method properly initializes the test fixture and delegates mock setup to a dedicated method, following good testing practices.


180-185: LGTM! Proper test cleanup.

The tearDown method correctly removes filters to prevent test pollution, which is essential for test isolation.

Comment thread tests/phpunit/Admin/PluginActionLinksTest.php
Comment thread tests/phpunit/Admin/PluginActionLinksTest.php

@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

♻️ Duplicate comments (1)
tests/phpunit/Admin/PluginActionLinksTest.php (1)

37-43: Potential test isolation issues with constant definitions.

Defining constants conditionally can cause test isolation issues if tests run in different orders. This approach was previously flagged and the issue persists.

🧹 Nitpick comments (2)
tests/phpunit/Admin/PluginActionLinksTest.php (2)

56-56: Remove unused parameter from mock function.

The $unused parameter in the mock function is not used and was flagged by static analysis.

-			function edac_link_wrapper( $url, $source, $campaign, $unused ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
+			function edac_link_wrapper( $url, $source, $campaign ) {

187-210: Proper handling of architectural limitations.

The approach of marking this test as incomplete with clear documentation is appropriate given PHP's constant redefinition limitations. The detailed comments provide excellent guidance for future refactoring.

Consider implementing dependency injection in the Plugin_Action_Links class to make constants testable:

public function __construct( $key_valid = null ) {
    $this->key_valid = $key_valid ?? ( defined( 'EDAC_KEY_VALID' ) ? EDAC_KEY_VALID : false );
}

This would enable proper testing of both scenarios without constant redefinition issues.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 55b5ab7 and 26165ae.

📒 Files selected for processing (1)
  • tests/phpunit/Admin/PluginActionLinksTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
tests/phpunit/Admin/PluginActionLinksTest.php (1)
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.
🪛 PHPMD (2.15.0)
tests/phpunit/Admin/PluginActionLinksTest.php

56-56: Avoid unused parameters such as '$unused'. (Unused Code Rules)

(UnusedFormalParameter)

🔇 Additional comments (2)
tests/phpunit/Admin/PluginActionLinksTest.php (2)

125-140: Good improvement in test logic for pro link conditions.

The test now properly checks the EDAC_KEY_VALID constant and asserts different outcomes based on its value. This addresses the previous feedback about test robustness.


174-182: Excellent accessibility testing approach.

The test properly verifies accessibility attributes for the pro link, which is especially important for an accessibility checker plugin. The conditional check ensures the test only runs when the pro link is present.

@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.

Tested this and the links look to go to the correct urls.

The Get Pro link wouldn't show for me though. I suggested a fix for that.

Comment thread admin/class-plugin-action-links.php Outdated
Co-authored-by: William Patton <will@pattonwebz.com>
@SteveJonesDev
SteveJonesDev merged commit 97b513c into develop Jul 8, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants