diff --git a/src/Helper/Helper_Interface_Deprecated_Features.php b/src/Helper/Helper_Interface_Deprecated_Features.php index 0c967d7ea..f90a76e39 100644 --- a/src/Helper/Helper_Interface_Deprecated_Features.php +++ b/src/Helper/Helper_Interface_Deprecated_Features.php @@ -31,16 +31,17 @@ interface Helper_Interface_Deprecated_Features { * - `group` (string) Deprecation::GROUP_UNSUPPORTED or Deprecation::GROUP_DEPRECATED * - `removed_in` (string) The Gravity PDF version the feature is, or will be, removed in * - `url` (string) Where the upgrade instructions live - * - `detect` (callable) Returns what was found on this site, and an empty array when the feature is unused + * - `detect` (callable) Returns what was found on this site, and an empty array when the feature is unused. + * Optional when `hooks` is declared * * A feature the default sentence describes badly declares one more: * * - `notice` (string) What becomes of the feature, taking the removal version as `%s`. Read by every * surface, so it has to make sense with nothing else around it * - * A feature made up of hooks declares more, so the detector can name the hooks and their replacements: + * A feature made up of hooks declares more. Without a `detect`, it's detected as hook name mapped to listener count: * - * - `hooks` (array) Each removed hook mapped to its replacement, '' when none exists + * - `hooks` (array) Each deprecated hook mapped to its replacement, '' when none exists * - `deprecated_in` (string) Optional. The Gravity PDF version the hooks were deprecated in, * read by Deprecation::apply_filters() while they still fire * - `hook_prefix` (string) Optional. Claims any hook starting with it as well, which is diff --git a/src/Statics/Deprecation.php b/src/Statics/Deprecation.php index a526077ed..50b0014b4 100644 --- a/src/Statics/Deprecation.php +++ b/src/Statics/Deprecation.php @@ -64,7 +64,7 @@ class Deprecation { protected static function get_providers(): array { return [ Deprecation_V3::class, - Deprecation_Tools_Tab::class, + Deprecation_Hooks::class, ]; } @@ -120,7 +120,7 @@ public static function get_signals(): array { $detected = []; foreach ( static::get_features() as $feature_key => $feature ) { - $detected[ $feature_key ] = call_user_func( $feature['detect'] ); + $detected[ $feature_key ] = static::detect_feature( $feature ); } static::$signals[ $key ] = array_filter( $detected ); @@ -129,6 +129,32 @@ public static function get_signals(): array { return static::$signals[ $key ]; } + /** + * Run a feature's detector, or count the listeners on its hooks when it has none + * + * @param array $feature The feature's registration + * + * @since 6.19.0 + */ + protected static function detect_feature( array $feature ): array { + if ( static::is_hook_only( $feature ) ) { + return static::get_hooks_with_listeners( $feature['hooks'], $feature['hook_prefix'] ?? '', $feature['internal_callbacks'] ?? [] ); + } + + return call_user_func( $feature['detect'] ); + } + + /** + * Whether a feature is detected purely by the listeners on its hooks + * + * @param array $feature The feature's registration + * + * @since 6.19.0 + */ + public static function is_hook_only( array $feature ): bool { + return isset( $feature['hooks'] ) && ! isset( $feature['detect'] ); + } + /** * Forget what the detectors found this request, here and in every provider * @@ -358,12 +384,23 @@ public static function apply_filters( string $hook_name, array $args, string $re $replacement, $removed_in === '' ? '' : sprintf( /* translators: %s: The Gravity PDF version the filter is removed in */ - esc_html__( 'This filter is removed in Gravity PDF %s.', 'gravity-pdf' ), + esc_html__( 'This hook is removed in Gravity PDF %s.', 'gravity-pdf' ), $removed_in ) ); } + /** + * Fire one of the deprecated actions, warning any third party still listening to it + * + * @param string $hook_name The deprecated action to fire + * + * @since 6.19.0 + */ + public static function do_action( string $hook_name ): void { + static::apply_filters( $hook_name, [ '' ] ); + } + /** * Whether anything worth reporting is listening to a deprecated hook * @@ -453,7 +490,7 @@ protected static function log_deprecated_filter( string $hook_name, string $repl $log->warning( sprintf( - 'The %1$s filter has a third-party listener attached%2$s.%3$s', + 'The %1$s hook has a third-party listener attached%2$s.%3$s', $hook_name, $removed_in !== '' ? sprintf( ' and is removed in Gravity PDF %s', $removed_in ) : '', $replacement !== '' ? sprintf( ' Use the %s filter instead.', $replacement ) : '' diff --git a/src/Statics/Deprecation_Hooks.php b/src/Statics/Deprecation_Hooks.php new file mode 100644 index 000000000..207fbf47c --- /dev/null +++ b/src/Statics/Deprecation_Hooks.php @@ -0,0 +1,62 @@ + [ + 'label' => __( 'Tools Tab Actions and Filters', 'gravity-pdf' ), + 'group' => Deprecation::GROUP_DEPRECATED, + 'deprecated_in' => '6.19.0', + 'removed_in' => '7.0', + 'url' => 'https://docs.gravitypdf.com/developers/filters/gfpdf_settings_tools/', + /* translators: %s: The Gravity PDF version the Tools tab hooks stop running in */ + 'notice' => __( 'Settings a plugin or custom code added to the Gravity PDF Tools tab now appear at the bottom of the General tab and will be removed in version %s. Ask your developer to update the code.', 'gravity-pdf' ), + 'hooks' => [ + 'gfpdf_settings_tools' => 'gfpdf_settings_general', + 'gfpdf_post_tools_settings_page' => 'gfpdf_post_general_settings_page', + ], + ], + ]; + } + + /** + * @inheritDoc + * @since 6.19.0 + */ + public static function get_stored_options(): array { + return []; + } + + /** + * @inheritDoc + * @since 6.19.0 + */ + public static function flush_cache(): void {} +} diff --git a/src/Statics/Deprecation_Tools_Tab.php b/src/Statics/Deprecation_Tools_Tab.php deleted file mode 100644 index 282576b1e..000000000 --- a/src/Statics/Deprecation_Tools_Tab.php +++ /dev/null @@ -1,88 +0,0 @@ - [ - 'label' => __( 'Tools Tab Actions and Filters', 'gravity-pdf' ), - 'group' => Deprecation::GROUP_UNSUPPORTED, - 'removed_in' => static::REMOVED_IN, - 'url' => 'https://docs.gravitypdf.com/developers/filters/gfpdf_settings_tools/', - 'detect' => [ static::class, 'get_active_hooks' ], - /* translators: %s: The Gravity PDF version the Tools tab was removed in */ - 'notice' => __( 'Custom code on this site adds to the Tools tab, which was removed in Gravity PDF %s, so what it adds is no longer shown. Move it to the General tab.', 'gravity-pdf' ), - 'hooks' => static::get_hooks(), - ], - ]; - } - - /** - * The hooks the Tools tab fired, mapped to their General tab equivalent - * - * @return array - * @since 6.19.0 - */ - protected static function get_hooks(): array { - return [ - 'gfpdf_settings_tools' => 'gfpdf_settings_general', - 'gfpdf_post_tools_settings_page' => 'gfpdf_post_general_settings_page', - ]; - } - - /** - * Get the Tools tab hooks that still have a listener attached - * - * @return array Hook name mapped to the number of listeners - * @since 6.19.0 - */ - public static function get_active_hooks(): array { - return Deprecation::get_hooks_with_listeners( static::get_hooks() ); - } - - /** - * @inheritDoc - * @since 6.19.0 - */ - public static function get_stored_options(): array { - return []; - } - - /** - * @inheritDoc - * @since 6.19.0 - */ - public static function flush_cache(): void {} -} diff --git a/src/Statics/Deprecation_V3.php b/src/Statics/Deprecation_V3.php index 7e2a9c389..3b9429a10 100644 --- a/src/Statics/Deprecation_V3.php +++ b/src/Statics/Deprecation_V3.php @@ -122,7 +122,6 @@ public static function get_features(): array { 'group' => Deprecation::GROUP_UNSUPPORTED, 'removed_in' => static::REMOVED_IN, 'url' => 'https://docs.gravitypdf.com/upgrade/deprecated-filters/', - 'detect' => [ static::class, 'get_active_deprecated_filters' ], /* The label is a category, so out of its report row the fallback would read as the whole hook API */ /* translators: %s: The Gravity PDF version the hooks were removed in */ 'notice' => __( 'Custom code on this site uses Gravity PDF hooks that were removed in version %s and has stopped running. Update it to use the current hooks.', 'gravity-pdf' ), @@ -175,12 +174,13 @@ protected static function get_deprecated_filters(): array { /** * Get the removed v3 hooks that still have a listener attached * - * Nothing in core registers on these any more, so every callback found is third party. - * * @return array Hook name mapped to the number of listeners * @since 6.17.0 + * @deprecated 6.19.0 Read `deprecated_filters` from Deprecation::get_signals() */ public static function get_active_deprecated_filters(): array { + _deprecated_function( __METHOD__, '6.19.0', Deprecation::class . '::get_signals()' ); + return Deprecation::get_hooks_with_listeners( static::get_deprecated_filters(), static::HOOK_PREFIX ); } diff --git a/src/View/View_Settings.php b/src/View/View_Settings.php index 6a83d7bd0..a253578a8 100644 --- a/src/View/View_Settings.php +++ b/src/View/View_Settings.php @@ -11,6 +11,7 @@ use GFPDF\Helper\Helper_Misc; use GFPDF\Helper\Helper_Options_Fields; use GFPDF\Helper\Helper_Templates; +use GFPDF\Statics\Deprecation; use GFPDF_Major_Compatibility_Checks; use GFPDF_Vendor\Psr\Log\LoggerInterface; @@ -270,6 +271,26 @@ public function general() { }, ]; + if ( $vars['edit_cap'] ) { + $this->options->register_settings( [ 'tools' => Deprecation::apply_filters( 'gfpdf_settings_tools', [ [] ] ) ] ); + } + + if ( $markup->get_section_fields( 'gfpdf_settings_tools' ) !== [] ) { + $tools_section = [ + 'id' => 'gfpdf_settings_tools', + 'width' => 'full', + 'title' => __( 'Tools', 'gravity-pdf' ), + 'callback' => static function () use ( $markup ) { + $markup->output_settings_fields( 'gfpdf_settings_tools', $markup::ENABLE_PANEL_TITLE ); + }, + 'content_class' => 'gform_settings_form', + ]; + + $vars['tools_callback'] = static function () use ( $markup, $tools_section ) { + $markup->fieldset( $tools_section, true ); + }; + } + /* load the system status view */ $this->load( 'general', $vars ); } diff --git a/src/View/View_System_Report.php b/src/View/View_System_Report.php index 902544686..0ecc84006 100644 --- a/src/View/View_System_Report.php +++ b/src/View/View_System_Report.php @@ -186,9 +186,13 @@ public function get_deprecated_feature( string $key, array $signal ): array { $feature = Deprecation::get_feature( $key ); $descriptions = $this->get_deprecated_feature_descriptions(); - $description = isset( $descriptions[ $key ] ) - ? call_user_func( $descriptions[ $key ], $signal, $feature ) - : $this->get_default_feature_description( $signal ); + if ( isset( $descriptions[ $key ] ) ) { + $description = call_user_func( $descriptions[ $key ], $signal, $feature ); + } elseif ( Deprecation::is_hook_only( $feature ) ) { + $description = $this->get_deprecated_filter_feature( $signal ); + } else { + $description = $this->get_default_feature_description( $signal ); + } /* Whatever the description leaves out, the feature's own registration answers */ return $description + [ @@ -201,8 +205,7 @@ public function get_deprecated_feature( string $key, array $signal ): array { /** * The method that describes each feature's detections, keyed by the feature it describes * - * A feature with no entry here is described generically, so a newly registered one reports something usable - * before it has copy of its own. + * A feature with no entry here is described by its listener counts if it's hook-only, otherwise generically. * * @return array * @since 6.17.0 @@ -212,8 +215,6 @@ protected function get_deprecated_feature_descriptions(): array { 'legacy_templates' => [ $this, 'get_legacy_templates_feature' ], 'business_plus_templates' => [ $this, 'get_legacy_templates_feature' ], 'legacy_endpoint' => [ $this, 'get_legacy_endpoint_feature' ], - 'deprecated_filters' => [ $this, 'get_deprecated_filter_feature' ], - 'tools_tab_hooks' => [ $this, 'get_deprecated_filter_feature' ], ]; } @@ -315,7 +316,7 @@ static function ( $form_id ) { } /** - * Describe the removed hooks that still have a listener attached + * Describe the deprecated hooks that still have a listener attached * * @param array $filters Hook name mapped to the number of listeners * diff --git a/src/View/html/Settings/general.php b/src/View/html/Settings/general.php index 050120f56..44b7961af 100644 --- a/src/View/html/Settings/general.php +++ b/src/View/html/Settings/general.php @@ -52,4 +52,16 @@ /* See https://docs.gravitypdf.com/developers/actions/gfpdf_post_general_settings_page for more details about this action */ do_action( 'gfpdf_post_general_settings_page' ); ?> + + + + +
+ + +
+ + + + diff --git a/tests/phpunit/integration/Controller/Test_Controller_System_Report.php b/tests/phpunit/integration/Controller/Test_Controller_System_Report.php index c98c29ce2..0bcf89a8f 100644 --- a/tests/phpunit/integration/Controller/Test_Controller_System_Report.php +++ b/tests/phpunit/integration/Controller/Test_Controller_System_Report.php @@ -411,12 +411,12 @@ public function test_system_report_removed_filters() { } public function test_system_report_tools_tab_hooks() { - $this->assertArrayNotHasKey( 'tools_tab_hooks', $this->get_unsupported_features() ); + $this->assertArrayNotHasKey( 'tools_tab_hooks', $this->get_report_section( Deprecation::GROUP_DEPRECATED ) ); add_filter( 'gfpdf_settings_tools', '__return_empty_array' ); Deprecation::flush_cache(); - $items = $this->get_unsupported_features(); + $items = $this->get_report_section( Deprecation::GROUP_DEPRECATED ); $this->assertArrayHasKey( 'tools_tab_hooks', $items ); $this->assertSame( 'gfpdf_settings_tools has 1 listener', $items['tools_tab_hooks']['value_export'] ); @@ -459,8 +459,7 @@ public function test_debug_information_reports_a_clean_site() { $this->assertStringContainsString( '

Unsupported Features

', $info['gravity-pdf-unsupported']['description'] ); $this->assertStringNotContainsString( '

', $info['gravity-pdf-unsupported']['description'] ); - /* Nothing declares the deprecated group since 7.0, so no surface carries an empty panel for it */ - $this->assertArrayNotHasKey( 'gravity-pdf-deprecated', $info ); + $this->assertSame( 'None detected', $info['gravity-pdf-deprecated']['fields']['deprecated']['value'] ); } public function test_debug_information_is_gated_on_the_gravity_forms_capability() { diff --git a/tests/phpunit/integration/Helper/Test_Settings.php b/tests/phpunit/integration/Helper/Test_Settings.php index 031e18c01..4e606ebc4 100644 --- a/tests/phpunit/integration/Helper/Test_Settings.php +++ b/tests/phpunit/integration/Helper/Test_Settings.php @@ -122,6 +122,79 @@ private function add_addon_2() { ); } + /** + * Render the General tab for a user who can, or can't, edit the settings + */ + private function render_general_tab( bool $can_edit ): string { + global $gfpdf; + + $user = $this->factory->user->create_and_get( [ 'role' => $can_edit ? 'administrator' : 'subscriber' ] ); + $user->add_cap( $can_edit ? 'gform_full_access' : 'gravityforms_view_settings' ); + wp_set_current_user( $user->ID ); + + $gfpdf->options->register_settings( $gfpdf->options->get_registered_fields() ); + + ob_start(); + $this->view->general(); + + return ob_get_clean(); + } + + private function add_tools_tab_listeners(): void { + add_filter( + 'gfpdf_settings_tools', + static function ( $settings ) { + $settings['my_tool'] = [ + 'id' => 'my_tool', + 'name' => 'My Tool', + 'type' => 'descriptive_text', + 'desc' => 'my-tool-description', + ]; + + return $settings; + } + ); + + add_action( + 'gfpdf_post_tools_settings_page', + static function () { + echo 'my-tools-action'; + } + ); + } + + public function test_the_tools_tab_hooks_run_at_the_bottom_of_the_general_tab() { + $this->setExpectedDeprecated( 'gfpdf_settings_tools' ); + $this->setExpectedDeprecated( 'gfpdf_post_tools_settings_page' ); + $this->add_tools_tab_listeners(); + + $html = $this->render_general_tab( true ); + + /* Outside the General form, which posts to options.php, then the action last */ + $general_form_end = strpos( $html, '' ); + $field = strpos( $html, 'my-tool-description' ); + $action = strpos( $html, 'my-tools-action' ); + + $this->assertMatchesRegularExpression( '#]*>\s*Tools\s*#', $html ); + $this->assertNotFalse( $general_form_end ); + $this->assertNotFalse( $field ); + $this->assertGreaterThan( $general_form_end, $field ); + $this->assertGreaterThan( $field, $action ); + } + + public function test_the_tools_tab_hooks_need_the_edit_settings_capability() { + $this->add_tools_tab_listeners(); + + $html = $this->render_general_tab( false ); + + $this->assertStringNotContainsString( 'my-tool-description', $html ); + $this->assertStringNotContainsString( 'my-tools-action', $html ); + } + + public function test_the_general_tab_has_one_form_without_tools_tab_listeners() { + $this->assertSame( 1, substr_count( $this->render_general_tab( true ), '

assertSame( - [ 'unsupported', 'php', 'directories', 'global', 'security', 'cache' ], + [ 'unsupported', 'deprecated', 'php', 'directories', 'global', 'security', 'cache' ], array_column( $structure['tables'], 'id' ) ); } diff --git a/tests/phpunit/integration/Statics/Test_Deprecation.php b/tests/phpunit/integration/Statics/Test_Deprecation.php index d46a411a2..d7a9a4ade 100644 --- a/tests/phpunit/integration/Statics/Test_Deprecation.php +++ b/tests/phpunit/integration/Statics/Test_Deprecation.php @@ -143,8 +143,7 @@ public function test_a_provider_supplies_its_own_features() { Fake_Deprecation::get_groups() ); - /* Every feature the v3 provider declares is gone in 7.0, so the deprecated group is left out entirely */ - $this->assertSame( [ Deprecation::GROUP_UNSUPPORTED ], Deprecation::get_groups() ); + $this->assertSame( [ Deprecation::GROUP_UNSUPPORTED, Deprecation::GROUP_DEPRECATED ], Deprecation::get_groups() ); Fake_Deprecated_Features::$detections = []; } @@ -168,6 +167,26 @@ public function test_delete_stored_data_removes_what_each_provider_stores() { $this->assertFalse( get_option( Deprecation_V3::LEGACY_ENDPOINT_OPTION ) ); } + public function test_a_hook_only_feature_reports_its_listeners() { + add_filter( Fake_Internal_Listener_Features::HOOK, Fake_Internal_Listener_Features::INTERNAL_CALLBACK ); + + $this->assertSame( [], Fake_Production_Deprecation::get_signals() ); + + add_filter( Fake_Internal_Listener_Features::HOOK, '__return_empty_string' ); + add_filter( Fake_Internal_Listener_Features::HOOK_PREFIX . '5', '__return_empty_string' ); + Fake_Production_Deprecation::flush_cache(); + + $this->assertSame( + [ + 'fake_hooks' => [ + Fake_Internal_Listener_Features::HOOK_PREFIX . '5' => 1, + Fake_Internal_Listener_Features::HOOK => 1, + ], + ], + Fake_Production_Deprecation::get_signals() + ); + } + public function test_get_feature_is_empty_for_an_unregistered_id() { $this->assertSame( [], Deprecation::get_feature( 'not-a-feature' ) ); } @@ -244,6 +263,8 @@ class Fake_Internal_Listener_Features implements Helper_Interface_Deprecated_Fea const HOOK = 'gfpdf_fake_internal_filter'; + const HOOK_PREFIX = 'gfpdf_fake_dynamic_'; + const INTERNAL_CALLBACK = [ self::class, 'internal_callback' ]; public static function get_features(): array { @@ -253,18 +274,14 @@ public static function get_features(): array { 'group' => Deprecation::GROUP_DEPRECATED, 'removed_in' => '7.1', 'url' => 'https://example.org/upgrade/fake-hooks/', - 'detect' => [ static::class, 'detect' ], 'hooks' => [ self::HOOK => '' ], + 'hook_prefix' => self::HOOK_PREFIX, 'deprecated_in' => '6.17.0', 'internal_callbacks' => [ self::INTERNAL_CALLBACK ], ], ]; } - public static function detect(): array { - return []; - } - public static function internal_callback( string $value ): string { return $value . ':internal'; } diff --git a/tests/phpunit/integration/Statics/Test_Deprecation_Tools_Tab.php b/tests/phpunit/integration/Statics/Test_Deprecation_Hooks.php similarity index 73% rename from tests/phpunit/integration/Statics/Test_Deprecation_Tools_Tab.php rename to tests/phpunit/integration/Statics/Test_Deprecation_Hooks.php index a0464a308..04f0a7b25 100644 --- a/tests/phpunit/integration/Statics/Test_Deprecation_Tools_Tab.php +++ b/tests/phpunit/integration/Statics/Test_Deprecation_Hooks.php @@ -16,7 +16,7 @@ /** * @group statics */ -class Test_Deprecation_Tools_Tab extends TestCase { +class Test_Deprecation_Hooks extends TestCase { use ResetsDetectedFeatures; @@ -30,8 +30,9 @@ public function set_up(): void { public function test_the_tools_tab_feature_is_registered() { $feature = Deprecation::get_feature( 'tools_tab_hooks' ); - $this->assertSame( Deprecation::GROUP_UNSUPPORTED, $feature['group'] ); - $this->assertSame( '6.19.0', $feature['removed_in'] ); + $this->assertSame( Deprecation::GROUP_DEPRECATED, $feature['group'] ); + $this->assertSame( '6.19.0', $feature['deprecated_in'] ); + $this->assertSame( '7.0', $feature['removed_in'] ); $this->assertSame( [ 'gfpdf_settings_tools' => 'gfpdf_settings_general', @@ -39,14 +40,13 @@ public function test_the_tools_tab_feature_is_registered() { ], $feature['hooks'] ); - $this->assertStringContainsString( '6.19.0', Deprecation::get_feature_notice( $feature ) ); + $this->assertStringContainsString( 'version 7.0', Deprecation::get_feature_notice( $feature ) ); } /** - * Nothing in core fires or listens to these any more, so a clean install reports nothing + * Core fires these but never listens, so a clean install reports nothing */ public function test_a_clean_install_reports_nothing() { - $this->assertSame( [], Deprecation_Tools_Tab::get_active_hooks() ); $this->assertArrayNotHasKey( 'tools_tab_hooks', Deprecation::get_signals() ); } @@ -57,7 +57,7 @@ public function test_listeners_on_the_tools_tab_hooks_are_reported() { add_action( 'gfpdf_post_tools_settings_page', $callback ); add_action( 'gfpdf_post_tools_settings_page', '__return_null' ); - /* A similarly named hook isn't one of the removed ones */ + /* A similarly named hook isn't one of these */ add_filter( 'gfpdf_settings_tools_sanitize', $callback ); $this->assertSame( @@ -65,12 +65,8 @@ public function test_listeners_on_the_tools_tab_hooks_are_reported() { 'gfpdf_post_tools_settings_page' => 2, 'gfpdf_settings_tools' => 1, ], - Deprecation_Tools_Tab::get_active_hooks() + Deprecation::refresh_signals()['tools_tab_hooks'] ); - - Deprecation::flush_cache(); - - $this->assertArrayHasKey( 'tools_tab_hooks', Deprecation::refresh_signals() ); $this->assertContains( 'tools_tab_hooks', Deprecation::get_detected_features() ); remove_filter( 'gfpdf_settings_tools', $callback ); diff --git a/tests/phpunit/integration/Statics/Test_Deprecation_V3.php b/tests/phpunit/integration/Statics/Test_Deprecation_V3.php index 60ee7ce92..654da622e 100644 --- a/tests/phpunit/integration/Statics/Test_Deprecation_V3.php +++ b/tests/phpunit/integration/Statics/Test_Deprecation_V3.php @@ -179,13 +179,13 @@ public function test_get_legacy_download_urls_skips_trashed_forms() { $this->assertSame( [], Deprecation_V3::get_legacy_download_urls() ); } - public function test_get_active_deprecated_filters_includes_dynamic_hooks() { + public function test_deprecated_filters_include_dynamic_hooks() { $callback = '__return_true'; add_filter( 'gfpdfe_pdf_template_10', $callback ); add_filter( 'gfpdf_rtl', $callback ); - $active = Deprecation_V3::get_active_deprecated_filters(); + $active = Deprecation::get_signals()['deprecated_filters']; $this->assertSame( 1, $active['gfpdfe_pdf_template_10'] ); $this->assertSame( 1, $active['gfpdf_rtl'] ); @@ -194,14 +194,14 @@ public function test_get_active_deprecated_filters_includes_dynamic_hooks() { remove_filter( 'gfpdf_rtl', $callback ); } - public function test_get_active_deprecated_filters_includes_the_legacy_hooks() { + public function test_deprecated_filters_include_the_legacy_hooks() { $callback = '__return_true'; /* These carry the gfpdf_legacy_ prefix rather than gfpdfe_, so only the map can find them */ add_filter( 'gfpdf_legacy_save_path', $callback ); add_action( 'gfpdf_legacy_pre_view_or_download_pdf', $callback ); - $active = Deprecation_V3::get_active_deprecated_filters(); + $active = Deprecation::get_signals()['deprecated_filters']; $this->assertSame( 1, $active['gfpdf_legacy_save_path'] ); $this->assertSame( 1, $active['gfpdf_legacy_pre_view_or_download_pdf'] ); @@ -210,11 +210,16 @@ public function test_get_active_deprecated_filters_includes_the_legacy_hooks() { remove_action( 'gfpdf_legacy_pre_view_or_download_pdf', $callback ); } - /** - * Nothing in core listens to these any more, so every callback the detector finds belongs to a third party - */ - public function test_get_active_deprecated_filters_reports_nothing_on_a_clean_install() { - $this->assertSame( [], Deprecation_V3::get_active_deprecated_filters() ); + public function test_deprecated_filters_report_nothing_on_a_clean_install() { + $this->assertArrayNotHasKey( 'deprecated_filters', Deprecation::get_signals() ); + } + + public function test_get_active_deprecated_filters_is_deprecated_but_still_works() { + $this->setExpectedDeprecated( 'GFPDF\\Statics\\Deprecation_V3::get_active_deprecated_filters' ); + + add_filter( 'gfpdf_rtl', '__return_true' ); + + $this->assertSame( [ 'gfpdf_rtl' => 1 ], Deprecation_V3::get_active_deprecated_filters() ); } /** diff --git a/tests/phpunit/integration/Test_Hook_Inventory.php b/tests/phpunit/integration/Test_Hook_Inventory.php index da7ff9939..24cf41be2 100644 --- a/tests/phpunit/integration/Test_Hook_Inventory.php +++ b/tests/phpunit/integration/Test_Hook_Inventory.php @@ -36,6 +36,7 @@ class Test_Hook_Inventory extends WP_UnitTestCase { */ private const WRAPPERS = [ 'deprecation::apply_filters' => [ 'filter', 0, 1, 0, [] ], + 'deprecation::do_action' => [ 'action', 0, 1, 0, [] ], 'save_pdf_and_do_action' => [ 'action', 2, 3, 5, [ '_{form_id}' ] ], ]; diff --git a/tests/phpunit/snapshots/hooks.txt b/tests/phpunit/snapshots/hooks.txt index 7378e6b0c..536306fbc 100644 --- a/tests/phpunit/snapshots/hooks.txt +++ b/tests/phpunit/snapshots/hooks.txt @@ -37,6 +37,7 @@ action gfpdf_post_save_notification_pdf 6 action gfpdf_post_save_notification_pdf_{form_id} 6 action gfpdf_post_save_pdf 5 action gfpdf_post_save_pdf_{form_id} 5 +action gfpdf_post_tools_settings_page 0 action gfpdf_post_uninstall_plugin 0 action gfpdf_post_view_or_download_pdf 5 action gfpdf_pre_generate_and_save_pdf 3 @@ -220,6 +221,7 @@ filter gfpdf_settings_general_security 1 filter gfpdf_settings_licenses 1 filter gfpdf_settings_navigation 1 filter gfpdf_settings_sanitize 4 +filter gfpdf_settings_tools 1 filter gfpdf_shortcode_signing_user_id 3 filter gfpdf_show_field_value 3 filter gfpdf_signature_width 2 diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index 803dd6aff..511a181de 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -1972,13 +1972,13 @@ parameters: - message: '#^Parameter \#1 \$text of function esc_attr expects string, int given\.$#' identifier: argument.type - count: 1 + count: 2 path: ../../src/View/html/Settings/general.php - message: '#^Variable \$args might not be defined\.$#' identifier: variable.undefined - count: 1 + count: 2 path: ../../src/View/html/Settings/general.php -