diff --git a/plugins/faustwp/includes/settings/callbacks.php b/plugins/faustwp/includes/settings/callbacks.php index 91a0d73f2..4a81aca67 100644 --- a/plugins/faustwp/includes/settings/callbacks.php +++ b/plugins/faustwp/includes/settings/callbacks.php @@ -203,7 +203,7 @@ function sanitize_faustwp_settings( $settings, $option ) { switch ( $name ) { case 'frontend_uri': - if ( '' === $value || preg_match( '#http(s?)://(.+)#i', $value ) ) { + if ( '' === $value || ( is_string( $value ) && preg_match( '#http(s?)://(.+)#i', $value ) ) ) { $settings[ $name ] = esc_url_raw( $value, $protocols ); } else { $errors[ $name ] = __( 'The Front-end site URL you entered did not appear to be a valid URL. Please enter a valid URL.', 'faustwp' ); @@ -566,5 +566,6 @@ function trim_frontend_uri_trailing_slash( $value, $name ) { return $value; } - return untrailingslashit( $value ); + // A front-end URL saved outside the settings screen may be null. + return untrailingslashit( (string) $value ); } diff --git a/plugins/faustwp/phpunit.xml.dist b/plugins/faustwp/phpunit.xml.dist index 14b76e3d9..b4107a0b1 100644 --- a/plugins/faustwp/phpunit.xml.dist +++ b/plugins/faustwp/phpunit.xml.dist @@ -3,6 +3,7 @@ backupGlobals="false" bootstrap="tests/bootstrap.php" colors="true" + convertDeprecationsToExceptions="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" diff --git a/plugins/faustwp/tests/integration/ProcessTelemetryRouteTests.php b/plugins/faustwp/tests/integration/ProcessTelemetryRouteTests.php index e2d720d0b..dc4809b70 100644 --- a/plugins/faustwp/tests/integration/ProcessTelemetryRouteTests.php +++ b/plugins/faustwp/tests/integration/ProcessTelemetryRouteTests.php @@ -7,6 +7,7 @@ class ProcessTelemetryRouteTests extends WP_UnitTestCase { + private $server; private $request; private $route_name; diff --git a/plugins/faustwp/tests/integration/SettingsCallbacksTests.php b/plugins/faustwp/tests/integration/SettingsCallbacksTests.php index d09238080..663a12adb 100644 --- a/plugins/faustwp/tests/integration/SettingsCallbacksTests.php +++ b/plugins/faustwp/tests/integration/SettingsCallbacksTests.php @@ -8,6 +8,7 @@ namespace WPE\FaustWP\Tests\Integration; use function WPE\FaustWP\Settings\sanitize_faustwp_settings; +use function WPE\FaustWP\Settings\trim_frontend_uri_trailing_slash; class SettingsCallbacksTests extends \WP_UnitTestCase { @@ -41,6 +42,20 @@ public function test_sanitize_faustwp_settings_does_not_change_existing_settings $this->assertSame( $this->init_settings, sanitize_faustwp_settings( $this->init_settings, $this->option ) ); } + public function test_sanitize_faustwp_settings_rejects_a_null_frontend_uri() { + $sanitized = sanitize_faustwp_settings( [ 'frontend_uri' => null ], $this->option ); + + $this->assertSame( $this->init_settings['frontend_uri'], $sanitized['frontend_uri'] ); + $errors = get_settings_errors( $this->option ); + $this->assertCount( 1, $errors ); + $this->assertEquals( $errors[0]['code'], 'faustwp_invalid_frontend_uri' ); + } + + public function test_trim_frontend_uri_trailing_slash_handles_a_null_frontend_uri() { + $this->assertSame( '', trim_frontend_uri_trailing_slash( null, 'frontend_uri' ) ); + $this->assertSame( 'http://localhost:3000', trim_frontend_uri_trailing_slash( 'http://localhost:3000/', 'frontend_uri' ) ); + } + public function test_sanitize_faustwp_settings_allows_valid_frontend_uris() { $valid_uris = [ // Clean URLs