Skip to content

Commit 97a4dee

Browse files
Deprecate Enhanced navigation feature integration (#718)
* Deprecate Enhanced navigation feature integration * Always return false if WC >= 9.3 * Always return false if WC >= 9.3 * Unit test SV_WC_Helper::is_wc_navigation_enabled method * Update woocommerce/class-sv-wc-helper.php Co-authored-by: Drew Jaynes <[email protected]> * Update woocommerce/class-sv-wc-helper.php Co-authored-by: Drew Jaynes <[email protected]> --------- Co-authored-by: Drew Jaynes <[email protected]>
1 parent 1b5a367 commit 97a4dee

File tree

3 files changed

+97
-13
lines changed

3 files changed

+97
-13
lines changed

tests/unit/HelperTest.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace SkyVerge\WooCommerce\PluginFramework\v5_14_0\Tests\Unit;
4+
5+
use ReflectionException;
6+
use SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Helper;
7+
use SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Plugin_Compatibility;
8+
use SkyVerge\WooCommerce\PluginFramework\v5_15_0\Tests\TestCase;
9+
10+
class HelperTest extends TestCase
11+
{
12+
/**
13+
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Helper::is_wc_navigation_enabled()
14+
*
15+
* @throws ReflectionException
16+
*/
17+
public function testCanDetermineIfNavigationFeaturedEnabled() : void
18+
{
19+
$this->mockStaticMethod(SV_WC_Plugin_Compatibility::class, 'is_wc_version_gte')
20+
->once()
21+
->with('9.3')
22+
->andReturnFalse();
23+
24+
$this->mockStaticMethod(SV_WC_Helper::class, 'isEnhancedNavigationFeatureEnabled')
25+
->once()
26+
->andReturnTrue();
27+
28+
$this->mockStaticMethod(SV_WC_Helper::class, 'enhancedNavigationDeprecationNotice')
29+
->never();
30+
31+
$this->assertTrue(SV_WC_Helper::is_wc_navigation_enabled());
32+
}
33+
34+
/**
35+
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Helper::is_wc_navigation_enabled()
36+
*
37+
* @throws ReflectionException
38+
*/
39+
public function testAlwaysDetermineNavigationFeaturedDisabled() : void
40+
{
41+
$this->mockStaticMethod(SV_WC_Plugin_Compatibility::class, 'is_wc_version_gte')
42+
->once()
43+
->with('9.3')
44+
->andReturnTrue();
45+
46+
$this->mockStaticMethod(SV_WC_Helper::class, 'enhancedNavigationDeprecationNotice')
47+
->once();
48+
49+
$this->mockStaticMethod(SV_WC_Helper::class, 'isEnhancedNavigationFeatureEnabled')
50+
->never();
51+
52+
$this->assertFalse(SV_WC_Helper::is_wc_navigation_enabled());
53+
}
54+
}

woocommerce/class-sv-wc-helper.php

+41-11
Original file line numberDiff line numberDiff line change
@@ -1030,9 +1030,9 @@ public static function is_current_screen( $id, $prop = 'id' ) {
10301030
*
10311031
* @return bool
10321032
*/
1033-
public static function is_enhanced_admin_screen() {
1034-
1035-
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() );
1033+
public static function is_enhanced_admin_screen() : bool
1034+
{
1035+
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());
10361036
}
10371037

10381038

@@ -1041,16 +1041,46 @@ public static function is_enhanced_admin_screen() {
10411041
*
10421042
* @since 5.10.6
10431043
*
1044+
* @deprecated with no alternatives
1045+
*
10441046
* @return bool
10451047
*/
1046-
public static function is_wc_navigation_enabled() {
1047-
1048-
return
1049-
is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Screen::class, 'register_post_type' ] ) &&
1050-
is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_item' ] ) &&
1051-
is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_category' ] ) &&
1052-
is_callable( [ \Automattic\WooCommerce\Admin\Features\Features::class, 'is_enabled' ] ) &&
1053-
\Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'navigation' );
1048+
public static function is_wc_navigation_enabled() : bool
1049+
{
1050+
if (SV_WC_Plugin_Compatibility::is_wc_version_gte('9.3')) {
1051+
self::enhancedNavigationDeprecationNotice();
1052+
return false;
1053+
}
1054+
1055+
return self::isEnhancedNavigationFeatureEnabled();
1056+
}
1057+
1058+
/**
1059+
* Determines whether Woo's Enhanced Eavigation feature is enabled.
1060+
*
1061+
* @since 5.15.1
1062+
*
1063+
* @return bool
1064+
*/
1065+
protected static function isEnhancedNavigationFeatureEnabled() : bool
1066+
{
1067+
return is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Screen::class, 'register_post_type']) &&
1068+
is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_item']) &&
1069+
is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_category']) &&
1070+
is_callable([\Automattic\WooCommerce\Admin\Features\Features::class, 'is_enabled']) &&
1071+
\Automattic\WooCommerce\Admin\Features\Features::is_enabled('navigation');
1072+
}
1073+
1074+
/**
1075+
* Logs a notice for the Enhanced Navigation feature being deprecated.
1076+
*
1077+
* @since 5.15.1
1078+
*
1079+
* @return void
1080+
*/
1081+
protected static function enhancedNavigationDeprecationNotice() : void
1082+
{
1083+
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');
10541084
}
10551085

10561086

woocommerce/class-sv-wc-plugin-compatibility.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ public static function is_wc_version_gt( $version ) {
191191
*
192192
* @return bool
193193
*/
194-
public static function is_enhanced_admin_available() {
195-
194+
public static function is_enhanced_admin_available() : bool
195+
{
196196
return self::is_wc_version_gte( '4.0' ) && function_exists( 'wc_admin_url' );
197197
}
198198

0 commit comments

Comments
 (0)