diff --git a/server-timing/class-perflab-server-timing-metric.php b/includes/server-timing/class-perflab-server-timing-metric.php
similarity index 100%
rename from server-timing/class-perflab-server-timing-metric.php
rename to includes/server-timing/class-perflab-server-timing-metric.php
diff --git a/server-timing/class-perflab-server-timing.php b/includes/server-timing/class-perflab-server-timing.php
similarity index 100%
rename from server-timing/class-perflab-server-timing.php
rename to includes/server-timing/class-perflab-server-timing.php
diff --git a/server-timing/defaults.php b/includes/server-timing/defaults.php
similarity index 100%
rename from server-timing/defaults.php
rename to includes/server-timing/defaults.php
diff --git a/server-timing/load.php b/includes/server-timing/load.php
similarity index 100%
rename from server-timing/load.php
rename to includes/server-timing/load.php
diff --git a/server-timing/object-cache.copy.php b/includes/server-timing/object-cache.copy.php
similarity index 84%
rename from server-timing/object-cache.copy.php
rename to includes/server-timing/object-cache.copy.php
index 7bd961b802..319483d375 100644
--- a/server-timing/object-cache.copy.php
+++ b/includes/server-timing/object-cache.copy.php
@@ -3,7 +3,7 @@
* Plugin Name: Performance Lab Server Timing Object Cache Drop-In
* Plugin URI: https://github.com/WordPress/performance
* Description: Performance Lab drop-in to register Server-Timing metrics early. This is not a real object cache drop-in and will not override other actual object cache drop-ins.
- * Version: 2
+ * Version: 3
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPLv2 or later
@@ -34,7 +34,7 @@
// Set constant to be able to later check for whether this file was loaded.
if ( ! defined( 'PERFLAB_OBJECT_CACHE_DROPIN_VERSION' ) ) {
- define( 'PERFLAB_OBJECT_CACHE_DROPIN_VERSION', 2 );
+ define( 'PERFLAB_OBJECT_CACHE_DROPIN_VERSION', 3 );
}
if ( ! function_exists( 'perflab_load_server_timing_api_from_dropin' ) ) {
@@ -58,17 +58,17 @@ function perflab_load_server_timing_api_from_dropin() {
$plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins';
$plugin_dir = $plugins_dir . '/performance-lab/';
- if ( ! file_exists( $plugin_dir . 'server-timing/load.php' ) ) {
+ if ( ! file_exists( $plugin_dir . 'includes/server-timing/load.php' ) ) {
$plugin_dir = $plugins_dir . '/performance/';
- if ( ! file_exists( $plugin_dir . 'server-timing/load.php' ) ) {
+ if ( ! file_exists( $plugin_dir . 'includes/server-timing/load.php' ) ) {
return;
}
}
- require_once $plugin_dir . 'server-timing/class-perflab-server-timing-metric.php';
- require_once $plugin_dir . 'server-timing/class-perflab-server-timing.php';
- require_once $plugin_dir . 'server-timing/load.php';
- require_once $plugin_dir . 'server-timing/defaults.php';
+ require_once $plugin_dir . 'includes/server-timing/class-perflab-server-timing-metric.php';
+ require_once $plugin_dir . 'includes/server-timing/class-perflab-server-timing.php';
+ require_once $plugin_dir . 'includes/server-timing/load.php';
+ require_once $plugin_dir . 'includes/server-timing/defaults.php';
}
}
perflab_load_server_timing_api_from_dropin();
diff --git a/modules/database/audit-autoloaded-options/helper.php b/includes/site-health/audit-autoloaded-options/helper.php
similarity index 100%
rename from modules/database/audit-autoloaded-options/helper.php
rename to includes/site-health/audit-autoloaded-options/helper.php
diff --git a/modules/database/audit-autoloaded-options/hooks.php b/includes/site-health/audit-autoloaded-options/hooks.php
similarity index 100%
rename from modules/database/audit-autoloaded-options/hooks.php
rename to includes/site-health/audit-autoloaded-options/hooks.php
diff --git a/modules/js-and-css/audit-enqueued-assets/helper.php b/includes/site-health/audit-enqueued-assets/helper.php
similarity index 100%
rename from modules/js-and-css/audit-enqueued-assets/helper.php
rename to includes/site-health/audit-enqueued-assets/helper.php
diff --git a/modules/js-and-css/audit-enqueued-assets/hooks.php b/includes/site-health/audit-enqueued-assets/hooks.php
similarity index 100%
rename from modules/js-and-css/audit-enqueued-assets/hooks.php
rename to includes/site-health/audit-enqueued-assets/hooks.php
diff --git a/includes/site-health/load.php b/includes/site-health/load.php
new file mode 100644
index 0000000000..8cf164b302
--- /dev/null
+++ b/includes/site-health/load.php
@@ -0,0 +1,23 @@
+ 'database/audit-autoloaded-options',
- 'site-health/audit-enqueued-assets' => 'js-and-css/audit-enqueued-assets',
- 'site-health/webp-support' => 'images/webp-support',
- );
-
- foreach ( $legacy_module_slugs as $legacy_slug => $current_slug ) {
- if ( isset( $module_settings[ $legacy_slug ] ) ) {
- $module_settings[ $current_slug ] = $module_settings[ $legacy_slug ];
- unset( $module_settings[ $legacy_slug ] );
- }
- }
-
- return $module_settings;
+ return (array) get_option( PERFLAB_MODULES_SETTING, perflab_get_modules_setting_default() );
}
/**
@@ -424,7 +413,7 @@ function perflab_maybe_set_object_cache_dropin() {
return;
}
- $wp_filesystem->copy( PERFLAB_PLUGIN_DIR_PATH . 'server-timing/object-cache.copy.php', $dropin_path );
+ $wp_filesystem->copy( PERFLAB_PLUGIN_DIR_PATH . 'includes/server-timing/object-cache.copy.php', $dropin_path );
}
// Set timeout of 1 hour before retrying again (only relevant in case the above failed).
diff --git a/modules/database/audit-autoloaded-options/can-load.php b/modules/database/audit-autoloaded-options/can-load.php
deleted file mode 100644
index 274a266348..0000000000
--- a/modules/database/audit-autoloaded-options/can-load.php
+++ /dev/null
@@ -1,19 +0,0 @@
-
- server-timing/object-cache.copy.php
+ includes/server-timing/object-cache.copy.php
.
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index 618e13ca19..55eff44c9d 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -7,9 +7,8 @@ parameters:
- default-enabled-modules.php
- load.php
- module-i18n.php
- - modules/
+ - includes/
- plugins/
- - server-timing/
- tests/
- uninstall.php
scanDirectories:
diff --git a/tests/server-timing/load-tests.php b/tests/includes/server-timing/load-tests.php
similarity index 100%
rename from tests/server-timing/load-tests.php
rename to tests/includes/server-timing/load-tests.php
diff --git a/tests/server-timing/perflab-server-timing-metric-tests.php b/tests/includes/server-timing/perflab-server-timing-metric-tests.php
similarity index 100%
rename from tests/server-timing/perflab-server-timing-metric-tests.php
rename to tests/includes/server-timing/perflab-server-timing-metric-tests.php
diff --git a/tests/server-timing/perflab-server-timing-tests.php b/tests/includes/server-timing/perflab-server-timing-tests.php
similarity index 100%
rename from tests/server-timing/perflab-server-timing-tests.php
rename to tests/includes/server-timing/perflab-server-timing-tests.php
diff --git a/tests/modules/database/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php
similarity index 100%
rename from tests/modules/database/audit-autoloaded-options/audit-autoloaded-options-test.php
rename to tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php
diff --git a/tests/modules/js-and-css/audit-enqueued-assets/audit-enqueued-assets-helper-test.php b/tests/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php
similarity index 100%
rename from tests/modules/js-and-css/audit-enqueued-assets/audit-enqueued-assets-helper-test.php
rename to tests/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php
diff --git a/tests/modules/js-and-css/audit-enqueued-assets/audit-enqueued-assets-test.php b/tests/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php
similarity index 100%
rename from tests/modules/js-and-css/audit-enqueued-assets/audit-enqueued-assets-test.php
rename to tests/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php
diff --git a/tests/load-tests.php b/tests/load-tests.php
index 825fa09bd5..4eef28e58b 100644
--- a/tests/load-tests.php
+++ b/tests/load-tests.php
@@ -97,36 +97,6 @@ static function ( $current_default, $option, $passed_default ) use ( &$has_passe
$this->assertEqualSetsWithIndex( $new_value, $settings );
}
- /**
- * @dataProvider data_legacy_modules
- */
- public function test_legacy_module_for_perflab_get_module_settings( $legacy_module_slug, $current_module_slug ) {
- $new_value = array( $legacy_module_slug => array( 'enabled' => true ) );
- update_option( PERFLAB_MODULES_SETTING, $new_value );
-
- $settings = perflab_get_module_settings();
- $this->assertArrayNotHasKey( $legacy_module_slug, $settings, 'The settings do not contain the old legacy module slug in the database' );
- $this->assertArrayHasKey( $current_module_slug, $settings, 'The settings contain an updated module slug in the database' );
- }
-
- /**
- * Data provider for test_legacy_module_for_perflab_get_module_settings().
- *
- * @return array {
- * @type array {
- * @type string $legacy_module_slug The legacy module slug.
- * @type string $current_module_slug The new/updated module slug.
- * }
- * }
- */
- public function data_legacy_modules() {
- return array(
- array( 'site-health/audit-autoloaded-options', 'database/audit-autoloaded-options' ),
- array( 'site-health/audit-enqueued-assets', 'js-and-css/audit-enqueued-assets' ),
- array( 'site-health/webp-support', 'images/webp-support' ),
- );
- }
-
public function test_perflab_get_active_modules() {
// Assert that by default there are no active modules.
$active_modules = perflab_get_active_modules();
@@ -181,45 +151,6 @@ public function test_perflab_render_generator() {
$this->assertStringContainsString( $expected, $output );
}
- /**
- * @dataProvider data_perflab_can_load_module
- */
- public function test_perflab_is_valid_module( $dummy_module, $expected_status ) {
- $this->assertSame( $expected_status, perflab_is_valid_module( $dummy_module ) );
- }
-
- public function data_perflab_is_valid_module() {
- return array(
- array( '', false ),
- array( '../tests/testdata/demo-modules/something/non-existing-module', false ),
- array( '../tests/testdata/demo-modules/js-and-css/demo-module-1', false ),
- array( '../tests/testdata/demo-modules/something/demo-module-2', true ),
- array( '../tests/testdata/demo-modules/images/demo-module-3', true ),
- array( '../tests/testdata/demo-modules/check-error/demo-module-4', false ),
- );
- }
-
- /**
- * @dataProvider data_perflab_can_load_module
- */
- public function test_perflab_can_load_module( $dummy_module, $expected_status ) {
- $this->assertSame( $expected_status, perflab_can_load_module( $dummy_module ) );
- }
-
- public function data_perflab_can_load_module() {
- return array(
- array( '../tests/testdata/demo-modules/js-and-css/demo-module-1', false ),
- array( '../tests/testdata/demo-modules/something/demo-module-2', true ),
- array( '../tests/testdata/demo-modules/images/demo-module-3', true ),
- );
- }
-
- public function test_perflab_can_load_module_with_not_loaded_module() {
- $can_load_module = perflab_can_load_module( '../tests/testdata/demo-modules/check-error/demo-module-4' );
- $this->assertInstanceOf( 'WP_Error', $can_load_module );
- $this->assertSame( 'cannot_load_module', $can_load_module->get_error_code() );
- }
-
public function test_perflab_activate_module() {
perflab_activate_module( __DIR__ . '/testdata/demo-modules/something/demo-module-2' );
$this->assertSame( 'activated', get_option( 'test_demo_module_activation_status' ) );
@@ -230,19 +161,6 @@ public function test_perflab_deactivate_module() {
$this->assertSame( 'deactivated', get_option( 'test_demo_module_activation_status' ) );
}
- private function get_expected_default_option() {
- // This code is essentially copied over from the perflab_register_modules_setting() function.
- $default_enabled_modules = require PERFLAB_PLUGIN_DIR_PATH . 'default-enabled-modules.php';
- return array_reduce(
- $default_enabled_modules,
- static function ( $module_settings, $module_dir ) {
- $module_settings[ $module_dir ] = array( 'enabled' => true );
- return $module_settings;
- },
- array()
- );
- }
-
public function test_perflab_maybe_set_object_cache_dropin_no_conflict() {
global $wp_filesystem;
@@ -255,7 +173,7 @@ public function test_perflab_maybe_set_object_cache_dropin_no_conflict() {
// Run function to place drop-in and ensure it exists afterwards.
perflab_maybe_set_object_cache_dropin();
$this->assertTrue( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) );
- $this->assertSame( file_get_contents( PERFLAB_PLUGIN_DIR_PATH . 'server-timing/object-cache.copy.php' ), $wp_filesystem->get_contents( WP_CONTENT_DIR . '/object-cache.php' ) );
+ $this->assertSame( file_get_contents( PERFLAB_PLUGIN_DIR_PATH . 'includes/server-timing/object-cache.copy.php' ), $wp_filesystem->get_contents( WP_CONTENT_DIR . '/object-cache.php' ) );
}
public function test_perflab_maybe_set_object_cache_dropin_no_conflict_but_failing() {
@@ -331,6 +249,6 @@ static function () {
WP_Filesystem();
// Simulate that the original object-cache.copy.php file exists.
- $wp_filesystem->put_contents( PERFLAB_PLUGIN_DIR_PATH . 'server-timing/object-cache.copy.php', file_get_contents( PERFLAB_PLUGIN_DIR_PATH . 'server-timing/object-cache.copy.php' ) );
+ $wp_filesystem->put_contents( PERFLAB_PLUGIN_DIR_PATH . 'includes/server-timing/object-cache.copy.php', file_get_contents( PERFLAB_PLUGIN_DIR_PATH . 'includes/server-timing/object-cache.copy.php' ) );
}
}