Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@
/tests/modules/images @adamsilverstein @getsource
/tests/testdata/modules/images @adamsilverstein @getsource

# Focus: JavaScript
/modules/javascript @aristath @sgomes
/tests/modules/javascript @aristath @sgomes
/tests/testdata/modules/javascript @aristath @sgomes

# Focus: Site Health
/modules/site-health
/tests/modules/site-health
/tests/testdata/modules/site-health
# Focus: JS & CSS
/modules/js-and-css @aristath @sgomes
/tests/modules/js-and-css @aristath @sgomes
/tests/testdata/modules/js-and-css @aristath @sgomes

# Focus: Measurement
/modules/measurement
Expand All @@ -36,19 +31,19 @@
/tests/testdata/modules/images/webp-uploads @adamsilverstein @felixarntz @mitogh

# Module: WebP Support Health Check
/modules/site-health/webp-support @adamsilverstein @kirtangajjar @mitogh
/tests/modules/site-health/webp-support @adamsilverstein @kirtangajjar @mitogh
/tests/testdata/modules/site-health/webp-support @adamsilverstein @kirtangajjar @mitogh
/modules/images/webp-support @adamsilverstein @kirtangajjar @mitogh
/tests/modules/images/webp-support @adamsilverstein @kirtangajjar @mitogh
/tests/testdata/modules/images/webp-support @adamsilverstein @kirtangajjar @mitogh

# Module: Autoloaded Options Health Check
/modules/site-health/audit-autoloaded-options @manuelRod
/tests/modules/site-health/audit-autoloaded-options @manuelRod
/tests/testdata/modules/site-health/audit-autoloaded-options @manuelRod
/modules/database/audit-autoloaded-options @manuelRod
/tests/modules/database/audit-autoloaded-options @manuelRod
/tests/testdata/modules/database/audit-autoloaded-options @manuelRod

# Module: Enqueued Assets Health Check
/modules/site-health/audit-enqueued-assets @manuelRod
/tests/modules/site-health/audit-enqueued-assets @manuelRod
/tests/testdata/modules/site-health/audit-enqueued-assets @manuelRod
/modules/js-and-css/audit-enqueued-assets @manuelRod
/tests/modules/js-and-css/audit-enqueued-assets @manuelRod
/tests/testdata/modules/js-and-css/audit-enqueued-assets @manuelRod

# Module: Persistent Object Cache Health Check
/modules/object-cache/persistent-object-cache-health-check @tillkruss @spacedmonkey
Expand All @@ -61,5 +56,5 @@
/tests/testdata/modules/images/dominant-color @pbearne @spacedmonkey

# Module: Full Page Cache Health Check
/modules/site-health/audit-full-page-cache @manuelRod @westonruter
/tests/modules/site-health/audit-full-page-cache @manuelRod @westonruter
/modules/object-cache/audit-full-page-cache @manuelRod @westonruter
/tests/modules/object-cache/audit-full-page-cache @manuelRod @westonruter
8 changes: 4 additions & 4 deletions admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ function perflab_get_focus_areas() {
'images' => array(
'name' => __( 'Images', 'performance-lab' ),
),
'javascript' => array(
'name' => __( 'JavaScript', 'performance-lab' ),
'js-and-css' => array(
'name' => __( 'JS & CSS', 'performance-lab' ),
),
'site-health' => array(
'name' => __( 'Site Health', 'performance-lab' ),
'database' => array(
'name' => __( 'Database', 'performance-lab' ),
),
'measurement' => array(
'name' => __( 'Measurement', 'performance-lab' ),
Expand Down
4 changes: 2 additions & 2 deletions bin/plugin/commands/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const { log, formats } = require( '../lib/logger' );
*/
const FOCUS_AREAS = {
images: 10,
javascript: 20,
'site-health': 30,
'js-and-css': 20,
database: 30,
measurement: 40,
'object-cache': 50,
};
Expand Down
4 changes: 2 additions & 2 deletions default-enabled-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */
return array(
'images/dominant-color',
'images/webp-support',
'images/webp-uploads',
'site-health/audit-full-page-cache',
'site-health/webp-support',
'object-cache/audit-full-page-cache',
'object-cache/persistent-object-cache-health-check',
);
/* THIS IS THE END OF THE GENERATED FILE */
18 changes: 17 additions & 1 deletion load.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,23 @@ function perflab_get_module_settings() {
// Even though a default value is registered for this setting, the default must be explicitly
// passed here, to support scenarios where this function is called before the 'init' action,
// for example when loading the active modules.
return (array) get_option( PERFLAB_MODULES_SETTING, perflab_get_modules_setting_default() );
$module_settings = (array) get_option( PERFLAB_MODULES_SETTING, perflab_get_modules_setting_default() );

$legacy_module_slugs = array(
'site-health/audit-autoloaded-options' => 'database/audit-autoloaded-options',
'site-health/audit-enqueued-assets' => 'js-and-css/audit-enqueued-assets',
'site-health/audit-full-page-cache' => 'object-cache/audit-full-page-cache',
'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;
}

/**
Expand Down
30 changes: 15 additions & 15 deletions tests/admin/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
class Admin_Load_Tests extends WP_UnitTestCase {

private static $demo_modules = array(
'javascript/demo-module-1' => array(
'js-and-css/demo-module-1' => array(
'name' => 'Demo Module 1',
'description' => 'This is the description for demo module 1.',
'experimental' => false,
'focus' => 'javascript',
'focus' => 'js-and-css',
'slug' => 'demo-module-1',
),
'something/demo-module-2' => array(
Expand All @@ -35,11 +35,11 @@ class Admin_Load_Tests extends WP_UnitTestCase {
'images' => array(
'name' => 'Images',
),
'javascript' => array(
'name' => 'JavaScript',
'js-and-css' => array(
'name' => 'js-and-css',
),
'site-health' => array(
'name' => 'Site Health',
'database' => array(
'name' => 'Database',
),
'measurement' => array(
'name' => 'Measurement',
Expand Down Expand Up @@ -118,9 +118,9 @@ public function test_perflab_load_modules_page() {
'after_section' => '',
'section_class' => '',
),
'javascript' => array(
'id' => 'javascript',
'title' => 'JavaScript',
'js-and-css' => array(
'id' => 'js-and-css',
'title' => 'js-and-css',
'callback' => null,
'before_section' => '',
'after_section' => '',
Expand All @@ -140,7 +140,7 @@ public function test_perflab_load_modules_page() {
$this->assertEqualSets(
array(
'images',
'javascript',
'js-and-css',
'other',
),
array_keys( $wp_settings_fields[ PERFLAB_MODULES_SCREEN ] )
Expand All @@ -150,8 +150,8 @@ public function test_perflab_load_modules_page() {
array_keys( $wp_settings_fields[ PERFLAB_MODULES_SCREEN ]['images'] )
);
$this->assertEqualSets(
array( 'javascript/demo-module-1' ),
array_keys( $wp_settings_fields[ PERFLAB_MODULES_SCREEN ]['javascript'] )
array( 'js-and-css/demo-module-1' ),
array_keys( $wp_settings_fields[ PERFLAB_MODULES_SCREEN ]['js-and-css'] )
);
$this->assertEqualSets(
array( 'something/demo-module-2' ),
Expand All @@ -168,7 +168,7 @@ public function test_perflab_render_modules_page() {
}

public function test_perflab_render_modules_page_field() {
$module_slug = 'javascript/demo-module-1';
$module_slug = 'js-and-css/demo-module-1';
$module_data = self::$demo_modules[ $module_slug ];
$module_settings = array( 'enabled' => false );

Expand Down Expand Up @@ -196,8 +196,8 @@ public function test_perflab_render_modules_page_field() {
public function test_perflab_get_focus_areas() {
$expected_focus_areas = array(
'images',
'javascript',
'site-health',
'js-and-css',
'database',
'measurement',
'object-cache',
);
Expand Down
35 changes: 33 additions & 2 deletions tests/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,37 @@ function( $default, $option, $passed_default ) use ( &$has_passed_default ) {
$this->assertSame( $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' );
Comment on lines +108 to +109
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As good habit like WP core,

Test methods with multiple assertions need a message parameter for each assertion, per Core Handbook - Writing PHPUnit Tests - Using Assertions.

}

/**
* 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/audit-full-page-cache', 'object-cache/audit-full-page-cache' ),
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();
Expand Down Expand Up @@ -162,7 +193,7 @@ 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/javascript/demo-module-1', 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 ),
);
Expand All @@ -177,7 +208,7 @@ public function test_perflab_can_load_module( $dummy_module, $expected_status )

public function data_perflab_can_load_module() {
return array(
array( '../tests/testdata/demo-modules/javascript/demo-module-1', 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 ),
);
Expand Down