Skip to content

Conversation

@pattonwebz
Copy link
Member

@pattonwebz pattonwebz commented Dec 2, 2025

Specifically the addition of JSON_UNESCAPED_SLASHES as a flag.

See: WordPress/wordpress-develop#9557

Checklist

  • PR is linked to the main issue in the repo
  • Tests are added that cover changes

Summary by CodeRabbit

  • Tests
    • Updated tests to handle WordPress 6.9+ behavior with version-aware assertions ensuring correct checks across WP versions.
    • Added explanatory comments to clarify intent and a minor formatting tweak for readability.

✏️ Tip: You can customize this high-level summary in your review settings.

Specifically the addition of JSON_UNESCAPED_SLASHES as a flag.

See: WordPress/wordpress-develop#9557
Copilot AI review requested due to automatic review settings December 2, 2025 23:52
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

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

Updates two unit tests in EnqueueAdminTest.php to use a WordPress-version-aware assertion for localized permalink JSON data, checking either escaped or unescaped slash forms depending on WP >= 6.9.

Changes

Cohort / File(s) Summary
Version-aware test assertions
tests/phpunit/Admin/EnqueueAdminTest.php
Rewrote testScanUrlUsesPermalinkForFrontpage and testScanUrlUsesPermalinkForPostsPage to perform conditional assertions based on WP version (6.9+ vs older). Added comments and a small formatting tweak (blank line before globals).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Areas to check:
    • Correctness of the WordPress version comparison logic.
    • Consistency between the two updated test methods.
    • Accuracy of the expected escaped vs. unescaped string literals.

Possibly related PRs

Poem

🐰 I hopped through tests with nimble care,
Checking slashes found here and there,
When six-point-nine arrives I cheer,
Unescaped paths now draw near,
Tests adjusted — hoppity, clear! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: updating tests to handle WordPress 6.9's changes to wp_json_encode flags, which aligns with the PR's core objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch william/pro-458-update-unit-tests-to-account-for-wp-69-wp_json_encode-flag

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c48ed70 and db28a49.

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

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.php: Follow WordPress Coding Standards (WPCS) in all PHP files
Class names use CamelCase (ClassNameConvention) for new classes
Use edac_ prefix for all custom action/filter hook names
Ensure PHP 7.4+ compatibility
Use type hints where appropriate (parameters, return types, properties)
Sanitize inputs, validate data, and escape outputs following WordPress security best practices; use nonces for forms/AJAX
Use the WordPress database API ($wpdb) for all database operations
Prefix functions and classes in the global namespace with edac_
Use WordPress transients for caching temporary data where appropriate
All user-facing text in PHP must be translatable using the accessibility-checker text domain
Use PHPDoc for all public classes, methods, and properties
Document all custom hooks (actions/filters) with docblocks including parameters and types

Files:

  • tests/phpunit/Admin/EnqueueAdminTest.php
tests/phpunit/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Place and write PHPUnit tests under /tests/phpunit

Files:

  • tests/phpunit/Admin/EnqueueAdminTest.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). (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 latest (+ ms)
  • GitHub Check: Integration Test: PHP 8.2 | WP latest (+ ms)

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @pattonwebz, 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 updates existing PHPUnit tests to maintain their validity and functionality across different WordPress versions, particularly in light of changes introduced in WordPress 6.9. The primary goal is to prevent test failures that would arise from a modification in how wp_json_encode handles URL escaping, ensuring the test suite remains robust and compatible with future WordPress core updates.

Highlights

  • WordPress 6.9 Compatibility: Updates tests to ensure compatibility with changes introduced in WordPress 6.9, specifically regarding the behavior of wp_json_encode.
  • JSON_UNESCAPED_SLASHES Flag: Addresses the impact of the JSON_UNESCAPED_SLASHES flag being added to wp_json_encode in WP 6.9, which alters how slashes are escaped in JSON output.
  • Conditional Test Assertions: Introduces version-specific checks within tests to accommodate the differing wp_json_encode behavior, ensuring tests pass on both WordPress 6.9+ and older versions.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

Copy link
Contributor

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

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 correctly updates the tests to handle changes in wp_json_encode flags in WordPress 6.9. The approach is sound. I've provided a couple of suggestions to refactor the duplicated logic in the tests, which will improve code readability and maintainability by reducing repetition.

Comment on lines +122 to +126
if ( version_compare( get_bloginfo( 'version' ), '6.9', '>=' ) ) {
$this->assertStringContainsString( esc_url_raw( get_permalink( $post->ID ) ), $localized_data );
} else {
$this->assertStringContainsString( str_replace( '/', '\\/', esc_url_raw( get_permalink( $post->ID ) ) ), $localized_data );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve readability and reduce code repetition, you can determine the expected URL format first and then perform the assertion once. This avoids repeating the assertStringContainsString call and makes the test's intent clearer.

		$expected_url = esc_url_raw( get_permalink( $post->ID ) );
		if ( version_compare( get_bloginfo( 'version' ), '6.9', '<' ) ) {
			$expected_url = str_replace( '/', '\\/', $expected_url );
		}
		$this->assertStringContainsString( $expected_url, $localized_data );

Comment on lines +154 to +158
if ( version_compare( get_bloginfo( 'version' ), '6.9', '>=' ) ) {
$this->assertStringContainsString( esc_url_raw( get_permalink( $post->ID ) ), $localized_data );
} else {
$this->assertStringContainsString( str_replace( '/', '\\/', esc_url_raw( get_permalink( $post->ID ) ) ), $localized_data );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the previous test, this logic can be simplified to avoid code repetition and improve readability. By preparing the expected URL string before the assertion, you only need to call assertStringContainsString once.

		$expected_url = esc_url_raw( get_permalink( $post->ID ) );
		if ( version_compare( get_bloginfo( 'version' ), '6.9', '<' ) ) {
			$expected_url = str_replace( '/', '\\/', $expected_url );
		}
		$this->assertStringContainsString( $expected_url, $localized_data );

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (2)
tests/phpunit/Admin/EnqueueAdminTest.php (2)

119-126: Version-aware assertion looks correct; consider minor DRY + WPCS cleanups

The conditional assertion correctly handles both escaped and unescaped slash behavior across WP versions, so the test logic itself looks good.

Optionally, you could:

  • Store the permalink in a local variable to avoid recomputing it twice.
  • Tweak inline comments to follow WPCS style (capitalize “WordPress”/“WP”, start sentences with a capital letter).

For example:

-		// In wp 6.9 there were changes to the flags passed to wp_json_encode() that made slashes no longer get escaped by default.
-		// we should check for both possibilities here to ensure compatibility across versions.
-		// see: https://github.com/WordPress/wordpress-develop/pull/9557 for more details.
-		if ( version_compare( get_bloginfo( 'version' ), '6.9', '>=' ) ) {
-			$this->assertStringContainsString( esc_url_raw( get_permalink( $post->ID ) ), $localized_data );
-		} else {
-			$this->assertStringContainsString( str_replace( '/', '\\/', esc_url_raw( get_permalink( $post->ID ) ) ), $localized_data );
-		}
+		// In WordPress 6.9, the flags passed to wp_json_encode() changed so slashes are no longer escaped by default.
+		// We should check for both possibilities here to ensure compatibility across versions.
+		// See: https://github.com/WordPress/wordpress-develop/pull/9557 for more details.
+		$permalink = esc_url_raw( get_permalink( $post->ID ) );
+		if ( version_compare( get_bloginfo( 'version' ), '6.9', '>=' ) ) {
+			$this->assertStringContainsString( $permalink, $localized_data );
+		} else {
+			$this->assertStringContainsString( str_replace( '/', '\\/', $permalink ), $localized_data );
+		}

As per coding guidelines, this keeps comments WPCS-compliant and the test body a bit cleaner.


138-158: Duplicate version-gated assertion block; consider extracting a small helper

This block mirrors the front page test logic and is also functionally correct for handling the wp_json_encode behavior change.

To reduce duplication and make future adjustments safer, you might extract the shared assertion into a private helper on the test class, e.g.:

private function assertPermalinkInLocalizedDataForCurrentWpVersion( int $post_id, string $localized_data ): void {
	$permalink = esc_url_raw( get_permalink( $post_id ) );

	if ( version_compare( get_bloginfo( 'version' ), '6.9', '>=' ) ) {
		$this->assertStringContainsString( $permalink, $localized_data );
	} else {
		$this->assertStringContainsString( str_replace( '/', '\\/', $permalink ), $localized_data );
	}
}

Then both tests can just call that helper. While not required for correctness, it keeps the tests more maintainable and avoids two places to touch if WP behavior shifts again. As per coding guidelines, this also helps keep test code simple and consistent.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 33e3c13 and c48ed70.

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

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.php: Follow WordPress Coding Standards (WPCS) in all PHP files
Class names use CamelCase (ClassNameConvention) for new classes
Use edac_ prefix for all custom action/filter hook names
Ensure PHP 7.4+ compatibility
Use type hints where appropriate (parameters, return types, properties)
Sanitize inputs, validate data, and escape outputs following WordPress security best practices; use nonces for forms/AJAX
Use the WordPress database API ($wpdb) for all database operations
Prefix functions and classes in the global namespace with edac_
Use WordPress transients for caching temporary data where appropriate
All user-facing text in PHP must be translatable using the accessibility-checker text domain
Use PHPDoc for all public classes, methods, and properties
Document all custom hooks (actions/filters) with docblocks including parameters and types

Files:

  • tests/phpunit/Admin/EnqueueAdminTest.php
tests/phpunit/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Place and write PHPUnit tests under /tests/phpunit

Files:

  • tests/phpunit/Admin/EnqueueAdminTest.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: Agent
  • GitHub Check: Integration Test: PHP 8.2 | WP latest (+ ms)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates unit tests to handle WordPress 6.9's changes to wp_json_encode() flags, specifically the addition of JSON_UNESCAPED_SLASHES which prevents forward slashes from being escaped by default.

  • Adds version-specific assertions to accommodate both WP 6.9+ (unescaped slashes) and earlier versions (escaped slashes)
  • Updates two test methods that verify localized script data containing URLs

$this->assertStringContainsString( 'edac_pageScanner', $localized_data );
$this->assertStringContainsString( str_replace( '/', '\\/', esc_url_raw( get_permalink( $post->ID ) ) ), $localized_data );
// In wp 6.9 there were changes to the flags passed to wp_json_encode() that made slashes no longer get escaped by default.
// we should check for both possibilities here to ensure compatibility across versions.
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

Comment capitalization should be consistent with WordPress coding standards. The first word after the comment marker should be capitalized: "we" should be "We" at the start of the sentence.

Suggested change
// we should check for both possibilities here to ensure compatibility across versions.
// We should check for both possibilities here to ensure compatibility across versions.

Copilot uses AI. Check for mistakes.
$this->assertStringContainsString( str_replace( '/', '\\/', esc_url_raw( get_permalink( $post->ID ) ) ), $localized_data );
// In wp 6.9 there were changes to the flags passed to wp_json_encode() that made slashes no longer get escaped by default.
// we should check for both possibilities here to ensure compatibility across versions.
// see: https://github.com/WordPress/wordpress-develop/pull/9557 for more details.
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

Comment capitalization should be consistent with WordPress coding standards. The first word after the comment marker should be capitalized: "see" should be "See" at the start of the sentence.

Suggested change
// see: https://github.com/WordPress/wordpress-develop/pull/9557 for more details.
// See: https://github.com/WordPress/wordpress-develop/pull/9557 for more details.

Copilot uses AI. Check for mistakes.
@pattonwebz
Copy link
Member Author

@copilot you have a lot of things to say about what I put in my comment. Fix it for me in a new PR.

Copy link
Contributor

Copilot AI commented Dec 2, 2025

@pattonwebz I've opened a new pull request, #1294, to work on those changes. Once the pull request is ready, I'll request review from you.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pattonwebz pattonwebz merged commit 4a59a02 into develop Dec 3, 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