From 56baaa4a9ac70cb95cc9a258d712eaf368b7f9ce Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 11:31:33 +0300 Subject: [PATCH 01/23] Add isWoocommerceActive to editors directory --- .../framework/site/post-site-information.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/editors/framework/site/post-site-information.php b/src/editors/framework/site/post-site-information.php index 4882642aa7a..c0f091eeb6d 100644 --- a/src/editors/framework/site/post-site-information.php +++ b/src/editors/framework/site/post-site-information.php @@ -3,6 +3,7 @@ namespace Yoast\WP\SEO\Editors\Framework\Site; use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; +use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Helpers\Product_Helper; use Yoast\WP\SEO\Helpers\Short_Link_Helper; use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository; @@ -35,6 +36,13 @@ class Post_Site_Information extends Base_Site_Information { */ private $promotion_manager; + /** + * The WooCommerce conditional. + * + * @var WooCommerce_Conditional $woocommerce_conditional + */ + protected $woocommerce_conditional; + /** * Constructs the class. * @@ -45,6 +53,7 @@ class Post_Site_Information extends Base_Site_Information { * @param Meta_Surface $meta The meta surface. * @param Product_Helper $product_helper The product helper. * @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action. + * @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional. * * @return void */ @@ -54,11 +63,13 @@ public function __construct( Wistia_Embed_Permission_Repository $wistia_embed_permission_repository, Meta_Surface $meta, Product_Helper $product_helper, - Alert_Dismissal_Action $alert_dismissal_action + Alert_Dismissal_Action $alert_dismissal_action, + WooCommerce_Conditional $woocommerce_conditional ) { parent::__construct( $short_link_helper, $wistia_embed_permission_repository, $meta, $product_helper ); - $this->promotion_manager = $promotion_manager; - $this->alert_dismissal_action = $alert_dismissal_action; + $this->promotion_manager = $promotion_manager; + $this->alert_dismissal_action = $alert_dismissal_action; + $this->woocommerce_conditional = $woocommerce_conditional; } /** @@ -85,6 +96,8 @@ public function get_legacy_site_information(): array { 'currentPromotions' => $this->promotion_manager->get_current_promotions(), 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), 'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '', + 'search_url' => $this->search_url(), + 'isWooCommerceActive' => $this->woocommerce_conditional->is_met(), 'metabox' => [ 'search_url' => $this->search_url(), 'post_edit_url' => $this->edit_url(), @@ -111,6 +124,7 @@ public function get_site_information(): array { 'search_url' => $this->search_url(), 'post_edit_url' => $this->edit_url(), 'base_url' => $this->base_url_for_js(), + 'isWooCommerceActive' => $this->woocommerce_conditional->is_met(), ]; return \array_merge( $data, parent::get_site_information() ); From 8e6784a133bb076bc06a0a1b576c995a41227bc9 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 11:32:53 +0300 Subject: [PATCH 02/23] removes isWoocommerceActive from metabox and elementor --- admin/metabox/class-metabox.php | 8 ++------ src/integrations/third-party/elementor.php | 5 +---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/admin/metabox/class-metabox.php b/admin/metabox/class-metabox.php index 1066a560ef6..1bf3ca7d972 100644 --- a/admin/metabox/class-metabox.php +++ b/admin/metabox/class-metabox.php @@ -7,7 +7,6 @@ use Yoast\WP\SEO\Conditionals\Third_Party\Jetpack_Boost_Active_Conditional; use Yoast\WP\SEO\Conditionals\Third_Party\Jetpack_Boost_Not_Premium_Conditional; -use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Editors\Application\Site\Website_Information_Repository; use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter; use Yoast\WP\SEO\Presenters\Admin\Meta_Fields_Presenter; @@ -879,10 +878,8 @@ public function enqueue() { 'log_level' => WPSEO_Utils::get_analysis_worker_log_level(), ]; - $woocommerce_conditional = new WooCommerce_Conditional(); - $woocommerce_active = $woocommerce_conditional->is_met(); - $addon_manager = new WPSEO_Addon_Manager(); - $woocommerce_seo_active = is_plugin_active( $addon_manager->get_plugin_file( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ); + $addon_manager = new WPSEO_Addon_Manager(); + $woocommerce_seo_active = is_plugin_active( $addon_manager->get_plugin_file( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ); $script_data = [ 'metabox' => $this->get_metabox_script_data(), @@ -900,7 +897,6 @@ public function enqueue() { 'isJetpackBoostActive' => ( $is_block_editor ) ? YoastSEO()->classes->get( Jetpack_Boost_Active_Conditional::class )->is_met() : false, 'isJetpackBoostNotPremium' => ( $is_block_editor ) ? YoastSEO()->classes->get( Jetpack_Boost_Not_Premium_Conditional::class )->is_met() : false, 'isWooCommerceSeoActive' => $woocommerce_seo_active, - 'isWooCommerceActive' => $woocommerce_active, ]; /** diff --git a/src/integrations/third-party/elementor.php b/src/integrations/third-party/elementor.php index e2405da7262..33327705745 100644 --- a/src/integrations/third-party/elementor.php +++ b/src/integrations/third-party/elementor.php @@ -17,7 +17,6 @@ use WPSEO_Shortlinker; use WPSEO_Utils; use Yoast\WP\SEO\Conditionals\Third_Party\Elementor_Edit_Conditional; -use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Editors\Application\Site\Website_Information_Repository; use Yoast\WP\SEO\Elementor\Infrastructure\Request_Post; use Yoast\WP\SEO\Helpers\Capability_Helper; @@ -409,8 +408,7 @@ public function enqueue() { 'enabled_features' => WPSEO_Utils::retrieve_enabled_features(), ]; - $woocommerce_conditional = new WooCommerce_Conditional(); - $permalink = $this->get_permalink(); + $permalink = $this->get_permalink(); $script_data = [ 'metabox' => $this->get_metabox_script_data( $permalink ), @@ -418,7 +416,6 @@ public function enqueue() { 'isPost' => true, 'isBlockEditor' => WP_Screen::get()->is_block_editor(), 'isElementorEditor' => true, - 'isWooCommerceActive' => $woocommerce_conditional->is_met(), 'postStatus' => \get_post_status( $post_id ), 'postType' => \get_post_type( $post_id ), 'analysis' => [ From d7258611e64e8c8bc13f6ee0f3c3eb13f5155401 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 11:49:18 +0300 Subject: [PATCH 03/23] fix tests --- .../framework/site/post-site-information.php | 1 - .../Site/Post_Site_Information_Test.php | 32 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/editors/framework/site/post-site-information.php b/src/editors/framework/site/post-site-information.php index c0f091eeb6d..bd04e597aa3 100644 --- a/src/editors/framework/site/post-site-information.php +++ b/src/editors/framework/site/post-site-information.php @@ -96,7 +96,6 @@ public function get_legacy_site_information(): array { 'currentPromotions' => $this->promotion_manager->get_current_promotions(), 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), 'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '', - 'search_url' => $this->search_url(), 'isWooCommerceActive' => $this->woocommerce_conditional->is_met(), 'metabox' => [ 'search_url' => $this->search_url(), diff --git a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php index c3ecc881b8f..e2d5b083cfd 100644 --- a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php @@ -6,6 +6,7 @@ use Brain\Monkey; use Mockery; use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; +use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Editors\Framework\Site\Post_Site_Information; use Yoast\WP\SEO\Helpers\Product_Helper; use Yoast\WP\SEO\Helpers\Short_Link_Helper; @@ -68,6 +69,13 @@ final class Post_Site_Information_Test extends TestCase { */ private $product_helper; + /** + * The WooCommerce conditional. + * + * @var WooCommerce_Conditional $woocommerce_conditional + */ + protected $woocommerce_conditional; + /** * The Post_Site_Information container. * @@ -82,14 +90,15 @@ final class Post_Site_Information_Test extends TestCase { */ protected function set_up() { parent::set_up(); - $this->promotion_manager = Mockery::mock( Promotion_Manager::class ); - $this->short_link_helper = Mockery::mock( Short_Link_Helper::class ); - $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); - $this->meta_surface = Mockery::mock( Meta_Surface::class ); - $this->product_helper = Mockery::mock( Product_Helper::class ); - $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); - - $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); + $this->promotion_manager = Mockery::mock( Promotion_Manager::class ); + $this->short_link_helper = Mockery::mock( Short_Link_Helper::class ); + $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); + $this->meta_surface = Mockery::mock( Meta_Surface::class ); + $this->product_helper = Mockery::mock( Product_Helper::class ); + $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); + $this->woocommerce_conditional = Mockery::mock( WooCommerce_Conditional::class ); + + $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action, $this->woocommerce_conditional ); $this->instance->set_permalink( 'perma' ); $this->set_mocks(); } @@ -117,6 +126,7 @@ public function test_legacy_site_information() { ], 'webinarIntroBlockEditorUrl' => 'https://expl.c', 'blackFridayBlockEditorUrl' => '', + 'isWooCommerceActive' => '', 'metabox' => [ 'search_url' => 'https://example.org', 'post_edit_url' => 'https://example.org', @@ -136,7 +146,7 @@ public function test_legacy_site_information() { ], 'pluginUrl' => '/location', 'wistiaEmbedPermission' => true, - + 'isWooCommerceActive' => '', ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); @@ -146,6 +156,7 @@ public function test_legacy_site_information() { $this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] ); $this->promotion_manager->expects( 'is' )->andReturnFalse(); $this->short_link_helper->expects( 'get' )->andReturn( 'https://expl.c' ); + $this->woocommerce_conditional->expects( 'is_met' )->andReturn( '' ); $this->assertSame( $expected, $this->instance->get_legacy_site_information() ); } @@ -177,7 +188,7 @@ public function test_site_information() { 'search_url' => 'https://example.org', 'post_edit_url' => 'https://example.org', 'base_url' => 'https://example.org', - + 'isWooCommerceActive' => '1', 'adminUrl' => 'https://example.org', 'linkParams' => [ 'param', @@ -201,6 +212,7 @@ public function test_site_information() { $this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] ); $this->promotion_manager->expects( 'is' )->andReturnFalse(); $this->short_link_helper->expects( 'get' )->andReturn( 'https://expl.c' ); + $this->woocommerce_conditional->expects( 'is_met' )->andReturn( '1' ); $this->assertSame( $expected, $this->instance->get_site_information() ); } From 4891b4ef87b404288d66897975543665a6e83500 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 13:09:50 +0300 Subject: [PATCH 04/23] fix wp tests --- .../Site/Post_Site_Information_Test.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php index a7034a1c5c5..c96860eaba1 100644 --- a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php @@ -5,6 +5,7 @@ use Mockery; use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; +use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Editors\Framework\Site\Post_Site_Information; use Yoast\WP\SEO\Helpers\Product_Helper; use Yoast\WP\SEO\Helpers\Short_Link_Helper; @@ -64,6 +65,13 @@ final class Post_Site_Information_Test extends TestCase { */ private $product_helper; + /** + * The WooCommerce conditional. + * + * @var WooCommerce_Conditional $woocommerce_conditional + */ + protected $woocommerce_conditional; + /** * The Post_Site_Information container. * @@ -82,11 +90,12 @@ public function set_up() { $this->short_link_helper = \YoastSEO()->helpers->short_link; $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); $this->wistia_embed_repo->expects( 'get_value_for_user' )->with( 0 )->andReturnTrue(); - $this->meta_surface = \YoastSEO()->meta; - $this->product_helper = \YoastSEO()->helpers->product; - $this->alert_dismissal_action = \YoastSEO()->classes->get( Alert_Dismissal_Action::class ); + $this->meta_surface = \YoastSEO()->meta; + $this->product_helper = \YoastSEO()->helpers->product; + $this->alert_dismissal_action = \YoastSEO()->classes->get( Alert_Dismissal_Action::class ); + $this->woocommerce_conditional = \YoastSEO()->classes->get( WooCommerce_Conditional::class ); - $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); + $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action, $this->woocommerce_conditional ); $this->instance->set_permalink( 'perma' ); } @@ -108,6 +117,7 @@ public function test_legacy_site_information() { 'currentPromotions' => [], 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), 'blackFridayBlockEditorUrl' => '', + 'isWooCommerceActive' => false, 'metabox' => [ 'search_url' => 'http://example.org/wp-admin/edit.php?seo_kw_filter={keyword}', @@ -150,6 +160,7 @@ public function test_site_information() { 'search_url' => 'http://example.org/wp-admin/edit.php?seo_kw_filter={keyword}', 'post_edit_url' => 'http://example.org/wp-admin/post.php?post={id}&action=edit', 'base_url' => 'http://example.org/', + 'isWooCommerceActive' => false, 'adminUrl' => 'http://example.org/wp-admin/admin.php', 'linkParams' => $this->short_link_helper->get_query_params(), 'pluginUrl' => 'http://example.org/wp-content/plugins/wordpress-seo', From d8a7ab237cf7d2654cc7eefbf1defdb55878e1fb Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 13:29:45 +0300 Subject: [PATCH 05/23] php fix-cs --- tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php index e2d5b083cfd..53d015981fb 100644 --- a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php @@ -146,7 +146,6 @@ public function test_legacy_site_information() { ], 'pluginUrl' => '/location', 'wistiaEmbedPermission' => true, - 'isWooCommerceActive' => '', ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); From 9a5b24050676dddc8690ecc62300c9ca72b69ae6 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 13:30:09 +0300 Subject: [PATCH 06/23] remove unused isWooCommerceActive property --- admin/class-config.php | 1 - 1 file changed, 1 deletion(-) diff --git a/admin/class-config.php b/admin/class-config.php index 0f8ce558885..408decb7a1f 100644 --- a/admin/class-config.php +++ b/admin/class-config.php @@ -98,7 +98,6 @@ public function config_page_scripts() { 'dismissedAlerts' => $dismissed_alerts, 'isRtl' => is_rtl(), 'isPremium' => YoastSEO()->helpers->product->is_premium(), - 'isWooCommerceActive' => $woocommerce_conditional->is_met(), 'currentPromotions' => YoastSEO()->classes->get( Promotion_Manager::class )->get_current_promotions(), 'webinarIntroSettingsUrl' => WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-settings' ), 'webinarIntroFirstTimeConfigUrl' => $this->get_webinar_shortlink(), From 924d33eaf7a2b30db3eaa14f0ef190fd4894b6f8 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 13:33:26 +0300 Subject: [PATCH 07/23] remove unused variables --- admin/class-config.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/admin/class-config.php b/admin/class-config.php index 408decb7a1f..0c8b468add4 100644 --- a/admin/class-config.php +++ b/admin/class-config.php @@ -6,7 +6,6 @@ */ use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; -use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Integrations\Academy_Integration; use Yoast\WP\SEO\Integrations\Settings_Integration; use Yoast\WP\SEO\Integrations\Support_Integration; @@ -91,7 +90,6 @@ public function config_page_scripts() { $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class ); $dismissed_alerts = $alert_dismissal_action->all_dismissed(); - $woocommerce_conditional = new WooCommerce_Conditional(); $script_data = [ 'userLanguageCode' => WPSEO_Language_Utils::get_language( get_user_locale() ), From b5a67e3c41fddcef80fdc209c437e7e90d534311 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 13:36:14 +0300 Subject: [PATCH 08/23] php fix-cs --- admin/class-config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/class-config.php b/admin/class-config.php index 0c8b468add4..351cedc12d0 100644 --- a/admin/class-config.php +++ b/admin/class-config.php @@ -88,8 +88,8 @@ public function config_page_scripts() { wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'thickbox' ); - $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class ); - $dismissed_alerts = $alert_dismissal_action->all_dismissed(); + $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class ); + $dismissed_alerts = $alert_dismissal_action->all_dismissed(); $script_data = [ 'userLanguageCode' => WPSEO_Language_Utils::get_language( get_user_locale() ), From 926410bd49315b2f156e0de58e03b3dc3b47c0e5 Mon Sep 17 00:00:00 2001 From: Vraja Das <65466507+vraja-pro@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:38:58 +0200 Subject: [PATCH 09/23] Update src/editors/framework/site/post-site-information.php Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com> --- src/editors/framework/site/post-site-information.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editors/framework/site/post-site-information.php b/src/editors/framework/site/post-site-information.php index bd04e597aa3..5149e7f27bb 100644 --- a/src/editors/framework/site/post-site-information.php +++ b/src/editors/framework/site/post-site-information.php @@ -41,7 +41,7 @@ class Post_Site_Information extends Base_Site_Information { * * @var WooCommerce_Conditional $woocommerce_conditional */ - protected $woocommerce_conditional; + private $woocommerce_conditional; /** * Constructs the class. From d223791cfcdc978494357086b3e32e0563bace71 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 4 Sep 2024 15:48:20 +0300 Subject: [PATCH 10/23] fix tests --- .../Editors/Framework/Site/Post_Site_Information_Test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php index 53d015981fb..de61c899c8b 100644 --- a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php @@ -126,7 +126,7 @@ public function test_legacy_site_information() { ], 'webinarIntroBlockEditorUrl' => 'https://expl.c', 'blackFridayBlockEditorUrl' => '', - 'isWooCommerceActive' => '', + 'isWooCommerceActive' => false, 'metabox' => [ 'search_url' => 'https://example.org', 'post_edit_url' => 'https://example.org', @@ -155,7 +155,7 @@ public function test_legacy_site_information() { $this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] ); $this->promotion_manager->expects( 'is' )->andReturnFalse(); $this->short_link_helper->expects( 'get' )->andReturn( 'https://expl.c' ); - $this->woocommerce_conditional->expects( 'is_met' )->andReturn( '' ); + $this->woocommerce_conditional->expects( 'is_met' )->andReturn( false ); $this->assertSame( $expected, $this->instance->get_legacy_site_information() ); } @@ -187,7 +187,7 @@ public function test_site_information() { 'search_url' => 'https://example.org', 'post_edit_url' => 'https://example.org', 'base_url' => 'https://example.org', - 'isWooCommerceActive' => '1', + 'isWooCommerceActive' => true, 'adminUrl' => 'https://example.org', 'linkParams' => [ 'param', @@ -211,7 +211,7 @@ public function test_site_information() { $this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] ); $this->promotion_manager->expects( 'is' )->andReturnFalse(); $this->short_link_helper->expects( 'get' )->andReturn( 'https://expl.c' ); - $this->woocommerce_conditional->expects( 'is_met' )->andReturn( '1' ); + $this->woocommerce_conditional->expects( 'is_met' )->andReturn( true ); $this->assertSame( $expected, $this->instance->get_site_information() ); } From 879f924971914a0b63282f8bf06fbbea870e1634 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:11:30 +0300 Subject: [PATCH 11/23] remove from post site information layer --- .../framework/site/post-site-information.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/editors/framework/site/post-site-information.php b/src/editors/framework/site/post-site-information.php index 5149e7f27bb..cfb6b94d65a 100644 --- a/src/editors/framework/site/post-site-information.php +++ b/src/editors/framework/site/post-site-information.php @@ -3,7 +3,6 @@ namespace Yoast\WP\SEO\Editors\Framework\Site; use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; -use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Helpers\Product_Helper; use Yoast\WP\SEO\Helpers\Short_Link_Helper; use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository; @@ -36,13 +35,6 @@ class Post_Site_Information extends Base_Site_Information { */ private $promotion_manager; - /** - * The WooCommerce conditional. - * - * @var WooCommerce_Conditional $woocommerce_conditional - */ - private $woocommerce_conditional; - /** * Constructs the class. * @@ -53,7 +45,6 @@ class Post_Site_Information extends Base_Site_Information { * @param Meta_Surface $meta The meta surface. * @param Product_Helper $product_helper The product helper. * @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action. - * @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional. * * @return void */ @@ -63,13 +54,11 @@ public function __construct( Wistia_Embed_Permission_Repository $wistia_embed_permission_repository, Meta_Surface $meta, Product_Helper $product_helper, - Alert_Dismissal_Action $alert_dismissal_action, - WooCommerce_Conditional $woocommerce_conditional + Alert_Dismissal_Action $alert_dismissal_action ) { parent::__construct( $short_link_helper, $wistia_embed_permission_repository, $meta, $product_helper ); $this->promotion_manager = $promotion_manager; $this->alert_dismissal_action = $alert_dismissal_action; - $this->woocommerce_conditional = $woocommerce_conditional; } /** @@ -96,7 +85,6 @@ public function get_legacy_site_information(): array { 'currentPromotions' => $this->promotion_manager->get_current_promotions(), 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), 'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '', - 'isWooCommerceActive' => $this->woocommerce_conditional->is_met(), 'metabox' => [ 'search_url' => $this->search_url(), 'post_edit_url' => $this->edit_url(), @@ -123,7 +111,6 @@ public function get_site_information(): array { 'search_url' => $this->search_url(), 'post_edit_url' => $this->edit_url(), 'base_url' => $this->base_url_for_js(), - 'isWooCommerceActive' => $this->woocommerce_conditional->is_met(), ]; return \array_merge( $data, parent::get_site_information() ); From 4848faa736295e2d4122782e1691e331d2a4b515 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:11:54 +0300 Subject: [PATCH 12/23] create an integration --- .../framework/integrations/woocommerce.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/editors/framework/integrations/woocommerce.php diff --git a/src/editors/framework/integrations/woocommerce.php b/src/editors/framework/integrations/woocommerce.php new file mode 100644 index 00000000000..2258a4d5ff0 --- /dev/null +++ b/src/editors/framework/integrations/woocommerce.php @@ -0,0 +1,55 @@ +woocommerce_conditional = $woocommerce_conditional; + } + + /** + * If the plugin is activated. + * + * @return bool If the plugin is activated. + */ + public function is_enabled(): bool { + return $this->woocommerce_conditional->is_met(); + } + + /** + * Return this object represented by a key value array. + * + * @return array Returns the name and if the feature is enabled. + */ + public function to_array(): array { + return [ 'isWooCommerceActive' => $this->is_enabled() ]; + } + + /** + * Returns this object represented by a key value structure that is compliant with the script data array. + * + * @return array Returns the legacy key and if the feature is enabled. + */ + public function to_legacy_array(): array { + return [ 'isWooCommerceActive' => $this->is_enabled() ]; + } +} From d102f16448cb906647fceda291211263827e559b Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:12:30 +0300 Subject: [PATCH 13/23] match the name of multilingual plugin check --- src/editors/framework/integrations/multilingual.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editors/framework/integrations/multilingual.php b/src/editors/framework/integrations/multilingual.php index 4f643dbca4a..1d78a5dd66a 100644 --- a/src/editors/framework/integrations/multilingual.php +++ b/src/editors/framework/integrations/multilingual.php @@ -61,7 +61,7 @@ public function is_enabled(): bool { * @return array Returns the name and if the feature is enabled. */ public function to_array(): array { - return [ 'multilingualPluginActive' => $this->is_enabled() ]; + return [ 'isMultilingualActive' => $this->is_enabled() ]; } /** From f83d3d2c558a98ed96b7164b1d4f0374b4694af4 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:12:47 +0300 Subject: [PATCH 14/23] change the helper to match --- packages/js/src/helpers/isWooCommerceActive.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/js/src/helpers/isWooCommerceActive.js b/packages/js/src/helpers/isWooCommerceActive.js index 26cf5318076..f7a6afcccc1 100644 --- a/packages/js/src/helpers/isWooCommerceActive.js +++ b/packages/js/src/helpers/isWooCommerceActive.js @@ -1,9 +1,11 @@ +import { get } from "lodash"; + /** * Checks if WooCommerce is active. * * @returns {boolean} True if WooCommerce is active. */ export const isWooCommerceActive = () => { - return window.wpseoScriptData && window.wpseoScriptData.isWooCommerceActive === "1"; + return get( window, "wpseoScriptData.metabox.isWooCommerceActive", false ); }; From 7bb6dd3b9ecfdef6e22d862a253db67016b03e51 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:13:07 +0300 Subject: [PATCH 15/23] update the selector --- packages/js/src/redux/selectors/isWooSEO.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/js/src/redux/selectors/isWooSEO.js b/packages/js/src/redux/selectors/isWooSEO.js index 531e12ea98f..01d847c129e 100644 --- a/packages/js/src/redux/selectors/isWooSEO.js +++ b/packages/js/src/redux/selectors/isWooSEO.js @@ -1,5 +1,6 @@ import { get } from "lodash"; import { getIsProduct } from "./editorContext"; +import { isWooCommerceActive } from "../../helpers/isWooCommerceActive"; /** * Determines whether the WooCommerce SEO addon is active. @@ -13,7 +14,7 @@ export const getIsWooSeoActive = () => Boolean( get( window, "wpseoScriptData.is * * @returns {boolean} True if WooCommerce is active. */ -export const getIsWooCommerceActive = () => Boolean( get( window, "wpseoScriptData.isWooCommerceActive", false ) ); +export const getIsWooCommerceActive = () => isWooCommerceActive(); /** * Determines whether the WooCommerce SEO addon is not active in a product page. From 4b7a72112bcd08b71c4924cc1e7198811d36a624 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:14:32 +0300 Subject: [PATCH 16/23] Revert "fix tests" This reverts commit d7258611e64e8c8bc13f6ee0f3c3eb13f5155401. --- .../Site/Post_Site_Information_Test.php | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php index de61c899c8b..c3ecc881b8f 100644 --- a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php @@ -6,7 +6,6 @@ use Brain\Monkey; use Mockery; use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; -use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Editors\Framework\Site\Post_Site_Information; use Yoast\WP\SEO\Helpers\Product_Helper; use Yoast\WP\SEO\Helpers\Short_Link_Helper; @@ -69,13 +68,6 @@ final class Post_Site_Information_Test extends TestCase { */ private $product_helper; - /** - * The WooCommerce conditional. - * - * @var WooCommerce_Conditional $woocommerce_conditional - */ - protected $woocommerce_conditional; - /** * The Post_Site_Information container. * @@ -90,15 +82,14 @@ final class Post_Site_Information_Test extends TestCase { */ protected function set_up() { parent::set_up(); - $this->promotion_manager = Mockery::mock( Promotion_Manager::class ); - $this->short_link_helper = Mockery::mock( Short_Link_Helper::class ); - $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); - $this->meta_surface = Mockery::mock( Meta_Surface::class ); - $this->product_helper = Mockery::mock( Product_Helper::class ); - $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); - $this->woocommerce_conditional = Mockery::mock( WooCommerce_Conditional::class ); - - $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action, $this->woocommerce_conditional ); + $this->promotion_manager = Mockery::mock( Promotion_Manager::class ); + $this->short_link_helper = Mockery::mock( Short_Link_Helper::class ); + $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); + $this->meta_surface = Mockery::mock( Meta_Surface::class ); + $this->product_helper = Mockery::mock( Product_Helper::class ); + $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); + + $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); $this->instance->set_permalink( 'perma' ); $this->set_mocks(); } @@ -126,7 +117,6 @@ public function test_legacy_site_information() { ], 'webinarIntroBlockEditorUrl' => 'https://expl.c', 'blackFridayBlockEditorUrl' => '', - 'isWooCommerceActive' => false, 'metabox' => [ 'search_url' => 'https://example.org', 'post_edit_url' => 'https://example.org', @@ -146,6 +136,7 @@ public function test_legacy_site_information() { ], 'pluginUrl' => '/location', 'wistiaEmbedPermission' => true, + ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); @@ -155,7 +146,6 @@ public function test_legacy_site_information() { $this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] ); $this->promotion_manager->expects( 'is' )->andReturnFalse(); $this->short_link_helper->expects( 'get' )->andReturn( 'https://expl.c' ); - $this->woocommerce_conditional->expects( 'is_met' )->andReturn( false ); $this->assertSame( $expected, $this->instance->get_legacy_site_information() ); } @@ -187,7 +177,7 @@ public function test_site_information() { 'search_url' => 'https://example.org', 'post_edit_url' => 'https://example.org', 'base_url' => 'https://example.org', - 'isWooCommerceActive' => true, + 'adminUrl' => 'https://example.org', 'linkParams' => [ 'param', @@ -211,7 +201,6 @@ public function test_site_information() { $this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] ); $this->promotion_manager->expects( 'is' )->andReturnFalse(); $this->short_link_helper->expects( 'get' )->andReturn( 'https://expl.c' ); - $this->woocommerce_conditional->expects( 'is_met' )->andReturn( true ); $this->assertSame( $expected, $this->instance->get_site_information() ); } From 5005e035a9dfae2fb64ce330c9ef2d20f22cc51e Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:22:10 +0300 Subject: [PATCH 17/23] restore post-site0information and tests --- .../framework/site/post-site-information.php | 4 ++-- .../Site/Post_Site_Information_Test.php | 19 ++++--------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/editors/framework/site/post-site-information.php b/src/editors/framework/site/post-site-information.php index cfb6b94d65a..4882642aa7a 100644 --- a/src/editors/framework/site/post-site-information.php +++ b/src/editors/framework/site/post-site-information.php @@ -57,8 +57,8 @@ public function __construct( Alert_Dismissal_Action $alert_dismissal_action ) { parent::__construct( $short_link_helper, $wistia_embed_permission_repository, $meta, $product_helper ); - $this->promotion_manager = $promotion_manager; - $this->alert_dismissal_action = $alert_dismissal_action; + $this->promotion_manager = $promotion_manager; + $this->alert_dismissal_action = $alert_dismissal_action; } /** diff --git a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php index c96860eaba1..a7034a1c5c5 100644 --- a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php @@ -5,7 +5,6 @@ use Mockery; use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; -use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; use Yoast\WP\SEO\Editors\Framework\Site\Post_Site_Information; use Yoast\WP\SEO\Helpers\Product_Helper; use Yoast\WP\SEO\Helpers\Short_Link_Helper; @@ -65,13 +64,6 @@ final class Post_Site_Information_Test extends TestCase { */ private $product_helper; - /** - * The WooCommerce conditional. - * - * @var WooCommerce_Conditional $woocommerce_conditional - */ - protected $woocommerce_conditional; - /** * The Post_Site_Information container. * @@ -90,12 +82,11 @@ public function set_up() { $this->short_link_helper = \YoastSEO()->helpers->short_link; $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); $this->wistia_embed_repo->expects( 'get_value_for_user' )->with( 0 )->andReturnTrue(); - $this->meta_surface = \YoastSEO()->meta; - $this->product_helper = \YoastSEO()->helpers->product; - $this->alert_dismissal_action = \YoastSEO()->classes->get( Alert_Dismissal_Action::class ); - $this->woocommerce_conditional = \YoastSEO()->classes->get( WooCommerce_Conditional::class ); + $this->meta_surface = \YoastSEO()->meta; + $this->product_helper = \YoastSEO()->helpers->product; + $this->alert_dismissal_action = \YoastSEO()->classes->get( Alert_Dismissal_Action::class ); - $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action, $this->woocommerce_conditional ); + $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); $this->instance->set_permalink( 'perma' ); } @@ -117,7 +108,6 @@ public function test_legacy_site_information() { 'currentPromotions' => [], 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), 'blackFridayBlockEditorUrl' => '', - 'isWooCommerceActive' => false, 'metabox' => [ 'search_url' => 'http://example.org/wp-admin/edit.php?seo_kw_filter={keyword}', @@ -160,7 +150,6 @@ public function test_site_information() { 'search_url' => 'http://example.org/wp-admin/edit.php?seo_kw_filter={keyword}', 'post_edit_url' => 'http://example.org/wp-admin/post.php?post={id}&action=edit', 'base_url' => 'http://example.org/', - 'isWooCommerceActive' => false, 'adminUrl' => 'http://example.org/wp-admin/admin.php', 'linkParams' => $this->short_link_helper->get_query_params(), 'pluginUrl' => 'http://example.org/wp-content/plugins/wordpress-seo', From 10a62bd173f3ea0eeedf292da155400c2ee01efe Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:35:27 +0300 Subject: [PATCH 18/23] Add tests to new integration --- .../Integrations/WooCommerce_Test.php | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/Unit/Editors/Framework/Integrations/WooCommerce_Test.php diff --git a/tests/Unit/Editors/Framework/Integrations/WooCommerce_Test.php b/tests/Unit/Editors/Framework/Integrations/WooCommerce_Test.php new file mode 100644 index 00000000000..c1e7647a105 --- /dev/null +++ b/tests/Unit/Editors/Framework/Integrations/WooCommerce_Test.php @@ -0,0 +1,85 @@ +woocommerce_conditional = Mockery::mock( WooCommerce_Conditional::class ); + $this->instance = new WooCommerce( $this->woocommerce_conditional ); + } + + /** + * Tests the is_enabled method. + * + * @dataProvider data_provider_is_enabled + * + * @param bool $woocommerce_enabled If the woocommerce plugin is enabled. + * @param bool $expected The expected outcome. + * + * @return void + */ + public function test_is_enabled( + bool $woocommerce_enabled, + bool $expected + ) { + + $this->woocommerce_conditional + ->expects( 'is_met' ) + ->times( 3 ) + ->andReturn( $woocommerce_enabled ); + + $this->assertSame( $expected, $this->instance->is_enabled() ); + $this->assertSame( [ 'isWooCommerceActive' => $this->instance->is_enabled() ], $this->instance->to_legacy_array() ); + } + + /** + * Data provider for test_is_enabled. + * + * @return array> + */ + public static function data_provider_is_enabled() { + return [ + 'Enabled' => [ + 'woocommerce_enabled' => true, + 'expected' => true, + ], + 'Disabled' => [ + 'woocommerce_enabled' => false, + 'expected' => false, + ], + ]; + } +} From d02fc4f4fa568d0c63297c8cb4933ff0160d7a90 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:40:30 +0300 Subject: [PATCH 19/23] Add comment why we have this selector. --- packages/js/src/redux/selectors/isWooSEO.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/redux/selectors/isWooSEO.js b/packages/js/src/redux/selectors/isWooSEO.js index 01d847c129e..c30ae0a483f 100644 --- a/packages/js/src/redux/selectors/isWooSEO.js +++ b/packages/js/src/redux/selectors/isWooSEO.js @@ -10,7 +10,7 @@ import { isWooCommerceActive } from "../../helpers/isWooCommerceActive"; export const getIsWooSeoActive = () => Boolean( get( window, "wpseoScriptData.isWooCommerceSeoActive", false ) ); /** - * Checks if WooCommerce is active. + * Checks if WooCommerce is active. Used also in premium. * * @returns {boolean} True if WooCommerce is active. */ From 1ee93dbe8ad27e5f6e021dccf5bb3f3e1e3cf5cf Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 5 Sep 2024 11:52:22 +0300 Subject: [PATCH 20/23] fix lint warning --- packages/js/src/redux/selectors/isWooSEO.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/js/src/redux/selectors/isWooSEO.js b/packages/js/src/redux/selectors/isWooSEO.js index c30ae0a483f..65c16f90b6a 100644 --- a/packages/js/src/redux/selectors/isWooSEO.js +++ b/packages/js/src/redux/selectors/isWooSEO.js @@ -24,8 +24,8 @@ export const getIsWooCommerceActive = () => isWooCommerceActive(); */ export const getIsWooSeoUpsell = ( state ) => { const isWooSeoActive = getIsWooSeoActive(); - const isWooCommerceActive = getIsWooCommerceActive(); + const isWoocommerceActive = getIsWooCommerceActive(); const isProductPage = getIsProduct( state ); - return ! isWooSeoActive && isWooCommerceActive && isProductPage; + return ! isWooSeoActive && isWoocommerceActive && isProductPage; }; From 6a7b865587880a85590909d927567e37f2beca6e Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Fri, 6 Sep 2024 10:03:07 +0300 Subject: [PATCH 21/23] remove isWooCommerceActive helper in favour if the redux selector --- packages/js/src/components/fills/MetaboxFill.js | 4 ++-- packages/js/src/helpers/isWooCommerceActive.js | 11 ----------- .../js/src/hooks/use-first-eligible-notification.js | 4 ++-- packages/js/src/redux/selectors/isWooSEO.js | 7 +++---- 4 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 packages/js/src/helpers/isWooCommerceActive.js diff --git a/packages/js/src/components/fills/MetaboxFill.js b/packages/js/src/components/fills/MetaboxFill.js index 6f8def95c95..95197220fae 100644 --- a/packages/js/src/components/fills/MetaboxFill.js +++ b/packages/js/src/components/fills/MetaboxFill.js @@ -23,7 +23,6 @@ import PremiumSEOAnalysisModal from "../modals/PremiumSEOAnalysisModal"; import KeywordUpsell from "../modals/KeywordUpsell"; import { BlackFridayProductEditorChecklistPromotion } from "../BlackFridayProductEditorChecklistPromotion"; import { BlackFridayPromotion } from "../BlackFridayPromotion"; -import { isWooCommerceActive } from "../../helpers/isWooCommerceActive"; import { withMetaboxWarningsCheck } from "../higherorder/withMetaboxWarningsCheck"; const BlackFridayProductEditorChecklistPromotionWithMetaboxWarningsCheck = withMetaboxWarningsCheck( BlackFridayProductEditorChecklistPromotion ); @@ -40,8 +39,9 @@ const BlackFridayPromotionWithMetaboxWarningsCheck = withMetaboxWarningsCheck( B export default function MetaboxFill( { settings } ) { const isTerm = useSelect( ( select ) => select( "yoast-seo/editor" ).getIsTerm(), [] ); const isProduct = useSelect( ( select ) => select( "yoast-seo/editor" ).getIsProduct(), [] ); + const isWooCommerceActive = useSelect( ( select ) => select( "yoast-seo/editor" ).getIsWooCommerceActive(), [] ); - const shouldShowWooCommerceChecklistPromo = isProduct && isWooCommerceActive(); + const shouldShowWooCommerceChecklistPromo = isProduct && isWooCommerceActive; return ( <> diff --git a/packages/js/src/helpers/isWooCommerceActive.js b/packages/js/src/helpers/isWooCommerceActive.js deleted file mode 100644 index f7a6afcccc1..00000000000 --- a/packages/js/src/helpers/isWooCommerceActive.js +++ /dev/null @@ -1,11 +0,0 @@ -import { get } from "lodash"; - -/** - * Checks if WooCommerce is active. - * - * @returns {boolean} True if WooCommerce is active. - */ -export const isWooCommerceActive = () => { - return get( window, "wpseoScriptData.metabox.isWooCommerceActive", false ); -}; - diff --git a/packages/js/src/hooks/use-first-eligible-notification.js b/packages/js/src/hooks/use-first-eligible-notification.js index 716a56f6048..044881c9291 100644 --- a/packages/js/src/hooks/use-first-eligible-notification.js +++ b/packages/js/src/hooks/use-first-eligible-notification.js @@ -2,7 +2,7 @@ import { BlackFridayPromotion } from "../components/BlackFridayPromotion"; import { BlackFridaySidebarChecklistPromotion } from "../components/BlackFridaySidebarChecklistPromotion"; import { TrustpilotReviewNotification, useTrustpilotReviewNotification } from "../components/trustpilot-review-notification"; import WebinarPromoNotification from "../components/WebinarPromoNotification"; -import { isWooCommerceActive } from "../helpers/isWooCommerceActive"; +import { getIsWooCommerceActive } from "../redux/selectors/isWooSEO"; import { shouldShowWebinarPromotionNotificationInSidebar } from "../helpers/shouldShowWebinarPromotionNotification"; /** @@ -44,7 +44,7 @@ export const useFirstEligibleNotification = ( { webinarIntroUrl } ) => { component: () => , }, { - getIsEligible: isWooCommerceActive, + getIsEligible: getIsWooCommerceActive, component: () => , }, { diff --git a/packages/js/src/redux/selectors/isWooSEO.js b/packages/js/src/redux/selectors/isWooSEO.js index 65c16f90b6a..ae686d605d1 100644 --- a/packages/js/src/redux/selectors/isWooSEO.js +++ b/packages/js/src/redux/selectors/isWooSEO.js @@ -1,6 +1,5 @@ import { get } from "lodash"; import { getIsProduct } from "./editorContext"; -import { isWooCommerceActive } from "../../helpers/isWooCommerceActive"; /** * Determines whether the WooCommerce SEO addon is active. @@ -14,7 +13,7 @@ export const getIsWooSeoActive = () => Boolean( get( window, "wpseoScriptData.is * * @returns {boolean} True if WooCommerce is active. */ -export const getIsWooCommerceActive = () => isWooCommerceActive(); +export const getIsWooCommerceActive = () => get( window, "wpseoScriptData.metabox.isWooCommerceActive", false ); /** * Determines whether the WooCommerce SEO addon is not active in a product page. @@ -24,8 +23,8 @@ export const getIsWooCommerceActive = () => isWooCommerceActive(); */ export const getIsWooSeoUpsell = ( state ) => { const isWooSeoActive = getIsWooSeoActive(); - const isWoocommerceActive = getIsWooCommerceActive(); + const isWooCommerceActive = getIsWooCommerceActive(); const isProductPage = getIsProduct( state ); - return ! isWooSeoActive && isWoocommerceActive && isProductPage; + return ! isWooSeoActive && isWooCommerceActive && isProductPage; }; From 83c4fcf22a27e3f647ab6f766f8b22151ef5bbe9 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Fri, 6 Sep 2024 10:04:30 +0300 Subject: [PATCH 22/23] restore comment --- packages/js/src/redux/selectors/isWooSEO.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/redux/selectors/isWooSEO.js b/packages/js/src/redux/selectors/isWooSEO.js index ae686d605d1..9b5113023bf 100644 --- a/packages/js/src/redux/selectors/isWooSEO.js +++ b/packages/js/src/redux/selectors/isWooSEO.js @@ -9,7 +9,7 @@ import { getIsProduct } from "./editorContext"; export const getIsWooSeoActive = () => Boolean( get( window, "wpseoScriptData.isWooCommerceSeoActive", false ) ); /** - * Checks if WooCommerce is active. Used also in premium. + * Checks if WooCommerce is active. * * @returns {boolean} True if WooCommerce is active. */ From e622c4d91589e2e499fc19328d2db04a9a018ecb Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Fri, 6 Sep 2024 10:51:36 +0300 Subject: [PATCH 23/23] increase test coverage --- .../Integrations/WooCommerce_Test.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Unit/Editors/Framework/Integrations/WooCommerce_Test.php b/tests/Unit/Editors/Framework/Integrations/WooCommerce_Test.php index c1e7647a105..6b1b66fa570 100644 --- a/tests/Unit/Editors/Framework/Integrations/WooCommerce_Test.php +++ b/tests/Unit/Editors/Framework/Integrations/WooCommerce_Test.php @@ -65,6 +65,30 @@ public function test_is_enabled( $this->assertSame( [ 'isWooCommerceActive' => $this->instance->is_enabled() ], $this->instance->to_legacy_array() ); } + /** + * Tests the to_array method. + * + * @dataProvider data_provider_is_enabled + * + * @param bool $woocommerce_enabled If the woocommerce plugin is enabled. + * @param bool $expected The expected outcome. + * + * @return void + */ + public function test_to_array( + bool $woocommerce_enabled, + bool $expected + ) { + + $this->woocommerce_conditional + ->expects( 'is_met' ) + ->times( 3 ) + ->andReturn( $woocommerce_enabled ); + + $this->assertSame( $expected, $this->instance->is_enabled() ); + $this->assertSame( [ 'isWooCommerceActive' => $this->instance->is_enabled() ], $this->instance->to_array() ); + } + /** * Data provider for test_is_enabled. *