diff --git a/tests/unit/HelperTest.php b/tests/unit/HelperTest.php new file mode 100644 index 000000000..28c8d5dcc --- /dev/null +++ b/tests/unit/HelperTest.php @@ -0,0 +1,54 @@ +mockStaticMethod(SV_WC_Plugin_Compatibility::class, 'is_wc_version_gte') + ->once() + ->with('9.3') + ->andReturnFalse(); + + $this->mockStaticMethod(SV_WC_Helper::class, 'isEnhancedNavigationFeatureEnabled') + ->once() + ->andReturnTrue(); + + $this->mockStaticMethod(SV_WC_Helper::class, 'enhancedNavigationDeprecationNotice') + ->never(); + + $this->assertTrue(SV_WC_Helper::is_wc_navigation_enabled()); + } + + /** + * @covers \SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Helper::is_wc_navigation_enabled() + * + * @throws ReflectionException + */ + public function testAlwaysDetermineNavigationFeaturedDisabled() : void + { + $this->mockStaticMethod(SV_WC_Plugin_Compatibility::class, 'is_wc_version_gte') + ->once() + ->with('9.3') + ->andReturnTrue(); + + $this->mockStaticMethod(SV_WC_Helper::class, 'enhancedNavigationDeprecationNotice') + ->once(); + + $this->mockStaticMethod(SV_WC_Helper::class, 'isEnhancedNavigationFeatureEnabled') + ->never(); + + $this->assertFalse(SV_WC_Helper::is_wc_navigation_enabled()); + } +} diff --git a/woocommerce/class-sv-wc-helper.php b/woocommerce/class-sv-wc-helper.php index 698cf9dbd..ff9480195 100644 --- a/woocommerce/class-sv-wc-helper.php +++ b/woocommerce/class-sv-wc-helper.php @@ -1030,9 +1030,9 @@ public static function is_current_screen( $id, $prop = 'id' ) { * * @return bool */ - public static function is_enhanced_admin_screen() { - - return is_admin() && SV_WC_Plugin_Compatibility::is_enhanced_admin_available() && ( \Automattic\WooCommerce\Admin\Loader::is_admin_page() || \Automattic\WooCommerce\Admin\Loader::is_embed_page() ); + public static function is_enhanced_admin_screen() : bool + { + return is_admin() && SV_WC_Plugin_Compatibility::is_enhanced_admin_available() && (\Automattic\WooCommerce\Admin\PageController::is_admin_page() || \Automattic\WooCommerce\Admin\PageController::is_embed_page()); } @@ -1041,16 +1041,46 @@ public static function is_enhanced_admin_screen() { * * @since 5.10.6 * + * @deprecated with no alternatives + * * @return bool */ - public static function is_wc_navigation_enabled() { - - return - is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Screen::class, 'register_post_type' ] ) && - is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_item' ] ) && - is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_category' ] ) && - is_callable( [ \Automattic\WooCommerce\Admin\Features\Features::class, 'is_enabled' ] ) && - \Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'navigation' ); + public static function is_wc_navigation_enabled() : bool + { + if (SV_WC_Plugin_Compatibility::is_wc_version_gte('9.3')) { + self::enhancedNavigationDeprecationNotice(); + return false; + } + + return self::isEnhancedNavigationFeatureEnabled(); + } + + /** + * Determines whether Woo's Enhanced Eavigation feature is enabled. + * + * @since 5.15.1 + * + * @return bool + */ + protected static function isEnhancedNavigationFeatureEnabled() : bool + { + return is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Screen::class, 'register_post_type']) && + is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_item']) && + is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_category']) && + is_callable([\Automattic\WooCommerce\Admin\Features\Features::class, 'is_enabled']) && + \Automattic\WooCommerce\Admin\Features\Features::is_enabled('navigation'); + } + + /** + * Logs a notice for the Enhanced Navigation feature being deprecated. + * + * @since 5.15.1 + * + * @return void + */ + protected static function enhancedNavigationDeprecationNotice() : void + { + error_log('The Enhanced navigation feature has been deprecated since WooCommerce 9.3 with no alternative. Navigation classes will be removed in WooCommerce 9.4'); } diff --git a/woocommerce/class-sv-wc-plugin-compatibility.php b/woocommerce/class-sv-wc-plugin-compatibility.php index 0980f03e3..f7cb0f796 100644 --- a/woocommerce/class-sv-wc-plugin-compatibility.php +++ b/woocommerce/class-sv-wc-plugin-compatibility.php @@ -191,8 +191,8 @@ public static function is_wc_version_gt( $version ) { * * @return bool */ - public static function is_enhanced_admin_available() { - + public static function is_enhanced_admin_available() : bool + { return self::is_wc_version_gte( '4.0' ) && function_exists( 'wc_admin_url' ); }