Skip to content

Commit

Permalink
Unit test SV_WC_Helper::is_wc_navigation_enabled method
Browse files Browse the repository at this point in the history
  • Loading branch information
nmolham-godaddy committed Sep 30, 2024
1 parent f5c05db commit 066a4fc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
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());
}
}
5 changes: 5 additions & 0 deletions woocommerce/class-sv-wc-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) &&
Expand Down

0 comments on commit 066a4fc

Please sign in to comment.