From 066a4fccd1299d55415b534d99189484720cd94e Mon Sep 17 00:00:00 2001 From: Nabeel Molham Date: Mon, 30 Sep 2024 13:06:52 +1000 Subject: [PATCH] Unit test SV_WC_Helper::is_wc_navigation_enabled method --- tests/unit/HelperTest.php | 54 ++++++++++++++++++++++++++++++ woocommerce/class-sv-wc-helper.php | 5 +++ 2 files changed, 59 insertions(+) create mode 100644 tests/unit/HelperTest.php 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 ec90df86e..3e4a0472a 100644 --- a/woocommerce/class-sv-wc-helper.php +++ b/woocommerce/class-sv-wc-helper.php @@ -1052,6 +1052,11 @@ public static function is_wc_navigation_enabled() : bool return false; } + return self::isEnhancedNavigationFeatureEnabled(); + } + + 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']) &&