Files
Geoff TaylorandGitHub 9ef79563ac fix: Elementor breaks transfer-session endpoint (#1004)
* fix: Elementor breaks transfer-session endpoint with 500 error

Elementor's LandingPages module creates a WP_Query during `init` which
fires `pre_get_posts` before WooCommerce session is initialized. Our
resolve_request handler ran on this early query and called
WC()->session->get_customer_id() on null, causing a fatal error.

Fix: Guard resolve_request to only run on the main front-end query and
bail if WC session is not yet initialized. Also add Elementor to the
test environment and add functional tests that reproduce the issue.

Closes #945

* chore: Add @param docblock for resolve_request $query parameter

* devops: Remove unused resolvers and add session transaction manager tests

Remove Coupon_Connection_Resolver and Customer_Connection_Resolver
which had 0% coverage and were never instantiated.

Add SessionTransactionManagerTest covering did_transaction_expire
edge cases and next_transaction invalid/expired queue handling.
2026-03-30 22:58:32 -04:00

168 lines
4.9 KiB
Bash
Executable File

#!/bin/bash
if [ "$USING_XDEBUG" == "1" ]; then
echo "Enabling XDebug 3"
mv /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/
fi
# Run WordPress docker entrypoint.
# shellcheck disable=SC1091
. docker-entrypoint.sh 'apache2'
set +u
# Create a basic MySQL client config that forces no SSL
echo "[client]
ssl=false
[mysql]
ssl=false
[mysqldump]
ssl=false" > /tmp/.my.cnf
# Ensure mysql is loaded
wait-for-it -s -t 300 "${DB_HOST}:${DB_PORT}" -- echo "Application database is operationally..."
# Setup tester scripts.
if [ ! -f "$WP_ROOT_FOLDER/setup-database.sh" ]; then
ln -s "$PROJECT_DIR/bin/setup-database.sh" "$WP_ROOT_FOLDER/setup-database.sh"
chmod +x "$WP_ROOT_FOLDER/setup-database.sh"
fi
# Update our domain to just be the docker container's IP address
export WORDPRESS_DOMAIN=${WORDPRESS_DOMAIN-$( hostname -i )}
export WORDPRESS_URL="http://$WORDPRESS_DOMAIN"
# Config WordPress
if [ -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then
echo "Deleting old wp-config.php"
rm -f "${WP_ROOT_FOLDER}/wp-config.php"
fi
echo "Creating wp-config.php..."
wp config create \
--path="${WP_ROOT_FOLDER}" \
--dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \
--dbpass="${DB_PASSWORD}" \
--dbhost="${DB_HOST}:${DB_PORT}" \
--dbprefix="${WP_TABLE_PREFIX}" \
--skip-check \
--quiet \
--allow-root
# Install WP if not yet installed
if ! $( wp core is-installed --allow-root ); then
echo "Installing WordPress..."
wp core install \
--path="${WP_ROOT_FOLDER}" \
--url="${WORDPRESS_URL}" \
--title='Test' \
--admin_user="${ADMIN_USERNAME}" \
--admin_password="${ADMIN_PASSWORD}" \
--admin_email="${ADMIN_EMAIL}" \
--allow-root
fi
# Use alternative database export for WordPress 6.8+ to avoid MariaDB SSL issues
if [[ "${WP_VERSION}" == "6.8"* ]]; then
echo "Using alternative database export method for WordPress 6.8+"
# Create a basic MySQL client config that forces no SSL
echo "[client]
ssl=false
[mysql]
ssl=false
[mysqldump]
ssl=false" > /tmp/.my.cnf
# Export using mysqldump directly with SSL disabled
MYSQL_PWD=${WORDPRESS_DB_PASSWORD} mysqldump \
--defaults-extra-file=/tmp/.my.cnf \
--user=${WORDPRESS_DB_USER} \
--host=${WORDPRESS_DB_HOST} \
--port=3306 \
--single-transaction \
--routines \
--triggers \
${WORDPRESS_DB_NAME} > "${DATA_DUMP_DIR}/dump.sql" 2>/dev/null || \
echo "Database export failed, but continuing with tests..."
# Clean up config file
rm -f /tmp/.my.cnf
else
# Use wp-cli for older WordPress versions
wp db export "${DATA_DUMP_DIR}/dump.sql" --allow-root
fi
echo "Activating plugins..."
wp plugin activate \
woocommerce woocommerce-gateway-stripe \
wp-graphql wp-graphql-jwt-authentication \
wp-graphql-woocommerce \
--allow-root
wp theme activate twentytwentyone --allow-root
echo "Enabling WP_DEBUG logging..."
wp config set WP_DEBUG true --raw --allow-root
wp config set WP_DEBUG_LOG "${PROJECT_DIR}/tests/_output/debug.log" --allow-root
wp config set WP_DEBUG_DISPLAY true --raw --allow-root
if ! wp config has GRAPHQL_JWT_AUTH_SECRET_KEY --allow-root; then
echo "Adding WPGraphQL-JWT-Authentication salt..."
wp config set GRAPHQL_JWT_AUTH_SECRET_KEY 'testingtesting123testingtesting123' --allow-root
fi
if ! wp config has GRAPHQL_WOOCOMMERCE_SECRET_KEY --allow-root; then
echo "Adding WooGraphQL JWT Session Handler salt..."
wp config set GRAPHQL_WOOCOMMERCE_SECRET_KEY 'testestestestestestestestestest!!' --allow-root
fi
if [[ -n "$IMPORT_WC_PRODUCTS" ]]; then
echo "Installing & Activating WordPress Importer..."
wp plugin install wordpress-importer --activate --allow-root
echo "Importing store products..."
wp import \
"${PLUGINS_DIR}/woocommerce/sample-data/sample_products.xml" \
--authors=skip --allow-root
fi
echo "Setting pretty permalinks..."
wp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root
echo "Prepare for app database dump..."
if [ -f "${PROJECT_DIR}/tests/_data/app_db.sql" ]; then
rm -f "${PROJECT_DIR}/tests/_data/app_db.sql"
fi
echo "Dumping app database..."
wp db export "${PROJECT_DIR}/tests/_data/app_db.sql" \
--dbuser="root" \
--dbpass="${ROOT_PASSWORD}" \
--skip-plugins \
--skip-themes \
--allow-root
# Create the "uploads" directory and set public permissions.
if [ ! -d "wp-content/uploads" ]; then
mkdir wp-content/uploads
fi
chmod 777 -R wp-content/uploads
# Download c3 for testing.
if [ ! -f "$PROJECT_DIR/c3.php" ]; then
echo "Downloading Codeception's c3.php"
curl -L 'https://raw.github.com/Codeception/c3/2.0/c3.php' > "$PROJECT_DIR/c3.php"
fi
# Ensure test output directory is writable by Apache for c3.php coverage collection.
mkdir -p "$PROJECT_DIR/tests/_output"
chmod 777 -R "$PROJECT_DIR/tests/_output"
if [ -n "$RUNNING_TEST_STANDALONE" ]; then
service apache2 start
fi
echo "Running WordPress version: $(wp core version --allow-root) at $(wp option get home --allow-root)"
exec "$@"