From 3528dd864f66af87bc4dd7a863e497ad93227a0f Mon Sep 17 00:00:00 2001 From: manuelRod Date: Wed, 19 Jan 2022 16:26:30 +0100 Subject: [PATCH 01/12] adding autoloaded options check to site health --- .../audit-autoloaded-options/load.php | 104 ++++++++++++++++++ .../audit-autoloaded-options-test.php | 41 +++++++ 2 files changed, 145 insertions(+) create mode 100644 modules/site-health/audit-autoloaded-options/load.php create mode 100644 tests/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php new file mode 100644 index 0000000000..aa163a3f4f --- /dev/null +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -0,0 +1,104 @@ + esc_html__( 'Autoloaded options', 'performance-lab' ), + 'test' => 'perflab_aao_autoloaded_options_test', + ); + return $tests; +} +add_filter( 'site_status_tests', 'perflab_aao_add_autoloaded_options_test' ); + +/** + * Callback for autoloaded_options test. + * + * @since 1.0.0 + * + * @return array + */ +function perflab_aao_autoloaded_options_test() { + + $autoloaded_options_size = perflab_aao_autoloaded_options_size(); + $autoloaded_options_count = perflab_aao_autoloaded_options_count(); + + $result = array( + 'label' => esc_html__( 'Autoloaded options', 'performance-lab' ), + 'status' => 'good', + 'badge' => array( + 'label' => esc_html__( 'Performance', 'performance-lab' ), + 'color' => 'blue', + ), + 'description' => sprintf( + /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ + '

' . esc_html__( 'The amount of %1$s autoloaded options (size: %2$s) in options table is acceptable.', 'performance-lab' ) . '

', + $autoloaded_options_count, + size_format( $autoloaded_options_size ) + ), + 'actions' => '', + 'test' => 'autoloaded_options', + ); + + /** + * Hostings can modify its limits depending on their own requirements. + */ + $limit = apply_filters( 'perflab_aao_autoloaded_options_limit_size_in_bytes', 100000 ); + + if ( $autoloaded_options_size > $limit ) { + $result['status'] = 'critical'; + $result['badge']['color'] = 'red'; + $result['description'] = sprintf( + /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ + '

' . esc_html__( 'Your website uses %1$s autoloaded options (size: %2$s). Try to reduce the number of autoloaded options or performance will be affected.', 'performance-lab' ) . '

', + $autoloaded_options_count, + size_format( $autoloaded_options_size ) + ); + $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); + + /** + * Hostings can add actions to take to reduce size of autoloaded options linking to their own guides. + */ + $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', 'How to solve it' ); + } + + return $result; +} + +/** + * Autoloaded options counter. + * + * @since 1.0.0 + * + * @return int + */ +function perflab_aao_autoloaded_options_count() { + return count( wp_load_alloptions() ); +} + +/** + * Calculate total amount of autoloaded data. + * + * @since 1.0.0 + * + * @return int autoloaded data in bytes. + */ +function perflab_aao_autoloaded_options_size() { + global $wpdb; + $autoloaded_options_size = $wpdb->get_row( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'', ARRAY_N ); + return current( $autoloaded_options_size ); +} diff --git a/tests/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php new file mode 100644 index 0000000000..5c2962d472 --- /dev/null +++ b/tests/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -0,0 +1,41 @@ +assertEquals( $autoloaded_options_count, perflab_aao_autoloaded_options_count() ); + + // Add autoload option. + add_option( 'test_option', 'test' ); + // We expect one more autoloaded option in the results. + $this->assertEquals( $autoloaded_options_count + 1, perflab_aao_autoloaded_options_count() ); + } + + /** + * Tests perflab_aao_autoloaded_options_size() + */ + public function test_perflab_aao_autoloaded_options_size() { + global $wpdb; + $autoloaded_options_size = $wpdb->get_row( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'', ARRAY_N ); + $autoloaded_options_size = current( $autoloaded_options_size ); + $this->assertEquals( $autoloaded_options_size, perflab_aao_autoloaded_options_size() ); + + // Add autoload option. + $test_option_string = 'test'; + $test_option_string_bytes = mb_strlen( $test_option_string, '8bit' ); + add_option( 'test_option', $test_option_string ); + $this->assertEquals( $autoloaded_options_size + $test_option_string_bytes, perflab_aao_autoloaded_options_size() ); + } + +} + From b5049c075f5720399f21c42ef95930cf9e8725ce Mon Sep 17 00:00:00 2001 From: manuelRod Date: Thu, 20 Jan 2022 12:52:03 +0100 Subject: [PATCH 02/12] adding tests --- .../audit-autoloaded-options/load.php | 2 +- .../audit-autoloaded-options-test.php | 85 +++++++++++++++++++ ...lass-autoloaded-options-mock-responses.php | 82 ++++++++++++++++++ .../class-autoloaded-options-set.php | 40 +++++++++ 4 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php create mode 100644 tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php create mode 100644 tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-set.php diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php index aa163a3f4f..57e0c095df 100644 --- a/modules/site-health/audit-autoloaded-options/load.php +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -57,7 +57,7 @@ function perflab_aao_autoloaded_options_test() { /** * Hostings can modify its limits depending on their own requirements. */ - $limit = apply_filters( 'perflab_aao_autoloaded_options_limit_size_in_bytes', 100000 ); + $limit = apply_filters( 'perflab_aao_autoloaded_options_limit_size_in_bytes', 800000 ); if ( $autoloaded_options_size > $limit ) { $result['status'] = 'critical'; diff --git a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php new file mode 100644 index 0000000000..9786bab010 --- /dev/null +++ b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -0,0 +1,85 @@ +assertEqualSets( Autoloaded_Options_Mock_Responses::return_added_test_info_site_health(), perflab_aao_add_autoloaded_options_test( array() ) ); + } + + /** + * Tests perflab_aao_autoloaded_options_test() when autoloaded options less than warning size. + */ + public function test_perflab_aao_autoloaded_options_test_no_warning() { + $autoloaded_options_size = perflab_aao_autoloaded_options_size(); + $autoloaded_options_count = perflab_aao_autoloaded_options_count(); + + if ( $autoloaded_options_size < self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ) { + $this->assertEqualSets( + perflab_aao_autoloaded_options_test(), + Autoloaded_Options_Mock_Responses::return_perflab_aao_autoloaded_options_test_less_than_limit( + $autoloaded_options_size, + $autoloaded_options_count + ) + ); + } + } + + /** + * Tests perflab_aao_autoloaded_options_test() when autoloaded options more than warning size. + */ + public function test_perflab_aao_autoloaded_options_test_warning() { + Autoloaded_Options_Set::set_autoloaded_option( self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ); + $autoloaded_options_size = perflab_aao_autoloaded_options_size(); + $autoloaded_options_count = perflab_aao_autoloaded_options_count(); + + if ( $autoloaded_options_size > self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ) { + $this->assertEqualSets( + perflab_aao_autoloaded_options_test(), + Autoloaded_Options_Mock_Responses::return_perflab_aao_autoloaded_options_test_bigger_than_limit( + $autoloaded_options_size, + $autoloaded_options_count + ) + ); + } + } + + /** + * Tests perflab_aao_autoloaded_options_count() + */ + public function test_perflab_aao_autoloaded_options_count() { + $autoloaded_options_count = count( wp_load_alloptions() ); + $this->assertEquals( $autoloaded_options_count, perflab_aao_autoloaded_options_count() ); + + // Add autoload option. + Autoloaded_Options_Set::set_autoloaded_option( 5 ); + // We expect one more autoloaded option in the results. + $this->assertEquals( $autoloaded_options_count + 1, perflab_aao_autoloaded_options_count() ); + } + + /** + * Tests perflab_aao_autoloaded_options_size() + */ + public function test_perflab_aao_autoloaded_options_size() { + global $wpdb; + $autoloaded_options_size = $wpdb->get_row( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'', ARRAY_N ); + $autoloaded_options_size = current( $autoloaded_options_size ); + $this->assertEquals( $autoloaded_options_size, perflab_aao_autoloaded_options_size() ); + + // Add autoload option. + $test_option_string = 'test'; + $test_option_string_bytes = mb_strlen( $test_option_string, '8bit' ); + Autoloaded_Options_Set::set_autoloaded_option( $test_option_string_bytes ); + $this->assertEquals( $autoloaded_options_size + $test_option_string_bytes, perflab_aao_autoloaded_options_size() ); + } + +} + diff --git a/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php b/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php new file mode 100644 index 0000000000..e11e343086 --- /dev/null +++ b/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php @@ -0,0 +1,82 @@ + esc_html__( 'Autoloaded options', 'performance-lab' ), + 'test' => 'perflab_aao_autoloaded_options_test', + ); + return $added_tests; + } + + /** + * Callback response for perflab_aao_autoloaded_options_test if autoloaded options are less than the limit. + * + * @param int $autoloaded_options_size Autoloaded options size in bytes. + * @param int $autoloaded_options_count Autoloaded options count. + * + * @return array + */ + public static function return_perflab_aao_autoloaded_options_test_less_than_limit( $autoloaded_options_size, $autoloaded_options_count ) { + $result = array( + 'label' => esc_html__( 'Autoloaded options', 'performance-lab' ), + 'status' => 'good', + 'badge' => array( + 'label' => esc_html__( 'Performance', 'performance-lab' ), + 'color' => 'blue', + ), + 'description' => sprintf( + /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ + '

' . esc_html__( 'The amount of %1$s autoloaded options (size: %2$s) in options table is acceptable.', 'performance-lab' ) . '

', + $autoloaded_options_count, + size_format( $autoloaded_options_size ) + ), + 'actions' => '', + 'test' => 'autoloaded_options', + ); + return $result; + } + + /** + * Callback response for perflab_aao_autoloaded_options_test if autoloaded options are more than the limit. + * + * @param int $autoloaded_options_size Autoloaded options size in bytes. + * @param int $autoloaded_options_count Autoloaded options count. + * + * @return array + */ + public static function return_perflab_aao_autoloaded_options_test_bigger_than_limit( $autoloaded_options_size, $autoloaded_options_count ) { + $result = self::return_perflab_aao_autoloaded_options_test_less_than_limit( $autoloaded_options_size, $autoloaded_options_count ); + + $result['status'] = 'critical'; + $result['badge']['color'] = 'red'; + $result['description'] = sprintf( + /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ + '

' . esc_html__( 'Your website uses %1$s autoloaded options (size: %2$s). Try to reduce the number of autoloaded options or performance will be affected.', 'performance-lab' ) . '

', + $autoloaded_options_count, + size_format( $autoloaded_options_size ) + ); + $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); + $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', 'How to solve it' ); + return $result; + } + + +} + diff --git a/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-set.php b/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-set.php new file mode 100644 index 0000000000..08bc64490d --- /dev/null +++ b/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-set.php @@ -0,0 +1,40 @@ + Date: Thu, 20 Jan 2022 12:52:22 +0100 Subject: [PATCH 03/12] moving file --- .../audit-autoloaded-options-test.php | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 tests/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php diff --git a/tests/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php deleted file mode 100644 index 5c2962d472..0000000000 --- a/tests/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ /dev/null @@ -1,41 +0,0 @@ -assertEquals( $autoloaded_options_count, perflab_aao_autoloaded_options_count() ); - - // Add autoload option. - add_option( 'test_option', 'test' ); - // We expect one more autoloaded option in the results. - $this->assertEquals( $autoloaded_options_count + 1, perflab_aao_autoloaded_options_count() ); - } - - /** - * Tests perflab_aao_autoloaded_options_size() - */ - public function test_perflab_aao_autoloaded_options_size() { - global $wpdb; - $autoloaded_options_size = $wpdb->get_row( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'', ARRAY_N ); - $autoloaded_options_size = current( $autoloaded_options_size ); - $this->assertEquals( $autoloaded_options_size, perflab_aao_autoloaded_options_size() ); - - // Add autoload option. - $test_option_string = 'test'; - $test_option_string_bytes = mb_strlen( $test_option_string, '8bit' ); - add_option( 'test_option', $test_option_string ); - $this->assertEquals( $autoloaded_options_size + $test_option_string_bytes, perflab_aao_autoloaded_options_size() ); - } - -} - From 74932f8009dc5039719b76282f1b348e6b916060 Mon Sep 17 00:00:00 2001 From: manuelRod Date: Mon, 24 Jan 2022 11:32:56 +0100 Subject: [PATCH 04/12] Adding resource link to actions --- modules/site-health/audit-autoloaded-options/load.php | 8 +++++++- .../class-autoloaded-options-mock-responses.php | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php index 57e0c095df..045c25afe9 100644 --- a/modules/site-health/audit-autoloaded-options/load.php +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -70,10 +70,16 @@ function perflab_aao_autoloaded_options_test() { ); $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); + $result['actions'] = sprintf( + /* translators: 1: HelpHub URL. 2: Link description. */ + '

%2$s

', + esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ), + esc_html__( 'More info about performance optimization', 'performance-lab' ) + ); /** * Hostings can add actions to take to reduce size of autoloaded options linking to their own guides. */ - $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', 'How to solve it' ); + $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', $result['actions'] ); } return $result; diff --git a/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php b/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php index e11e343086..f889f8a1e5 100644 --- a/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php +++ b/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php @@ -73,7 +73,16 @@ public static function return_perflab_aao_autoloaded_options_test_bigger_than_li size_format( $autoloaded_options_size ) ); $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); - $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', 'How to solve it' ); + $result['actions'] = sprintf( + /* translators: 1: HelpHub URL. 2: Link description. */ + '

%2$s

', + esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ), + esc_html__( 'More info about performance optimization', 'performance-lab' ) + ); + /** + * Hostings can add actions to take to reduce size of autoloaded options linking to their own guides. + */ + $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', $result['actions'] ); return $result; } From 11dd3f3a1e77bf060e5858084afecf0a987aa6c6 Mon Sep 17 00:00:00 2001 From: manuelRod Date: Tue, 8 Feb 2022 14:50:50 +0100 Subject: [PATCH 05/12] simplify code --- .../audit-autoloaded-options/load.php | 13 +------------ .../audit-autoloaded-options-test.php | 17 ++--------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php index 045c25afe9..194b820bd3 100644 --- a/modules/site-health/audit-autoloaded-options/load.php +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -35,7 +35,7 @@ function perflab_aao_add_autoloaded_options_test( $tests ) { function perflab_aao_autoloaded_options_test() { $autoloaded_options_size = perflab_aao_autoloaded_options_size(); - $autoloaded_options_count = perflab_aao_autoloaded_options_count(); + $autoloaded_options_count = count( wp_load_alloptions() ); $result = array( 'label' => esc_html__( 'Autoloaded options', 'performance-lab' ), @@ -85,17 +85,6 @@ function perflab_aao_autoloaded_options_test() { return $result; } -/** - * Autoloaded options counter. - * - * @since 1.0.0 - * - * @return int - */ -function perflab_aao_autoloaded_options_count() { - return count( wp_load_alloptions() ); -} - /** * Calculate total amount of autoloaded data. * diff --git a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index 9786bab010..5591756bfd 100644 --- a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -20,7 +20,7 @@ public function test_perflab_aao_add_autoloaded_options_test() { */ public function test_perflab_aao_autoloaded_options_test_no_warning() { $autoloaded_options_size = perflab_aao_autoloaded_options_size(); - $autoloaded_options_count = perflab_aao_autoloaded_options_count(); + $autoloaded_options_count = count( wp_load_alloptions() ); if ( $autoloaded_options_size < self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ) { $this->assertEqualSets( @@ -39,7 +39,7 @@ public function test_perflab_aao_autoloaded_options_test_no_warning() { public function test_perflab_aao_autoloaded_options_test_warning() { Autoloaded_Options_Set::set_autoloaded_option( self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ); $autoloaded_options_size = perflab_aao_autoloaded_options_size(); - $autoloaded_options_count = perflab_aao_autoloaded_options_count(); + $autoloaded_options_count = count( wp_load_alloptions() ); if ( $autoloaded_options_size > self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ) { $this->assertEqualSets( @@ -52,19 +52,6 @@ public function test_perflab_aao_autoloaded_options_test_warning() { } } - /** - * Tests perflab_aao_autoloaded_options_count() - */ - public function test_perflab_aao_autoloaded_options_count() { - $autoloaded_options_count = count( wp_load_alloptions() ); - $this->assertEquals( $autoloaded_options_count, perflab_aao_autoloaded_options_count() ); - - // Add autoload option. - Autoloaded_Options_Set::set_autoloaded_option( 5 ); - // We expect one more autoloaded option in the results. - $this->assertEquals( $autoloaded_options_count + 1, perflab_aao_autoloaded_options_count() ); - } - /** * Tests perflab_aao_autoloaded_options_size() */ From be7b17d7679ac5990207b7909ae7f45dabbc8163 Mon Sep 17 00:00:00 2001 From: manuelRod Date: Tue, 15 Feb 2022 12:29:56 +0100 Subject: [PATCH 06/12] some small refactor, + adding better documentation to filters --- .../audit-autoloaded-options/load.php | 21 +++++- .../audit-autoloaded-options-test.php | 65 ++++++++++++------- .../class-autoloaded-options-set.php | 40 ------------ 3 files changed, 62 insertions(+), 64 deletions(-) delete mode 100644 tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-set.php diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php index 194b820bd3..3c5591423f 100644 --- a/modules/site-health/audit-autoloaded-options/load.php +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -56,6 +56,10 @@ function perflab_aao_autoloaded_options_test() { /** * Hostings can modify its limits depending on their own requirements. + * + * @since 1.0.0 + * + * @param int $limit Autoloaded options threshold size. Default 800000. */ $limit = apply_filters( 'perflab_aao_autoloaded_options_limit_size_in_bytes', 800000 ); @@ -68,6 +72,14 @@ function perflab_aao_autoloaded_options_test() { $autoloaded_options_count, size_format( $autoloaded_options_size ) ); + + /** + * Hostings can modify description to be shown on site health screen. + * + * @since 1.0.0 + * + * @param string $description Description message when autoloaded options bigger than treshold. + */ $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); $result['actions'] = sprintf( @@ -76,8 +88,13 @@ function perflab_aao_autoloaded_options_test() { esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ), esc_html__( 'More info about performance optimization', 'performance-lab' ) ); + /** * Hostings can add actions to take to reduce size of autoloaded options linking to their own guides. + * + * @since 1.0.0 + * + * @param string $actions Call to Action to be used to point to the right direction to solve the issue. */ $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', $result['actions'] ); } @@ -94,6 +111,6 @@ function perflab_aao_autoloaded_options_test() { */ function perflab_aao_autoloaded_options_size() { global $wpdb; - $autoloaded_options_size = $wpdb->get_row( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'', ARRAY_N ); - return current( $autoloaded_options_size ); + $autoloaded_options_size = $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' ); + return $autoloaded_options_size; } diff --git a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index 5591756bfd..725f38db7f 100644 --- a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -22,34 +22,30 @@ public function test_perflab_aao_autoloaded_options_test_no_warning() { $autoloaded_options_size = perflab_aao_autoloaded_options_size(); $autoloaded_options_count = count( wp_load_alloptions() ); - if ( $autoloaded_options_size < self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ) { - $this->assertEqualSets( - perflab_aao_autoloaded_options_test(), - Autoloaded_Options_Mock_Responses::return_perflab_aao_autoloaded_options_test_less_than_limit( - $autoloaded_options_size, - $autoloaded_options_count - ) - ); - } + $this->assertEqualSets( + perflab_aao_autoloaded_options_test(), + Autoloaded_Options_Mock_Responses::return_perflab_aao_autoloaded_options_test_less_than_limit( + $autoloaded_options_size, + $autoloaded_options_count + ) + ); } /** * Tests perflab_aao_autoloaded_options_test() when autoloaded options more than warning size. */ public function test_perflab_aao_autoloaded_options_test_warning() { - Autoloaded_Options_Set::set_autoloaded_option( self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ); + self::set_autoloaded_option( self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ); $autoloaded_options_size = perflab_aao_autoloaded_options_size(); $autoloaded_options_count = count( wp_load_alloptions() ); - if ( $autoloaded_options_size > self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ) { - $this->assertEqualSets( - perflab_aao_autoloaded_options_test(), - Autoloaded_Options_Mock_Responses::return_perflab_aao_autoloaded_options_test_bigger_than_limit( - $autoloaded_options_size, - $autoloaded_options_count - ) - ); - } + $this->assertEqualSets( + perflab_aao_autoloaded_options_test(), + Autoloaded_Options_Mock_Responses::return_perflab_aao_autoloaded_options_test_bigger_than_limit( + $autoloaded_options_size, + $autoloaded_options_count + ) + ); } /** @@ -57,16 +53,41 @@ public function test_perflab_aao_autoloaded_options_test_warning() { */ public function test_perflab_aao_autoloaded_options_size() { global $wpdb; - $autoloaded_options_size = $wpdb->get_row( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'', ARRAY_N ); - $autoloaded_options_size = current( $autoloaded_options_size ); + $autoloaded_options_size = $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' ); $this->assertEquals( $autoloaded_options_size, perflab_aao_autoloaded_options_size() ); // Add autoload option. $test_option_string = 'test'; $test_option_string_bytes = mb_strlen( $test_option_string, '8bit' ); - Autoloaded_Options_Set::set_autoloaded_option( $test_option_string_bytes ); + self::set_autoloaded_option( $test_option_string_bytes ); $this->assertEquals( $autoloaded_options_size + $test_option_string_bytes, perflab_aao_autoloaded_options_size() ); } + /** + * Sets an autoloaded option. + * + * @param int $bytes bytes to load in options. + */ + public static function set_autoloaded_option( $bytes = 800000 ) { + $heavy_option_string = self::random_string_generator( $bytes ); + add_option( 'test_set_autoloaded_option', $heavy_option_string ); + } + + /** + * Generate random string with certain $length. + * + * @param int $length Length of string to create. + * @return string + */ + protected static function random_string_generator( $length ) { + $seed = 'abcd123'; + $length_seed = strlen( $seed ); + $string = ''; + for ( $x = 0; $x < $length; $x++ ) { + $string .= $seed[ rand( 0, $length_seed - 1 ) ]; + } + return $string; + } + } diff --git a/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-set.php b/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-set.php deleted file mode 100644 index 08bc64490d..0000000000 --- a/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-set.php +++ /dev/null @@ -1,40 +0,0 @@ - Date: Mon, 28 Feb 2022 15:39:50 +0100 Subject: [PATCH 07/12] nitpick --- modules/site-health/audit-autoloaded-options/load.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php index 3c5591423f..e2c32d81e9 100644 --- a/modules/site-health/audit-autoloaded-options/load.php +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -111,6 +111,5 @@ function perflab_aao_autoloaded_options_test() { */ function perflab_aao_autoloaded_options_size() { global $wpdb; - $autoloaded_options_size = $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' ); - return $autoloaded_options_size; + return $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' ); } From a1ebb71b7e3ca7680f45e796df08e298d2003c8d Mon Sep 17 00:00:00 2001 From: manuelRod Date: Fri, 11 Mar 2022 15:03:37 +0100 Subject: [PATCH 08/12] nitpicks --- .../audit-autoloaded-options/load.php | 67 ++++++++++--------- .../audit-autoloaded-options-test.php | 4 +- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php index e2c32d81e9..e3b2c4b601 100644 --- a/modules/site-health/audit-autoloaded-options/load.php +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -63,42 +63,43 @@ function perflab_aao_autoloaded_options_test() { */ $limit = apply_filters( 'perflab_aao_autoloaded_options_limit_size_in_bytes', 800000 ); - if ( $autoloaded_options_size > $limit ) { - $result['status'] = 'critical'; - $result['badge']['color'] = 'red'; - $result['description'] = sprintf( - /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ - '

' . esc_html__( 'Your website uses %1$s autoloaded options (size: %2$s). Try to reduce the number of autoloaded options or performance will be affected.', 'performance-lab' ) . '

', - $autoloaded_options_count, - size_format( $autoloaded_options_size ) - ); + if ( $autoloaded_options_size < $limit ) { + return $result; + } - /** - * Hostings can modify description to be shown on site health screen. - * - * @since 1.0.0 - * - * @param string $description Description message when autoloaded options bigger than treshold. - */ - $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); + $result['status'] = 'critical'; + $result['badge']['color'] = 'red'; + $result['description'] = sprintf( + /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ + '

' . esc_html__( 'Your website uses %1$s autoloaded options (size: %2$s). Try to reduce the number of autoloaded options or performance will be affected.', 'performance-lab' ) . '

', + $autoloaded_options_count, + size_format( $autoloaded_options_size ) + ); - $result['actions'] = sprintf( - /* translators: 1: HelpHub URL. 2: Link description. */ - '

%2$s

', - esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ), - esc_html__( 'More info about performance optimization', 'performance-lab' ) - ); + /** + * Hostings can modify description to be shown on site health screen. + * + * @since 1.0.0 + * + * @param string $description Description message when autoloaded options bigger than treshold. + */ + $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); - /** - * Hostings can add actions to take to reduce size of autoloaded options linking to their own guides. - * - * @since 1.0.0 - * - * @param string $actions Call to Action to be used to point to the right direction to solve the issue. - */ - $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', $result['actions'] ); - } + $result['actions'] = sprintf( + /* translators: 1: HelpHub URL. 2: Link description. */ + '

%2$s

', + esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ), + esc_html__( 'More info about performance optimization', 'performance-lab' ) + ); + /** + * Hostings can add actions to take to reduce size of autoloaded options linking to their own guides. + * + * @since 1.0.0 + * + * @param string $actions Call to Action to be used to point to the right direction to solve the issue. + */ + $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', $result['actions'] ); return $result; } @@ -111,5 +112,5 @@ function perflab_aao_autoloaded_options_test() { */ function perflab_aao_autoloaded_options_size() { global $wpdb; - return $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' ); + return (int) $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' ); } diff --git a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index 725f38db7f..deb1cbacaa 100644 --- a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -60,7 +60,7 @@ public function test_perflab_aao_autoloaded_options_size() { $test_option_string = 'test'; $test_option_string_bytes = mb_strlen( $test_option_string, '8bit' ); self::set_autoloaded_option( $test_option_string_bytes ); - $this->assertEquals( $autoloaded_options_size + $test_option_string_bytes, perflab_aao_autoloaded_options_size() ); + $this->assertSame( $autoloaded_options_size + $test_option_string_bytes, perflab_aao_autoloaded_options_size() ); } /** @@ -76,7 +76,7 @@ public static function set_autoloaded_option( $bytes = 800000 ) { /** * Generate random string with certain $length. * - * @param int $length Length of string to create. + * @param int $length Length ( in bytes ) of string to create. * @return string */ protected static function random_string_generator( $length ) { From 389a0ff660ea27465d8f14a425a0e392088b8d08 Mon Sep 17 00:00:00 2001 From: manuelRod Date: Mon, 14 Mar 2022 17:09:51 +0100 Subject: [PATCH 09/12] moving mock response class to dataproviders. --- .../audit-autoloaded-options-test.php | 117 +++++++++++++++--- ...lass-autoloaded-options-mock-responses.php | 91 -------------- 2 files changed, 97 insertions(+), 111 deletions(-) delete mode 100644 tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php diff --git a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index deb1cbacaa..314ad87523 100644 --- a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -7,44 +7,39 @@ class Audit_Autoloaded_Options_Tests extends WP_UnitTestCase { const WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES = 800000; + const AUTOLOADED_OPTION_KEY = 'test_set_autoloaded_option'; /** + * @dataProvider provider_added_test_info_site_health + * * Tests perflab_aao_add_autoloaded_options_test() */ - public function test_perflab_aao_add_autoloaded_options_test() { - $this->assertEqualSets( Autoloaded_Options_Mock_Responses::return_added_test_info_site_health(), perflab_aao_add_autoloaded_options_test( array() ) ); + public function test_perflab_aao_add_autoloaded_options_test( $provider_added_test_info_site_health ) { + $this->assertEqualSets( $provider_added_test_info_site_health, perflab_aao_add_autoloaded_options_test( array() ) ); } /** + * @dataProvider provider_autoloaded_options_less_than_limit + * * Tests perflab_aao_autoloaded_options_test() when autoloaded options less than warning size. */ - public function test_perflab_aao_autoloaded_options_test_no_warning() { - $autoloaded_options_size = perflab_aao_autoloaded_options_size(); - $autoloaded_options_count = count( wp_load_alloptions() ); - + public function test_perflab_aao_autoloaded_options_test_no_warning( $provider_autoloaded_options_less_than_limit ) { $this->assertEqualSets( perflab_aao_autoloaded_options_test(), - Autoloaded_Options_Mock_Responses::return_perflab_aao_autoloaded_options_test_less_than_limit( - $autoloaded_options_size, - $autoloaded_options_count - ) + $provider_autoloaded_options_less_than_limit ); } /** + * @dataProvider provider_autoloaded_options_bigger_than_limit + * * Tests perflab_aao_autoloaded_options_test() when autoloaded options more than warning size. */ - public function test_perflab_aao_autoloaded_options_test_warning() { + public function test_perflab_aao_autoloaded_options_test_warning( $provider_autoloaded_options_bigger_than_limit ) { self::set_autoloaded_option( self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ); - $autoloaded_options_size = perflab_aao_autoloaded_options_size(); - $autoloaded_options_count = count( wp_load_alloptions() ); - $this->assertEqualSets( perflab_aao_autoloaded_options_test(), - Autoloaded_Options_Mock_Responses::return_perflab_aao_autoloaded_options_test_bigger_than_limit( - $autoloaded_options_size, - $autoloaded_options_count - ) + $provider_autoloaded_options_bigger_than_limit ); } @@ -64,13 +59,20 @@ public function test_perflab_aao_autoloaded_options_size() { } /** - * Sets an autoloaded option. + * Sets a test autoloaded option. * * @param int $bytes bytes to load in options. */ public static function set_autoloaded_option( $bytes = 800000 ) { $heavy_option_string = self::random_string_generator( $bytes ); - add_option( 'test_set_autoloaded_option', $heavy_option_string ); + add_option( self::AUTOLOADED_OPTION_KEY, $heavy_option_string ); + } + + /** + * Deletes test autoloaded option. + */ + public static function delete_autoloaded_option() { + delete_option( self::AUTOLOADED_OPTION_KEY ); } /** @@ -89,5 +91,80 @@ protected static function random_string_generator( $length ) { return $string; } + /** + * This is the information we are adding into site_status_tests hook. + * + * @return array + */ + function provider_added_test_info_site_health() { + $added_tests = array(); + $added_tests['direct']['autoloaded_options'] = array( + 'label' => esc_html__( 'Autoloaded options', 'performance-lab' ), + 'test' => 'perflab_aao_autoloaded_options_test', + ); + return array( array( $added_tests ) ); + } + + /** + * Data provider for perflab_aao_autoloaded_options_test if autoloaded options are less than the limit. + * + * @return array + */ + public function provider_autoloaded_options_less_than_limit() { + $autoloaded_options_size = perflab_aao_autoloaded_options_size(); + $autoloaded_options_count = count( wp_load_alloptions() ); + + $result = array( + 'label' => esc_html__( 'Autoloaded options', 'performance-lab' ), + 'status' => 'good', + 'badge' => array( + 'label' => esc_html__( 'Performance', 'performance-lab' ), + 'color' => 'blue', + ), + 'description' => sprintf( + /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ + '

' . esc_html__( 'The amount of %1$s autoloaded options (size: %2$s) in options table is acceptable.', 'performance-lab' ) . '

', + $autoloaded_options_count, + size_format( $autoloaded_options_size ) + ), + 'actions' => '', + 'test' => 'autoloaded_options', + ); + return array( array( $result ) ); + } + + /** + * Data provider for perflab_aao_autoloaded_options_test if autoloaded options are more than the limit. + * + * @return array + */ + public function provider_autoloaded_options_bigger_than_limit() { + $result = perflab_aao_autoloaded_options_test(); + + self::set_autoloaded_option( self::WARNING_AUTOLOADED_SIZE_LIMIT_IN_BYTES ); + $autoloaded_options_size = perflab_aao_autoloaded_options_size(); + $autoloaded_options_count = count( wp_load_alloptions() ); + self::delete_autoloaded_option(); + + $result['status'] = 'critical'; + $result['badge']['color'] = 'red'; + $result['description'] = sprintf( + /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ + '

' . esc_html__( 'Your website uses %1$s autoloaded options (size: %2$s). Try to reduce the number of autoloaded options or performance will be affected.', 'performance-lab' ) . '

', + $autoloaded_options_count, + size_format( $autoloaded_options_size ) + ); + + $result['actions'] = sprintf( + /* translators: 1: HelpHub URL. 2: Link description. */ + '

%2$s

', + esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ), + esc_html__( 'More info about performance optimization', 'performance-lab' ) + ); + + return array( array( $result ) ); + } + + } diff --git a/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php b/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php deleted file mode 100644 index f889f8a1e5..0000000000 --- a/tests/testdata/modules/site-health/audit-autoloaded-options/class-autoloaded-options-mock-responses.php +++ /dev/null @@ -1,91 +0,0 @@ - esc_html__( 'Autoloaded options', 'performance-lab' ), - 'test' => 'perflab_aao_autoloaded_options_test', - ); - return $added_tests; - } - - /** - * Callback response for perflab_aao_autoloaded_options_test if autoloaded options are less than the limit. - * - * @param int $autoloaded_options_size Autoloaded options size in bytes. - * @param int $autoloaded_options_count Autoloaded options count. - * - * @return array - */ - public static function return_perflab_aao_autoloaded_options_test_less_than_limit( $autoloaded_options_size, $autoloaded_options_count ) { - $result = array( - 'label' => esc_html__( 'Autoloaded options', 'performance-lab' ), - 'status' => 'good', - 'badge' => array( - 'label' => esc_html__( 'Performance', 'performance-lab' ), - 'color' => 'blue', - ), - 'description' => sprintf( - /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ - '

' . esc_html__( 'The amount of %1$s autoloaded options (size: %2$s) in options table is acceptable.', 'performance-lab' ) . '

', - $autoloaded_options_count, - size_format( $autoloaded_options_size ) - ), - 'actions' => '', - 'test' => 'autoloaded_options', - ); - return $result; - } - - /** - * Callback response for perflab_aao_autoloaded_options_test if autoloaded options are more than the limit. - * - * @param int $autoloaded_options_size Autoloaded options size in bytes. - * @param int $autoloaded_options_count Autoloaded options count. - * - * @return array - */ - public static function return_perflab_aao_autoloaded_options_test_bigger_than_limit( $autoloaded_options_size, $autoloaded_options_count ) { - $result = self::return_perflab_aao_autoloaded_options_test_less_than_limit( $autoloaded_options_size, $autoloaded_options_count ); - - $result['status'] = 'critical'; - $result['badge']['color'] = 'red'; - $result['description'] = sprintf( - /* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */ - '

' . esc_html__( 'Your website uses %1$s autoloaded options (size: %2$s). Try to reduce the number of autoloaded options or performance will be affected.', 'performance-lab' ) . '

', - $autoloaded_options_count, - size_format( $autoloaded_options_size ) - ); - $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); - $result['actions'] = sprintf( - /* translators: 1: HelpHub URL. 2: Link description. */ - '

%2$s

', - esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ), - esc_html__( 'More info about performance optimization', 'performance-lab' ) - ); - /** - * Hostings can add actions to take to reduce size of autoloaded options linking to their own guides. - */ - $result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', $result['actions'] ); - return $result; - } - - -} - From 7c6a9f7f2d1facb77cd3b888dd3efd26b99b070b Mon Sep 17 00:00:00 2001 From: manuelRod Date: Tue, 15 Mar 2022 11:57:04 +0100 Subject: [PATCH 10/12] updating some comments --- modules/site-health/audit-autoloaded-options/load.php | 8 ++++---- .../audit-autoloaded-options-test.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php index e3b2c4b601..1dd7bab77e 100644 --- a/modules/site-health/audit-autoloaded-options/load.php +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -55,7 +55,7 @@ function perflab_aao_autoloaded_options_test() { ); /** - * Hostings can modify its limits depending on their own requirements. + * Filters max bytes threshold to trigger warning in Site Health. * * @since 1.0.0 * @@ -77,11 +77,11 @@ function perflab_aao_autoloaded_options_test() { ); /** - * Hostings can modify description to be shown on site health screen. + * Filters description to be shown on Site Health warning when threshold is met. * * @since 1.0.0 * - * @param string $description Description message when autoloaded options bigger than treshold. + * @param string $description Description message when autoloaded options bigger than threshold. */ $result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] ); @@ -93,7 +93,7 @@ function perflab_aao_autoloaded_options_test() { ); /** - * Hostings can add actions to take to reduce size of autoloaded options linking to their own guides. + * Filters actionable information to tackle the problem. It can be a link to an external guide. * * @since 1.0.0 * diff --git a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index 314ad87523..a95373396c 100644 --- a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -96,7 +96,7 @@ protected static function random_string_generator( $length ) { * * @return array */ - function provider_added_test_info_site_health() { + public function provider_added_test_info_site_health() { $added_tests = array(); $added_tests['direct']['autoloaded_options'] = array( 'label' => esc_html__( 'Autoloaded options', 'performance-lab' ), From b6a1949fa6a0c61422a03a309b14931d94e03b73 Mon Sep 17 00:00:00 2001 From: manuelRod Date: Wed, 16 Mar 2022 15:30:43 +0100 Subject: [PATCH 11/12] simplifying test using wp_generate_password instead of custom random string generator --- .../audit-autoloaded-options-test.php | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index a95373396c..48acbfc9a6 100644 --- a/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/modules/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -64,7 +64,7 @@ public function test_perflab_aao_autoloaded_options_size() { * @param int $bytes bytes to load in options. */ public static function set_autoloaded_option( $bytes = 800000 ) { - $heavy_option_string = self::random_string_generator( $bytes ); + $heavy_option_string = wp_generate_password( $bytes ); add_option( self::AUTOLOADED_OPTION_KEY, $heavy_option_string ); } @@ -75,22 +75,6 @@ public static function delete_autoloaded_option() { delete_option( self::AUTOLOADED_OPTION_KEY ); } - /** - * Generate random string with certain $length. - * - * @param int $length Length ( in bytes ) of string to create. - * @return string - */ - protected static function random_string_generator( $length ) { - $seed = 'abcd123'; - $length_seed = strlen( $seed ); - $string = ''; - for ( $x = 0; $x < $length; $x++ ) { - $string .= $seed[ rand( 0, $length_seed - 1 ) ]; - } - return $string; - } - /** * This is the information we are adding into site_status_tests hook. * From 725bbd4ad3628e8cf7b52a299ccbb238d994c406 Mon Sep 17 00:00:00 2001 From: manuelRod Date: Fri, 18 Mar 2022 10:57:09 +0100 Subject: [PATCH 12/12] marking as experimental --- modules/site-health/audit-autoloaded-options/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/site-health/audit-autoloaded-options/load.php b/modules/site-health/audit-autoloaded-options/load.php index 1dd7bab77e..179fe4d0f7 100644 --- a/modules/site-health/audit-autoloaded-options/load.php +++ b/modules/site-health/audit-autoloaded-options/load.php @@ -2,7 +2,7 @@ /** * Module Name: Audit Autoloaded Options * Description: Adds Autoloaded options checker in Site Health checks. - * Experimental: No + * Experimental: Yes * * @package performance-lab * @since 1.0.0