From c3170feb13cb415b5a97a67efb2a6ff530871be4 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 22 Jun 2022 14:12:51 +0530 Subject: [PATCH 01/28] Added: Mechanism to not load module if core version is available --- admin/load.php | 31 ++++++++----- load.php | 56 +++++++++++++++++++++--- modules/images/webp-uploads/can-load.php | 22 ++++++++++ 3 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 modules/images/webp-uploads/can-load.php diff --git a/admin/load.php b/admin/load.php index dfda69f04a..13f6bfa3e9 100644 --- a/admin/load.php +++ b/admin/load.php @@ -126,29 +126,38 @@ function perflab_render_modules_page() { * @param array $module_settings Associative array of the module's current settings. */ function perflab_render_modules_page_field( $module_slug, $module_data, $module_settings ) { - $base_id = sprintf( 'module_%s', $module_slug ); - $base_name = sprintf( '%1$s[%2$s]', PERFLAB_MODULES_SETTING, $module_slug ); - $enabled = isset( $module_settings['enabled'] ) && $module_settings['enabled']; + $base_id = sprintf( 'module_%s', $module_slug ); + $base_name = sprintf( '%1$s[%2$s]', PERFLAB_MODULES_SETTING, $module_slug ); + $enabled = isset( $module_settings['enabled'] ) && $module_settings['enabled']; + $can_load_module = perflab_can_load_module( $module_slug ); ?>
diff --git a/load.php b/load.php index 83d1146846..b41b97398d 100644 --- a/load.php +++ b/load.php @@ -134,7 +134,25 @@ function( $module_settings ) { */ $modules = apply_filters( 'perflab_active_modules', $modules ); - return $modules; + $active_modules = array(); + foreach ( $modules as $module ) { + + // Do not load module if it marge in WordPress. + $can_load_module = perflab_can_load_module( $module ); + if ( ! $can_load_module ) { + continue; + } + + // Do not load module if it no longer exists. + $module_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; + if ( ! file_exists( $module_file ) ) { + continue; + } + + $active_modules[] = $module; + } + + return $active_modules; } /** @@ -168,6 +186,35 @@ function perflab_render_generator() { } add_action( 'wp_head', 'perflab_render_generator' ); +/** + * Don't load the performance modules if the core version of the module is available. + * + * @since n.e.x.t + */ +function perflab_can_load_module( $module ) { + $module_load_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/can-load.php'; + + // If the load file does not exist, the feature is not in core and the module can be loaded. + if ( ! file_exists( $module_load_file ) ) { + return true; + } + + // Require the file to include the add_filter function. + require_once $module_load_file; + + /** + * Filters whether the module can load or not. + * + * You can set this to false in order to disable the module. + * + * @since n.e.x.t + * + * @param bool $can_load_module Whether to load module. default true. + * @param string $module The name of the module. + */ + return apply_filters( 'perflab_can_load_module', true, $module ); +} + /** * Loads the active performance modules. * @@ -181,13 +228,8 @@ function perflab_load_active_modules() { } foreach ( $active_modules as $module ) { - // Do not load module if it no longer exists. - $module_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; - if ( ! file_exists( $module_file ) ) { - continue; - } - require_once $module_file; + require_once plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; } } diff --git a/modules/images/webp-uploads/can-load.php b/modules/images/webp-uploads/can-load.php new file mode 100644 index 0000000000..ff8efb2f76 --- /dev/null +++ b/modules/images/webp-uploads/can-load.php @@ -0,0 +1,22 @@ + Date: Wed, 22 Jun 2022 14:15:52 +0530 Subject: [PATCH 02/28] Added: New line --- modules/images/webp-uploads/can-load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/images/webp-uploads/can-load.php b/modules/images/webp-uploads/can-load.php index ff8efb2f76..2439b8df06 100644 --- a/modules/images/webp-uploads/can-load.php +++ b/modules/images/webp-uploads/can-load.php @@ -19,4 +19,4 @@ function perflab_check_webp_uploads_core_functions( $can_load, $module ) { } return true; -} \ No newline at end of file +} From 42a82fcb6b8a244e1413fceebb6b993e91034852 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 22 Jun 2022 14:46:08 +0530 Subject: [PATCH 03/28] Fix: Code linting --- modules/images/webp-uploads/can-load.php | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/images/webp-uploads/can-load.php b/modules/images/webp-uploads/can-load.php index 2439b8df06..172c70f461 100644 --- a/modules/images/webp-uploads/can-load.php +++ b/modules/images/webp-uploads/can-load.php @@ -6,17 +6,25 @@ * @package performance-lab */ -add_filter( 'perflab_can_load_module', 'perflab_check_webp_uploads_core_functions', 10, 2 ); - +/** + * Filters whether the module can load or not. + * + * @since n.e.x.t + * + * @param bool $can_load_module Whether to load module. default true. + * @param string $module The name of the module. + * @return bool whether to load module or not. + */ function perflab_check_webp_uploads_core_functions( $can_load, $module ) { - if ( 'images/webp-uploads' !== $module ) { - return $can_load; - } + if ( 'images/webp-uploads' !== $module ) { + return $can_load; + } - if ( function_exists( 'wp_image_use_alternate_mime_types' ) ) { - return false; - } + if ( function_exists( 'wp_image_use_alternate_mime_types' ) ) { + return false; + } - return true; + return true; } +add_filter( 'perflab_can_load_module', 'perflab_check_webp_uploads_core_functions', 10, 2 ); From 5294f83e93729db4142480a6b0e53837a2165e50 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 22 Jun 2022 14:52:26 +0530 Subject: [PATCH 04/28] Fix: Docblock for functions --- load.php | 3 +++ modules/images/webp-uploads/can-load.php | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/load.php b/load.php index b41b97398d..9d2c89d889 100644 --- a/load.php +++ b/load.php @@ -190,6 +190,9 @@ function perflab_render_generator() { * Don't load the performance modules if the core version of the module is available. * * @since n.e.x.t + * + * @param string $module The name of the module. + * @return bool Whether to load module or not. */ function perflab_can_load_module( $module ) { $module_load_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/can-load.php'; diff --git a/modules/images/webp-uploads/can-load.php b/modules/images/webp-uploads/can-load.php index 172c70f461..a6e1c9a50c 100644 --- a/modules/images/webp-uploads/can-load.php +++ b/modules/images/webp-uploads/can-load.php @@ -11,9 +11,9 @@ * * @since n.e.x.t * - * @param bool $can_load_module Whether to load module. default true. - * @param string $module The name of the module. - * @return bool whether to load module or not. + * @param bool $can_load Whether to load module. default true. + * @param string $module The name of the module. + * @return bool Whether to load module or not. */ function perflab_check_webp_uploads_core_functions( $can_load, $module ) { From eef08c5b7fcf9d447b84f5523c6f5c60d17925d6 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 22 Jun 2022 17:27:51 +0530 Subject: [PATCH 05/28] Update some tests --- tests/load-tests.php | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/load-tests.php b/tests/load-tests.php index 126819bcaf..49d213be92 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -110,18 +110,28 @@ function( $module_settings ) { ); $this->assertSame( $expected_active_modules, $active_modules ); - // Assert that option updates affect the active modules correctly. + // Assert that dummy module option doesn't show in active modules. $new_value = array( 'inactive-module' => array( 'enabled' => false ), 'active-module' => array( 'enabled' => true ), ); update_option( PERFLAB_MODULES_SETTING, $new_value ); $active_modules = perflab_get_active_modules(); - $this->assertSame( array( 'active-module' ), $active_modules ); + $this->assertSame( array(), $active_modules ); + + // Assert that it only allow existing modules. + $new_value = array( + 'inactive-module' => array( 'enabled' => false ), + 'images/webp-uploads' => array( 'enabled' => true ), + 'object-cache/persistent-object-cache-health-check' => array( 'enabled' => true ), + ); + update_option( PERFLAB_MODULES_SETTING, $new_value ); + $active_modules = perflab_get_active_modules(); + $this->assertSame( array( 'images/webp-uploads', 'object-cache/persistent-object-cache-health-check' ), $active_modules ); } public function test_perflab_get_generator_content() { - // Assert that it returns the current version and active modules. + // Assert that it doesn't returns dummy modules. $dummy_active_modules = array( 'images/a-module', 'object-cache/another-module' ); add_filter( 'perflab_active_modules', @@ -129,7 +139,25 @@ function() use ( $dummy_active_modules ) { return $dummy_active_modules; } ); - $expected = 'Performance Lab ' . PERFLAB_VERSION . '; modules: ' . implode( ', ', $dummy_active_modules ); + $expected = 'Performance Lab ' . PERFLAB_VERSION . '; modules: '; + $content = perflab_get_generator_content(); + $this->assertSame( $expected, $content ); + + // Assert that it returns active modules. + $new_value = array( + 'inactive-module' => array( 'enabled' => false ), + 'images/webp-uploads' => array( 'enabled' => true ), + 'object-cache/persistent-object-cache-health-check' => array( 'enabled' => true ), + ); + update_option( PERFLAB_MODULES_SETTING, $new_value ); + $dummy_active_modules = array( 'images/webp-uploads', 'object-cache/persistent-object-cache-health-check' ); + add_filter( + 'perflab_active_modules', + function() use ( $dummy_active_modules ) { + return $dummy_active_modules; + } + ); + $expected = 'Performance Lab ' . PERFLAB_VERSION . '; modules: '.implode( ', ', $dummy_active_modules ); $content = perflab_get_generator_content(); $this->assertSame( $expected, $content ); } From 1ee00289fe59c6a2b6aa8283e9f3c6a0df9a4915 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 22 Jun 2022 17:36:10 +0530 Subject: [PATCH 06/28] Fix: PHP lint --- tests/load-tests.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/load-tests.php b/tests/load-tests.php index 49d213be92..aa2c491e22 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -121,8 +121,8 @@ function( $module_settings ) { // Assert that it only allow existing modules. $new_value = array( - 'inactive-module' => array( 'enabled' => false ), - 'images/webp-uploads' => array( 'enabled' => true ), + 'inactive-module' => array( 'enabled' => false ), + 'images/webp-uploads' => array( 'enabled' => true ), 'object-cache/persistent-object-cache-health-check' => array( 'enabled' => true ), ); update_option( PERFLAB_MODULES_SETTING, $new_value ); @@ -145,8 +145,8 @@ function() use ( $dummy_active_modules ) { // Assert that it returns active modules. $new_value = array( - 'inactive-module' => array( 'enabled' => false ), - 'images/webp-uploads' => array( 'enabled' => true ), + 'inactive-module' => array( 'enabled' => false ), + 'images/webp-uploads' => array( 'enabled' => true ), 'object-cache/persistent-object-cache-health-check' => array( 'enabled' => true ), ); update_option( PERFLAB_MODULES_SETTING, $new_value ); @@ -157,7 +157,7 @@ function() use ( $dummy_active_modules ) { return $dummy_active_modules; } ); - $expected = 'Performance Lab ' . PERFLAB_VERSION . '; modules: '.implode( ', ', $dummy_active_modules ); + $expected = 'Performance Lab ' . PERFLAB_VERSION . '; modules: ' . implode( ', ', $dummy_active_modules ); $content = perflab_get_generator_content(); $this->assertSame( $expected, $content ); } From 8750d5a60525eaa13ae959c38606fe0bb45f80c9 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 22 Jun 2022 11:46:23 -0700 Subject: [PATCH 07/28] Simplify boolean check for function existence. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Crisoforo Gaspar Hernández --- modules/images/webp-uploads/can-load.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/images/webp-uploads/can-load.php b/modules/images/webp-uploads/can-load.php index a6e1c9a50c..884e70e202 100644 --- a/modules/images/webp-uploads/can-load.php +++ b/modules/images/webp-uploads/can-load.php @@ -21,10 +21,6 @@ function perflab_check_webp_uploads_core_functions( $can_load, $module ) { return $can_load; } - if ( function_exists( 'wp_image_use_alternate_mime_types' ) ) { - return false; - } - - return true; + return ! function_exists( 'wp_image_use_alternate_mime_types' ); } add_filter( 'perflab_can_load_module', 'perflab_check_webp_uploads_core_functions', 10, 2 ); From f06ba7d03414a6b89312cb6ef59365280d1dc089 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 23 Jun 2022 16:52:00 +0530 Subject: [PATCH 08/28] Fix: Text related changes --- admin/load.php | 24 +++++++++++------------- load.php | 10 +++++----- modules/images/webp-uploads/can-load.php | 2 +- tests/load-tests.php | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/admin/load.php b/admin/load.php index 13f6bfa3e9..b255a15431 100644 --- a/admin/load.php +++ b/admin/load.php @@ -144,20 +144,18 @@ function perflab_render_modules_page_field( $module_slug, $module_data, $module_ __( '%s is already part of your WordPress version and therefore cannot be loaded as part of the plugin.', 'performance-lab' ), esc_html( $module_data['name'] ) ); + } elseif ( $module_data['experimental'] ) { + printf( + /* translators: %s: module name */ + __( 'Enable %s (experimental)', 'performance-lab' ), + esc_html( $module_data['name'] ) + ); } else { - if ( $module_data['experimental'] ) { - printf( - /* translators: %s: module name */ - __( 'Enable %s (experimental)', 'performance-lab' ), - esc_html( $module_data['name'] ) - ); - } else { - printf( - /* translators: %s: module name */ - __( 'Enable %s', 'performance-lab' ), - esc_html( $module_data['name'] ) - ); - } + printf( + /* translators: %s: module name */ + __( 'Enable %s', 'performance-lab' ), + esc_html( $module_data['name'] ) + ); } ?> diff --git a/load.php b/load.php index 9d2c89d889..53079d4f83 100644 --- a/load.php +++ b/load.php @@ -137,13 +137,13 @@ function( $module_settings ) { $active_modules = array(); foreach ( $modules as $module ) { - // Do not load module if it marge in WordPress. + // Do not load module if it cannot be loaded, e.g. if it was already merged and is available in WordPress core. $can_load_module = perflab_can_load_module( $module ); if ( ! $can_load_module ) { continue; } - // Do not load module if it no longer exists. + // Do not load module if no longer exists. $module_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; if ( ! file_exists( $module_file ) ) { continue; @@ -187,7 +187,7 @@ function perflab_render_generator() { add_action( 'wp_head', 'perflab_render_generator' ); /** - * Don't load the performance modules if the core version of the module is available. + * Checks whether the given module can be loaded in the current environment. * * @since n.e.x.t * @@ -197,7 +197,7 @@ function perflab_render_generator() { function perflab_can_load_module( $module ) { $module_load_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/can-load.php'; - // If the load file does not exist, the feature is not in core and the module can be loaded. + // If the `can-load.php` file does not exist, assume the module can be loaded. if ( ! file_exists( $module_load_file ) ) { return true; } @@ -212,7 +212,7 @@ function perflab_can_load_module( $module ) { * * @since n.e.x.t * - * @param bool $can_load_module Whether to load module. default true. + * @param bool $can_load_module Whether to load module. Default true. * @param string $module The name of the module. */ return apply_filters( 'perflab_can_load_module', true, $module ); diff --git a/modules/images/webp-uploads/can-load.php b/modules/images/webp-uploads/can-load.php index 884e70e202..972aec9da9 100644 --- a/modules/images/webp-uploads/can-load.php +++ b/modules/images/webp-uploads/can-load.php @@ -11,7 +11,7 @@ * * @since n.e.x.t * - * @param bool $can_load Whether to load module. default true. + * @param bool $can_load Whether to load module. Default true. * @param string $module The name of the module. * @return bool Whether to load module or not. */ diff --git a/tests/load-tests.php b/tests/load-tests.php index aa2c491e22..cb84b62be0 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -119,7 +119,7 @@ function( $module_settings ) { $active_modules = perflab_get_active_modules(); $this->assertSame( array(), $active_modules ); - // Assert that it only allow existing modules. + // Assert that only allows existing modules. $new_value = array( 'inactive-module' => array( 'enabled' => false ), 'images/webp-uploads' => array( 'enabled' => true ), From 073d872985f0336a27b151eb2af2834704ea34e9 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 24 Jun 2022 09:54:21 +0530 Subject: [PATCH 09/28] Update: logic for perflab_can_load_module --- load.php | 26 ++++++++++-------------- modules/images/webp-uploads/can-load.php | 19 ++--------------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/load.php b/load.php index 53079d4f83..ba2b80f218 100644 --- a/load.php +++ b/load.php @@ -191,8 +191,8 @@ function perflab_render_generator() { * * @since n.e.x.t * - * @param string $module The name of the module. - * @return bool Whether to load module or not. + * @param string $module Slug of the module. + * @return bool Whether the module can be loaded or not. */ function perflab_can_load_module( $module ) { $module_load_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/can-load.php'; @@ -202,20 +202,16 @@ function perflab_can_load_module( $module ) { return true; } - // Require the file to include the add_filter function. - require_once $module_load_file; + // Require the file to get the closure for whether the module can load. + $can_load = require $module_load_file; - /** - * Filters whether the module can load or not. - * - * You can set this to false in order to disable the module. - * - * @since n.e.x.t - * - * @param bool $can_load_module Whether to load module. Default true. - * @param string $module The name of the module. - */ - return apply_filters( 'perflab_can_load_module', true, $module ); + // If the `can-load.php` file is invalid and does not return a closure, assume the module can be loaded. + if ( ! is_callable( $can_load ) ) { + return true; + } + + // Call the closure to determine whether the module can be loaded. + return $can_load(); } /** diff --git a/modules/images/webp-uploads/can-load.php b/modules/images/webp-uploads/can-load.php index 972aec9da9..5634b2c354 100644 --- a/modules/images/webp-uploads/can-load.php +++ b/modules/images/webp-uploads/can-load.php @@ -6,21 +6,6 @@ * @package performance-lab */ -/** - * Filters whether the module can load or not. - * - * @since n.e.x.t - * - * @param bool $can_load Whether to load module. Default true. - * @param string $module The name of the module. - * @return bool Whether to load module or not. - */ -function perflab_check_webp_uploads_core_functions( $can_load, $module ) { - - if ( 'images/webp-uploads' !== $module ) { - return $can_load; - } - +return function() { return ! function_exists( 'wp_image_use_alternate_mime_types' ); -} -add_filter( 'perflab_can_load_module', 'perflab_check_webp_uploads_core_functions', 10, 2 ); +}; From a0235c808cb61bb08eb15121abc1491e8883961b Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 29 Jun 2022 15:36:10 +0530 Subject: [PATCH 10/28] Fix: Feedback related to disabled checkbox --- admin/load.php | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/admin/load.php b/admin/load.php index b255a15431..335dbc55db 100644 --- a/admin/load.php +++ b/admin/load.php @@ -136,28 +136,34 @@ function perflab_render_modules_page_field( $module_slug, $module_data, $module_

" class="description"> From ca1cd0fdbcad5a511643b8e733c94fae8d011b4d Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 29 Jun 2022 15:39:51 +0530 Subject: [PATCH 11/28] Fix: Lint white space issue --- admin/load.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/admin/load.php b/admin/load.php index 335dbc55db..39baac34d9 100644 --- a/admin/load.php +++ b/admin/load.php @@ -149,19 +149,19 @@ function perflab_render_modules_page_field( $module_slug, $module_data, $module_ " name="" aria-describedby="" value="1"> (experimental)', 'performance-lab' ), - esc_html( $module_data['name'] ) - ); - } else { - printf( - /* translators: %s: module name */ - __( 'Enable %s', 'performance-lab' ), - esc_html( $module_data['name'] ) - ); - } + if ( $module_data['experimental'] ) { + printf( + /* translators: %s: module name */ + __( 'Enable %s (experimental)', 'performance-lab' ), + esc_html( $module_data['name'] ) + ); + } else { + printf( + /* translators: %s: module name */ + __( 'Enable %s', 'performance-lab' ), + esc_html( $module_data['name'] ) + ); + } ?> From 3f6244df3fd20beeebd7cd656fe1e26df2f06232 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 29 Jun 2022 16:55:55 +0530 Subject: [PATCH 12/28] Perflab_get_active_and_valid_modules() is introduced, and review is implemented --- load.php | 41 +++++++++++++++++++++++++++++------------ tests/load-tests.php | 14 ++------------ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/load.php b/load.php index ba2b80f218..fcc7d4c3d6 100644 --- a/load.php +++ b/load.php @@ -134,8 +134,25 @@ function( $module_settings ) { */ $modules = apply_filters( 'perflab_active_modules', $modules ); - $active_modules = array(); - foreach ( $modules as $module ) { + return $modules; +} + +/** + * Gets the active and valid performance modules. + * + * @since n.e.x.t + * + * @return array List of active valid module slugs. + */ +function perflab_get_active_and_valid_modules() { + $active_modules = perflab_get_active_modules(); + + if ( ! $active_modules ) { + return array(); + } + + $active_and_valid_modules = array(); + foreach ( $active_modules as $module ) { // Do not load module if it cannot be loaded, e.g. if it was already merged and is available in WordPress core. $can_load_module = perflab_can_load_module( $module ); @@ -149,10 +166,10 @@ function( $module_settings ) { continue; } - $active_modules[] = $module; + $active_and_valid_modules[] = $module; } - return $active_modules; + return $active_and_valid_modules; } /** @@ -163,12 +180,12 @@ function( $module_settings ) { * @since 1.1.0 */ function perflab_get_generator_content() { - $active_modules = perflab_get_active_modules(); + $active_and_valid_modules = perflab_get_active_and_valid_modules(); return sprintf( 'Performance Lab %1$s; modules: %2$s', PERFLAB_VERSION, - implode( ', ', $active_modules ) + implode( ', ', $active_and_valid_modules ) ); } @@ -215,24 +232,24 @@ function perflab_can_load_module( $module ) { } /** - * Loads the active performance modules. + * Loads the active and valid performance modules. * * @since 1.0.0 */ -function perflab_load_active_modules() { - $active_modules = perflab_get_active_modules(); +function perflab_load_active_and_valid_modules() { + $active_and_valid_modules = perflab_get_active_and_valid_modules(); - if ( empty( $active_modules ) ) { + if ( empty( $active_and_valid_modules ) ) { return; } - foreach ( $active_modules as $module ) { + foreach ( $active_and_valid_modules as $module ) { require_once plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; } } -perflab_load_active_modules(); +perflab_load_active_and_valid_modules(); // Only load admin integration when in admin. if ( is_admin() ) { diff --git a/tests/load-tests.php b/tests/load-tests.php index cb84b62be0..cca17666f3 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -110,24 +110,14 @@ function( $module_settings ) { ); $this->assertSame( $expected_active_modules, $active_modules ); - // Assert that dummy module option doesn't show in active modules. + // Assert that only allows existing modules. $new_value = array( 'inactive-module' => array( 'enabled' => false ), 'active-module' => array( 'enabled' => true ), ); update_option( PERFLAB_MODULES_SETTING, $new_value ); $active_modules = perflab_get_active_modules(); - $this->assertSame( array(), $active_modules ); - - // Assert that only allows existing modules. - $new_value = array( - 'inactive-module' => array( 'enabled' => false ), - 'images/webp-uploads' => array( 'enabled' => true ), - 'object-cache/persistent-object-cache-health-check' => array( 'enabled' => true ), - ); - update_option( PERFLAB_MODULES_SETTING, $new_value ); - $active_modules = perflab_get_active_modules(); - $this->assertSame( array( 'images/webp-uploads', 'object-cache/persistent-object-cache-health-check' ), $active_modules ); + $this->assertSame( array( 'active-module' ), $active_modules ); } public function test_perflab_get_generator_content() { From 7c5365c3a21ea447c85df2d92f1500e1b79e3199 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 30 Jun 2022 09:44:42 +0530 Subject: [PATCH 13/28] Fix: Admin settings review --- admin/load.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/load.php b/admin/load.php index 39baac34d9..62b334d340 100644 --- a/admin/load.php +++ b/admin/load.php @@ -137,8 +137,8 @@ function perflab_render_modules_page_field( $module_slug, $module_data, $module_

" class="description"> diff --git a/load.php b/load.php index 0c81888189..d3244542c1 100644 --- a/load.php +++ b/load.php @@ -144,15 +144,14 @@ function( $module_settings ) { * * @return array List of active valid module slugs. */ -function perflab_get_active_and_valid_modules() { - $active_modules = perflab_get_active_modules(); +function perflab_get_valid_modules( array $modules = array() ) { - if ( ! $active_modules ) { + if ( ! is_array( $modules ) ) { return array(); } - $active_and_valid_modules = array(); - foreach ( $active_modules as $module ) { + $valid_modules = array(); + foreach ( $modules as $module ) { // Do not load module if no longer exists. $module_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; @@ -161,15 +160,14 @@ function perflab_get_active_and_valid_modules() { } // Do not load module if it cannot be loaded, e.g. if it was already merged and is available in WordPress core. - $can_load_module = perflab_can_load_module( $module ); - if ( ! $can_load_module ) { + if ( ! perflab_can_load_module( $module ) ) { continue; } - $active_and_valid_modules[] = $module; + $valid_modules[] = $module; } - return $active_and_valid_modules; + return $valid_modules; } /** @@ -180,7 +178,7 @@ function perflab_get_active_and_valid_modules() { * @since 1.1.0 */ function perflab_get_generator_content() { - $active_and_valid_modules = perflab_get_active_and_valid_modules(); + $active_and_valid_modules = perflab_get_valid_modules( perflab_get_active_modules() ); return sprintf( 'Performance Lab %1$s; modules: %2$s', @@ -220,15 +218,15 @@ function perflab_can_load_module( $module ) { } // Require the file to get the closure for whether the module can load. - $can_load = require $module_load_file; + $module = require $module_load_file; // If the `can-load.php` file is invalid and does not return a closure, assume the module can be loaded. - if ( ! is_callable( $can_load ) ) { + if ( ! is_callable( $module ) ) { return true; } // Call the closure to determine whether the module can be loaded. - return $can_load(); + return (bool) $module(); } /** @@ -238,7 +236,7 @@ function perflab_can_load_module( $module ) { * @since n.e.x.t Renamed to perflab_load_active_and_valid_modules(). */ function perflab_load_active_and_valid_modules() { - $active_and_valid_modules = perflab_get_active_and_valid_modules(); + $active_and_valid_modules = perflab_get_valid_modules( perflab_get_active_modules() ); if ( empty( $active_and_valid_modules ) ) { return; From d403b7a5aca6c08243ef742a62d425e2aafd549e Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 4 Jul 2022 12:06:44 +0530 Subject: [PATCH 21/28] Update unit tests in response to the review --- load.php | 1 + tests/load-tests.php | 20 +++++++++---------- .../images/demo-module-3/can-load.php | 4 +--- .../javascript/demo-module-1/can-load.php | 4 +--- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/load.php b/load.php index d3244542c1..5c71d4f04d 100644 --- a/load.php +++ b/load.php @@ -142,6 +142,7 @@ function( $module_settings ) { * * @since n.e.x.t * + * @param array $modules List of active module slugs. * @return array List of active valid module slugs. */ function perflab_get_valid_modules( array $modules = array() ) { diff --git a/tests/load-tests.php b/tests/load-tests.php index 382b002b8e..387ded5101 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -154,16 +154,15 @@ public function test_perflab_get_active_and_valid_modules() { global $wp_version; // Assert that it returns the empty array for dummy modules. - $dummy_active_modules = array( 'javascript/demo-module-1', 'something/demo-module-2', 'images/demo-module-3' ); - add_filter( - 'perflab_active_modules', - function() use ( $dummy_active_modules ) { - return $dummy_active_modules; - } + $dummy_active_modules = array( + '../tests/testdata/demo-modules/javascript/demo-module-1', + '../tests/testdata/demo-modules/something/demo-module-2', + '../tests/testdata/demo-modules/images/demo-module-3', ); - $output = perflab_get_active_and_valid_modules(); + + $output = perflab_get_valid_modules( $dummy_active_modules ); $this->assertIsArray( $output ); - $this->assertSame( array(), $output ); + $this->assertSame( array( '../tests/testdata/demo-modules/something/demo-module-2', '../tests/testdata/demo-modules/images/demo-module-3' ), $output ); // Assert that it returns the array for modules. if ( $wp_version >= '6.1' ) { @@ -174,7 +173,7 @@ function() use ( $active_modules ) { return $active_modules; } ); - $output = perflab_get_active_and_valid_modules(); + $output = perflab_get_valid_modules( perflab_get_active_modules() ); // Remove Image module as it will marge in 6.1. $remove_marge_modules = array_shift( $active_modules ); @@ -190,11 +189,10 @@ public function test_perflab_can_load_module() { 'images/demo-module-3' => true, ); - foreach ( $demo_modules as $module => $can_load ) { + foreach( $demo_modules as $module => $can_load ) { $output = perflab_can_load_module( '../tests/testdata/demo-modules/' . $module ); $this->assertSame( $can_load, $output ); } - } private function get_expected_default_option() { diff --git a/tests/testdata/demo-modules/images/demo-module-3/can-load.php b/tests/testdata/demo-modules/images/demo-module-3/can-load.php index cf61f5d314..1a2e176bcb 100644 --- a/tests/testdata/demo-modules/images/demo-module-3/can-load.php +++ b/tests/testdata/demo-modules/images/demo-module-3/can-load.php @@ -6,6 +6,4 @@ * @package performance-lab */ -return function() { - return true; -}; +return '__return_true'; \ No newline at end of file diff --git a/tests/testdata/demo-modules/javascript/demo-module-1/can-load.php b/tests/testdata/demo-modules/javascript/demo-module-1/can-load.php index 3eb39c87ba..16a702c300 100644 --- a/tests/testdata/demo-modules/javascript/demo-module-1/can-load.php +++ b/tests/testdata/demo-modules/javascript/demo-module-1/can-load.php @@ -6,6 +6,4 @@ * @package performance-lab */ -return function() { - return false; -}; +return '__return_false'; From 232d4627757910f261f5ce45d94d2851f364809f Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 4 Jul 2022 12:15:07 +0530 Subject: [PATCH 22/28] Correct lint --- tests/load-tests.php | 3 ++- tests/testdata/demo-modules/images/demo-module-3/can-load.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/load-tests.php b/tests/load-tests.php index 387ded5101..7b1fdd7708 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -189,10 +189,11 @@ public function test_perflab_can_load_module() { 'images/demo-module-3' => true, ); - foreach( $demo_modules as $module => $can_load ) { + foreach ( $demo_modules as $module => $can_load ) { $output = perflab_can_load_module( '../tests/testdata/demo-modules/' . $module ); $this->assertSame( $can_load, $output ); } + } private function get_expected_default_option() { diff --git a/tests/testdata/demo-modules/images/demo-module-3/can-load.php b/tests/testdata/demo-modules/images/demo-module-3/can-load.php index 1a2e176bcb..a8aabaf890 100644 --- a/tests/testdata/demo-modules/images/demo-module-3/can-load.php +++ b/tests/testdata/demo-modules/images/demo-module-3/can-load.php @@ -6,4 +6,4 @@ * @package performance-lab */ -return '__return_true'; \ No newline at end of file +return '__return_true'; From 3388874fd146f9e05da916972632dbd00d571cb6 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 4 Jul 2022 13:28:03 +0530 Subject: [PATCH 23/28] Update function name for test --- tests/load-tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/load-tests.php b/tests/load-tests.php index 7b1fdd7708..ce748a06fb 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -150,7 +150,7 @@ public function test_perflab_render_generator() { $this->assertContains( $expected, $output ); } - public function test_perflab_get_active_and_valid_modules() { + public function test_perflab_get_valid_modules() { global $wp_version; // Assert that it returns the empty array for dummy modules. From a156b1aa74293fcfeae71a0c905d890b72c1046f Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 7 Jul 2022 12:11:54 +0530 Subject: [PATCH 24/28] Address code review feedback --- load.php | 39 ++++++++++-------------- tests/load-tests.php | 71 +++++++++++++++++++------------------------- 2 files changed, 47 insertions(+), 63 deletions(-) diff --git a/load.php b/load.php index 5c71d4f04d..405d51c2c4 100644 --- a/load.php +++ b/load.php @@ -142,33 +142,27 @@ function( $module_settings ) { * * @since n.e.x.t * - * @param array $modules List of active module slugs. - * @return array List of active valid module slugs. + * @param string $module Slug of the module. + * @return null|string Module slug name on success, null on failure. */ -function perflab_get_valid_modules( array $modules = array() ) { +function perflab_is_valid_module( $module ) { - if ( ! is_array( $modules ) ) { - return array(); + if ( empty( $module ) ) { + return; } - $valid_modules = array(); - foreach ( $modules as $module ) { - - // Do not load module if no longer exists. - $module_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; - if ( ! file_exists( $module_file ) ) { - continue; - } - - // Do not load module if it cannot be loaded, e.g. if it was already merged and is available in WordPress core. - if ( ! perflab_can_load_module( $module ) ) { - continue; - } + // Do not load module if no longer exists. + $module_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; + if ( ! file_exists( $module_file ) ) { + return; + } - $valid_modules[] = $module; + // Do not load module if it cannot be loaded, e.g. if it was already merged and is available in WordPress core. + if ( ! perflab_can_load_module( $module ) ) { + return; } - return $valid_modules; + return $module; } /** @@ -179,7 +173,7 @@ function perflab_get_valid_modules( array $modules = array() ) { * @since 1.1.0 */ function perflab_get_generator_content() { - $active_and_valid_modules = perflab_get_valid_modules( perflab_get_active_modules() ); + $active_and_valid_modules = array_filter( perflab_get_active_modules(), 'perflab_is_valid_module' ); return sprintf( 'Performance Lab %1$s; modules: %2$s', @@ -237,8 +231,7 @@ function perflab_can_load_module( $module ) { * @since n.e.x.t Renamed to perflab_load_active_and_valid_modules(). */ function perflab_load_active_and_valid_modules() { - $active_and_valid_modules = perflab_get_valid_modules( perflab_get_active_modules() ); - + $active_and_valid_modules = array_filter( perflab_get_active_modules(), 'perflab_is_valid_module' );; if ( empty( $active_and_valid_modules ) ) { return; } diff --git a/tests/load-tests.php b/tests/load-tests.php index ce748a06fb..ac52a89ab6 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -131,8 +131,9 @@ function() use ( $active_modules ) { return $active_modules; } ); - $expected = 'Performance Lab ' . PERFLAB_VERSION . '; modules: ' . implode( ', ', $active_modules ); - $content = perflab_get_generator_content(); + $active_modules = array_filter( perflab_get_active_modules(), 'perflab_is_valid_module' ); + $expected = 'Performance Lab ' . PERFLAB_VERSION . '; modules: ' . implode( ', ', $active_modules ); + $content = perflab_get_generator_content(); $this->assertSame( $expected, $content ); } @@ -150,50 +151,40 @@ public function test_perflab_render_generator() { $this->assertContains( $expected, $output ); } - public function test_perflab_get_valid_modules() { - global $wp_version; - - // Assert that it returns the empty array for dummy modules. - $dummy_active_modules = array( - '../tests/testdata/demo-modules/javascript/demo-module-1', - '../tests/testdata/demo-modules/something/demo-module-2', - '../tests/testdata/demo-modules/images/demo-module-3', - ); - - $output = perflab_get_valid_modules( $dummy_active_modules ); - $this->assertIsArray( $output ); - $this->assertSame( array( '../tests/testdata/demo-modules/something/demo-module-2', '../tests/testdata/demo-modules/images/demo-module-3' ), $output ); - - // Assert that it returns the array for modules. - if ( $wp_version >= '6.1' ) { - $active_modules = require plugin_dir_path( PERFLAB_MAIN_FILE ) . 'default-enabled-modules.php'; - add_filter( - 'perflab_active_modules', - function() use ( $active_modules ) { - return $active_modules; - } - ); - $output = perflab_get_valid_modules( perflab_get_active_modules() ); + public function test_empty_module_for_perflab_is_valid_module() { + // Assert that it return null for empty module. + $this->assertEmpty( perflab_is_valid_module( '' ) ); + } - // Remove Image module as it will marge in 6.1. - $remove_marge_modules = array_shift( $active_modules ); - $this->assertSame( $active_modules, $output ); - } + /** + * @dataProvider provider_dummy_valid_modules + */ + public function test_perflab_is_valid_module( $dummy_module ) { + $output = perflab_is_valid_module( $dummy_module ); + $this->assertNotEmpty( $output ); + $this->assertIsString( $output ); } - public function test_perflab_can_load_module() { - // Assert that it validates the ability to load modules that are not in the core. - $demo_modules = array( - 'javascript/demo-module-1' => false, - 'something/demo-module-2' => true, - 'images/demo-module-3' => true, + public function provider_dummy_valid_modules() { + return array( + array( '../tests/testdata/demo-modules/something/demo-module-2' ), + array( '../tests/testdata/demo-modules/images/demo-module-3' ), ); + } - foreach ( $demo_modules as $module => $can_load ) { - $output = perflab_can_load_module( '../tests/testdata/demo-modules/' . $module ); - $this->assertSame( $can_load, $output ); - } + /** + * @dataProvider provider_dummy_can_load_modules + */ + public function test_perflab_can_load_module( $dummy_can_load_modules, $module_status ) { + $this->assertSame( $module_status, perflab_can_load_module( $dummy_can_load_modules ) ); + } + public function provider_dummy_can_load_modules() { + return array( + array( '../tests/testdata/demo-modules/javascript/demo-module-1', false ), + array( '../tests/testdata/demo-modules/something/demo-module-2', true ), + array( '../tests/testdata/demo-modules/images/demo-module-3', true ), + ); } private function get_expected_default_option() { From ac6163ababcd1d886885c8a35576084069b96593 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 7 Jul 2022 12:17:33 +0530 Subject: [PATCH 25/28] Fix minor lint issue --- load.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/load.php b/load.php index 405d51c2c4..be9115a69e 100644 --- a/load.php +++ b/load.php @@ -231,7 +231,8 @@ function perflab_can_load_module( $module ) { * @since n.e.x.t Renamed to perflab_load_active_and_valid_modules(). */ function perflab_load_active_and_valid_modules() { - $active_and_valid_modules = array_filter( perflab_get_active_modules(), 'perflab_is_valid_module' );; + $active_and_valid_modules = array_filter( perflab_get_active_modules(), 'perflab_is_valid_module' ); + if ( empty( $active_and_valid_modules ) ) { return; } From b7597907346109fa5c65225f6bef79565729d6fd Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 8 Jul 2022 12:22:55 +0530 Subject: [PATCH 26/28] Address review feedback --- load.php | 14 +++++--------- tests/load-tests.php | 29 ++++++++++++----------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/load.php b/load.php index be9115a69e..e3cabe076b 100644 --- a/load.php +++ b/load.php @@ -143,26 +143,26 @@ function( $module_settings ) { * @since n.e.x.t * * @param string $module Slug of the module. - * @return null|string Module slug name on success, null on failure. + * @return bool True if the module is active and valid, otherwise false. */ function perflab_is_valid_module( $module ) { if ( empty( $module ) ) { - return; + return false; } // Do not load module if no longer exists. $module_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; if ( ! file_exists( $module_file ) ) { - return; + return false; } // Do not load module if it cannot be loaded, e.g. if it was already merged and is available in WordPress core. if ( ! perflab_can_load_module( $module ) ) { - return; + return false; } - return $module; + return true; } /** @@ -233,10 +233,6 @@ function perflab_can_load_module( $module ) { function perflab_load_active_and_valid_modules() { $active_and_valid_modules = array_filter( perflab_get_active_modules(), 'perflab_is_valid_module' ); - if ( empty( $active_and_valid_modules ) ) { - return; - } - foreach ( $active_and_valid_modules as $module ) { require_once plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php'; diff --git a/tests/load-tests.php b/tests/load-tests.php index ac52a89ab6..c0fd354c1b 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -151,35 +151,30 @@ public function test_perflab_render_generator() { $this->assertContains( $expected, $output ); } - public function test_empty_module_for_perflab_is_valid_module() { - // Assert that it return null for empty module. - $this->assertEmpty( perflab_is_valid_module( '' ) ); - } - /** - * @dataProvider provider_dummy_valid_modules + * @dataProvider data_perflab_can_load_module */ - public function test_perflab_is_valid_module( $dummy_module ) { - $output = perflab_is_valid_module( $dummy_module ); - $this->assertNotEmpty( $output ); - $this->assertIsString( $output ); + public function test_perflab_is_valid_module( $dummy_module, $expected_status ) { + $this->assertSame( $expected_status , perflab_is_valid_module( $dummy_module ) ); } - public function provider_dummy_valid_modules() { + public function data_perflab_is_valid_module() { return array( - array( '../tests/testdata/demo-modules/something/demo-module-2' ), - array( '../tests/testdata/demo-modules/images/demo-module-3' ), + array( '', false ), + array( '../tests/testdata/demo-modules/javascript/demo-module-1', false ), + array( '../tests/testdata/demo-modules/something/demo-module-2', true ), + array( '../tests/testdata/demo-modules/images/demo-module-3', true ), ); } /** - * @dataProvider provider_dummy_can_load_modules + * @dataProvider data_perflab_can_load_module */ - public function test_perflab_can_load_module( $dummy_can_load_modules, $module_status ) { - $this->assertSame( $module_status, perflab_can_load_module( $dummy_can_load_modules ) ); + public function test_perflab_can_load_module( $dummy_module, $expected_status ) { + $this->assertSame( $expected_status , perflab_can_load_module( $dummy_module ) ); } - public function provider_dummy_can_load_modules() { + public function data_perflab_can_load_module() { return array( array( '../tests/testdata/demo-modules/javascript/demo-module-1', false ), array( '../tests/testdata/demo-modules/something/demo-module-2', true ), From 09c507fa2c006b0d5d2ce5f7a4c74dedcbf7a2b6 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 8 Jul 2022 12:27:00 +0530 Subject: [PATCH 27/28] Fix: Minor lind error --- tests/load-tests.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/load-tests.php b/tests/load-tests.php index c0fd354c1b..1166ca2d09 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -154,8 +154,8 @@ public function test_perflab_render_generator() { /** * @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 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() { @@ -170,8 +170,8 @@ public function data_perflab_is_valid_module() { /** * @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 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() { From e54b7d78fd08cce90aa755890bbb4cfffed68198 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 8 Jul 2022 10:36:51 -0700 Subject: [PATCH 28/28] Add test case for file_exists check in perflab_is_valid_module(). --- load.php | 6 +----- tests/load-tests.php | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/load.php b/load.php index e3cabe076b..10ba39313a 100644 --- a/load.php +++ b/load.php @@ -158,11 +158,7 @@ function perflab_is_valid_module( $module ) { } // Do not load module if it cannot be loaded, e.g. if it was already merged and is available in WordPress core. - if ( ! perflab_can_load_module( $module ) ) { - return false; - } - - return true; + return perflab_can_load_module( $module ); } /** diff --git a/tests/load-tests.php b/tests/load-tests.php index 1166ca2d09..870713d985 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -161,6 +161,7 @@ public function test_perflab_is_valid_module( $dummy_module, $expected_status ) 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/something/demo-module-2', true ), array( '../tests/testdata/demo-modules/images/demo-module-3', true ),