Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Enhanced navigation feature integration #718

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tests/unit/HelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace SkyVerge\WooCommerce\PluginFramework\v5_14_0\Tests\Unit;

use ReflectionException;
use SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Helper;
use SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Plugin_Compatibility;
use SkyVerge\WooCommerce\PluginFramework\v5_15_0\Tests\TestCase;

class HelperTest extends TestCase
{
/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Helper::is_wc_navigation_enabled()
*
* @throws ReflectionException
*/
public function testCanDetermineIfNavigationFeaturedEnabled() : void
{
$this->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());
}
}
52 changes: 41 additions & 11 deletions woocommerce/class-sv-wc-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}


Expand All @@ -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
nmolham-godaddy marked this conversation as resolved.
Show resolved Hide resolved
{
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
nmolham-godaddy marked this conversation as resolved.
Show resolved Hide resolved
{
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');
}


Expand Down
4 changes: 2 additions & 2 deletions woocommerce/class-sv-wc-plugin-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

Expand Down
Loading