From 3abb030c542c67c973dc846b4cf9188eadf79e0f Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 18 Feb 2026 11:22:57 -0700 Subject: [PATCH 1/8] Update our PHPUnit workflow to run tests in wp-env --- .github/workflows/phpunit.yml | 108 ++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 51 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index bfb0a850..a8171196 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -1,6 +1,4 @@ name: PHPUnit -permissions: - contents: read on: push: @@ -11,65 +9,73 @@ on: branches: - develop +permissions: + contents: read + jobs: - check-diffs: + phpunit: + name: Test PHP ${{ matrix.php }} WP ${{ matrix.wp }} runs-on: ubuntu-latest - outputs: - has_changed: ${{ steps.files-changed.outputs.RSA_PHP_FILES_CHANGED }} + strategy: + fail-fast: false + matrix: + php: [ '8.4', '8.3', '8.2', '8.1', '8.0', '7.4' ] + wp: [ latest, trunk ] + env: + WP_ENV_PHP_VERSION: ${{ matrix.php }} + WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }} steps: - - name: Checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - fetch-depth: 0 - - - name: Get updated PHP files - id: changed-files - uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1 - with: - files: | - **/*.php - composer.json - composer.lock - phpunit.xml - - - id: files-changed + - name: Configure environment variables run: | - if [[ ( "${{ steps.changed-files.outputs.any_changed }}" == 'true' && "${{ github.event_name }}" == "pull_request" ) || "${{ github.event_name }}" == "push" ]]; then - echo "RSA_PHP_FILES_CHANGED=yes" >> $GITHUB_OUTPUT - fi + echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV" + echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV" - phpunit: - runs-on: ubuntu-latest - needs: check-diffs - if: needs.check-diffs.outputs.has_changed == 'yes' - - steps: - - name: Checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + persist-credentials: false - - uses: getong/mariadb-action@d6d2ec41fd5588f369be4c9398ce77ee725ca9ea # v1.11 + ## + # This allows Composer dependencies to be installed using a single step. + # + # Since the tests are currently run within the Docker containers where the PHP version varies, + # the same PHP version needs to be configured for the action runner machine so that the correct + # dependency versions are installed and cached. + ## + - name: Set up PHP + uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4 + with: + php-version: '${{ matrix.php }}' + coverage: none - - name: Set PHP version - uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 - with: - php-version: '7.4' - coverage: none - tools: composer:v2 + - name: Install Composer dependencies + uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1 - - name: Install dependencies - run: composer install + - name: Setup Node + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 + with: + cache: 'npm' + node-version-file: '.nvmrc' - - name: install node v16 - uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 - with: - node-version-file: '.nvmrc' + - name: Install NPM dependencies + run: npm ci && npm run build - - name: Install dependencies - run: npm i && npm run build + - name: Start the Docker testing environment + uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2 + with: + timeout_minutes: 10 + max_attempts: 3 + command: | + npm run env:start - - name: Setup WP Tests - run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 + - name: Log versions + run: | + npm run env -- run cli php -- -v + npm run env -- run cli wp core version - - name: PHPUnit - run: './vendor/bin/phpunit' + - name: Run PHPUnit tests + id: phpunit + run: | + npm run test:php From 2d4b4beffa631c9523062f558fbe6cfd9d3fd14a Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 18 Feb 2026 11:23:04 -0700 Subject: [PATCH 2/8] Remove the install script and bin directory that isn't needed anymore --- bin/install-wp-tests.sh | 171 ---------------------------------------- 1 file changed, 171 deletions(-) delete mode 100755 bin/install-wp-tests.sh diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh deleted file mode 100755 index d1172496..00000000 --- a/bin/install-wp-tests.sh +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/env bash - -if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" - exit 1 -fi - -DB_NAME=$1 -DB_USER=$2 -DB_PASS=$3 -DB_HOST=${4-localhost} -WP_VERSION=${5-latest} -SKIP_DB_CREATE=${6-false} - -TMPDIR=${TMPDIR-/tmp} -TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") -WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} -WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} - -download() { - if [ `which curl` ]; then - curl -s "$1" > "$2"; - elif [ `which wget` ]; then - wget -nv -O "$2" "$1" - fi -} - -# Check if git is installed -check_git_installed() { - if ! command -v git > /dev/null; then - echo "Error: git is not installed. Please install git and try again." - exit 1 - fi -} - -if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then - WP_TESTS_TAG="branches/$WP_VERSION" -elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then - if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then - # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x - WP_TESTS_TAG="tags/${WP_VERSION%??}" - else - WP_TESTS_TAG="tags/$WP_VERSION" - fi -elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - WP_BRANCH="trunk" - WP_TESTS_TAG="trunk" -else - # http serves a single offer, whereas https serves multiple. we only want one - download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json - grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json - LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') - if [[ -z "$LATEST_VERSION" ]]; then - echo "Latest WordPress version could not be found" - exit 1 - fi - WP_BRANCH=$LATEST_VERSION - WP_TESTS_TAG="tags/$LATEST_VERSION" -fi - -set -ex - -install_wp() { - - if [ -d $WP_CORE_DIR ]; then - return; - fi - - mkdir -p $WP_CORE_DIR - - if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - mkdir -p $TMPDIR/wordpress-nightly - download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip - unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/ - mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR - else - if [ $WP_VERSION == 'latest' ]; then - local ARCHIVE_NAME='latest' - elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then - # https serves multiple offers, whereas http serves single. - download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json - if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then - # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x - LATEST_VERSION=${WP_VERSION%??} - else - # otherwise, scan the releases and get the most up to date minor version of the major release - local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'` - LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1) - fi - if [[ -z "$LATEST_VERSION" ]]; then - local ARCHIVE_NAME="wordpress-$WP_VERSION" - else - local ARCHIVE_NAME="wordpress-$LATEST_VERSION" - fi - else - local ARCHIVE_NAME="wordpress-$WP_VERSION" - fi - download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz - tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR - fi - - download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php -} - -install_test_suite() { - # portable in-place argument for both GNU sed and Mac OSX sed - if [[ $(uname -s) == 'Darwin' ]]; then - local ioption='-i .bak' - else - local ioption='-i' - fi - - # set up testing suite if it doesn't yet exist - if [ ! -d $WP_TESTS_DIR ]; then - # set up testing suite - mkdir -p $WP_TESTS_DIR - check_git_installed - git clone --depth 1 --branch $WP_BRANCH https://github.com/wordpress/wordpress-develop $TMPDIR/wordpress-develop - rm -r $TMPDIR/wordpress-develop/.git - mv $TMPDIR/wordpress-develop/tests/phpunit/includes/ $WP_TESTS_DIR/includes - mv $TMPDIR/wordpress-develop/tests/phpunit/data/ $WP_TESTS_DIR/data - rm -r $TMPDIR/wordpress-develop - fi - - if [ ! -f wp-tests-config.php ]; then - download https://raw.githubusercontent.com/wordpress/wordpress-develop/${WP_BRANCH}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php - # remove all forward slashes in the end - WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") - sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php - fi - -} - -install_db() { - - if [ ${SKIP_DB_CREATE} = "true" ]; then - return 0 - fi - - # parse DB_HOST for port or socket references - local PARTS=(${DB_HOST//\:/ }) - local DB_HOSTNAME=${PARTS[0]}; - local DB_SOCK_OR_PORT=${PARTS[1]}; - local EXTRA="" - - if ! [ -z $DB_HOSTNAME ] ; then - if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then - EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" - elif ! [ -z $DB_SOCK_OR_PORT ] ; then - EXTRA=" --socket=$DB_SOCK_OR_PORT" - elif ! [ -z $DB_HOSTNAME ] ; then - EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" - fi - fi - - # create database - if [ -z $DB_PASS ] ; then - echo 'No DB password' - mysqladmin create $DB_NAME --user="$DB_USER" $EXTRA - else - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA - fi -} - -install_wp -install_test_suite -install_db From 4b79a0e89a43242a728c63ceddce72015934f23c Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 18 Feb 2026 11:26:48 -0700 Subject: [PATCH 3/8] Update our PHPUnit config --- phpunit.xml | 32 -------------------------------- phpunit.xml.dist | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 phpunit.xml create mode 100644 phpunit.xml.dist diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 145e5507..00000000 --- a/phpunit.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - tests/php - tests/php/code-coverage.php - tests/php/multisite - tests/php/whitelist - - - - - restricted_site_access.php - - - - - - - - - - - - - - - diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000..5c1e29c5 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,33 @@ + + + + + ./tests/php + ./tests/php/code-coverage.php + ./tests/php/multisite + ./tests/php/whitelist + + + + + restricted_site_access.php + + + + + + + From 75204207b24e144848ec48f67e949c1e0120ad15 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 18 Feb 2026 11:27:03 -0700 Subject: [PATCH 4/8] Update dependencies. Add test script --- composer.json | 2 +- composer.lock | 28 +++++++++++++++------------- package.json | 1 + 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index d3e757eb..fc358467 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require-dev": { "10up/phpcs-composer": "dev-master", "phpunit/phpunit": "9.6.33", - "yoast/phpunit-polyfills": "1.x-dev" + "yoast/phpunit-polyfills": "^4.0" }, "scripts": { "test": "phpunit", diff --git a/composer.lock b/composer.lock index 1dc52415..dd85ab1c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "25745e064f54b27840e96eb7f8c41fda", + "content-hash": "6fd370623dfabe05dfe3cc2d1cafc786", "packages": [ { "name": "10up/wp-compat-validation-tool", @@ -2587,29 +2587,31 @@ }, { "name": "yoast/phpunit-polyfills", - "version": "1.x-dev", + "version": "dev-main", "source": { "type": "git", "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", - "reference": "f1f7e15daf4f0e7225757ff902322df6d47c1385" + "reference": "134921bfca9b02d8f374c48381451da1d98402f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/f1f7e15daf4f0e7225757ff902322df6d47c1385", - "reference": "f1f7e15daf4f0e7225757ff902322df6d47c1385", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/134921bfca9b02d8f374c48381451da1d98402f9", + "reference": "134921bfca9b02d8f374c48381451da1d98402f9", "shasum": "" }, "require": { - "php": ">=5.4", - "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "php": ">=7.1", + "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0 || ^11.0 || ^12.0" }, "require-dev": { - "yoast/yoastcs": "^2.3.0" + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "yoast/yoastcs": "^3.1.0" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "2.x-dev" + "dev-main": "4.x-dev" } }, "autoload": { @@ -2641,9 +2643,10 @@ ], "support": { "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", + "security": "https://github.com/Yoast/PHPUnit-Polyfills/security/policy", "source": "https://github.com/Yoast/PHPUnit-Polyfills" }, - "time": "2023-09-27T10:45:26+00:00" + "time": "2025-02-09T18:58:54+00:00" } ], "aliases": [], @@ -2651,8 +2654,7 @@ "stability-flags": { "10up/phpcs-composer": 20, "10up/wp-compat-validation-tool": 20, - "mlocati/ip-lib": 20, - "yoast/phpunit-polyfills": 20 + "mlocati/ip-lib": 20 }, "prefer-stable": false, "prefer-lowest": false, @@ -2660,5 +2662,5 @@ "php": ">=7.4" }, "platform-dev": {}, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/package.json b/package.json index ef30147a..f0dc96d7 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "lint:js": "wp-scripts lint-js assets/js/src", "cypress:open": "cypress open --config-file tests/cypress/config.js --e2e --browser chrome", "cypress:run": "cypress run --config-file tests/cypress/config.js", + "test:php": "wp-env run tests-cli --env-cwd=wp-content/plugins/restricted-site-access vendor/bin/phpunit -c phpunit.xml", "env": "wp-env", "env:start": "wp-env start", "env:stop": "wp-env stop", From c479bb5027d856cd98c2216f841c1bbd3a41c93b Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 18 Feb 2026 11:52:51 -0700 Subject: [PATCH 5/8] Clean up bootstrap file --- tests/php/bootstrap.php | 59 ++++++++++------------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php index 26b50c06..f17387f8 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -1,62 +1,31 @@ bootstrap(); +// Start up the WP testing environment. +require $_tests_dir . '/includes/bootstrap.php'; From 95d580dd07c474cd4ff05dfca46a5508c7bed48f Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 18 Feb 2026 11:53:18 -0700 Subject: [PATCH 6/8] Modify wp-env config. Remove unneeded init step. Fix test command --- .gitignore | 4 +++- .wp-env.json | 17 ++++++++++++++--- package.json | 2 +- tests/_output/.gitkeep | 0 tests/bin/initialize.sh | 1 - 5 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 tests/_output/.gitkeep diff --git a/.gitignore b/.gitignore index 75cedab8..4a1ab6cd 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ assets/js/build tests/cypress/screenshots tests/cypress/videos -tests/cypress/reports \ No newline at end of file +tests/cypress/reports +/tests/_output/* +!/tests/_output/.gitkeep diff --git a/.wp-env.json b/.wp-env.json index 687beea8..d00ee768 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,11 +1,22 @@ { + "$schema": "https://schemas.wp.org/trunk/wp-env.json", "core": null, "plugins": [ ".", "./tests/rsa-seeder" ], - "config": { - "WP_ALLOW_MULTISITE": true - }, + "multisite": true, "env": { + "development": { + "config": { + "WP_DEVELOPMENT_MODE": "plugin", + "WP_ENVIRONMENT_TYPE": "development", + "WP_DEBUG": true, + "WP_DEBUG_LOG": "/var/www/html/wp-content/plugins/restricted-site-access/tests/_output/debug.log" + } + }, "tests": { + "config": { + "WP_DEBUG": true, + "FS_METHOD": "direct" + }, "mappings": { ".htaccess": "./tests/bin/.htaccess" } diff --git a/package.json b/package.json index f0dc96d7..9065abaf 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lint:js": "wp-scripts lint-js assets/js/src", "cypress:open": "cypress open --config-file tests/cypress/config.js --e2e --browser chrome", "cypress:run": "cypress run --config-file tests/cypress/config.js", - "test:php": "wp-env run tests-cli --env-cwd=wp-content/plugins/restricted-site-access vendor/bin/phpunit -c phpunit.xml", + "test:php": "wp-env run tests-cli --env-cwd=wp-content/plugins/restricted-site-access vendor/bin/phpunit -c phpunit.xml.dist", "env": "wp-env", "env:start": "wp-env start", "env:stop": "wp-env stop", diff --git a/tests/_output/.gitkeep b/tests/_output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tests/bin/initialize.sh b/tests/bin/initialize.sh index b9e23b08..c650d6a3 100755 --- a/tests/bin/initialize.sh +++ b/tests/bin/initialize.sh @@ -1,7 +1,6 @@ #!/bin/bash wp-env run tests-wordpress chmod -c ugo+w /var/www/html -wp-env run tests-cli wp core multisite-convert --title='RSA Multisite' wp-env run tests-cli wp post create --post_type=page --post_title='One' --post_status='publish' wp-env run tests-cli wp post create --post_type=page --post_title='Two' --post_status='publish' wp-env run tests-cli wp plugin activate rsa-seeder --network From 0fbcd3d479efbccfd7df35ea11310777bea5d16c Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 18 Feb 2026 12:36:12 -0700 Subject: [PATCH 7/8] Make some changes around how we convert to multisite to get things working --- .gitignore | 1 + .wp-env.json | 12 +++++++++--- package.json | 1 - restricted_site_access.php | 6 +++--- tests/bin/initialize.sh | 13 ++++++++++++- tests/php/bootstrap.php | 2 +- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 4a1ab6cd..fb5f5629 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ tests/cypress/videos tests/cypress/reports /tests/_output/* !/tests/_output/.gitkeep +/tests/.phpunit.result.cache diff --git a/.wp-env.json b/.wp-env.json index d00ee768..3b2a0f69 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,8 +1,10 @@ { "$schema": "https://schemas.wp.org/trunk/wp-env.json", "core": null, - "plugins": [ ".", "./tests/rsa-seeder" ], - "multisite": true, + "plugins": [".", "./tests/rsa-seeder"], + "config": { + "WP_ALLOW_MULTISITE": true + }, "env": { "development": { "config": { @@ -18,8 +20,12 @@ "FS_METHOD": "direct" }, "mappings": { - ".htaccess": "./tests/bin/.htaccess" + ".htaccess": "./tests/bin/.htaccess", + "wp-cli.yml": "./tests/bin/wp-cli.yml" } } + }, + "lifecycleScripts": { + "afterStart": "bash ./tests/bin/initialize.sh" } } diff --git a/package.json b/package.json index 9065abaf..13af9511 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "env": "wp-env", "env:start": "wp-env start", "env:stop": "wp-env stop", - "postenv:start": "./tests/bin/initialize.sh", "start": "wp-scripts start", "build": "wp-scripts build" }, diff --git a/restricted_site_access.php b/restricted_site_access.php index fbe14fd0..ac367b08 100644 --- a/restricted_site_access.php +++ b/restricted_site_access.php @@ -567,14 +567,14 @@ public static function restrict_access( $wp ) { if ( 2 === self::$rsa_options['approach'] ) { $redirect_url_without_scheme = trailingslashit( preg_replace( '(^https?://)', '', $results['url'] ) ); $current_url_without_scheme = trailingslashit( preg_replace( '(^https?://)', '', home_url( $request_uri ) ) ); - $current_url_path = trailingslashit( wp_parse_url( home_url( $request_uri ), PHP_URL_PATH ) ); + $current_url_path = trailingslashit( (string) ( wp_parse_url( home_url( $request_uri ), PHP_URL_PATH ) ?? '' ) ); if ( ( $current_url_path === $redirect_url_without_scheme ) || ( $redirect_url_without_scheme === $current_url_without_scheme ) ) { return; } - $redirection_url_host = trailingslashit( wp_parse_url( $results['url'], PHP_URL_HOST ) ); - $current_url_host = trailingslashit( wp_parse_url( home_url( $request_uri ), PHP_URL_HOST ) ); + $redirection_url_host = trailingslashit( (string) ( wp_parse_url( $results['url'], PHP_URL_HOST ) ?? '' ) ); + $current_url_host = trailingslashit( (string) ( wp_parse_url( home_url( $request_uri ), PHP_URL_HOST ) ?? '' ) ); $cookie_path = wp_parse_url( home_url( '/' ), PHP_URL_PATH ); if ( $redirection_url_host === $current_url_host || '/' === $redirection_url_host ) { diff --git a/tests/bin/initialize.sh b/tests/bin/initialize.sh index c650d6a3..8b51b5d8 100755 --- a/tests/bin/initialize.sh +++ b/tests/bin/initialize.sh @@ -1,7 +1,18 @@ #!/bin/bash +set -e + wp-env run tests-wordpress chmod -c ugo+w /var/www/html +wp-env run tests-cli wp rewrite structure '/%postname%/' --hard + +# Convert tests env to multisite. wp-env has issues with multisite:true from scratch +# (database credentials get lost in tests-cli). Starting single-site then converting +# avoids this. +status=0 +wp-env run tests-cli wp site list || status=$? +if [ $status -ne 0 ]; then + wp-env run tests-cli wp core multisite-convert --title='RSA Multisite' +fi wp-env run tests-cli wp post create --post_type=page --post_title='One' --post_status='publish' wp-env run tests-cli wp post create --post_type=page --post_title='Two' --post_status='publish' wp-env run tests-cli wp plugin activate rsa-seeder --network -wp-env run tests-cli wp rewrite structure '/%postname%/' --hard diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php index f17387f8..40b476c0 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -22,7 +22,7 @@ 'muplugins_loaded', static function (): void { require dirname( __DIR__, 2 ) . '/restricted_site_access.php'; - define( 'RSA_TEST_PLUGIN_BASENAME', plugin_basename( 'restricted_site_access.php' ) ); + define( 'RSA_TEST_PLUGIN_BASENAME', plugin_basename( dirname( __DIR__, 2 ) . '/restricted_site_access.php' ) ); define( 'PHP_UNIT_TESTS_ENV', true ); } ); From 78d2409085e184e93a3c143d335001889250b84f Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Wed, 18 Feb 2026 12:56:31 -0700 Subject: [PATCH 8/8] Ensure permalinks are cleared after adding a term --- tests/rsa-seeder/rsa-seeder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/rsa-seeder/rsa-seeder.php b/tests/rsa-seeder/rsa-seeder.php index 2ea88358..0f050459 100644 --- a/tests/rsa-seeder/rsa-seeder.php +++ b/tests/rsa-seeder/rsa-seeder.php @@ -426,6 +426,8 @@ function () { wp_insert_term( 'Now', 'category' ); + flush_rewrite_rules(); + return true; }, ) @@ -491,6 +493,8 @@ function () { wp_insert_term( 'Now', 'category' ); + flush_rewrite_rules(); + return true; }, )