From e5eae0606253486506e9799bd97cb274199d02cc Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Fri, 27 Jan 2023 14:52:12 +0530 Subject: [PATCH 01/26] Working on adding Force_Single_Plugin_Preparation class --- .../Force_Single_Plugin_Preparation.php | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 includes/Checker/Preparations/Force_Single_Plugin_Preparation.php diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php new file mode 100644 index 000000000..dcc091cde --- /dev/null +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -0,0 +1,98 @@ +plugin_basename = $plugin_basename; + } + + /** + * Runs this preparation step for the environment and returns a cleanup function. + * + * @since n.e.x.t + * + * @global array $wp_theme_directories + * + * @return callable Cleanup function to revert any changes made here. + * + * @throws Exception Thrown when preparation fails. + */ + public function prepare() { + // Override the theme slug and name. + add_filter( 'template', array( $this, 'get_theme_slug' ) ); + add_filter( 'stylesheet', array( $this, 'get_theme_slug' ) ); + add_filter( 'pre_option_template', array( $this, 'get_theme_slug' ) ); + add_filter( 'pre_option_stylesheet', array( $this, 'get_theme_slug' ) ); + add_filter( 'pre_option_current_theme', array( $this, 'get_theme_name' ) ); + + // Override the theme directory. + add_filter( 'pre_option_template_root', array( $this, 'get_theme_root' ) ); + add_filter( 'pre_option_stylesheet_root', array( $this, 'get_theme_root' ) ); + + // Register the custom themes directory if relevant. + if ( ! empty( $this->themes_dir ) ) { + register_theme_directory( $this->themes_dir ); + + // Force new directory scan to ensure the test theme directory is available. + search_theme_directories( true ); + } + + // Return the cleanup function. + return function() { + global $wp_theme_directories; + + remove_filter( 'template', array( $this, 'get_theme_slug' ) ); + remove_filter( 'stylesheet', array( $this, 'get_theme_slug' ) ); + remove_filter( 'pre_option_template', array( $this, 'get_theme_slug' ) ); + remove_filter( 'pre_option_stylesheet', array( $this, 'get_theme_slug' ) ); + remove_filter( 'pre_option_current_theme', array( $this, 'get_theme_name' ) ); + + remove_filter( 'pre_option_template_root', array( $this, 'get_theme_root' ) ); + remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_theme_root' ) ); + + if ( ! empty( $this->themes_dir ) ) { + $index = array_search( untrailingslashit( $this->themes_dir ), $wp_theme_directories, true ); + if ( false !== $index ) { + array_splice( $wp_theme_directories, $index, 1 ); + $wp_theme_directories = array_values( $wp_theme_directories ); + + // Force new directory scan to remove the test theme directory. + search_theme_directories( true ); + } + } + }; + } +} From 9409735ac9c83f3c74a60c13d432f24d776497ee Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Fri, 27 Jan 2023 15:06:13 +0530 Subject: [PATCH 02/26] Working on adding Force_Single_Plugin_Preparation class --- .../Force_Single_Plugin_Preparation.php | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index dcc091cde..29e3a9800 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -32,7 +32,7 @@ class Force_Single_Plugin_Preparation implements Preparation { * * @since n.e.x.t * - * @param string $plugin_basename Slug of the plugin. + * @param string $plugin_basename Slug of the plugin, E.g. "akismet\akismet.php". */ public function __construct( $plugin_basename ) { @@ -51,23 +51,16 @@ public function __construct( $plugin_basename ) { * @throws Exception Thrown when preparation fails. */ public function prepare() { - // Override the theme slug and name. - add_filter( 'template', array( $this, 'get_theme_slug' ) ); - add_filter( 'stylesheet', array( $this, 'get_theme_slug' ) ); - add_filter( 'pre_option_template', array( $this, 'get_theme_slug' ) ); - add_filter( 'pre_option_stylesheet', array( $this, 'get_theme_slug' ) ); - add_filter( 'pre_option_current_theme', array( $this, 'get_theme_name' ) ); - - // Override the theme directory. - add_filter( 'pre_option_template_root', array( $this, 'get_theme_root' ) ); - add_filter( 'pre_option_stylesheet_root', array( $this, 'get_theme_root' ) ); - - // Register the custom themes directory if relevant. - if ( ! empty( $this->themes_dir ) ) { - register_theme_directory( $this->themes_dir ); - - // Force new directory scan to ensure the test theme directory is available. - search_theme_directories( true ); + + // Check if the plugin exists. + if ( validate_plugin( $this->plugin_basename ) ) { + + throw new Exception( + sprintf( + 'Plugin is not exists at %1$s', + $this->plugin_basename + ) + ); } // Return the cleanup function. @@ -95,4 +88,19 @@ public function prepare() { } }; } + + /** + * Filter active plugins. + * + * @param array $active_plugins List of active plugins. + * + * @return void + */ + public function filter_active_plugins( $active_plugins ) { + + if ( in_array( $this->plugin_basename, $active_plugins, true ) ) { + + // $active_plugins + } + } } From 3b65eff5d720610602a772f3b15a07270cba085c Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Fri, 27 Jan 2023 15:09:50 +0530 Subject: [PATCH 03/26] Working on adding Force_Single_Plugin_Preparation class --- .../Preparations/Force_Single_Plugin_Preparation.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 29e3a9800..7285f88b9 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -52,12 +52,15 @@ public function __construct( $plugin_basename ) { */ public function prepare() { + $valid_plugin = validate_plugin( $this->plugin_basename ); + // Check if the plugin exists. - if ( validate_plugin( $this->plugin_basename ) ) { + if ( is_wp_error( $valid_plugin ) ) { throw new Exception( sprintf( - 'Plugin is not exists at %1$s', + '%1$s %2$s', + __( 'Plugin is not exists at', 'plugin-check' ), $this->plugin_basename ) ); From ec73b57a43e031fa44d7125552b4295c74a481cc Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Tue, 31 Jan 2023 11:46:03 +0530 Subject: [PATCH 04/26] Add Force_Single_Plugin_Preparation class --- .../Force_Single_Plugin_Preparation.php | 38 +++---- .../Force_Single_Plugin_Preparation_Tests.php | 101 ++++++++++++++++++ 2 files changed, 115 insertions(+), 24 deletions(-) create mode 100644 tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 7285f88b9..5f9ca6d3e 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -66,29 +66,14 @@ public function prepare() { ); } + add_filter( 'option_active_plugins', array( $this, 'filter_active_plugins' ) ); + add_filter( 'default_option_active_plugins', array( $this, 'filter_active_plugins' ) ); + // Return the cleanup function. return function() { - global $wp_theme_directories; - - remove_filter( 'template', array( $this, 'get_theme_slug' ) ); - remove_filter( 'stylesheet', array( $this, 'get_theme_slug' ) ); - remove_filter( 'pre_option_template', array( $this, 'get_theme_slug' ) ); - remove_filter( 'pre_option_stylesheet', array( $this, 'get_theme_slug' ) ); - remove_filter( 'pre_option_current_theme', array( $this, 'get_theme_name' ) ); - - remove_filter( 'pre_option_template_root', array( $this, 'get_theme_root' ) ); - remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_theme_root' ) ); - - if ( ! empty( $this->themes_dir ) ) { - $index = array_search( untrailingslashit( $this->themes_dir ), $wp_theme_directories, true ); - if ( false !== $index ) { - array_splice( $wp_theme_directories, $index, 1 ); - $wp_theme_directories = array_values( $wp_theme_directories ); - - // Force new directory scan to remove the test theme directory. - search_theme_directories( true ); - } - } + + remove_filter( 'option_active_plugins', array( $this, 'filter_active_plugins' ) ); + remove_filter( 'default_option_active_plugins', array( $this, 'filter_active_plugins' ) ); }; } @@ -97,13 +82,18 @@ public function prepare() { * * @param array $active_plugins List of active plugins. * - * @return void + * @return array List of active plugins. */ - public function filter_active_plugins( $active_plugins ) { + public function filter_active_plugins( $active_plugins = array() ) { if ( in_array( $this->plugin_basename, $active_plugins, true ) ) { - // $active_plugins + return array( + $this->plugin_basename, + 'plugin-check/plugin-check.php', // At the moment it is added static, we can update this with constant. + ); } + + return $active_plugins; } } diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php new file mode 100644 index 000000000..9d2ba7329 --- /dev/null +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -0,0 +1,101 @@ +prepare(); + + } catch ( Exception $e ) { + + $message = $e->getMessage(); + } + + $this->assertEquals( 'Plugin is not exists at akismet/akismet.php', $message ); + } + + /** + * @covers Force_Single_Plugin_Preparation::prepare(). + * + * @throws Exception Exception. + */ + public function test_prepare() { + + $preparation = new Force_Single_Plugin_Preparation( 'plugin-check/plugin-check.php' ); + + $plugins = array( + 'akismet/akismet.php', + 'plugin-check/plugin-check.php', + 'wp-reset/wp-reset.php', + ); + + update_option( 'active_plugins', $plugins ); + + $cleanup = $preparation->prepare(); + + $active_plugins = get_option( 'active_plugins' ); + + $cleanup(); + + $this->assertIsCallable( $cleanup ); + + $this->assertContains( 'plugin-check/plugin-check.php', $active_plugins ); + + $this->assertEquals( + array( + 'plugin-check/plugin-check.php', + 'plugin-check/plugin-check.php', + ), + $active_plugins + ); + } + + /** + * @covers Force_Single_Plugin_Preparation::filter_active_plugins(). + */ + public function test_filter_active_plugins() { + + $preparation = new Force_Single_Plugin_Preparation( 'wp-reset/wp-reset.php' ); + + $plugins = array( + 'akismet/akismet.php', + 'plugin-check/plugin-check.php', + 'wp-reset/wp-reset.php', + ); + + $active_plugins = $preparation->filter_active_plugins( $plugins ); + + $this->assertEquals( + array( + 'wp-reset/wp-reset.php', + 'plugin-check/plugin-check.php', + ), + $active_plugins + ); + } +} From eb4a03df495936faf2307532baa7ca6dd3c3a3fa Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Wed, 1 Feb 2023 10:32:07 +0530 Subject: [PATCH 05/26] Update spacings Co-authored-by: Joe Grainger <904708+jjgrainger@users.noreply.github.com> --- .../Force_Single_Plugin_Preparation_Tests.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index 9d2ba7329..18c467ead 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -24,19 +24,15 @@ public function set_up() { public function test_prepare_plugin_exists() { $preparation = new Force_Single_Plugin_Preparation( 'akismet/akismet.php' ); - - $message = ''; + $message = ''; try { - $preparation->prepare(); - } catch ( Exception $e ) { - $message = $e->getMessage(); } - $this->assertEquals( 'Plugin is not exists at akismet/akismet.php', $message ); + $this->assertEquals( 'The plugin akismet/akismet.php does not exists', $message ); } /** From 5a2648d91fbcf3d074807c23a8a81bce611d3277 Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Wed, 1 Feb 2023 10:32:59 +0530 Subject: [PATCH 06/26] Update class description. Co-authored-by: Joe Grainger <904708+jjgrainger@users.noreply.github.com> --- .../Checker/Preparations/Force_Single_Plugin_Preparation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 5f9ca6d3e..40fcd9d0c 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -11,7 +11,7 @@ use Exception; /** - * Class for the preparation step to force the plugin to be checks as the only active plugin. + * Class for the preparation to force the plugin to be checked as the only active plugin. * * This ensures the plugin is checked as much in isolation as possible. * From b03abc780b0cd3aab073720d412b49ed85340449 Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Wed, 1 Feb 2023 10:33:39 +0530 Subject: [PATCH 07/26] Remove unwanted function Co-authored-by: Joe Grainger <904708+jjgrainger@users.noreply.github.com> --- .../Preparations/Force_Single_Plugin_Preparation_Tests.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index 18c467ead..293aa37b3 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -13,10 +13,6 @@ class Force_Single_Plugin_Preparation_Tests extends WP_UnitTestCase { - public function set_up() { - - parent::set_up(); - } /** * @covers Force_Single_Plugin_Preparation::prepare(). From fed225edb783f2a566b6a25e01bb111cf34c61b2 Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Wed, 1 Feb 2023 10:33:53 +0530 Subject: [PATCH 08/26] Update message Co-authored-by: Joe Grainger <904708+jjgrainger@users.noreply.github.com> --- .../Checker/Preparations/Force_Single_Plugin_Preparation.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 40fcd9d0c..06f229f0f 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -59,8 +59,7 @@ public function prepare() { throw new Exception( sprintf( - '%1$s %2$s', - __( 'Plugin is not exists at', 'plugin-check' ), + __( 'The plugin %s does not exists', 'plugin-check' ), $this->plugin_basename ) ); From 7c87571c857817a69459f65088689436ba10dcbc Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Wed, 1 Feb 2023 10:34:59 +0530 Subject: [PATCH 09/26] Remove unwanted doc block --- .../Force_Single_Plugin_Preparation_Tests.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index 293aa37b3..6656dcaae 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -13,10 +13,6 @@ class Force_Single_Plugin_Preparation_Tests extends WP_UnitTestCase { - - /** - * @covers Force_Single_Plugin_Preparation::prepare(). - */ public function test_prepare_plugin_exists() { $preparation = new Force_Single_Plugin_Preparation( 'akismet/akismet.php' ); @@ -31,11 +27,6 @@ public function test_prepare_plugin_exists() { $this->assertEquals( 'The plugin akismet/akismet.php does not exists', $message ); } - /** - * @covers Force_Single_Plugin_Preparation::prepare(). - * - * @throws Exception Exception. - */ public function test_prepare() { $preparation = new Force_Single_Plugin_Preparation( 'plugin-check/plugin-check.php' ); @@ -67,9 +58,6 @@ public function test_prepare() { ); } - /** - * @covers Force_Single_Plugin_Preparation::filter_active_plugins(). - */ public function test_filter_active_plugins() { $preparation = new Force_Single_Plugin_Preparation( 'wp-reset/wp-reset.php' ); From 249b1815b543f34564175cbe4bbdf398563d1a11 Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Wed, 1 Feb 2023 10:36:27 +0530 Subject: [PATCH 10/26] Fix phplint issue --- .../Checker/Preparations/Force_Single_Plugin_Preparation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 06f229f0f..2b6892063 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -59,6 +59,7 @@ public function prepare() { throw new Exception( sprintf( + // translators: plugin basename. __( 'The plugin %s does not exists', 'plugin-check' ), $this->plugin_basename ) From 9682778c76810c4a70ff592aa93e4bf36e75c013 Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Wed, 1 Feb 2023 15:43:57 +0530 Subject: [PATCH 11/26] Remove unwanted doc block --- .../Checker/Preparations/Force_Single_Plugin_Preparation.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 2b6892063..f92fbd54e 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -44,8 +44,6 @@ public function __construct( $plugin_basename ) { * * @since n.e.x.t * - * @global array $wp_theme_directories - * * @return callable Cleanup function to revert any changes made here. * * @throws Exception Thrown when preparation fails. From 655ba469ffdc45c74b35991bcdc556aaa43803f4 Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Thu, 2 Feb 2023 11:54:57 +0530 Subject: [PATCH 12/26] Remove blank line. Co-authored-by: Felix Arntz --- .../Checker/Preparations/Force_Single_Plugin_Preparation.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index f92fbd54e..08b1c2452 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -35,7 +35,6 @@ class Force_Single_Plugin_Preparation implements Preparation { * @param string $plugin_basename Slug of the plugin, E.g. "akismet\akismet.php". */ public function __construct( $plugin_basename ) { - $this->plugin_basename = $plugin_basename; } From 392dad7e7f6ee1ee777982152a48f610dc60b98e Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Thu, 2 Feb 2023 11:55:56 +0530 Subject: [PATCH 13/26] Provide the more detailed context from the WP_Error Co-authored-by: Felix Arntz --- .../Preparations/Force_Single_Plugin_Preparation.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 08b1c2452..7bf0d350e 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -56,9 +56,10 @@ public function prepare() { throw new Exception( sprintf( - // translators: plugin basename. - __( 'The plugin %s does not exists', 'plugin-check' ), - $this->plugin_basename + /* translators: 1: plugin basename, 2: error message */ + __( 'Invalid plugin %1$s: %2$s', 'plugin-check' ), + $this->plugin_basename, + $valid_plugin->get_error_message() ) ); } From 2de9ff9e6c43a10c82ae0515985a83f54c55c16d Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Thu, 2 Feb 2023 11:56:19 +0530 Subject: [PATCH 14/26] Remove blank line Co-authored-by: Felix Arntz --- .../Checker/Preparations/Force_Single_Plugin_Preparation.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 7bf0d350e..4eb206757 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -69,7 +69,6 @@ public function prepare() { // Return the cleanup function. return function() { - remove_filter( 'option_active_plugins', array( $this, 'filter_active_plugins' ) ); remove_filter( 'default_option_active_plugins', array( $this, 'filter_active_plugins' ) ); }; From 2e11efe21fed6b2aad1cfd676c4e835bedc7f09c Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Thu, 2 Feb 2023 12:03:23 +0530 Subject: [PATCH 15/26] Update error message --- .../Preparations/Force_Single_Plugin_Preparation_Tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index 6656dcaae..44fc2a671 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -24,7 +24,7 @@ public function test_prepare_plugin_exists() { $message = $e->getMessage(); } - $this->assertEquals( 'The plugin akismet/akismet.php does not exists', $message ); + $this->assertEquals( 'Invalid plugin akismet/akismet.php: Plugin file does not exist.', $message ); } public function test_prepare() { From 1242c16a49c1538d49233a8d648fb57d6527fc55 Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Thu, 2 Feb 2023 16:32:40 +0530 Subject: [PATCH 16/26] Address feedbacks --- .../Preparations/Force_Single_Plugin_Preparation.php | 9 +++------ plugin-check.php | 1 + .../Force_Single_Plugin_Preparation_Tests.php | 2 -- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 4eb206757..15987c2ce 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -48,7 +48,6 @@ public function __construct( $plugin_basename ) { * @throws Exception Thrown when preparation fails. */ public function prepare() { - $valid_plugin = validate_plugin( $this->plugin_basename ); // Check if the plugin exists. @@ -78,16 +77,14 @@ public function prepare() { * Filter active plugins. * * @param array $active_plugins List of active plugins. - * * @return array List of active plugins. */ - public function filter_active_plugins( $active_plugins = array() ) { - - if ( in_array( $this->plugin_basename, $active_plugins, true ) ) { + public function filter_active_plugins( $active_plugins ) { + if ( is_array( $active_plugins ) && in_array( $this->plugin_basename, $active_plugins, true ) ) { return array( $this->plugin_basename, - 'plugin-check/plugin-check.php', // At the moment it is added static, we can update this with constant. + plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ), ); } diff --git a/plugin-check.php b/plugin-check.php index 685f752e5..d53e50619 100644 --- a/plugin-check.php +++ b/plugin-check.php @@ -18,6 +18,7 @@ define( 'WP_PLUGIN_CHECK_VERSION', 'n.e.x.t' ); define( 'WP_PLUGIN_CHECK_MINIMUM_PHP', '5.6' ); define( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) ); +define( 'WP_PLUGIN_CHECK_MAIN_FILE', __FILE__ ); /** * Checks basic requirements and loads the plugin. diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index 44fc2a671..a887d8633 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -47,8 +47,6 @@ public function test_prepare() { $this->assertIsCallable( $cleanup ); - $this->assertContains( 'plugin-check/plugin-check.php', $active_plugins ); - $this->assertEquals( array( 'plugin-check/plugin-check.php', From 44eaa89b9070d831a13b84d9e3a3105698f2bb0c Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Thu, 2 Feb 2023 17:02:43 +0530 Subject: [PATCH 17/26] Address feedbacks --- .../Force_Single_Plugin_Preparation.php | 9 +++++ .../Force_Single_Plugin_Preparation_Tests.php | 35 ++++++++++--------- tests/bootstrap.php | 5 +++ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 15987c2ce..645031441 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -82,6 +82,15 @@ public function prepare() { public function filter_active_plugins( $active_plugins ) { if ( is_array( $active_plugins ) && in_array( $this->plugin_basename, $active_plugins, true ) ) { + $plugin_check_base_file = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ); + + if ( $this->plugin_basename === $plugin_check_base_file ) { + + return array( + $this->plugin_basename, + ); + } + return array( $this->plugin_basename, plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ), diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index a887d8633..ca400d52f 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -13,27 +13,29 @@ class Force_Single_Plugin_Preparation_Tests extends WP_UnitTestCase { - public function test_prepare_plugin_exists() { - - $preparation = new Force_Single_Plugin_Preparation( 'akismet/akismet.php' ); - $message = ''; - - try { - $preparation->prepare(); - } catch ( Exception $e ) { - $message = $e->getMessage(); - } - - $this->assertEquals( 'Invalid plugin akismet/akismet.php: Plugin file does not exist.', $message ); - } +// public function test_prepare_plugin_exists() { +// +// $preparation = new Force_Single_Plugin_Preparation( 'akismet/akismet.php' ); +// $message = ''; +// +// try { +// $preparation->prepare(); +// } catch ( Exception $e ) { +// $message = $e->getMessage(); +// } +// +// $this->assertEquals( 'Invalid plugin akismet/akismet.php: Plugin file does not exist.', $message ); +// } public function test_prepare() { - $preparation = new Force_Single_Plugin_Preparation( 'plugin-check/plugin-check.php' ); + $plugin_check_base_file = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ); + + $preparation = new Force_Single_Plugin_Preparation( $plugin_check_base_file ); $plugins = array( 'akismet/akismet.php', - 'plugin-check/plugin-check.php', + $plugin_check_base_file, 'wp-reset/wp-reset.php', ); @@ -49,8 +51,7 @@ public function test_prepare() { $this->assertEquals( array( - 'plugin-check/plugin-check.php', - 'plugin-check/plugin-check.php', + $plugin_check_base_file, ), $active_plugins ); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8857a0030..59daf57ba 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -24,5 +24,10 @@ $_test_root = '/tmp/wordpress-tests-lib'; } +// Force plugin to be active. +$GLOBALS['wp_tests_options'] = array( + 'active_plugins' => array( basename( TESTS_PLUGIN_DIR ) . '/plugin-check.php' ), +); + // Start up the WP testing environment. require $_test_root . '/includes/bootstrap.php'; From 0b3d186a37405d4726a985b9f5240780e28f1a2b Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Thu, 2 Feb 2023 17:20:36 +0530 Subject: [PATCH 18/26] Address feedbacks --- .../Force_Single_Plugin_Preparation_Tests.php | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index ca400d52f..a19256c92 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -13,29 +13,30 @@ class Force_Single_Plugin_Preparation_Tests extends WP_UnitTestCase { -// public function test_prepare_plugin_exists() { -// -// $preparation = new Force_Single_Plugin_Preparation( 'akismet/akismet.php' ); -// $message = ''; -// -// try { -// $preparation->prepare(); -// } catch ( Exception $e ) { -// $message = $e->getMessage(); -// } -// -// $this->assertEquals( 'Invalid plugin akismet/akismet.php: Plugin file does not exist.', $message ); -// } + protected $plugin_basename_file; - public function test_prepare() { + public function set_up() { + parent::set_up(); + + $this->plugin_basename_file = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ); + } + + public function test_prepare_plugin_exists() { - $plugin_check_base_file = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ); + $preparation = new Force_Single_Plugin_Preparation( 'akismet/akismet.php' ); + + $this->expectException( 'Exception' ); + $this->expectExceptionMessage( 'Invalid plugin akismet/akismet.php: Plugin file does not exist.' ); + $preparation->prepare(); + } + + public function test_prepare() { - $preparation = new Force_Single_Plugin_Preparation( $plugin_check_base_file ); + $preparation = new Force_Single_Plugin_Preparation( $this->plugin_basename_file ); $plugins = array( 'akismet/akismet.php', - $plugin_check_base_file, + $this->plugin_basename_file, 'wp-reset/wp-reset.php', ); @@ -47,11 +48,9 @@ public function test_prepare() { $cleanup(); - $this->assertIsCallable( $cleanup ); - - $this->assertEquals( + $this->assertSame( array( - $plugin_check_base_file, + $this->plugin_basename_file, ), $active_plugins ); @@ -63,18 +62,28 @@ public function test_filter_active_plugins() { $plugins = array( 'akismet/akismet.php', - 'plugin-check/plugin-check.php', + $this->plugin_basename_file, 'wp-reset/wp-reset.php', ); $active_plugins = $preparation->filter_active_plugins( $plugins ); - $this->assertEquals( + $this->assertSame( array( 'wp-reset/wp-reset.php', - 'plugin-check/plugin-check.php', + $this->plugin_basename_file, ), $active_plugins ); + + $plugins = array( + 'akismet/akismet.php', + $this->plugin_basename_file, + 'test-plugin/test-plugin.php', + ); + + $active_plugins = $preparation->filter_active_plugins( $plugins ); + + $this->assertSame( $plugins, $active_plugins ); } } From 890b2a83d7e23310cfb9602ebbe7458c0833bda5 Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Thu, 2 Feb 2023 17:30:41 +0530 Subject: [PATCH 19/26] Address feedbacks --- .../Force_Single_Plugin_Preparation.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index 645031441..f5707e57a 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -82,19 +82,13 @@ public function prepare() { public function filter_active_plugins( $active_plugins ) { if ( is_array( $active_plugins ) && in_array( $this->plugin_basename, $active_plugins, true ) ) { - $plugin_check_base_file = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ); - - if ( $this->plugin_basename === $plugin_check_base_file ) { - - return array( - $this->plugin_basename, - ); - } - - return array( + $plugins = array( $this->plugin_basename, plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ), ); + + // Make sure no duplicate plugin files send in response. + return array_unique( $plugins ); } return $active_plugins; From a24749701da93ceb758431cd87cb97427d149fd4 Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Fri, 3 Feb 2023 17:49:19 +0530 Subject: [PATCH 20/26] Address feedbacks --- .../Force_Single_Plugin_Preparation.php | 17 ++++++++++++----- tests/Checker/Check_Context_Tests.php | 4 ++-- .../Force_Single_Plugin_Preparation_Tests.php | 11 +++++++++-- tests/Plugin_Context_Tests.php | 4 ++-- tests/Plugin_Main_Tests.php | 2 +- tests/bootstrap.php | 7 ++----- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php index f5707e57a..5041b283d 100644 --- a/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php +++ b/includes/Checker/Preparations/Force_Single_Plugin_Preparation.php @@ -82,13 +82,20 @@ public function prepare() { public function filter_active_plugins( $active_plugins ) { if ( is_array( $active_plugins ) && in_array( $this->plugin_basename, $active_plugins, true ) ) { - $plugins = array( + $plugin_base_file = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ); + + // If the plugin-check is the only available plugin then return that one only. + if ( $this->plugin_basename === $plugin_base_file ) { + + return array( + $plugin_base_file, + ); + } + + return array( $this->plugin_basename, - plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ), + $plugin_base_file, ); - - // Make sure no duplicate plugin files send in response. - return array_unique( $plugins ); } return $active_plugins; diff --git a/tests/Checker/Check_Context_Tests.php b/tests/Checker/Check_Context_Tests.php index 1dfff4926..e151fc0e3 100644 --- a/tests/Checker/Check_Context_Tests.php +++ b/tests/Checker/Check_Context_Tests.php @@ -12,11 +12,11 @@ public function set_up() { parent::set_up(); $this->plugin_name = basename( TESTS_PLUGIN_DIR ); - $this->check_context = new Check_Context( WP_PLUGIN_DIR . '/' . $this->plugin_name . '/plugin-check.php' ); + $this->check_context = new Check_Context( WP_PLUGIN_DIR . '/' . plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ) ); } public function test_basename() { - $this->assertSame( $this->plugin_name . '/plugin-check.php', $this->check_context->basename() ); + $this->assertSame( plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ), $this->check_context->basename() ); } public function test_path() { diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index a19256c92..a2ac0e0af 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -30,6 +30,9 @@ public function test_prepare_plugin_exists() { $preparation->prepare(); } + /** + * @throws Exception Throw exception. + */ public function test_prepare() { $preparation = new Force_Single_Plugin_Preparation( $this->plugin_basename_file ); @@ -46,14 +49,18 @@ public function test_prepare() { $active_plugins = get_option( 'active_plugins' ); - $cleanup(); - $this->assertSame( array( $this->plugin_basename_file, ), $active_plugins ); + + $cleanup(); + + $active_plugins = get_option( 'active_plugins' ); + + $this->assertSame( $active_plugins, $plugins ); } public function test_filter_active_plugins() { diff --git a/tests/Plugin_Context_Tests.php b/tests/Plugin_Context_Tests.php index 74f8b1975..857e73ca7 100644 --- a/tests/Plugin_Context_Tests.php +++ b/tests/Plugin_Context_Tests.php @@ -12,11 +12,11 @@ public function set_up() { parent::set_up(); $this->plugin_name = basename( TESTS_PLUGIN_DIR ); - $this->plugin_context = new Plugin_Context( WP_PLUGIN_DIR . '/' . $this->plugin_name . '/plugin-check.php' ); + $this->plugin_context = new Plugin_Context( WP_PLUGIN_DIR . '/' . plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ) ); } public function test_basename() { - $this->assertSame( $this->plugin_name . '/plugin-check.php', $this->plugin_context->basename() ); + $this->assertSame( plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ), $this->plugin_context->basename() ); } public function test_path() { diff --git a/tests/Plugin_Main_Tests.php b/tests/Plugin_Main_Tests.php index 79f472541..bcf9c9069 100644 --- a/tests/Plugin_Main_Tests.php +++ b/tests/Plugin_Main_Tests.php @@ -12,7 +12,7 @@ class Plugin_Main_Tests extends WP_UnitTestCase { public function set_up() { parent::set_up(); - $this->plugin_main = new Plugin_Main( basename( dirname( __DIR__ ) ) . '/plugin-check.php' ); + $this->plugin_main = new Plugin_Main( plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ) ); } public function test_context() { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 59daf57ba..a250d222b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -24,10 +24,7 @@ $_test_root = '/tmp/wordpress-tests-lib'; } -// Force plugin to be active. -$GLOBALS['wp_tests_options'] = array( - 'active_plugins' => array( basename( TESTS_PLUGIN_DIR ) . '/plugin-check.php' ), -); - // Start up the WP testing environment. require $_test_root . '/includes/bootstrap.php'; + +require TESTS_PLUGIN_DIR . '/plugin-check.php'; From 198452b838d762662b8e5822f3f5b37b1dad0c31 Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Fri, 3 Feb 2023 18:02:42 +0530 Subject: [PATCH 21/26] Fix error --- tests/bootstrap.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 2a1673113..a250d222b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -24,11 +24,6 @@ $_test_root = '/tmp/wordpress-tests-lib'; } -// Force plugin to be active. -$GLOBALS['wp_tests_options'] = array( - 'active_plugins' => array( basename( TESTS_PLUGIN_DIR ) . '/plugin-check.php' ), -); - // Start up the WP testing environment. require $_test_root . '/includes/bootstrap.php'; From 1102175b53e1cbe9976a85f98ffa86aeed106ead Mon Sep 17 00:00:00 2001 From: jjgrainger Date: Sun, 5 Feb 2023 20:58:03 +0000 Subject: [PATCH 22/26] fix active_plugins in prepare test --- .../Force_Single_Plugin_Preparation_Tests.php | 26 +++++++------------ tests/bootstrap.php | 7 +++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php index a2ac0e0af..52b7aa843 100644 --- a/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php +++ b/tests/Checker/Preparations/Force_Single_Plugin_Preparation_Tests.php @@ -34,33 +34,25 @@ public function test_prepare_plugin_exists() { * @throws Exception Throw exception. */ public function test_prepare() { + // Remove the WP tests active plugins filter which interfers with this test. + remove_filter( 'pre_option_active_plugins', 'wp_tests_options' ); - $preparation = new Force_Single_Plugin_Preparation( $this->plugin_basename_file ); - - $plugins = array( + $preparation = new Force_Single_Plugin_Preparation( $this->plugin_basename_file ); + $active_plugins = array( 'akismet/akismet.php', $this->plugin_basename_file, 'wp-reset/wp-reset.php', ); - update_option( 'active_plugins', $plugins ); + update_option( 'active_plugins', $active_plugins ); $cleanup = $preparation->prepare(); - - $active_plugins = get_option( 'active_plugins' ); - - $this->assertSame( - array( - $this->plugin_basename_file, - ), - $active_plugins - ); - + $before = get_option( 'active_plugins' ); $cleanup(); + $after = get_option( 'active_plugins' ); - $active_plugins = get_option( 'active_plugins' ); - - $this->assertSame( $active_plugins, $plugins ); + $this->assertSame( array( $this->plugin_basename_file ), $before ); + $this->assertSame( $active_plugins, $after ); } public function test_filter_active_plugins() { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a250d222b..59daf57ba 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -24,7 +24,10 @@ $_test_root = '/tmp/wordpress-tests-lib'; } +// Force plugin to be active. +$GLOBALS['wp_tests_options'] = array( + 'active_plugins' => array( basename( TESTS_PLUGIN_DIR ) . '/plugin-check.php' ), +); + // Start up the WP testing environment. require $_test_root . '/includes/bootstrap.php'; - -require TESTS_PLUGIN_DIR . '/plugin-check.php'; From 52b9da668379e3d5730c25a7eefd0435f8cae84b Mon Sep 17 00:00:00 2001 From: vishalkakadiya Date: Mon, 6 Feb 2023 19:18:27 +0530 Subject: [PATCH 23/26] Address feedbacks --- plugin-check.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-check.php b/plugin-check.php index d53e50619..5c31b12b2 100644 --- a/plugin-check.php +++ b/plugin-check.php @@ -17,8 +17,8 @@ define( 'WP_PLUGIN_CHECK_VERSION', 'n.e.x.t' ); define( 'WP_PLUGIN_CHECK_MINIMUM_PHP', '5.6' ); -define( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) ); define( 'WP_PLUGIN_CHECK_MAIN_FILE', __FILE__ ); +define( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH', plugin_dir_path( WP_PLUGIN_CHECK_MAIN_FILE ) ); /** * Checks basic requirements and loads the plugin. @@ -43,7 +43,7 @@ function wp_plugin_check_load() { // Setup the plugin. $class_name = 'WordPress\\Plugin_Check\\Plugin_Main'; - $instance = new $class_name( __FILE__ ); + $instance = new $class_name( WP_PLUGIN_CHECK_MAIN_FILE ); $instance->add_hooks(); } From 26e73d87f40953839ac3c3a93e1f06deb3626b6d Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Tue, 7 Feb 2023 10:43:10 +0530 Subject: [PATCH 24/26] Address feedback - Update constant Co-authored-by: Felix Arntz --- tests/Checker/Check_Context_Tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Checker/Check_Context_Tests.php b/tests/Checker/Check_Context_Tests.php index e151fc0e3..a5c893bdc 100644 --- a/tests/Checker/Check_Context_Tests.php +++ b/tests/Checker/Check_Context_Tests.php @@ -12,7 +12,7 @@ public function set_up() { parent::set_up(); $this->plugin_name = basename( TESTS_PLUGIN_DIR ); - $this->check_context = new Check_Context( WP_PLUGIN_DIR . '/' . plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ) ); + $this->check_context = new Check_Context( WP_PLUGIN_CHECK_MAIN_FILE ); } public function test_basename() { From ce1cd3d987ca454c58611764d8def77b2989ce96 Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Tue, 7 Feb 2023 10:44:04 +0530 Subject: [PATCH 25/26] Address feedback - Update constant Co-authored-by: Felix Arntz --- tests/Plugin_Context_Tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Plugin_Context_Tests.php b/tests/Plugin_Context_Tests.php index 857e73ca7..3a865d59c 100644 --- a/tests/Plugin_Context_Tests.php +++ b/tests/Plugin_Context_Tests.php @@ -12,7 +12,7 @@ public function set_up() { parent::set_up(); $this->plugin_name = basename( TESTS_PLUGIN_DIR ); - $this->plugin_context = new Plugin_Context( WP_PLUGIN_DIR . '/' . plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ) ); + $this->plugin_context = new Plugin_Context( WP_PLUGIN_CHECK_MAIN_FILE ); } public function test_basename() { From d44e74653feb958a51bd19361b84c523d3a52070 Mon Sep 17 00:00:00 2001 From: Vishal Kakadiya Date: Tue, 7 Feb 2023 10:44:15 +0530 Subject: [PATCH 26/26] Address feedback - Update constant Co-authored-by: Felix Arntz --- tests/Plugin_Main_Tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Plugin_Main_Tests.php b/tests/Plugin_Main_Tests.php index bcf9c9069..755421dac 100644 --- a/tests/Plugin_Main_Tests.php +++ b/tests/Plugin_Main_Tests.php @@ -12,7 +12,7 @@ class Plugin_Main_Tests extends WP_UnitTestCase { public function set_up() { parent::set_up(); - $this->plugin_main = new Plugin_Main( plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ) ); + $this->plugin_main = new Plugin_Main( WP_PLUGIN_CHECK_MAIN_FILE ); } public function test_context() {