diff --git a/.github/workflows/composer-diff.yml b/.github/workflows/composer-diff.yml
new file mode 100644
index 0000000..35e28dd
--- /dev/null
+++ b/.github/workflows/composer-diff.yml
@@ -0,0 +1,28 @@
+name: Composer Diff
+on:
+ pull_request:
+ paths:
+ - 'composer.lock'
+permissions:
+ contents: write
+ pull-requests: write
+jobs:
+ composer-diff:
+ name: Composer Diff
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ - name: Generate composer diff
+ id: composer_diff
+ uses: IonBazan/composer-diff-action@v1
+ - uses: marocchino/sticky-pull-request-comment@v2
+ if: ${{ steps.composer_diff.outputs.composer_diff_exit_code != 0 }}
+ with:
+ header: composer-diff
+ message: |
+ Composer Changes
+
+ ${{ steps.composer_diff.outputs.composer_diff }}
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 447e296..9fa8884 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Lint
run: |
composer install
diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml
deleted file mode 100644
index 17025cf..0000000
--- a/.github/workflows/shellcheck.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-name: Shellcheck
-on:
- push:
- paths:
- - 'bin/*.sh'
-jobs:
- shellcheck:
- name: Shellcheck
- runs-on: ubuntu-latest
- steps:
- - name: Checkout code
- uses: actions/checkout@v3
- - name: Shellcheck
- run: find bin/ -name "*.sh" | grep -v "install-wp-tests.sh" | xargs shellcheck
\ No newline at end of file
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 125d9e6..46d56ae 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: PHP Compatibility
uses: pantheon-systems/phpcompatibility-action@dev
with:
@@ -26,23 +26,35 @@ jobs:
services:
mariadb:
image: mariadb:10.6
+ strategy:
+ matrix:
+ php_version: [7.4, 8.1, 8.3] # Versions represent newest 7.x, WP supported with exclusions, and beta support.
steps:
- - uses: actions/checkout@v3
- - name: Setup PHP 8.3
+ - uses: actions/checkout@v4
+ - name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: 8.3
+ php-version: ${{ matrix.php_version }}
extensions: mysqli, zip, imagick
- name: Start MySQL
run: sudo systemctl start mysql
- name: Cache dependencies
- uses: actions/cache@v3
+ uses: actions/cache@v4
with:
path: ~/vendor
key: test-phpunit-dependencies-${{ hashFiles('composer.json') }}
restore-keys: test-phpunit-dependencies-${{ hashFiles('composer.json') }}
- name: Install Composer dependencies
- run: composer install
+ run: |
+ if [ ${{ matrix.php_version }} = "7.4" ]; then
+ composer update
+ fi
+ composer install
+ - name: Install WP-CLI
+ run: |
+ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
+ chmod +x wp-cli.phar
+ sudo mv wp-cli.phar /usr/local/bin/wp
- name: Run PHPUnit
run: bash ./bin/phpunit-test.sh
diff --git a/.gitignore b/.gitignore
index 9a4f997..26ab0af 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,9 @@
# Ignore composer files.
/vendor
-composer.lock
\ No newline at end of file
+composer.lock
+
+# Ignore bin files copied from wpunit-helpers
+/bin/install-local-tests.sh
+/bin/install-wp-tests.sh
+/bin/phpunit-test.sh
+/bin/helpers.sh
\ No newline at end of file
diff --git a/bin/install-local-tests.sh b/bin/install-local-tests.sh
deleted file mode 100755
index c1f8cc5..0000000
--- a/bin/install-local-tests.sh
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/bin/bash
-set -e
-
-# Initialize variables with default values
-TMPDIR="/tmp"
-DB_NAME="wordpress_test"
-DB_USER="root"
-DB_PASS=""
-DB_HOST="127.0.0.1"
-WP_VERSION="latest"
-SKIP_DB=""
-
-# Display usage information
-usage() {
- echo "Usage:"
- echo "./install-local-tests.sh [--dbname=wordpress_test] [--dbuser=root] [--dbpass=''] [--dbhost=127.0.0.1] [--wpversion=latest] [--no-db]"
-}
-
-# Parse command-line arguments
-for i in "$@"
-do
-case $i in
- --dbname=*)
- DB_NAME="${i#*=}"
- shift
- ;;
- --dbuser=*)
- DB_USER="${i#*=}"
- shift
- ;;
- --dbpass=*)
- DB_PASS="${i#*=}"
- shift
- ;;
- --dbhost=*)
- DB_HOST="${i#*=}"
- shift
- ;;
- --wpversion=*)
- WP_VERSION="${i#*=}"
- shift
- ;;
- --no-db)
- SKIP_DB="true"
- shift
- ;;
- *)
- # unknown option
- usage
- exit 1
- ;;
-esac
-done
-
-# Run install-wp-tests.sh
-echo "Installing local tests into ${TMPDIR}"
-bash "$(dirname "$0")/install-wp-tests.sh" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" "$WP_VERSION" "$SKIP_DB"
-
-# Run PHPUnit
-echo "Running PHPUnit"
-composer phpunit
diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh
deleted file mode 100755
index 675dd97..0000000
--- a/bin/install-wp-tests.sh
+++ /dev/null
@@ -1,151 +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}
-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
-}
-
-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_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_TESTS_TAG="tags/$LATEST_VERSION"
-fi
-
-set -e
-
-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
- svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
- svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
- fi
-
- if [ ! -f wp-tests-config.php ]; then
- download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/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
- mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
-}
-
-install_wp
-install_test_suite
-install_db
diff --git a/bin/phpunit-test.sh b/bin/phpunit-test.sh
deleted file mode 100755
index ae53b42..0000000
--- a/bin/phpunit-test.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-
-set -e
-
-DIRNAME=$(dirname "$0")
-
-echo "๐ค Installing WP Unit tests..."
-bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest
-
-echo "๐ Copying wp-latest.json..."
-cp /tmp/wp-latest.json "${DIRNAME}/../tests/wp-latest.json"
-
-echo "๐โโ๏ธ Running PHPUnit on Single Site"
-composer phpunit --ansi
-
-echo "๐งน Removing files before testing nightly WP..."
-rm -rf "$WP_TESTS_DIR" "$WP_CORE_DIR"
-rm "${DIRNAME}/../tests/wp-latest.json"
-
-echo "๐ค Installing WP Unit tests with WP nightly version..."
-bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 nightly true
-echo "๐ Copying wp-latest.json..."
-cp /tmp/wp-latest.json "${DIRNAME}/../tests/wp-latest.json"
-echo "๐โโ๏ธ Running PHPUnit on Single Site (Nightly WordPress)"
-composer phpunit --ansi
-
-bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest true
-echo "๐โโ๏ธ Running PHPUnit on Multisite"
-composer test:multisite --ansi
diff --git a/composer.json b/composer.json
index 2852cb7..b5c1fd9 100644
--- a/composer.json
+++ b/composer.json
@@ -8,15 +8,26 @@
},
"require-dev": {
"pantheon-systems/pantheon-wp-coding-standards": "^2.0",
+ "pantheon-systems/wpunit-helpers": "^2.0",
"phpunit/phpunit": "^9",
"yoast/phpunit-polyfills": "^2.0"
},
"config": {
"allow-plugins": {
- "dealerdirect/phpcodesniffer-composer-installer": true
+ "dealerdirect/phpcodesniffer-composer-installer": true,
+ "pantheon-systems/wpunit-helpers": true
}
},
"scripts": {
+ "chmod-scripts": [
+ "chmod +x bin/*.sh"
+ ],
+ "post-install-cmd": [
+ "@chmod-scripts"
+ ],
+ "post-update-cmd": [
+ "@chmod-scripts"
+ ],
"lint": [
"@phplint",
"@phpcs"
@@ -30,7 +41,8 @@
"@test:multisite"
],
"test:multisite": "WP_MULTISITE=1 vendor/bin/phpunit --colors=always",
- "test:install": "bin/install-local-tests.sh --no-db",
- "test:install:withdb": "bin/install-local-tests.sh"
+ "test:install": "bin/install-local-tests.sh --skip-db=true",
+ "test:install:withdb": "bin/install-local-tests.sh",
+ "test:install:nightly": "bin/install-local-tests.sh --version=nightly --skip-db=true"
}
}
diff --git a/inc/fonts.php b/inc/fonts.php
new file mode 100644
index 0000000..c029f69
--- /dev/null
+++ b/inc/fonts.php
@@ -0,0 +1,60 @@
+ test -> live).
+ *
+ * @param bool $modify_fonts_dir Whether to modify the fonts directory.
+ */
+ $modify_fonts_dir = apply_filters( 'pantheon_modify_fonts_dir', true );
+
+ if ( $modify_fonts_dir ) {
+ // Use the new font_dir filter added in WordPress 6.5. See https://github.com/WordPress/gutenberg/pull/57697.
+ add_filter( 'font_dir', __NAMESPACE__ . '\\pantheon_font_dir', 9 );
+ }
+}
+add_action( 'init', __NAMESPACE__ . '\\bootstrap' );
+
+/**
+ * Define a custom font directory for the WP Font Library.
+ * Default to {WP_CONTENT_DIR}/uploads/fonts.
+ *
+ * @param array $defaults The default settings for the font directory.
+ */
+function pantheon_font_dir( $defaults ) {
+ global $_pantheon_upload_dir;
+ // Set our font directory.
+ $font_dir = $_pantheon_upload_dir['basedir'] . '/fonts';
+ $font_url = $_pantheon_upload_dir['baseurl'] . '/fonts';
+
+ $defaults['path'] = $font_dir;
+ $defaults['url'] = $font_url;
+ $defaults['basedir'] = $font_dir;
+ $defaults['baseurl'] = $font_url;
+
+ return $defaults;
+}
diff --git a/pantheon.php b/pantheon.php
index 639db31..940e5a1 100644
--- a/pantheon.php
+++ b/pantheon.php
@@ -18,6 +18,10 @@
if ( ! defined( 'DISABLE_PANTHEON_UPDATE_NOTICES' ) || ! DISABLE_PANTHEON_UPDATE_NOTICES ) {
require_once 'inc/pantheon-updates.php';
}
+ // If the WP Font Library exists, we can add our font directory modifications. Use version_compare because the Font Library isn't actually loaded yet.
+ if ( version_compare( _pantheon_get_current_wordpress_version(), '6.5' ) ) {
+ require_once 'inc/fonts.php';
+ }
if ( ! defined( 'RETURN_TO_PANTHEON_BUTTON' ) || RETURN_TO_PANTHEON_BUTTON ) {
require_once 'inc/pantheon-login-form-mods.php';
}
diff --git a/tests/phpunit/test-fonts.php b/tests/phpunit/test-fonts.php
new file mode 100644
index 0000000..d2e4b3f
--- /dev/null
+++ b/tests/phpunit/test-fonts.php
@@ -0,0 +1,188 @@
+original_pantheon_upload_dir = $_pantheon_upload_dir; // Backup original global if needed.
+
+ // Manually set the global variable to a mocked value.
+ $_pantheon_upload_dir = [
+ 'basedir' => WP_CONTENT_DIR . '/uploads',
+ 'baseurl' => 'http://example.org/wp-content/uploads',
+ ];
+ }
+
+ public function tearDown(): void {
+ // Restore original global state after each test if necessary.
+ global $_pantheon_upload_dir;
+ $_pantheon_upload_dir = $this->original_pantheon_upload_dir;
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test the font library modifications have been loaded.
+ */
+ public function test_font_library_modifications() {
+ $this->assertTrue( function_exists( 'Pantheon\Fonts\bootstrap' ) );
+ $this->assertEquals( has_action( 'init', 'Pantheon\Fonts\bootstrap' ), 10 );
+ }
+
+ /**
+ * Test the pantheon_font_dir function.
+ */
+ public function test_pantheon_font_dir() {
+ $this->assertTrue( function_exists( 'Pantheon\Fonts\pantheon_font_dir' ) );
+
+ $this->maybe_get_font_library();
+ if ( ! function_exists( 'wp_get_font_dir' ) ) {
+ // If the function still doesn't exist after trying to get the font library from gutenberg, mark the test skipped.
+ $this->markTestSkipped( 'The wp_get_font_dir function is not available. We\'re probably not using WP 6.5+' );
+ }
+
+ // Remove the filters we apply to `font_dir` so we're getting the default data.
+ remove_all_filters( 'font_dir' );
+ $default_fonts = wp_get_font_dir();
+ $font_dir = Fonts\pantheon_font_dir( $default_fonts );
+
+ $this->assertNotEquals( $default_fonts, $font_dir );
+ $this->assertEquals( array_keys( $default_fonts ), array_keys( $font_dir ) );
+ $this->assertArrayHasKey( 'path', $font_dir );
+ $this->assertArrayHasKey( 'url', $font_dir );
+ $this->assertArrayHasKey( 'basedir', $font_dir );
+ $this->assertArrayHasKey( 'baseurl', $font_dir );
+ $this->assertStringContainsString( 'uploads/fonts', $font_dir['path'] );
+ $this->assertStringContainsString( 'uploads/fonts', $font_dir['url'] );
+ $this->assertStringContainsString( 'uploads/fonts', $font_dir['basedir'] );
+ $this->assertStringContainsString( 'uploads/fonts', $font_dir['baseurl'] );
+ }
+
+ /**
+ * Test that our filtered font directory is filtered properly.
+ */
+ public function test_pantheon_font_dir_filter() {
+ $this->maybe_get_font_library();
+ if ( ! function_exists( 'wp_get_font_dir' ) ) {
+ // If the function still doesn't exist after trying to get the font library from gutenberg, mark the test skipped.
+ $this->markTestSkipped( 'The wp_get_font_dir function is not available. We\'re probably not using WP 6.5+' );
+ }
+
+ add_filter( 'font_dir', '\\Pantheon\\Fonts\\pantheon_font_dir' );
+ $font_dir = wp_get_font_dir();
+
+ $expected = [
+ 'path' => WP_CONTENT_DIR . '/uploads/fonts',
+ 'url' => WP_CONTENT_URL . '/uploads/fonts',
+ 'subdir' => '',
+ 'basedir' => WP_CONTENT_DIR . '/uploads/fonts',
+ 'baseurl' => WP_CONTENT_URL . '/uploads/fonts',
+ 'error' => false,
+ ];
+
+ $this->assertEquals( $expected, $font_dir );
+ }
+
+ /**
+ * Test that using the font_dir filter at priority 10 overrides our modifications.
+ */
+ public function test_pantheon_fonts_dir_filter() {
+ $this->maybe_get_font_library();
+ if ( ! function_exists( 'wp_get_font_dir' ) ) {
+ // If the function still doesn't exist after trying to get the font library from gutenberg, mark the test skipped.
+ $this->markTestSkipped( 'The wp_get_font_dir function is not available. We\'re probably not using WP 6.5+' );
+ }
+
+ $custom_directory = [
+ 'path' => WP_CONTENT_DIR . '/custom-fonts',
+ 'url' => WP_CONTENT_URL . '/custom-fonts',
+ 'basedir' => WP_CONTENT_DIR . '/custom-fonts',
+ 'baseurl' => WP_CONTENT_URL . '/custom-fonts',
+ ];
+
+ add_filter( 'font_dir', function ( $defaults ) use ( $custom_directory ) {
+ $defaults['path'] = $custom_directory['path'];
+ $defaults['url'] = $custom_directory['url'];
+ $defaults['basedir'] = $custom_directory['basedir'];
+ $defaults['baseurl'] = $custom_directory['baseurl'];
+ return $defaults;
+ } );
+
+ Fonts\bootstrap();
+ $font_dir = wp_get_font_dir();
+
+ $expected = [
+ 'path' => WP_CONTENT_DIR . '/custom-fonts',
+ 'url' => WP_CONTENT_URL . '/custom-fonts',
+ 'subdir' => '',
+ 'basedir' => WP_CONTENT_DIR . '/custom-fonts',
+ 'baseurl' => WP_CONTENT_URL . '/custom-fonts',
+ 'error' => false,
+ ];
+
+ $this->assertEquals( $expected, $font_dir );
+ }
+
+ /**
+ * Test that the font directory modifications can be disabled.
+ */
+ public function test_disable_pantheon_font_dir_mods() {
+ $this->maybe_get_font_library();
+ if ( ! function_exists( 'wp_get_font_dir' ) ) {
+ // If the function still doesn't exist after trying to get the font library from gutenberg, mark the test skipped.
+ $this->markTestSkipped( 'The wp_get_font_dir function is not available. We\'re probably not using WP 6.5+' );
+ }
+
+ // Disable the font directory modifications.
+ add_filter( 'pantheon_modify_fonts_dir', '__return_false' );
+ $modify_fonts_dir = apply_filters( 'pantheon_modify_fonts_dir', true );
+ $this->assertFalse( $modify_fonts_dir );
+
+ $font_dir = wp_get_font_dir();
+
+ $expected = [
+ 'path' => WP_CONTENT_DIR . '/fonts',
+ 'url' => WP_CONTENT_URL . '/fonts',
+ 'subdir' => '',
+ 'basedir' => WP_CONTENT_DIR . '/fonts',
+ 'baseurl' => WP_CONTENT_URL . '/fonts',
+ 'error' => false,
+ ];
+
+ $this->assertEquals( $expected, $font_dir );
+ }
+
+ /**
+ * Get the font library from Gutenberg if it's not available.
+ */
+ private function maybe_get_font_library() {
+ $fonts_php = WP_PLUGIN_DIR . '/gutenberg/lib/compat/wordpress-6.5/fonts/fonts.php';
+ if ( ! function_exists( 'wp_get_font_dir' ) && file_exists( $fonts_php ) ) {
+ require_once $fonts_php;
+ }
+ }
+}
diff --git a/tests/phpunit/test-pantheon-updates.php b/tests/phpunit/test-pantheon-updates.php
index 02a7f23..a703c4e 100644
--- a/tests/phpunit/test-pantheon-updates.php
+++ b/tests/phpunit/test-pantheon-updates.php
@@ -30,8 +30,9 @@ public function __construct() {
* @return string|bool The latest WordPress version or false if the file doesn't exist.
*/
private static function get_latest_wp_version_from_file() {
- $file = dirname( __DIR__ ) . '/wp-latest.json';
-
+ global $_tests_dir;
+
+ $file = dirname( $_tests_dir ) . '/wp-latest.json';
if ( ! file_exists( $file ) ) {
return false;
}
@@ -65,7 +66,11 @@ public function test_pantheon_get_current_wordpress_version() {
// Run the function.
$result = _pantheon_get_current_wordpress_version();
$current_version = self::get_latest_wp_version_from_file();
-
+
+ // If the current version is greater than the result, then we downloaded a nightly version for testing.
+ if ( $this->is_prerelease() ) {
+ $this->markTestSkipped( 'The current version is greater than the result. We downloaded a nightly version for testing.' );
+ }
// Check that the returned version is correct. This value needs to be changed when the WordPress version is updated.
$this->assertEquals( $current_version, $result );
}
@@ -101,6 +106,10 @@ public function test_pantheon_get_latest_wordpress_version() {
* Test the _pantheon_upstream_update_notice function for latest core.
*/
public function test_pantheon_upstream_update_notice_core_latest() {
+ if ( $this->is_prerelease() ) {
+ $this->markTestSkipped( 'The current version is greater than the result. We will get a different message than the one this test expects.' );
+ }
+
set_current_screen( 'update-core' );
// Simulate that the core is the latest version.
@@ -129,6 +138,10 @@ public function test_pantheon_upstream_update_notice_core_latest() {
* Test the _pantheon_upstream_update_notice function for older core.
*/
public function test_pantheon_upstream_update_notice_core_not_latest() {
+ if ( $this->is_prerelease() ) {
+ $this->markTestSkipped( 'The current version is greater than the result. We will get a different message than the one this test expects.' );
+ }
+
set_current_screen( 'update-core' );
// Simulate that the core is not the latest version.
@@ -158,14 +171,38 @@ public function test_pantheon_upstream_update_notice_core_not_latest() {
*/
private static function get_next_beta_version() {
$version_parts = explode( '.', self::$wp_version );
- $version_parts[2] = (int) $version_parts[2] + 1;
+ $version_parts[1] = (int) $version_parts[1] + 1;
return implode( '.', $version_parts ) . '-beta';
}
+ /**
+ * Check if we're using a beta version.
+ */
+ private static function is_prerelease() {
+ $current_version = _pantheon_get_current_wordpress_version();
+ $installed_version = self::get_latest_wp_version_from_file();
+
+ // If the current version and the installed version are the same, then we're not using a prerelease.
+ if ( $current_version === $installed_version ) {
+ return false;
+ }
+
+ // If the version derived from WordPress is higher than the version in the wp-version.json file, then we're using a prerelease.
+ if ( version_compare( $current_version, $installed_version, '>' ) ) {
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Test the _pantheon_upstream_update_notice function for beta/pre-release version.
*/
public function test_pantheon_upstream_update_notice_core_prerelease() {
+ if ( $this->is_prerelease() ) {
+ $this->markTestSkipped( 'The current version is greater than the result. We will get a different message than the one this test expects.' );
+ }
+
$beta_version = self::get_next_beta_version();
set_current_screen( 'update-core' );