test: add wu_create_site integration tests for subdomain slug sanitization#828
Conversation
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🔨 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! Login credentials: |
|
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:
|
…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
a6688bc to
fe29677
Compare
🔨 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! Login credentials: |
Merge SummaryPR #828 merged to main. All CI checks passed. Changes delivered:
Test results (local): OK (23 tests, 39 assertions) 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. |
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 containingmy-cool-siteand does NOT fail withinvalid_site_path.test_create_site_returns_error_for_empty_subdomain_slug— confirms a path of only invalid characters like/!!!/returnsWP_Error('invalid_site_path'), preventing malformed hostnames.EDIT:
inc/functions/site.php— wrapped theis_subdomain_install()call inwu_create_site()withapply_filters('wu_is_subdomain_install', is_subdomain_install()). This allows tests to force the subdomain code path without redefining theSUBDOMAIN_INSTALLconstant (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-coverage→ OK (23 tests, 39 assertions)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-coverage→ OK (2 tests, 3 assertions)Implementation Notes
The original stash content used
add_filter('subdomain_install', '__return_true')butis_subdomain_install()in WordPress core reads theSUBDOMAIN_INSTALLconstant directly (not viaapply_filters), so the filter had no effect. The fix introduceswu_is_subdomain_installas a dedicated testability hook on thewu_create_sitecode path only.Resolves #826