From 2fdd911808e0d9188ed3c5578b2ed3d014fb87b6 Mon Sep 17 00:00:00 2001 From: Travis Weston Date: Mon, 22 Jul 2024 12:36:04 -0400 Subject: [PATCH 01/19] WIP: issue-95 From 8b616fa1b6ecb20d1fdbd0b2921f137a19ed2d58 Mon Sep 17 00:00:00 2001 From: Travis Weston Date: Mon, 22 Jul 2024 12:51:46 -0400 Subject: [PATCH 02/19] Fix infinite loop in force 2fa logic --- .../class-force-two-factor-authentication.php | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/alley/wp/alleyvate/features/class-force-two-factor-authentication.php b/src/alley/wp/alleyvate/features/class-force-two-factor-authentication.php index 1be66780..98781977 100644 --- a/src/alley/wp/alleyvate/features/class-force-two-factor-authentication.php +++ b/src/alley/wp/alleyvate/features/class-force-two-factor-authentication.php @@ -26,7 +26,7 @@ final class Force_Two_Factor_Authentication implements Feature { */ public function boot(): void { if ( self::is_vip_environment() ) { - add_filter( 'wpcom_vip_is_two_factor_forced', [ self::class, 'filter__wpcom_vip_is_two_factor_forced' ], \PHP_INT_MAX ); + add_filter( 'wpcom_vip_two_factor_enforcement_cap', [ self::class, 'filter__wpcom_vip_two_factor_enforcement_cap' ], \PHP_INT_MAX ); return; } @@ -36,16 +36,6 @@ public function boot(): void { add_action( 'admin_notices', [ self::class, 'action__admin_notices' ] ); } - /** - * For VIP environments we can skip all of the functionality, and only focus on returning true if the current user - * can edit posts. - * - * @return bool - */ - public static function filter__wpcom_vip_is_two_factor_forced(): bool { - return self::force_to_enable_2fa(); - } - /** * Filter the user capabilities to restrict them to just those capabilities required to enabled two factor authentication. * @@ -89,6 +79,15 @@ public static function action__admin_notices(): void { } } + /** + * Returns the capability level that accounts will be required to use 2fa. + * + * @return string + */ + public static function filter__wpcom_vip_two_factor_enforcement_cap(): string { + return apply_filters( 'alleyvate_force_2fa_capability', 'edit_posts' ); + } + /** * Adds an Admin Notice notifying the end user that they need to enable Two Factor authentication. */ @@ -165,7 +164,7 @@ private static function should_use_two_factor_authentication(): bool { * @return bool */ private static function force_to_enable_2fa(): bool { - $capability_min = apply_filters( 'alleyvate_force_2fa_capability', 'edit_posts' ); + $capability_min = self::filter__wpcom_vip_two_factor_enforcement_cap(); // Remove the filter to avoid infinite loops. $removed = remove_filter( 'map_meta_cap', [ self::class, 'filter__map_meta_cap' ], 0 ); From 84504e77ecbbe1e7d3480734c799671e48a0a21c Mon Sep 17 00:00:00 2001 From: Travis Weston Date: Mon, 22 Jul 2024 12:52:17 -0400 Subject: [PATCH 03/19] Ready for review From 5f2ae029d8bd4007647a20421db7f2dc05743df5 Mon Sep 17 00:00:00 2001 From: Travis Weston Date: Mon, 22 Jul 2024 13:46:16 -0400 Subject: [PATCH 04/19] Bump version to 3.2.0 --- CHANGELOG.md | 8 +++++++- wp-alleyvate.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f984868..0bb090c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,16 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/en/1.0.0/). -## Unreleased +## 3.2.0 + +### Added * `disable_apple_news_non_prod_push`: Added a feature to disable pushing to Apple News when not on a production environment. +### Changed + +* `force_two_factor_authentication`: Fixed an infinite loop issue on VIP sites. + ## 3.1.0 ### Added diff --git a/wp-alleyvate.php b/wp-alleyvate.php index 6018cd29..d96bde1b 100644 --- a/wp-alleyvate.php +++ b/wp-alleyvate.php @@ -14,7 +14,7 @@ * Plugin Name: Alleyvate * Plugin URI: https://github.com/alleyinteractive/wp-alleyvate * Description: Defaults for WordPress sites by Alley - * Version: 3.1.0 + * Version: 3.2.0 * Author: Alley * Author URI: https://www.alley.com * Requires at least: 6.2 From 6bcb8b58700fd618388748078d35c8e0abe109ef Mon Sep 17 00:00:00 2001 From: Travis Weston Date: Mon, 22 Jul 2024 13:52:00 -0400 Subject: [PATCH 05/19] Use correct changelog header --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bb090c6..09242e5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a C * `disable_apple_news_non_prod_push`: Added a feature to disable pushing to Apple News when not on a production environment. -### Changed +### Fixed * `force_two_factor_authentication`: Fixed an infinite loop issue on VIP sites. From a1af3602dd815d6159ab48368c5827799e981509 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 10:40:42 -0400 Subject: [PATCH 06/19] Adding scaffolder feature --- .editorconfig | 2 +- .scaffold/feature/config.yml | 17 ++++++++++++++++ .scaffold/feature/feature.php.hbs | 27 ++++++++++++++++++++++++++ .scaffold/feature/test.php.hbs | 32 +++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 .scaffold/feature/config.yml create mode 100644 .scaffold/feature/feature.php.hbs create mode 100644 .scaffold/feature/test.php.hbs diff --git a/.editorconfig b/.editorconfig index 15c079d5..cc982c2d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,7 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[*.{php,neon}] +[*.{php,neon,php.hbs}] indent_size = 4 indent_style = tab diff --git a/.scaffold/feature/config.yml b/.scaffold/feature/config.yml new file mode 100644 index 00000000..0965d1de --- /dev/null +++ b/.scaffold/feature/config.yml @@ -0,0 +1,17 @@ +name: wp-alleyvate@feature + +inputs: + - name: featureName + description: "Feature Name" + type: string + - name: tests + description: "Include Tests?" + type: boolean + default: true + +files: + - source: feature.php.hbs + destination: src/alley/wp/alleyvate/features/{{ wpClassFilename inputs.featureName }} + - source: test.php.hbs + if: "{{ inputs.tests }}" + destination: tests/alley/wp/alleyvate/features/{{ wpClassFilename inputs.featureName prefix="test-" }} diff --git a/.scaffold/feature/feature.php.hbs b/.scaffold/feature/feature.php.hbs new file mode 100644 index 00000000..09364f14 --- /dev/null +++ b/.scaffold/feature/feature.php.hbs @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @package wp-alleyvate + */ + +namespace Alley\WP\Alleyvate\Features; + +use Alley\WP\Types\Feature; + +/** + * {{ wpClassName inputs.featureName }} feature. + */ +final class {{ wpClassName inputs.featureName }} implements Feature { + /** + * Boot the feature. + */ + public function boot(): void { + // ... + } +} diff --git a/.scaffold/feature/test.php.hbs b/.scaffold/feature/test.php.hbs new file mode 100644 index 00000000..a33c3187 --- /dev/null +++ b/.scaffold/feature/test.php.hbs @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @package wp-alleyvate + * + * @phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited, Generic.CodeAnalysis.EmptyStatement.DetectedCatch, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + */ + +declare( strict_types=1 ); + +namespace Alley\WP\Alleyvate\Features; + +use Mantle\Testing\Concerns\Refresh_Database; +use Mantle\Testing\Exceptions\WP_Die_Exception; +use Mantle\Testkit\Test_Case; + +/** + * Tests for {{ wpClassName inputs.featureName }} feature. + */ +final class {{ wpClassName inputs.featureName prefix="Test_" }} extends Test_Case { + use Refresh_Database; + + public function test_example(): void { + $this->assertTrue( true ); + } +} From 9eaf6e39ae0cc3314b65a229d565be60e116882e Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 10:41:01 -0400 Subject: [PATCH 07/19] Adding scaffolder feature --- {.scaffold => .scaffolder}/feature/config.yml | 0 {.scaffold => .scaffolder}/feature/feature.php.hbs | 0 {.scaffold => .scaffolder}/feature/test.php.hbs | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {.scaffold => .scaffolder}/feature/config.yml (100%) rename {.scaffold => .scaffolder}/feature/feature.php.hbs (100%) rename {.scaffold => .scaffolder}/feature/test.php.hbs (100%) diff --git a/.scaffold/feature/config.yml b/.scaffolder/feature/config.yml similarity index 100% rename from .scaffold/feature/config.yml rename to .scaffolder/feature/config.yml diff --git a/.scaffold/feature/feature.php.hbs b/.scaffolder/feature/feature.php.hbs similarity index 100% rename from .scaffold/feature/feature.php.hbs rename to .scaffolder/feature/feature.php.hbs diff --git a/.scaffold/feature/test.php.hbs b/.scaffolder/feature/test.php.hbs similarity index 100% rename from .scaffold/feature/test.php.hbs rename to .scaffolder/feature/test.php.hbs From db7cfae7dbd2ec005c8f44a0832ae37ca3c54b1d Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 10:41:43 -0400 Subject: [PATCH 08/19] Adding the scaffold script --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index caf8f5bc..9c5eb5f4 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "phpcs": "phpcs", "phpstan": "phpstan --memory-limit=768M", "phpunit": "phpunit", + "scaffold": "npx npx @alleyinteractive/scaffolder@latest wp-alleyvate@feature", "test": [ "@lint", "@phpunit" From abab2f7d938e4c8aa2e0d5b6b2cfcdf3c9565aae Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 10:47:21 -0400 Subject: [PATCH 09/19] Improve scaffodler files --- .scaffolder/feature/feature.php.hbs | 2 +- .scaffolder/feature/test.php.hbs | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.scaffolder/feature/feature.php.hbs b/.scaffolder/feature/feature.php.hbs index 09364f14..8f9835e0 100644 --- a/.scaffolder/feature/feature.php.hbs +++ b/.scaffolder/feature/feature.php.hbs @@ -22,6 +22,6 @@ final class {{ wpClassName inputs.featureName }} implements Feature { * Boot the feature. */ public function boot(): void { - // ... + // ... } } diff --git a/.scaffolder/feature/test.php.hbs b/.scaffolder/feature/test.php.hbs index a33c3187..c935854a 100644 --- a/.scaffolder/feature/test.php.hbs +++ b/.scaffolder/feature/test.php.hbs @@ -8,8 +8,6 @@ * file that was distributed with this source code. * * @package wp-alleyvate - * - * @phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited, Generic.CodeAnalysis.EmptyStatement.DetectedCatch, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound */ declare( strict_types=1 ); @@ -26,6 +24,25 @@ use Mantle\Testkit\Test_Case; final class {{ wpClassName inputs.featureName prefix="Test_" }} extends Test_Case { use Refresh_Database; + /** + * Feature instance. + * + * @var {{ wpClassName inputs.featureName }} + */ + private {{ wpClassName inputs.featureName }} $feature; + + /** + * Set up. + */ + protected function setUp(): void { + parent::setUp(); + + $this->feature = new {{ wpClassName inputs.featureName }}(); + } + + /** + * Example Test. + */ public function test_example(): void { $this->assertTrue( true ); } From 7906246ef54906b889d7572f4517252c64cf877a Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 10:56:52 -0400 Subject: [PATCH 10/19] Adding disable_site_health_directories feature --- .scaffolder/feature/test.php.hbs | 4 +- CHANGELOG.md | 6 ++ README.md | 5 ++ .../class-disable-site-health-directories.php | 62 +++++++++++++++++++ src/alley/wp/alleyvate/load.php | 4 ++ .../test-disable-site-health-directories.php | 52 ++++++++++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/alley/wp/alleyvate/features/class-disable-site-health-directories.php create mode 100644 tests/alley/wp/alleyvate/features/test-disable-site-health-directories.php diff --git a/.scaffolder/feature/test.php.hbs b/.scaffolder/feature/test.php.hbs index c935854a..dcd2fbcf 100644 --- a/.scaffolder/feature/test.php.hbs +++ b/.scaffolder/feature/test.php.hbs @@ -15,7 +15,6 @@ declare( strict_types=1 ); namespace Alley\WP\Alleyvate\Features; use Mantle\Testing\Concerns\Refresh_Database; -use Mantle\Testing\Exceptions\WP_Die_Exception; use Mantle\Testkit\Test_Case; /** @@ -44,6 +43,9 @@ final class {{ wpClassName inputs.featureName prefix="Test_" }} extends Test_Cas * Example Test. */ public function test_example(): void { + // Activate the feature. + $this->feature->boot(); + $this->assertTrue( true ); } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 09242e5f..d713c74a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/en/1.0.0/). +## 3.3.0 + +### Added + +* `disable_site_health_directories`: Added a feature to disable the site health check for information about the WordPress directories and their sizes. + ## 3.2.0 ### Added diff --git a/README.md b/README.md index 0ae125e8..d012f93c 100644 --- a/README.md +++ b/README.md @@ -99,10 +99,15 @@ which have been shown to force those environments to use an insecure protocol at This feature disables sending password change notification emails to site admins. +### `disable_site_health_directories` + +This feature disables the site health check for information about the WordPress directories and their sizes. + ### `disable_sticky_posts` This feature disables WordPress sticky posts entirely, including the ability to set and query sticky posts. + ### `disable_trackbacks` This feature disables WordPress from sending or receiving trackbacks or pingbacks. diff --git a/src/alley/wp/alleyvate/features/class-disable-site-health-directories.php b/src/alley/wp/alleyvate/features/class-disable-site-health-directories.php new file mode 100644 index 00000000..7f123eec --- /dev/null +++ b/src/alley/wp/alleyvate/features/class-disable-site-health-directories.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @package wp-alleyvate + */ + +namespace Alley\WP\Alleyvate\Features; + +use Alley\WP\Types\Feature; + +/** + * Disable_Site_Health_Directories feature. + */ +final class Disable_Site_Health_Directories implements Feature { + /** + * Boot the feature. + */ + public function boot(): void { + add_filter( 'rest_pre_dispatch', [ $this, 'filter_rest_pre_dispatch' ], 10, 3 ); + add_filter( 'debug_information', [ $this, 'filter_debug_information' ] ); + } + + /** + * Filter REST API requests to remove Site Health directories. + * + * @param mixed $result Response to replace the requested version with. Can be anything a normal endpoint can return, or null to not hijack the request. + * @param \WP_REST_Server $server Server instance. + * @param \WP_REST_Request $request Request used to generate the response. + * @return mixed Response to replace the requested version with. + */ + public function filter_rest_pre_dispatch( $result, $server, $request ) { + if ( $request->get_route() === '/wp-site-health/v1/directory-sizes' ) { + return new \WP_Error( 'rest_disabled', 'REST API endpoint disabled.', [ 'status' => 403 ] ); + } + + return $result; + } + + /** + * Filter debug information to remove Site Health directories. + * + * @param array}> $info Debug information. + * @return array}> Debug information. + */ + public function filter_debug_information( $info ): array { + if ( ! \is_array( $info ) ) { + $info = []; + } + + if ( isset( $info['wp-paths-sizes'] ) ) { + unset( $info['wp-paths-sizes'] ); + } + + return $info; + } +} diff --git a/src/alley/wp/alleyvate/load.php b/src/alley/wp/alleyvate/load.php index ecaa7832..84ee4da0 100644 --- a/src/alley/wp/alleyvate/load.php +++ b/src/alley/wp/alleyvate/load.php @@ -57,6 +57,10 @@ function load(): void { 'disable_password_change_notification', new Features\Disable_Password_Change_Notification(), ), + new Feature( + 'disable_site_health_directories', + new Features\Disable_Site_Health_Directories(), + ), new Feature( 'disable_sticky_posts', new Features\Disable_Sticky_Posts(), diff --git a/tests/alley/wp/alleyvate/features/test-disable-site-health-directories.php b/tests/alley/wp/alleyvate/features/test-disable-site-health-directories.php new file mode 100644 index 00000000..da2f8719 --- /dev/null +++ b/tests/alley/wp/alleyvate/features/test-disable-site-health-directories.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @package wp-alleyvate + */ + +declare( strict_types=1 ); + +namespace Alley\WP\Alleyvate\Features; + +use Mantle\Testing\Concerns\Refresh_Database; +use Mantle\Testkit\Test_Case; + +/** + * Tests for Disable_Site_Health_Directories feature. + */ +final class Test_Disable_Site_Health_Directories extends Test_Case { + use Refresh_Database; + + /** + * Feature instance. + * + * @var Disable_Site_Health_Directories + */ + private Disable_Site_Health_Directories $feature; + + /** + * Set up. + */ + protected function setUp(): void { + parent::setUp(); + + $this->feature = new Disable_Site_Health_Directories(); + } + + /** + * Test that the REST API endpoint is disabled. + */ + public function test_rest_api_disabled(): void { + $this->feature->boot(); + + $this->acting_as( 'administrator' ); + + $this->get( rest_url( 'wp-site-health/v1/directory-sizes' ) )->assertStatus( 403 ); + } +} From 64da6b441a67584516a947e00962e08698efa945 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 10:59:42 -0400 Subject: [PATCH 11/19] Running fixer --- src/alley/wp/alleyvate/class-feature.php | 2 +- .../alleyvate/features/class-disable-deep-pagination.php | 2 +- src/alley/wp/alleyvate/features/class-prevent-framing.php | 2 +- .../test-disable-block-editor-rest-api-preload-paths.php | 8 ++++---- .../alley/wp/alleyvate/features/test-disable-comments.php | 8 ++++---- .../wp/alleyvate/features/test-disable-trackbacks.php | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/alley/wp/alleyvate/class-feature.php b/src/alley/wp/alleyvate/class-feature.php index 515c3d73..01031862 100644 --- a/src/alley/wp/alleyvate/class-feature.php +++ b/src/alley/wp/alleyvate/class-feature.php @@ -81,7 +81,7 @@ public function add_debug_information( $info ): array { $info['wp-alleyvate']['fields'] ??= []; $info['wp-alleyvate']['fields'][] = [ - 'label' => sprintf( + 'label' => \sprintf( /* translators: %s: Feature name. */ __( 'Feature: %s', 'alley' ), $this->handle, diff --git a/src/alley/wp/alleyvate/features/class-disable-deep-pagination.php b/src/alley/wp/alleyvate/features/class-disable-deep-pagination.php index 50fbd872..eab66e23 100644 --- a/src/alley/wp/alleyvate/features/class-disable-deep-pagination.php +++ b/src/alley/wp/alleyvate/features/class-disable-deep-pagination.php @@ -52,7 +52,7 @@ public static function filter__posts_where( $where, $wp_query ) { } wp_die( - sprintf( + \sprintf( /* translators: The maximum number of pages. */ esc_html__( 'Invalid Request: Pagination beyond page %d has been disabled for performance reasons.', 'alley' ), esc_html( $max_pages ), diff --git a/src/alley/wp/alleyvate/features/class-prevent-framing.php b/src/alley/wp/alleyvate/features/class-prevent-framing.php index f4d58861..40a8b724 100644 --- a/src/alley/wp/alleyvate/features/class-prevent-framing.php +++ b/src/alley/wp/alleyvate/features/class-prevent-framing.php @@ -81,7 +81,7 @@ public static function filter__wp_headers( $headers ): array { if ( ! \in_array( $headers['X-Frame-Options'], [ 'DENY', 'SAMEORIGIN' ], true ) && 0 !== strpos( $headers['X-Frame-Options'], 'ALLOW-FROM' ) ) { _doing_it_wrong( __METHOD__, - sprintf( + \sprintf( /* translators: %s: The value of the X-Frame-Options header. */ esc_html__( 'Invalid value for %s. Must be DENY, SAMEORIGIN, or ALLOW-FROM uri.', 'alley' ), 'X-Frame-Options' diff --git a/tests/alley/wp/alleyvate/features/test-disable-block-editor-rest-api-preload-paths.php b/tests/alley/wp/alleyvate/features/test-disable-block-editor-rest-api-preload-paths.php index 60576591..ed1581f3 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-block-editor-rest-api-preload-paths.php +++ b/tests/alley/wp/alleyvate/features/test-disable-block-editor-rest-api-preload-paths.php @@ -64,13 +64,13 @@ public function test_disable_block_editor_rest_api_preload_paths(): void { // ph rest_get_route_for_post_type_items( 'wp_block' ) ), add_query_arg( 'context', 'edit', $rest_path ), - sprintf( '/wp/v2/types/%s?context=edit', $post_type ), + \sprintf( '/wp/v2/types/%s?context=edit', $post_type ), '/wp/v2/users/me', [ rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ], [ rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ], [ rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ], [ rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ], - sprintf( '%s/autosaves?context=edit', $rest_path ), + \sprintf( '%s/autosaves?context=edit', $rest_path ), '/wp/v2/settings', [ '/wp/v2/settings', 'OPTIONS' ], ]; @@ -111,13 +111,13 @@ public function check_preloads_paths( mixed $preload_paths, string $rest_path, s $this->assertContains( '/wp/v2/types?context=view', $preload_paths ); $this->assertContains( '/wp/v2/taxonomies?context=view', $preload_paths ); $this->assertContains( add_query_arg( 'context', 'edit', $rest_path ), $preload_paths ); - $this->assertContains( sprintf( '/wp/v2/types/%s?context=edit', $post_type ), $preload_paths ); + $this->assertContains( \sprintf( '/wp/v2/types/%s?context=edit', $post_type ), $preload_paths ); $this->assertContains( '/wp/v2/users/me', $preload_paths ); $this->assertContains( [ rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ], $preload_paths ); $this->assertContains( [ rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ], $preload_paths ); $this->assertContains( [ rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ], $preload_paths ); $this->assertContains( [ rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ], $preload_paths ); - $this->assertContains( sprintf( '%s/autosaves?context=edit', $rest_path ), $preload_paths ); + $this->assertContains( \sprintf( '%s/autosaves?context=edit', $rest_path ), $preload_paths ); $this->assertContains( '/wp/v2/settings', $preload_paths ); $this->assertContains( [ '/wp/v2/settings', 'OPTIONS' ], $preload_paths ); } diff --git a/tests/alley/wp/alleyvate/features/test-disable-comments.php b/tests/alley/wp/alleyvate/features/test-disable-comments.php index 2d64cdf0..e2beecd1 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-comments.php +++ b/tests/alley/wp/alleyvate/features/test-disable-comments.php @@ -187,7 +187,7 @@ public function test_remove_post_type_support(): void { $this->assertTrue( post_type_supports( 'post', 'comments' ) ); // Ensure the comment status is reported as open and the replies link exists out of the box. - $result = rest_do_request( sprintf( '/wp/v2/posts/%d', $post_id ) ); + $result = rest_do_request( \sprintf( '/wp/v2/posts/%d', $post_id ) ); $this->assertSame( 'open', $result->data['comment_status'] ); $this->assertArrayHasKey( 'replies', $result->get_links() ); @@ -198,7 +198,7 @@ public function test_remove_post_type_support(): void { $this->assertFalse( post_type_supports( 'post', 'comments' ) ); // Ensure the comment status is reported as closed and the replies link has been removed. - $result = rest_do_request( sprintf( '/wp/v2/posts/%d', $post_id ) ); + $result = rest_do_request( \sprintf( '/wp/v2/posts/%d', $post_id ) ); $this->assertSame( 'closed', $result->data['comment_status'] ); $this->assertArrayNotHasKey( 'replies', $result->get_links() ); } @@ -222,7 +222,7 @@ public function test_remove_rest_routes(): void { // Ensure comment routes are successful before the plugin is active. $result_generic = rest_do_request( new \WP_REST_Request( 'GET', '/wp/v2/comments' ) ); - $result_specific = rest_do_request( new \WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $comment_id ) ) ); + $result_specific = rest_do_request( new \WP_REST_Request( 'GET', \sprintf( '/wp/v2/comments/%d', $comment_id ) ) ); $this->assertSame( 200, $result_generic->get_status() ); $this->assertSame( 200, $result_specific->get_status() ); @@ -236,7 +236,7 @@ public function test_remove_rest_routes(): void { // Ensure comment routes 404. $result_generic = rest_do_request( new \WP_REST_Request( 'GET', '/wp/v2/comments' ) ); - $result_specific = rest_do_request( new \WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $comment_id ) ) ); + $result_specific = rest_do_request( new \WP_REST_Request( 'GET', \sprintf( '/wp/v2/comments/%d', $comment_id ) ) ); $this->assertSame( 404, $result_generic->get_status() ); $this->assertSame( 404, $result_specific->get_status() ); } diff --git a/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php b/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php index 081265d4..7cee3c5a 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php +++ b/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php @@ -90,7 +90,7 @@ public function test_remove_trackback_support(): void { $this->assertTrue( post_type_supports( 'post', 'trackbacks' ) ); // Ensure the ping status is reported as open out of the box. - $result = rest_do_request( sprintf( '/wp/v2/posts/%d', $post_id ) ); + $result = rest_do_request( \sprintf( '/wp/v2/posts/%d', $post_id ) ); $this->assertSame( 'open', $result->data['ping_status'] ); // Removing post type support happens on 'init', which has already occurred, so we need to call the callback directly. @@ -100,7 +100,7 @@ public function test_remove_trackback_support(): void { $this->assertFalse( post_type_supports( 'post', 'trackbacks' ) ); // Ensure the ping status is reported as closed. - $result = rest_do_request( sprintf( '/wp/v2/posts/%d', $post_id ) ); + $result = rest_do_request( \sprintf( '/wp/v2/posts/%d', $post_id ) ); $this->assertSame( 'closed', $result->data['ping_status'] ); } } From 0199f6c1c86626b18da203dad60fba1225b08360 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 11:06:08 -0400 Subject: [PATCH 12/19] Starting the move to phpunit 11 --- composer.json | 10 +++--- phpunit.xml | 14 ++++---- .../Features/CacheSlowQueriesTest.php} | 2 +- .../Alleyvate/Features/CleanAdminBarTest.php} | 2 +- .../Features/Concerns/RemoveMetaBox.php} | 4 +-- .../DisableAppleNewsNonProdPushTest.php} | 2 +- .../DisableAttachmentRoutingTest.php} | 2 +- ...bleBlockEditorRestApiPreloadPathsTest.php} | 2 +- .../Features/DisableCommentsTest.php} | 4 +-- .../DisableCustomFieldsMetaBoxTest.php} | 4 +-- .../Features/DisableDashboardWidgetsTest.php} | 2 +- .../Features/DisableDeepPaginationTest.php} | 32 +++---------------- ...DisablePasswordChangeNotificationTest.php} | 2 +- .../Features/DisableStickyPostsTest.php} | 2 +- .../Features/DisableTrackbacksTest.php} | 2 +- .../Features/DisallowFileEditTest.php} | 2 +- .../Wp/Alleyvate/Features/LoginNonceTest.php} | 2 +- .../Features/PreventFramingTest.php} | 2 +- .../RedirectGuessShortcircuitTest.php} | 2 +- .../Features/RemoveShortlinkTest.php} | 2 +- .../UserEnumerationRestrictionsTest.php} | 6 ++-- 21 files changed, 41 insertions(+), 61 deletions(-) rename tests/{alley/wp/alleyvate/features/test-cache-slow-queries.php => Alley/Wp/Alleyvate/Features/CacheSlowQueriesTest.php} (98%) rename tests/{alley/wp/alleyvate/features/test-clean-admin-bar.php => Alley/Wp/Alleyvate/Features/CleanAdminBarTest.php} (98%) rename tests/{alley/wp/alleyvate/features/concerns/trait-remove-meta-box.php => Alley/Wp/Alleyvate/Features/Concerns/RemoveMetaBox.php} (96%) rename tests/{alley/wp/alleyvate/features/test-disable-apple-news-non-prod-push.php => Alley/Wp/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php} (97%) rename tests/{alley/wp/alleyvate/features/test-disable-attachment-routing.php => Alley/Wp/Alleyvate/Features/DisableAttachmentRoutingTest.php} (98%) rename tests/{alley/wp/alleyvate/features/test-disable-block-editor-rest-api-preload-paths.php => Alley/Wp/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php} (98%) rename tests/{alley/wp/alleyvate/features/test-disable-comments.php => Alley/Wp/Alleyvate/Features/DisableCommentsTest.php} (99%) rename tests/{alley/wp/alleyvate/features/test-disable-custom-fields-meta-box.php => Alley/Wp/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php} (90%) rename tests/{alley/wp/alleyvate/features/test-disable-dashboard-widgets.php => Alley/Wp/Alleyvate/Features/DisableDashboardWidgetsTest.php} (96%) rename tests/{alley/wp/alleyvate/features/test-disable-deep-pagination.php => Alley/Wp/Alleyvate/Features/DisableDeepPaginationTest.php} (91%) rename tests/{alley/wp/alleyvate/features/test-disable-password-change-notification.php => Alley/Wp/Alleyvate/Features/DisablePasswordChangeNotificationTest.php} (94%) rename tests/{alley/wp/alleyvate/features/test-disable-sticky-posts.php => Alley/Wp/Alleyvate/Features/DisableStickyPostsTest.php} (97%) rename tests/{alley/wp/alleyvate/features/test-disable-trackbacks.php => Alley/Wp/Alleyvate/Features/DisableTrackbacksTest.php} (98%) rename tests/{alley/wp/alleyvate/features/test-disallow-file-edit.php => Alley/Wp/Alleyvate/Features/DisallowFileEditTest.php} (94%) rename tests/{alley/wp/alleyvate/features/test-login-nonce.php => Alley/Wp/Alleyvate/Features/LoginNonceTest.php} (98%) rename tests/{alley/wp/alleyvate/features/test-prevent-framing.php => Alley/Wp/Alleyvate/Features/PreventFramingTest.php} (98%) rename tests/{alley/wp/alleyvate/features/test-redirect-guess-shortcircuit.php => Alley/Wp/Alleyvate/Features/RedirectGuessShortcircuitTest.php} (95%) rename tests/{alley/wp/alleyvate/features/test-remove-shortlink.php => Alley/Wp/Alleyvate/Features/RemoveShortlinkTest.php} (95%) rename tests/{alley/wp/alleyvate/features/test-user-enumeration-restrictions.php => Alley/Wp/Alleyvate/Features/UserEnumerationRestrictionsTest.php} (93%) diff --git a/composer.json b/composer.json index caf8f5bc..09af3bb9 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require-dev": { "alleyinteractive/alley-coding-standards": "^2.0", "friendsofphp/php-cs-fixer": "^3.8", - "mantle-framework/testkit": "^0.12", + "mantle-framework/testkit": "^1.0", "szepeviktor/phpstan-wordpress": "^1.3" }, "scripts": { @@ -44,13 +44,15 @@ "@phpunit" ] }, + "autoload-dev": { + "psr-4": { + "Alley\\WP\\Alleyvate\\": "tests/Alley/WP/Alleyvate" + } + }, "extra": { "wordpress-autoloader": { "autoload": { "Alley\\": "src/alley/" - }, - "autoload-dev": { - "Alley\\": "tests/alley/" } } } diff --git a/phpunit.xml b/phpunit.xml index 0ad5694f..5e0707ba 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,13 @@ + - - tests/alley/wp/ - + + tests/alley/wp/ + diff --git a/tests/alley/wp/alleyvate/features/test-cache-slow-queries.php b/tests/Alley/Wp/Alleyvate/Features/CacheSlowQueriesTest.php similarity index 98% rename from tests/alley/wp/alleyvate/features/test-cache-slow-queries.php rename to tests/Alley/Wp/Alleyvate/Features/CacheSlowQueriesTest.php index aac48e2c..6e49dd9a 100644 --- a/tests/alley/wp/alleyvate/features/test-cache-slow-queries.php +++ b/tests/Alley/Wp/Alleyvate/Features/CacheSlowQueriesTest.php @@ -21,7 +21,7 @@ /** * Tests for caching slow queries. */ -final class Test_Cache_Slow_Queries extends Test_Case { +final class CacheSlowQueriesTest extends Test_Case { use Admin_Screen; use Refresh_Database; diff --git a/tests/alley/wp/alleyvate/features/test-clean-admin-bar.php b/tests/Alley/Wp/Alleyvate/Features/CleanAdminBarTest.php similarity index 98% rename from tests/alley/wp/alleyvate/features/test-clean-admin-bar.php rename to tests/Alley/Wp/Alleyvate/Features/CleanAdminBarTest.php index 426e6fd1..cca9a9fa 100644 --- a/tests/alley/wp/alleyvate/features/test-clean-admin-bar.php +++ b/tests/Alley/Wp/Alleyvate/Features/CleanAdminBarTest.php @@ -21,7 +21,7 @@ /** * Tests for the cleaning of the admin bar. */ -final class Test_Clean_Admin_Bar extends Test_Case { +final class CleanAdminBarTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/concerns/trait-remove-meta-box.php b/tests/Alley/Wp/Alleyvate/Features/Concerns/RemoveMetaBox.php similarity index 96% rename from tests/alley/wp/alleyvate/features/concerns/trait-remove-meta-box.php rename to tests/Alley/Wp/Alleyvate/Features/Concerns/RemoveMetaBox.php index 9329466e..39b8a0df 100644 --- a/tests/alley/wp/alleyvate/features/concerns/trait-remove-meta-box.php +++ b/tests/Alley/Wp/Alleyvate/Features/Concerns/RemoveMetaBox.php @@ -1,6 +1,6 @@ * @@ -22,7 +22,7 @@ /** * Test the removal of a meta box. */ -trait Remove_Meta_Box { +trait RemoveMetaBox { use Admin_Screen; /** diff --git a/tests/alley/wp/alleyvate/features/test-disable-apple-news-non-prod-push.php b/tests/Alley/Wp/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php similarity index 97% rename from tests/alley/wp/alleyvate/features/test-disable-apple-news-non-prod-push.php rename to tests/Alley/Wp/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php index 8e2501f2..90508137 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-apple-news-non-prod-push.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php @@ -18,7 +18,7 @@ /** * Test Disable_Apple_News_Non_Prod_Push */ -final class Disable_Apple_News_Non_Prod_Push_Test extends Test_Case { +final class DisableAppleNewsNonProdPushTest extends Test_Case { /** * The Feature class. * diff --git a/tests/alley/wp/alleyvate/features/test-disable-attachment-routing.php b/tests/Alley/Wp/Alleyvate/Features/DisableAttachmentRoutingTest.php similarity index 98% rename from tests/alley/wp/alleyvate/features/test-disable-attachment-routing.php rename to tests/Alley/Wp/Alleyvate/Features/DisableAttachmentRoutingTest.php index 7007da7e..0968808c 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-attachment-routing.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableAttachmentRoutingTest.php @@ -20,7 +20,7 @@ /** * Tests for fully disabling attachment routing. */ -final class Test_Disable_Attachment_Routing extends Test_Case { +final class DisableAttachmentRoutingTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/test-disable-block-editor-rest-api-preload-paths.php b/tests/Alley/Wp/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php similarity index 98% rename from tests/alley/wp/alleyvate/features/test-disable-block-editor-rest-api-preload-paths.php rename to tests/Alley/Wp/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php index 60576591..c5b14223 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-block-editor-rest-api-preload-paths.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php @@ -19,7 +19,7 @@ /** * Tests for disabling block editor REST API preload paths. */ -final class Test_Disable_Block_Editor_Rest_Api_Preload_Paths extends Test_Case { +final class DisableBlockEditorRestApiPreloadPathsTest extends Test_Case { /** * Feature instance. diff --git a/tests/alley/wp/alleyvate/features/test-disable-comments.php b/tests/Alley/Wp/Alleyvate/Features/DisableCommentsTest.php similarity index 99% rename from tests/alley/wp/alleyvate/features/test-disable-comments.php rename to tests/Alley/Wp/Alleyvate/Features/DisableCommentsTest.php index 2d64cdf0..0bfcb3ec 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-comments.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableCommentsTest.php @@ -20,8 +20,8 @@ /** * Tests for fully disabling comment functionality. */ -final class Test_Disable_Comments extends Test_Case { - use Concerns\Remove_Meta_Box; +final class DisableCommentsTest extends Test_Case { + use Concerns\RemoveMetaBox; use Admin_Screen; use Refresh_Database; diff --git a/tests/alley/wp/alleyvate/features/test-disable-custom-fields-meta-box.php b/tests/Alley/Wp/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php similarity index 90% rename from tests/alley/wp/alleyvate/features/test-disable-custom-fields-meta-box.php rename to tests/Alley/Wp/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php index 3f3bf78f..960612b2 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-custom-fields-meta-box.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php @@ -19,8 +19,8 @@ /** * Tests for the disabling of the custom fields meta box. */ -final class Test_Disable_Custom_Fields_Meta_Box extends Test_Case { - use Concerns\Remove_Meta_Box; +final class DisableCustomFieldsMetaBoxTest extends Test_Case { + use Concerns\RemoveMetaBox; /** * Feature instance. diff --git a/tests/alley/wp/alleyvate/features/test-disable-dashboard-widgets.php b/tests/Alley/Wp/Alleyvate/Features/DisableDashboardWidgetsTest.php similarity index 96% rename from tests/alley/wp/alleyvate/features/test-disable-dashboard-widgets.php rename to tests/Alley/Wp/Alleyvate/Features/DisableDashboardWidgetsTest.php index 5167cddc..edb88dee 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-dashboard-widgets.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableDashboardWidgetsTest.php @@ -20,7 +20,7 @@ /** * Tests for disabling selected unpopular dashboard widgets. */ -final class Test_Disable_Dashboard_Widgets extends Test_Case { +final class DisableDashboardWidgetsTest extends Test_Case { use Admin_Screen; use Refresh_Database; diff --git a/tests/alley/wp/alleyvate/features/test-disable-deep-pagination.php b/tests/Alley/Wp/Alleyvate/Features/DisableDeepPaginationTest.php similarity index 91% rename from tests/alley/wp/alleyvate/features/test-disable-deep-pagination.php rename to tests/Alley/Wp/Alleyvate/Features/DisableDeepPaginationTest.php index c4666b21..d98f0253 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-deep-pagination.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableDeepPaginationTest.php @@ -22,28 +22,22 @@ /** * Tests for fully disabling comment functionality. */ -final class Test_Disable_Deep_Pagination extends Test_Case { +final class DisableDeepPaginationTest extends Test_Case { use Refresh_Database; use Admin_Screen; /** - * Feature instance. - * - * @var Disable_Deep_Pagination + * Feature instance.@var Disable_Deep_Pagination */ private Disable_Deep_Pagination $feature; /** - * Filter function for max number of pages. - * - * @var callable|null + * Filter function for max number of pages.@var callable|null */ private $filter = null; /** - * The wp_die_handler callable. - * - * @var callable|null + * The wp_die_handler callable.@var callable|null */ private $handler = null; @@ -88,8 +82,6 @@ protected function tearDown(): void { /** * Verify the maximum pages are listed at 100. - * - * @test */ public function test_maximum_posts_restricted() { $this->feature->boot(); @@ -107,8 +99,6 @@ public function test_maximum_posts_restricted() { /** * Do not filter WP Admin queries. - * - * @test */ public function test_admin_queries_are_unaffected() { // Enable the Admin screen. @@ -131,8 +121,6 @@ public function test_admin_queries_are_unaffected() { /** * Allow filtering of the maximum number of posts. - * - * @test */ public function test_maximum_number_of_posts_can_be_filtered() { // Enable the Admin screen. @@ -162,8 +150,6 @@ public function test_maximum_number_of_posts_can_be_filtered() { /** * Validate that all expected pages can be accessed. - * - * @test */ public function test_all_expected_available_pages_can_be_accessed() { // Enable the Admin screen. @@ -190,8 +176,6 @@ public function test_all_expected_available_pages_can_be_accessed() { * We should allow developers to dangerously override this filter in code, when necessary, as a * one-time override of the filter. This will allow us to not have to litter our code with hundreds * of one-time-use filters. - * - * @test */ public function test_can_dangerously_override_page_limit() { $this->feature->boot(); @@ -212,8 +196,6 @@ public function test_can_dangerously_override_page_limit() { /** * Unauthenticated REST queries should be filtered. - * - * @test */ public function test_unauthenticated_rest_queries_are_filtered() { $this->feature->boot(); @@ -229,8 +211,6 @@ public function test_unauthenticated_rest_queries_are_filtered() { /** * Authenticated REST queries should NOT be filtered. - * - * @test */ public function test_authenticated_rest_queries_are_not_filtered() { $this->feature->boot(); @@ -244,9 +224,7 @@ public function test_authenticated_rest_queries_are_not_filtered() { } /** - * Helper function for swapping out the max pages filter. - * - * @param int $max The max pages to return. + * Helper function for swapping out the max pages filter.@param int $max The max pages to return. */ private function filter_max_pages( int $max ): void { if ( ! empty( $this->filter ) ) { diff --git a/tests/alley/wp/alleyvate/features/test-disable-password-change-notification.php b/tests/Alley/Wp/Alleyvate/Features/DisablePasswordChangeNotificationTest.php similarity index 94% rename from tests/alley/wp/alleyvate/features/test-disable-password-change-notification.php rename to tests/Alley/Wp/Alleyvate/Features/DisablePasswordChangeNotificationTest.php index 2abe1f44..2d45455d 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-password-change-notification.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisablePasswordChangeNotificationTest.php @@ -20,7 +20,7 @@ /** * Tests for disabling the password change notification. */ -final class Test_Disable_Password_Change_Notification extends Test_Case { +final class DisablePasswordChangeNotificationTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/test-disable-sticky-posts.php b/tests/Alley/Wp/Alleyvate/Features/DisableStickyPostsTest.php similarity index 97% rename from tests/alley/wp/alleyvate/features/test-disable-sticky-posts.php rename to tests/Alley/Wp/Alleyvate/Features/DisableStickyPostsTest.php index b588117f..50929a18 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-sticky-posts.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableStickyPostsTest.php @@ -20,7 +20,7 @@ /** * Tests for fully disabling sticky posts. */ -final class Test_Disable_Sticky_Posts extends Test_Case { +final class DisableStickyPostsTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php b/tests/Alley/Wp/Alleyvate/Features/DisableTrackbacksTest.php similarity index 98% rename from tests/alley/wp/alleyvate/features/test-disable-trackbacks.php rename to tests/Alley/Wp/Alleyvate/Features/DisableTrackbacksTest.php index 081265d4..807192df 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisableTrackbacksTest.php @@ -18,7 +18,7 @@ /** * Tests for fully disabling pingback and trackback functionality. */ -final class Test_Disable_Trackbacks extends Test_Case { +final class DisableTrackbacksTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/test-disallow-file-edit.php b/tests/Alley/Wp/Alleyvate/Features/DisallowFileEditTest.php similarity index 94% rename from tests/alley/wp/alleyvate/features/test-disallow-file-edit.php rename to tests/Alley/Wp/Alleyvate/Features/DisallowFileEditTest.php index 725f716e..78d66f66 100644 --- a/tests/alley/wp/alleyvate/features/test-disallow-file-edit.php +++ b/tests/Alley/Wp/Alleyvate/Features/DisallowFileEditTest.php @@ -19,7 +19,7 @@ /** * Tests for the disallowing of file editing. */ -final class Test_Disallow_File_Edit extends Test_Case { +final class DisallowFileEditTest extends Test_Case { /** * Feature instance. diff --git a/tests/alley/wp/alleyvate/features/test-login-nonce.php b/tests/Alley/Wp/Alleyvate/Features/LoginNonceTest.php similarity index 98% rename from tests/alley/wp/alleyvate/features/test-login-nonce.php rename to tests/Alley/Wp/Alleyvate/Features/LoginNonceTest.php index 4e125a96..a9e04893 100644 --- a/tests/alley/wp/alleyvate/features/test-login-nonce.php +++ b/tests/Alley/Wp/Alleyvate/Features/LoginNonceTest.php @@ -23,7 +23,7 @@ /** * Tests for the login nonce. */ -final class Test_Login_Nonce extends Test_Case { +final class LoginNonceTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/test-prevent-framing.php b/tests/Alley/Wp/Alleyvate/Features/PreventFramingTest.php similarity index 98% rename from tests/alley/wp/alleyvate/features/test-prevent-framing.php rename to tests/Alley/Wp/Alleyvate/Features/PreventFramingTest.php index a8a78d08..4c439df3 100644 --- a/tests/alley/wp/alleyvate/features/test-prevent-framing.php +++ b/tests/Alley/Wp/Alleyvate/Features/PreventFramingTest.php @@ -20,7 +20,7 @@ /** * Tests for the preventing the iframing of a site. */ -final class Test_Prevent_Framing extends Test_Case { +final class PreventFramingTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/test-redirect-guess-shortcircuit.php b/tests/Alley/Wp/Alleyvate/Features/RedirectGuessShortcircuitTest.php similarity index 95% rename from tests/alley/wp/alleyvate/features/test-redirect-guess-shortcircuit.php rename to tests/Alley/Wp/Alleyvate/Features/RedirectGuessShortcircuitTest.php index c8665bf3..bc20c86d 100644 --- a/tests/alley/wp/alleyvate/features/test-redirect-guess-shortcircuit.php +++ b/tests/Alley/Wp/Alleyvate/Features/RedirectGuessShortcircuitTest.php @@ -20,7 +20,7 @@ /** * Tests for short-circuiting the redirect URL guessing for 404 requests. */ -final class Test_Redirect_Guess_Shortcircuit extends Test_Case { +final class RedirectGuessShortcircuitTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/test-remove-shortlink.php b/tests/Alley/Wp/Alleyvate/Features/RemoveShortlinkTest.php similarity index 95% rename from tests/alley/wp/alleyvate/features/test-remove-shortlink.php rename to tests/Alley/Wp/Alleyvate/Features/RemoveShortlinkTest.php index 456fc7aa..7a642ff5 100644 --- a/tests/alley/wp/alleyvate/features/test-remove-shortlink.php +++ b/tests/Alley/Wp/Alleyvate/Features/RemoveShortlinkTest.php @@ -20,7 +20,7 @@ /** * Tests for removing the shortlink link tag from the head of pages. */ -final class Test_Remove_Shortlink extends Test_Case { +final class RemoveShortlinkTest extends Test_Case { use Refresh_Database; /** diff --git a/tests/alley/wp/alleyvate/features/test-user-enumeration-restrictions.php b/tests/Alley/Wp/Alleyvate/Features/UserEnumerationRestrictionsTest.php similarity index 93% rename from tests/alley/wp/alleyvate/features/test-user-enumeration-restrictions.php rename to tests/Alley/Wp/Alleyvate/Features/UserEnumerationRestrictionsTest.php index 2755fd58..c3575dfc 100644 --- a/tests/alley/wp/alleyvate/features/test-user-enumeration-restrictions.php +++ b/tests/Alley/Wp/Alleyvate/Features/UserEnumerationRestrictionsTest.php @@ -16,11 +16,12 @@ use Mantle\Testing\Concerns\Refresh_Database; use Mantle\Testkit\Test_Case; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for the user enumeration restrictions feature. */ -final class Test_User_Enumeration_Restrictions extends Test_Case { +final class UserEnumerationRestrictionsTest extends Test_Case { use Refresh_Database; /** @@ -42,11 +43,10 @@ protected function setUp(): void { /** * User should receive the given response code when accessing user routes. * - * @dataProvider data_rest_enumeration_by_user - * * @param bool $logged_in Whether a user is logged in. * @param int $expected_status Expected response code. */ + #[DataProvider('data_rest_enumeration_by_user')] public function test_rest_enumeration_by_user( bool $logged_in, int $expected_status ): void { /* * Individual users can be read anonymously over the REST API only From 4f63a2a62455194109fab25e03b132ba97c0d6ae Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 11:10:48 -0400 Subject: [PATCH 13/19] Finishing phpunit 11 migration --- phpcs.xml | 5 +++++ phpunit.xml | 2 +- src/alley/wp/alleyvate/class-feature.php | 2 +- .../features/class-disable-deep-pagination.php | 2 +- .../alleyvate/features/class-prevent-framing.php | 2 +- .../Alleyvate/Features/CacheSlowQueriesTest.php | 0 .../Alleyvate/Features/CleanAdminBarTest.php | 0 .../Features/Concerns/RemoveMetaBox.php | 0 .../Features/DisableAppleNewsNonProdPushTest.php | 0 .../Features/DisableAttachmentRoutingTest.php | 0 ...DisableBlockEditorRestApiPreloadPathsTest.php | 8 ++++---- .../Alleyvate/Features/DisableCommentsTest.php | 8 ++++---- .../Features/DisableCustomFieldsMetaBoxTest.php | 0 .../Features/DisableDashboardWidgetsTest.php | 0 .../Features/DisableDeepPaginationTest.php | 16 ++++++++++++---- .../DisablePasswordChangeNotificationTest.php | 0 .../Features/DisableStickyPostsTest.php | 0 .../Alleyvate/Features/DisableTrackbacksTest.php | 4 ++-- .../Alleyvate/Features/DisallowFileEditTest.php | 0 .../Alleyvate/Features/LoginNonceTest.php | 0 .../Alleyvate/Features/PreventFramingTest.php | 0 .../Features/RedirectGuessShortcircuitTest.php | 0 .../Alleyvate/Features/RemoveShortlinkTest.php | 0 .../Features/UserEnumerationRestrictionsTest.php | 4 ++-- 24 files changed, 33 insertions(+), 20 deletions(-) rename tests/Alley/{Wp => WP}/Alleyvate/Features/CacheSlowQueriesTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/CleanAdminBarTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/Concerns/RemoveMetaBox.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableAttachmentRoutingTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php (93%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableCommentsTest.php (97%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableDashboardWidgetsTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableDeepPaginationTest.php (94%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisablePasswordChangeNotificationTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableStickyPostsTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisableTrackbacksTest.php (96%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/DisallowFileEditTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/LoginNonceTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/PreventFramingTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/RedirectGuessShortcircuitTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/RemoveShortlinkTest.php (100%) rename tests/Alley/{Wp => WP}/Alleyvate/Features/UserEnumerationRestrictionsTest.php (94%) diff --git a/phpcs.xml b/phpcs.xml index 545eb479..2a6591f2 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -41,6 +41,11 @@ tests/ + + + tests/ + + diff --git a/phpunit.xml b/phpunit.xml index 5e0707ba..878ea827 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,6 +8,6 @@ cacheDirectory=".phpunit.result.cache" > - tests/alley/wp/ + tests/alley/wp/ diff --git a/src/alley/wp/alleyvate/class-feature.php b/src/alley/wp/alleyvate/class-feature.php index 515c3d73..01031862 100644 --- a/src/alley/wp/alleyvate/class-feature.php +++ b/src/alley/wp/alleyvate/class-feature.php @@ -81,7 +81,7 @@ public function add_debug_information( $info ): array { $info['wp-alleyvate']['fields'] ??= []; $info['wp-alleyvate']['fields'][] = [ - 'label' => sprintf( + 'label' => \sprintf( /* translators: %s: Feature name. */ __( 'Feature: %s', 'alley' ), $this->handle, diff --git a/src/alley/wp/alleyvate/features/class-disable-deep-pagination.php b/src/alley/wp/alleyvate/features/class-disable-deep-pagination.php index 50fbd872..eab66e23 100644 --- a/src/alley/wp/alleyvate/features/class-disable-deep-pagination.php +++ b/src/alley/wp/alleyvate/features/class-disable-deep-pagination.php @@ -52,7 +52,7 @@ public static function filter__posts_where( $where, $wp_query ) { } wp_die( - sprintf( + \sprintf( /* translators: The maximum number of pages. */ esc_html__( 'Invalid Request: Pagination beyond page %d has been disabled for performance reasons.', 'alley' ), esc_html( $max_pages ), diff --git a/src/alley/wp/alleyvate/features/class-prevent-framing.php b/src/alley/wp/alleyvate/features/class-prevent-framing.php index f4d58861..40a8b724 100644 --- a/src/alley/wp/alleyvate/features/class-prevent-framing.php +++ b/src/alley/wp/alleyvate/features/class-prevent-framing.php @@ -81,7 +81,7 @@ public static function filter__wp_headers( $headers ): array { if ( ! \in_array( $headers['X-Frame-Options'], [ 'DENY', 'SAMEORIGIN' ], true ) && 0 !== strpos( $headers['X-Frame-Options'], 'ALLOW-FROM' ) ) { _doing_it_wrong( __METHOD__, - sprintf( + \sprintf( /* translators: %s: The value of the X-Frame-Options header. */ esc_html__( 'Invalid value for %s. Must be DENY, SAMEORIGIN, or ALLOW-FROM uri.', 'alley' ), 'X-Frame-Options' diff --git a/tests/Alley/Wp/Alleyvate/Features/CacheSlowQueriesTest.php b/tests/Alley/WP/Alleyvate/Features/CacheSlowQueriesTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/CacheSlowQueriesTest.php rename to tests/Alley/WP/Alleyvate/Features/CacheSlowQueriesTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/CleanAdminBarTest.php b/tests/Alley/WP/Alleyvate/Features/CleanAdminBarTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/CleanAdminBarTest.php rename to tests/Alley/WP/Alleyvate/Features/CleanAdminBarTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/Concerns/RemoveMetaBox.php b/tests/Alley/WP/Alleyvate/Features/Concerns/RemoveMetaBox.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/Concerns/RemoveMetaBox.php rename to tests/Alley/WP/Alleyvate/Features/Concerns/RemoveMetaBox.php diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php b/tests/Alley/WP/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableAppleNewsNonProdPushTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableAttachmentRoutingTest.php b/tests/Alley/WP/Alleyvate/Features/DisableAttachmentRoutingTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/DisableAttachmentRoutingTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableAttachmentRoutingTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php b/tests/Alley/WP/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php similarity index 93% rename from tests/Alley/Wp/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php index c5b14223..e43fff55 100644 --- a/tests/Alley/Wp/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php +++ b/tests/Alley/WP/Alleyvate/Features/DisableBlockEditorRestApiPreloadPathsTest.php @@ -64,13 +64,13 @@ public function test_disable_block_editor_rest_api_preload_paths(): void { // ph rest_get_route_for_post_type_items( 'wp_block' ) ), add_query_arg( 'context', 'edit', $rest_path ), - sprintf( '/wp/v2/types/%s?context=edit', $post_type ), + \sprintf( '/wp/v2/types/%s?context=edit', $post_type ), '/wp/v2/users/me', [ rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ], [ rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ], [ rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ], [ rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ], - sprintf( '%s/autosaves?context=edit', $rest_path ), + \sprintf( '%s/autosaves?context=edit', $rest_path ), '/wp/v2/settings', [ '/wp/v2/settings', 'OPTIONS' ], ]; @@ -111,13 +111,13 @@ public function check_preloads_paths( mixed $preload_paths, string $rest_path, s $this->assertContains( '/wp/v2/types?context=view', $preload_paths ); $this->assertContains( '/wp/v2/taxonomies?context=view', $preload_paths ); $this->assertContains( add_query_arg( 'context', 'edit', $rest_path ), $preload_paths ); - $this->assertContains( sprintf( '/wp/v2/types/%s?context=edit', $post_type ), $preload_paths ); + $this->assertContains( \sprintf( '/wp/v2/types/%s?context=edit', $post_type ), $preload_paths ); $this->assertContains( '/wp/v2/users/me', $preload_paths ); $this->assertContains( [ rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ], $preload_paths ); $this->assertContains( [ rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ], $preload_paths ); $this->assertContains( [ rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ], $preload_paths ); $this->assertContains( [ rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ], $preload_paths ); - $this->assertContains( sprintf( '%s/autosaves?context=edit', $rest_path ), $preload_paths ); + $this->assertContains( \sprintf( '%s/autosaves?context=edit', $rest_path ), $preload_paths ); $this->assertContains( '/wp/v2/settings', $preload_paths ); $this->assertContains( [ '/wp/v2/settings', 'OPTIONS' ], $preload_paths ); } diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableCommentsTest.php b/tests/Alley/WP/Alleyvate/Features/DisableCommentsTest.php similarity index 97% rename from tests/Alley/Wp/Alleyvate/Features/DisableCommentsTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableCommentsTest.php index 0bfcb3ec..b2a17b29 100644 --- a/tests/Alley/Wp/Alleyvate/Features/DisableCommentsTest.php +++ b/tests/Alley/WP/Alleyvate/Features/DisableCommentsTest.php @@ -187,7 +187,7 @@ public function test_remove_post_type_support(): void { $this->assertTrue( post_type_supports( 'post', 'comments' ) ); // Ensure the comment status is reported as open and the replies link exists out of the box. - $result = rest_do_request( sprintf( '/wp/v2/posts/%d', $post_id ) ); + $result = rest_do_request( \sprintf( '/wp/v2/posts/%d', $post_id ) ); $this->assertSame( 'open', $result->data['comment_status'] ); $this->assertArrayHasKey( 'replies', $result->get_links() ); @@ -198,7 +198,7 @@ public function test_remove_post_type_support(): void { $this->assertFalse( post_type_supports( 'post', 'comments' ) ); // Ensure the comment status is reported as closed and the replies link has been removed. - $result = rest_do_request( sprintf( '/wp/v2/posts/%d', $post_id ) ); + $result = rest_do_request( \sprintf( '/wp/v2/posts/%d', $post_id ) ); $this->assertSame( 'closed', $result->data['comment_status'] ); $this->assertArrayNotHasKey( 'replies', $result->get_links() ); } @@ -222,7 +222,7 @@ public function test_remove_rest_routes(): void { // Ensure comment routes are successful before the plugin is active. $result_generic = rest_do_request( new \WP_REST_Request( 'GET', '/wp/v2/comments' ) ); - $result_specific = rest_do_request( new \WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $comment_id ) ) ); + $result_specific = rest_do_request( new \WP_REST_Request( 'GET', \sprintf( '/wp/v2/comments/%d', $comment_id ) ) ); $this->assertSame( 200, $result_generic->get_status() ); $this->assertSame( 200, $result_specific->get_status() ); @@ -236,7 +236,7 @@ public function test_remove_rest_routes(): void { // Ensure comment routes 404. $result_generic = rest_do_request( new \WP_REST_Request( 'GET', '/wp/v2/comments' ) ); - $result_specific = rest_do_request( new \WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $comment_id ) ) ); + $result_specific = rest_do_request( new \WP_REST_Request( 'GET', \sprintf( '/wp/v2/comments/%d', $comment_id ) ) ); $this->assertSame( 404, $result_generic->get_status() ); $this->assertSame( 404, $result_specific->get_status() ); } diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php b/tests/Alley/WP/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableCustomFieldsMetaBoxTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableDashboardWidgetsTest.php b/tests/Alley/WP/Alleyvate/Features/DisableDashboardWidgetsTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/DisableDashboardWidgetsTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableDashboardWidgetsTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableDeepPaginationTest.php b/tests/Alley/WP/Alleyvate/Features/DisableDeepPaginationTest.php similarity index 94% rename from tests/Alley/Wp/Alleyvate/Features/DisableDeepPaginationTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableDeepPaginationTest.php index d98f0253..022a6d0a 100644 --- a/tests/Alley/Wp/Alleyvate/Features/DisableDeepPaginationTest.php +++ b/tests/Alley/WP/Alleyvate/Features/DisableDeepPaginationTest.php @@ -27,17 +27,23 @@ final class DisableDeepPaginationTest extends Test_Case { use Admin_Screen; /** - * Feature instance.@var Disable_Deep_Pagination + * Feature instance. + * + * @var Disable_Deep_Pagination */ private Disable_Deep_Pagination $feature; /** - * Filter function for max number of pages.@var callable|null + * Filter function for max number of pages. + * + * @var callable|null */ private $filter = null; /** - * The wp_die_handler callable.@var callable|null + * The wp_die_handler callable. + * + * @var callable|null */ private $handler = null; @@ -224,7 +230,9 @@ public function test_authenticated_rest_queries_are_not_filtered() { } /** - * Helper function for swapping out the max pages filter.@param int $max The max pages to return. + * Helper function for swapping out the max pages filter. + * + * @param int $max The max pages to return. */ private function filter_max_pages( int $max ): void { if ( ! empty( $this->filter ) ) { diff --git a/tests/Alley/Wp/Alleyvate/Features/DisablePasswordChangeNotificationTest.php b/tests/Alley/WP/Alleyvate/Features/DisablePasswordChangeNotificationTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/DisablePasswordChangeNotificationTest.php rename to tests/Alley/WP/Alleyvate/Features/DisablePasswordChangeNotificationTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableStickyPostsTest.php b/tests/Alley/WP/Alleyvate/Features/DisableStickyPostsTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/DisableStickyPostsTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableStickyPostsTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/DisableTrackbacksTest.php b/tests/Alley/WP/Alleyvate/Features/DisableTrackbacksTest.php similarity index 96% rename from tests/Alley/Wp/Alleyvate/Features/DisableTrackbacksTest.php rename to tests/Alley/WP/Alleyvate/Features/DisableTrackbacksTest.php index 807192df..eddef607 100644 --- a/tests/Alley/Wp/Alleyvate/Features/DisableTrackbacksTest.php +++ b/tests/Alley/WP/Alleyvate/Features/DisableTrackbacksTest.php @@ -90,7 +90,7 @@ public function test_remove_trackback_support(): void { $this->assertTrue( post_type_supports( 'post', 'trackbacks' ) ); // Ensure the ping status is reported as open out of the box. - $result = rest_do_request( sprintf( '/wp/v2/posts/%d', $post_id ) ); + $result = rest_do_request( \sprintf( '/wp/v2/posts/%d', $post_id ) ); $this->assertSame( 'open', $result->data['ping_status'] ); // Removing post type support happens on 'init', which has already occurred, so we need to call the callback directly. @@ -100,7 +100,7 @@ public function test_remove_trackback_support(): void { $this->assertFalse( post_type_supports( 'post', 'trackbacks' ) ); // Ensure the ping status is reported as closed. - $result = rest_do_request( sprintf( '/wp/v2/posts/%d', $post_id ) ); + $result = rest_do_request( \sprintf( '/wp/v2/posts/%d', $post_id ) ); $this->assertSame( 'closed', $result->data['ping_status'] ); } } diff --git a/tests/Alley/Wp/Alleyvate/Features/DisallowFileEditTest.php b/tests/Alley/WP/Alleyvate/Features/DisallowFileEditTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/DisallowFileEditTest.php rename to tests/Alley/WP/Alleyvate/Features/DisallowFileEditTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/LoginNonceTest.php b/tests/Alley/WP/Alleyvate/Features/LoginNonceTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/LoginNonceTest.php rename to tests/Alley/WP/Alleyvate/Features/LoginNonceTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/PreventFramingTest.php b/tests/Alley/WP/Alleyvate/Features/PreventFramingTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/PreventFramingTest.php rename to tests/Alley/WP/Alleyvate/Features/PreventFramingTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/RedirectGuessShortcircuitTest.php b/tests/Alley/WP/Alleyvate/Features/RedirectGuessShortcircuitTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/RedirectGuessShortcircuitTest.php rename to tests/Alley/WP/Alleyvate/Features/RedirectGuessShortcircuitTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/RemoveShortlinkTest.php b/tests/Alley/WP/Alleyvate/Features/RemoveShortlinkTest.php similarity index 100% rename from tests/Alley/Wp/Alleyvate/Features/RemoveShortlinkTest.php rename to tests/Alley/WP/Alleyvate/Features/RemoveShortlinkTest.php diff --git a/tests/Alley/Wp/Alleyvate/Features/UserEnumerationRestrictionsTest.php b/tests/Alley/WP/Alleyvate/Features/UserEnumerationRestrictionsTest.php similarity index 94% rename from tests/Alley/Wp/Alleyvate/Features/UserEnumerationRestrictionsTest.php rename to tests/Alley/WP/Alleyvate/Features/UserEnumerationRestrictionsTest.php index c3575dfc..f1c09c05 100644 --- a/tests/Alley/Wp/Alleyvate/Features/UserEnumerationRestrictionsTest.php +++ b/tests/Alley/WP/Alleyvate/Features/UserEnumerationRestrictionsTest.php @@ -46,7 +46,7 @@ protected function setUp(): void { * @param bool $logged_in Whether a user is logged in. * @param int $expected_status Expected response code. */ - #[DataProvider('data_rest_enumeration_by_user')] + #[DataProvider( 'dataprovider_rest_enumeration_by_user' )] public function test_rest_enumeration_by_user( bool $logged_in, int $expected_status ): void { /* * Individual users can be read anonymously over the REST API only @@ -98,7 +98,7 @@ public function test_rest_enumeration_by_user( bool $logged_in, int $expected_st * * @return array */ - public function data_rest_enumeration_by_user(): array { + public static function dataprovider_rest_enumeration_by_user(): array { return [ 'logged-out user' => [ false, 401 ], 'logged-in user' => [ true, 200 ], From 904693be091f1ffd104c9d405f596b1243e1eb44 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 11:13:25 -0400 Subject: [PATCH 14/19] Migrating to shared actions --- .github/workflows/all-pr-tests.yml | 49 ++++++++++++++++++++++++++++++ .github/workflows/cs.yml | 35 --------------------- .github/workflows/tests.yml | 20 ------------ composer.json | 2 ++ 4 files changed, 51 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/all-pr-tests.yml delete mode 100644 .github/workflows/cs.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/all-pr-tests.yml b/.github/workflows/all-pr-tests.yml new file mode 100644 index 00000000..d0e83faf --- /dev/null +++ b/.github/workflows/all-pr-tests.yml @@ -0,0 +1,49 @@ +name: "All Pull Request Tests" + +on: + pull_request: + branches: + - develop + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + # We use a single job to ensure that all steps run in the same environment and + # reduce the number of minutes used. + pr-tests: + # Don't run on draft PRs + if: github.event.pull_request.draft == false + # Timeout after 10 minutes + timeout-minutes: 10 + # Define a matrix of PHP/WordPress versions to test against + strategy: + matrix: + php: [8.1, 8.2, 8.3] + wordpress: ["latest"] + multisite: [false, true] + runs-on: ubuntu-latest + # Cancel any existing runs of this workflow + concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}-P${{ matrix.php }}-WP${{ matrix.wordpress }}-MS${{ matrix.multisite }} + cancel-in-progress: true + # Name the job in the matrix + name: "PR Tests PHP ${{ matrix.php }} WordPress ${{ matrix.wordpress }} Multisite ${{ matrix.multisite }}" + steps: + - uses: actions/checkout@v4 + + - name: Run General Tests + # See https://github.com/alleyinteractive/action-test-general for more options + uses: alleyinteractive/action-test-general@develop + + - name: Run Node Tests + # See https://github.com/alleyinteractive/action-test-node for more options. + # Defaults to the latest LTS version. + uses: alleyinteractive/action-test-node@develop + + - name: Run PHP Tests + # See https://github.com/alleyinteractive/action-test-php for more options + uses: alleyinteractive/action-test-php@develop + with: + php-version: '${{ matrix.php }}' + skip-wordpress-install: 'true' + wordpress-version: '${{ matrix.wordpress }}' + wordpress-multisite: '${{ matrix.multisite }}' diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml deleted file mode 100644 index 16809505..00000000 --- a/.github/workflows/cs.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Coding Standards - -on: - pull_request: - -jobs: - cs: - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - php: [ 8.3 ] - steps: - - name: Cancel previous runs of this workflow (pull requests only) - if: ${{ github.event_name == 'pull_request' }} - uses: styfle/cancel-workflow-action@0.5.0 - with: - access_token: ${{ github.token }} - - - name: Check out code - uses: actions/checkout@v3 - - - name: Set up PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - - - name: Install composer dependencies - uses: ramsey/composer-install@v2 - - - name: Run Linting - run: composer lint - - - name: Run PHP-CS-Fixer - run: vendor/bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no --allow-risky=yes diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index f5908701..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Tests - -on: - pull_request: - -jobs: - phpunit: - strategy: - fail-fast: true - matrix: - php: [ 8.1, 8.2, 8.3 ] - wp_version: [ "latest" ] - multisite: [ false, true ] - name: WordPress ${{ matrix.wp_version }} @ PHP ${{ matrix.php }} (WP_MULTISITE=${{ matrix.multisite }}) - uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main - with: - command: "phpunit" - php: ${{ matrix.php }} - wordpress: ${{ matrix.wp_version }} - multisite: ${{ matrix.multisite }} diff --git a/composer.json b/composer.json index 09af3bb9..90c5b4ba 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,10 @@ }, "scripts": { "fixer": "php-cs-fixer -v fix --allow-risky=yes", + "fixer:test": "php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no --allow-risky=yes", "lint": [ "@phpcs", + "@fixer:test", "@phpstan" ], "phpcbf": "phpcbf", From bb482918e102fe488a31b43ae265893f5ed6f3e7 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 11:17:25 -0400 Subject: [PATCH 15/19] Fix workflow --- .github/workflows/all-pr-tests.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/all-pr-tests.yml b/.github/workflows/all-pr-tests.yml index d0e83faf..92c2c862 100644 --- a/.github/workflows/all-pr-tests.yml +++ b/.github/workflows/all-pr-tests.yml @@ -2,8 +2,6 @@ name: "All Pull Request Tests" on: pull_request: - branches: - - develop types: [opened, synchronize, reopened, ready_for_review] jobs: From c36fb6e01a2bbc3bd2e901588c732c1e3857f04c Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 11:20:53 -0400 Subject: [PATCH 16/19] Fix workflow --- .github/workflows/all-pr-tests.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/all-pr-tests.yml b/.github/workflows/all-pr-tests.yml index 92c2c862..c789696f 100644 --- a/.github/workflows/all-pr-tests.yml +++ b/.github/workflows/all-pr-tests.yml @@ -32,11 +32,6 @@ jobs: # See https://github.com/alleyinteractive/action-test-general for more options uses: alleyinteractive/action-test-general@develop - - name: Run Node Tests - # See https://github.com/alleyinteractive/action-test-node for more options. - # Defaults to the latest LTS version. - uses: alleyinteractive/action-test-node@develop - - name: Run PHP Tests # See https://github.com/alleyinteractive/action-test-php for more options uses: alleyinteractive/action-test-php@develop From 79b2e2988b27fc37b02e4b147d37f1aca1562f84 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 11:44:38 -0400 Subject: [PATCH 17/19] Skip audit --- .github/workflows/all-pr-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/all-pr-tests.yml b/.github/workflows/all-pr-tests.yml index c789696f..9e80456b 100644 --- a/.github/workflows/all-pr-tests.yml +++ b/.github/workflows/all-pr-tests.yml @@ -37,6 +37,7 @@ jobs: uses: alleyinteractive/action-test-php@develop with: php-version: '${{ matrix.php }}' + skip-audit: 'true' skip-wordpress-install: 'true' wordpress-version: '${{ matrix.wordpress }}' wordpress-multisite: '${{ matrix.multisite }}' From 17f1d05e0ca1617562e3240d42a33679d8997cb3 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 26 Aug 2024 11:47:44 -0400 Subject: [PATCH 18/19] Disable fail-fast, fix phpunit --- .github/workflows/all-pr-tests.yml | 1 + phpunit.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/all-pr-tests.yml b/.github/workflows/all-pr-tests.yml index 9e80456b..8b163f59 100644 --- a/.github/workflows/all-pr-tests.yml +++ b/.github/workflows/all-pr-tests.yml @@ -14,6 +14,7 @@ jobs: timeout-minutes: 10 # Define a matrix of PHP/WordPress versions to test against strategy: + fail-fast: false matrix: php: [8.1, 8.2, 8.3] wordpress: ["latest"] diff --git a/phpunit.xml b/phpunit.xml index 878ea827..557c77f2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,6 +8,6 @@ cacheDirectory=".phpunit.result.cache" > - tests/alley/wp/ + tests/Alley/WP/ From 6c29fd62be013527a924a282388e9b4b5e1563e9 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Tue, 3 Sep 2024 10:59:03 -0400 Subject: [PATCH 19/19] Fix class --- .../WP/Alleyvate/Features/DisableSiteHealthDirectoriesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Alley/WP/Alleyvate/Features/DisableSiteHealthDirectoriesTest.php b/tests/Alley/WP/Alleyvate/Features/DisableSiteHealthDirectoriesTest.php index da2f8719..e813087d 100644 --- a/tests/Alley/WP/Alleyvate/Features/DisableSiteHealthDirectoriesTest.php +++ b/tests/Alley/WP/Alleyvate/Features/DisableSiteHealthDirectoriesTest.php @@ -20,7 +20,7 @@ /** * Tests for Disable_Site_Health_Directories feature. */ -final class Test_Disable_Site_Health_Directories extends Test_Case { +final class DisableSiteHealthDirectoriesTest extends Test_Case { use Refresh_Database; /**