Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions rtc-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,46 @@ setup_wpcli() {
printf ' cp "%s/rtc-test.php" "%s/"\n' "${SCRIPT_DIR}" "${mu_plugins_dir}"
fi

# Ensure pretty permalinks are enabled because these tests use /wp-json/ endpoints
# and therefore require /wp-json/ routing to be available.
local perm_struct site_url rest_url
perm_struct="$(wp "${WP_FLAGS[@]}" option get permalink_structure 2>/dev/null)" || perm_struct=""
if [ -z "${perm_struct}" ]; then
local site_url rest_probe_url rest_probe_code
printf 'Permalinks: default (query-string) -- setting to /%%postname%%/\n'
if wp "${WP_FLAGS[@]}" rewrite structure '/%postname%/' --hard >/dev/null 2>&1; then
:
else
printf 'Permalinks: hard rewrite failed; retrying without --hard\n'
wp "${WP_FLAGS[@]}" rewrite structure '/%postname%/' >/dev/null 2>&1 \
Comment on lines +827 to +833
|| die "Could not set permalink structure. Set it manually: Settings > Permalinks."
wp "${WP_FLAGS[@]}" rewrite flush >/dev/null 2>&1 \
|| die "Could not flush rewrite rules after setting permalink structure."
fi
Comment on lines +835 to +837
site_url="$(wp "${WP_FLAGS[@]}" option get siteurl 2>/dev/null)" || site_url=""
rest_url="${site_url%/}/wp-json/"
if [ -n "${site_url}" ] && curl -fsS -o /dev/null "${rest_url}" >/dev/null 2>&1; then
Comment on lines +838 to +840
printf 'Permalinks: set to /%%postname%%/\n'
# Re-check the REST API after changing permalinks. Updating the option
# alone is not enough if server rewrite rules are still misconfigured.
site_url="$(wp "${WP_FLAGS[@]}" option get siteurl 2>/dev/null)" || site_url=""
rest_probe_url="${site_url%/}/wp-json/"
rest_probe_code="$(curl -sS -L -o /dev/null -w '%{http_code}' "${rest_probe_url}" 2>/dev/null)" || rest_probe_code=""
Comment on lines +840 to +846
case "${rest_probe_code}" in
2*)
printf 'REST API: %s (OK after permalink update)\n' "${rest_probe_url}"
;;
*)
die "Permalinks were updated, but ${rest_probe_url} is still unreachable (HTTP ${rest_probe_code:-request failed}). Check web server rewrite rules and try again."
;;
esac
else
die "Could not make REST API reachable after setting permalink structure. Check permalinks/web server config and verify ${rest_url:-/wp-json/}."
fi
Comment on lines +840 to +857
else
printf 'Permalinks: %s\n' "${perm_struct}"
fi

# Always use the dedicated rtctest user so setup controls the password.
# We generate the password here and either create or reset the account.
local rtctest_wp_pass
Expand Down Expand Up @@ -880,7 +920,8 @@ setup_wpcli() {
fi

# Check if SAVEQUERIES is already defined and enabled in wp-config.php.
Comment thread
coleplx marked this conversation as resolved.
savequeries_value=$(wp "${WP_FLAGS[@]}" config get SAVEQUERIES 2>/dev/null)
local savequeries_value
savequeries_value=$(wp "${WP_FLAGS[@]}" config get SAVEQUERIES 2>/dev/null || true)
if [ "$savequeries_value" = "true" ] || [ "$savequeries_value" = "1" ]; then
printf 'SAVEQUERIES: already enabled in wp-config.php\n'
# Enable SAVEQUERIES so the plugin can record per-request DB time.
Expand Down Expand Up @@ -943,18 +984,20 @@ setup_manual() {
printf 'WP-CLI not available. Manual setup steps:\n\n'
printf '1. Copy rtc-test.php to the site'"'"'s mu-plugins directory:\n'
printf ' cp rtc-test.php /path/to/wp-content/mu-plugins/\n\n'
printf '2. Enable RTC: WP Admin > Settings > Writing > "Enable early access to\n'
printf '2. Enable pretty permalinks: WP Admin > Settings > Permalinks\n'
printf ' (any structure other than "Plain" works; e.g. Post name)\n\n'
printf '3. Enable RTC: WP Admin > Settings > Writing > "Enable early access to\n'
printf ' real-time collaboration"\n\n'
printf '3. Note a post ID for an existing editor-role user you want to test with.\n\n'
printf '4. Copy .env.example to .env and fill in the required values:\n\n'
printf '4. Note a post ID for an existing editor-role user you want to test with.\n\n'
printf '5. Copy .env.example to .env and fill in the required values:\n\n'
printf ' cp .env.example .env\n\n'
printf ' Required values:\n'
printf ' WP_URL="%s"\n' "${WP_URL}"
printf ' WP_USER="<login>"\n'
printf ' WP_PASS="<password>"\n'
printf ' WP_PATH="<absolute path to WordPress root>"\n'
printf ' POST_ID=<post_id>\n\n'
printf '5. Then run:\n'
printf '6. Then run:\n'
printf ' bash rtc-test.sh refresh-auth # logs in and writes cookie jar + nonce\n\n'
printf 'After that, all test commands are available.\n'
}
Expand Down