Skip to content

test: add wu_create_site integration tests for subdomain slug sanitization#828

Merged
superdav42 merged 1 commit intomainfrom
feature/t826-wu-create-site-integration-tests
Apr 13, 2026
Merged

test: add wu_create_site integration tests for subdomain slug sanitization#828
superdav42 merged 1 commit intomainfrom
feature/t826-wu-create-site-integration-tests

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Adds two integration tests that verify the subdomain slug sanitization introduced in GH#812 (PR #822) works end-to-end at the wu_create_site() API level — the layer tested here is distinct from the unit tests in PR #822 which tested the sanitization helper directly.

Changes

EDIT: tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php — appended two new methods to the test class:

  • test_create_site_sanitizes_subdomain_slug — confirms a path like /My Cool Site!/ produces a sanitized subdomain hostname containing my-cool-site and does NOT fail with invalid_site_path.
  • test_create_site_returns_error_for_empty_subdomain_slug — confirms a path of only invalid characters like /!!!/ returns WP_Error('invalid_site_path'), preventing malformed hostnames.

EDIT: inc/functions/site.php — wrapped the is_subdomain_install() call in wu_create_site() with apply_filters('wu_is_subdomain_install', is_subdomain_install()). This allows tests to force the subdomain code path without redefining the SUBDOMAIN_INSTALL constant (which cannot be changed after definition in a running PHP process). The filter name is unique (wu_is_subdomain_install) to avoid conflicting with any WordPress core filter.

Runtime Testing

Risk: Low — test-only files plus a minimal filterable wrapper in production code.

  • vendor/bin/phpunit tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php --no-coverageOK (23 tests, 39 assertions)
  • Targeted filter: vendor/bin/phpunit tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php --filter "test_create_site_sanitizes_subdomain_slug|test_create_site_returns_error_for_empty_subdomain_slug" --no-coverageOK (2 tests, 3 assertions)

Implementation Notes

The original stash content used add_filter('subdomain_install', '__return_true') but is_subdomain_install() in WordPress core reads the SUBDOMAIN_INSTALL constant directly (not via apply_filters), so the filter had no effect. The fix introduces wu_is_subdomain_install as a dedicated testability hook on the wu_create_site code path only.

Resolves #826

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 25 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 8 minutes and 25 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6cf6cf09-30c8-485c-aa4d-761bc1f0557b

📥 Commits

Reviewing files that changed from the base of the PR and between e6629f5 and fe29677.

📒 Files selected for processing (2)
  • inc/functions/site.php
  • tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/t826-wu-create-site-integration-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 13, 2026

Performance Test Results

Performance test results for e4e437d are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 (+1 / +2% ) 37.79 MB 818.50 ms (-29.00 ms / -4% ) 155.50 ms (-15.50 ms / -10% ) 1004.50 ms (-82.50 ms / -8% ) 1942.00 ms (-94.00 ms / -5% ) 1835.85 ms (-97.15 ms / -5% ) 93.90 ms (+3.85 ms / +4% )
1 56 49.02 MB 865.50 ms (-84.50 ms / -10% ) 141.50 ms (-4.50 ms / -3% ) 1008.50 ms (-87.50 ms / -9% ) 1952.00 ms (-130.00 ms / -7% ) 1870.15 ms (-133.70 ms / -7% ) 81.10 ms

…ation

Adds two integration tests to Site_Functions_Extended_Test that verify
the subdomain slug sanitization introduced in GH#812 (PR #822) works
end-to-end at the wu_create_site() API level:

- test_create_site_sanitizes_subdomain_slug: verifies that a path with
  special characters (e.g. '/My Cool Site!/') produces a sanitized
  subdomain hostname containing 'my-cool-site' and does NOT fail with
  'invalid_site_path'.

- test_create_site_returns_error_for_empty_subdomain_slug: verifies that
  a path of only invalid characters (e.g. '/!!!/') returns WP_Error with
  'invalid_site_path', preventing malformed hostnames.

To make these tests runnable in the subdirectory test environment (where
is_subdomain_install() checks the SUBDOMAIN_INSTALL constant), a new
filter 'wu_is_subdomain_install' wraps the is_subdomain_install() call
in wu_create_site(). Tests override via add_filter('wu_is_subdomain_install',
'__return_true') to force the subdomain code path without redefining constants.

Resolves #826
@superdav42 superdav42 force-pushed the feature/t826-wu-create-site-integration-tests branch from a6688bc to fe29677 Compare April 13, 2026 22:40
@superdav42 superdav42 merged commit dfde78d into main Apr 13, 2026
7 checks passed
@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42
Copy link
Copy Markdown
Collaborator Author

Merge Summary

PR #828 merged to main. All CI checks passed.

Changes delivered:

  • — Added two integration tests at the wu_create_site() API level for subdomain slug sanitization (GH#812 / PR GH#812: fix: sanitize subdomain slug in wu_create_site #822)
  • — Added wu_is_subdomain_install filter wrapping is_subdomain_install() in wu_create_site() to allow test-environment override (required because the PHP constant cannot be redefined at runtime)

Test results (local): OK (23 tests, 39 assertions)
CI results: All 10 checks passed (PHP 8.2–8.5, Cypress 8.1+8.2, Code Quality, PHP Lint, Build, WP Performance Metrics)


aidevops.sh v3.8.11 plugin for OpenCode v1.4.3 with claude-sonnet-4-6 spent 18m and 2,024 tokens on this as a headless worker. Overall, 14m since this issue was created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add wu_create_site integration tests for subdomain slug sanitization

1 participant