-
Notifications
You must be signed in to change notification settings - Fork 9
[DEVREL-29] allow pretty permalinks to be handled for rest endpoints by default #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
c088dd7
allow pretty permalinks to be handled for rest endpoints by default
jazzsequence 710b50c
DEVREL-29: handle pretty permalinks for rest endpoints by default (#182)
jazzsequence 05feec7
DEVREL-29: Update tests for handling plain permalinks (#182)
jazzsequence ef77ab2
remove todo
jazzsequence 40df9d1
remove commented-out code
jazzsequence 5c44fc5
Merge branch 'devrel-29-fix-subdir-wpms-url-issue-2' of github.com:pa…
jazzsequence 7c6f344
Merge branch 'default' into devrel-29-fix-subdir-wpms-url-issue-2
jazzsequence 38d26a5
fix bats test
jazzsequence 9f64264
return early
jazzsequence 5a9df6d
remove redundant else
jazzsequence 3dafef0
fix spacing
jazzsequence 25d993f
add helper functions
jazzsequence 7a0418e
add teardown
jazzsequence 1d159f2
use helper functions
jazzsequence 9667586
add a test that checks the json body of the api endpoint for hello-wo…
jazzsequence 34307e8
change delete site step to only run on success
jazzsequence 7f71978
remove the hard failure for mixed PRs
jazzsequence 6e6f5de
add a manual delete test sites workflow
jazzsequence b73befd
fix path to bats test
jazzsequence 0f1a143
we can't actually delete the subdomain test site
jazzsequence 8677a46
use bats-assert
jazzsequence d061302
log, but don't display errors
jazzsequence 1f08945
fix path to bats-assert
jazzsequence 2e8cb9d
load bats-support
jazzsequence 21c356e
bats-assert and bats-support should be installed by the action
jazzsequence 286ca44
use bats-action standard way of loading libraries
jazzsequence af5527c
remove export for BATS_LIB_PATH
jazzsequence 79cec77
don't use bats_load_library
jazzsequence 891ed5d
set the lib path in the action env
jazzsequence 36a8463
move the BATS_LIB_PATH into the run command
jazzsequence 593d190
try exporting locally again
jazzsequence bdfe05a
filter out terminus noise from wp commands
jazzsequence 58780a7
use partial assertion for home url path
jazzsequence b2cd0a3
setup permalinks always
jazzsequence 185dde3
run a full env:clear-cache and wait before moving on
jazzsequence 8bb2f21
ensure permalinks are pretty for playwright tests
jazzsequence f6c7fa4
fix terminus site name
jazzsequence 208d41c
fix workflow:wait
jazzsequence 8c17c92
need site env and move wait
jazzsequence 8f10153
fix tests
jazzsequence a3c7444
standardize vars
jazzsequence 66deb3b
don't require wp-cli commands for post id and url
jazzsequence 10f13ab
just remove clear-cache
jazzsequence f6925be
remove trap line to test
jazzsequence 42d41b3
change assert_match to assert_success
jazzsequence 0a3665e
click the continue button if the continue button exists
jazzsequence e78fe30
try a different means of clicking the button
jazzsequence f086bd2
adjust tests for more robust single/multisite handling
jazzsequence 53bfdb7
update service-level to plan
jazzsequence 0100597
set the plan to a real plan
jazzsequence 57acb56
set the plan to free before delete
jazzsequence 0b46728
update changelog
jazzsequence 844687e
dont run tests when delete test sites workflow is updated
jazzsequence bb98ef9
downgrade sites before delete
jazzsequence 5ee4a1c
bypass interstertial page via http headers
jazzsequence 8da04ff
add || true to plan:set command
jazzsequence 2904fc3
test php 8.4 too
jazzsequence d52081b
better handling of check commits step
jazzsequence e49c94c
style
jazzsequence 01be302
ensure the comment only appears once
jazzsequence a86c250
remove backticks
jazzsequence 4e672ee
but maybe it should be a blockquote
jazzsequence ae94198
combine multisite checks
jazzsequence File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| # wp wrapper function | ||
| _wp() { | ||
| terminus wp -- ${SITE_ID}.dev "$@" | ||
| } | ||
|
|
||
| # Helper function to get REST URL via WP-CLI | ||
| get_rest_url() { | ||
| _wp eval 'echo get_rest_url();' | ||
| } | ||
|
|
||
| # Helper function to get home_url path via WP-CLI | ||
| get_home_url_path() { | ||
| _wp eval 'echo rtrim(parse_url(home_url(), PHP_URL_PATH) ?: "", "/");' | ||
| } | ||
|
|
||
| setup_suite() { | ||
| # Ensure WP is installed and we are in the right directory | ||
| _wp core is-installed || (echo "WordPress not installed. Run setup script first." && exit 1) | ||
| } | ||
|
|
||
| @test "Check REST URL with default (pretty) permalinks (after setup script flush)" { | ||
| run get_rest_url | ||
| assert_success | ||
| # Default setup script sets /%postname%/ and flushes. | ||
| # Expecting /wp/wp-json/ because home_url path should be /wp | ||
| assert_output --partial "/wp/wp-json/" | ||
| } | ||
|
|
||
| @test "Check REST URL with plain permalinks" { | ||
| # Set plain permalinks and flush | ||
| _wp option update permalink_structure '' --quiet | ||
| _wp rewrite flush --hard --quiet | ||
| run get_rest_url | ||
| assert_success | ||
| # With plain permalinks, expect ?rest_route= based on home_url | ||
| # Check if it contains the problematic /wp-json/wp/ segment (it shouldn't) | ||
| refute_output --partial "/wp-json/wp/" | ||
| # Check if it contains the expected ?rest_route= | ||
| assert_output --partial "?rest_route=/" | ||
|
|
||
| # Restore pretty permalinks for subsequent tests | ||
| _wp option update permalink_structure '/%postname%/' --quiet | ||
| _wp rewrite flush --hard --quiet | ||
| } | ||
|
|
||
| @test "Check REST URL with pretty permalinks *before* flush (Simulates new site)" { | ||
| # Set pretty permalinks *without* flushing | ||
| _wp option update permalink_structure '/%postname%/' --quiet | ||
| # DO NOT FLUSH HERE | ||
|
|
||
| # Check home_url path to confirm /wp setup | ||
| run get_home_url_path | ||
| assert_success | ||
| assert_output "/wp" | ||
|
|
||
| # Now check get_rest_url() - this is where the original issue might occur | ||
| run get_rest_url | ||
| assert_success | ||
| # Assert that the output *should* be the correct /wp/wp-json/ even before flush, | ||
| # assuming the fix (either integrated or separate filter) is in place. | ||
| # If the fix is NOT in place, this might output /wp-json/ and fail. | ||
| # If the plain permalink fix was active, it might output /wp/wp-json/wp/ and fail. | ||
| assert_output --partial "/wp/wp-json/" | ||
| refute_output --partial "/wp-json/wp/" # Ensure the bad structure isn't present | ||
|
|
||
| # Clean up: Flush permalinks | ||
| _wp rewrite flush --hard --quiet | ||
| } | ||
|
|
||
| @test "Access pretty REST API path directly with plain permalinks active" { | ||
| # Set plain permalinks and flush | ||
| _wp option update permalink_structure '' --quiet | ||
| _wp rewrite flush --hard --quiet | ||
|
|
||
| # Get the full home URL to construct the test URL | ||
| SITE_URL=$( _wp option get home ) | ||
| # Construct the pretty-style REST API URL | ||
| # Note: home_url() includes /wp, so we append /wp-json/... directly | ||
| TEST_URL="${SITE_URL}/wp-json/wp/v2/posts" | ||
|
|
||
| # Make a curl request to the pretty URL | ||
| # -s: silent, -o /dev/null: discard body, -w '%{http_code}': output only HTTP code | ||
| # -L: follow redirects (we expect NO redirect, so this helps verify) | ||
| # We expect a 200 OK if the internal handling works, or maybe 404 if not found, | ||
| # but crucially NOT a 301/302 redirect. | ||
| run curl -s -o /dev/null -w '%{http_code}' -L "${TEST_URL}" | ||
jazzsequence marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert_success | ||
| # Assert that the final HTTP status code is 200 (OK) | ||
| # If it were redirecting, -L would follow, but the *initial* code wouldn't be 200. | ||
| # If the internal handling fails, it might be 404 or other error. | ||
| assert_output "200" | ||
|
|
||
| # Restore pretty permalinks for subsequent tests | ||
| _wp option update permalink_structure '/%postname%/' --quiet | ||
| _wp rewrite flush --hard --quiet | ||
jazzsequence marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.