Skip to content

Commit

Permalink
fix php tests for integrations page
Browse files Browse the repository at this point in the history
fix tests to run in separate process.

This is done because the conditional foe jetpack and elementor returns different results when running the test separately.
  • Loading branch information
vraja-pro committed Jan 6, 2025
1 parent 657eccc commit 4c3bbdd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
13 changes: 5 additions & 8 deletions src/integrations/admin/integrations-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
use WPSEO_Addon_Manager;
use WPSEO_Admin_Asset_Manager;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Conditionals\Jetpack_Conditional;
use Yoast\WP\SEO\Conditionals\Google_Site_Kit_Feature_Conditional;
use Yoast\WP\SEO\Conditionals\Jetpack_Conditional;
use Yoast\WP\SEO\Conditionals\Third_Party\Elementor_Activated_Conditional;


use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Woocommerce_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
Expand Down Expand Up @@ -115,8 +113,8 @@ public function enqueue_assets() {

$this->admin_asset_manager->enqueue_script( 'integrations-page' );

$elementor_conditional = new Elementor_Activated_Conditional();
$jetpack_conditional = new Jetpack_Conditional();
$elementor_conditional = new Elementor_Activated_Conditional();
$jetpack_conditional = new Jetpack_Conditional();
$google_site_kit_conditional = new Google_Site_Kit_Feature_Conditional();

$woocommerce_seo_file = 'wpseo-woocommerce/wpseo-woocommerce.php';
Expand All @@ -143,7 +141,6 @@ public function enqueue_assets() {
$ssp_active = \class_exists( PodcastEpisode::class );
$wp_recipe_maker_active = \class_exists( WP_Recipe_Maker::class );
$mastodon_active = $this->is_mastodon_active();


$woocommerce_seo_activate_url = \wp_nonce_url(
\self_admin_url( 'plugins.php?action=activate&plugin=' . $woocommerce_seo_file ),
Expand Down Expand Up @@ -197,10 +194,10 @@ public function enqueue_assets() {
'mastodon_active' => $mastodon_active,
'is_multisite' => \is_multisite(),
'plugin_url' => \plugins_url( '', \WPSEO_FILE ),
'googleSiteKit' => [
'googleSiteKit' => [
'isInstalled' => \file_exists( \WP_PLUGIN_DIR . '/' . $google_site_kit_file ),
'isActive' => \is_plugin_active( $google_site_kit_file ),
'afterSetup' => \get_option( 'googlesitekit_has_connected_admins', false ) === "1",
'afterSetup' => \get_option( 'googlesitekit_has_connected_admins', false ) === '1',
'isConnected' => $this->options_helper->get( 'google_site_kit_connected', false ),
'featureEnabled' => $google_site_kit_conditional->is_met(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public function test_register_hooks() {
/**
* Tests the registration of the hooks.
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
* @covers ::enqueue_assets
*
* @return void
Expand All @@ -119,13 +122,13 @@ public function test_enqueue_assets() {
Monkey\Functions\expect( 'get_site_url' )
->andReturn( 'https://www.example.com' );

Monkey\Functions\expect( 'is_plugin_active' )->times( 5 )->andReturnTrue();
Monkey\Functions\expect( 'is_plugin_active' )->times( 6 )->andReturnTrue();
Monkey\Functions\expect( 'wp_nonce_url' )->times( 3 )->andReturn( 'nonce' );
Monkey\Functions\expect( 'self_admin_url' )->times( 3 )->andReturn( 'https://www.example.com' );
Monkey\Functions\expect( 'plugins_url' )->andReturn( 'https://www.example.com' );
Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://www.example.com' );

$this->options_helper->expects( 'get' )->times( 5 )->andReturnTrue();
$this->options_helper->expects( 'get' )->times( 6 )->andReturnTrue();

$this->admin_asset_manager->expects( 'localize_script' )->with(
'integrations-page',
Expand All @@ -137,8 +140,8 @@ public function test_enqueue_assets() {
'allow_algolia_integration' => true,
'wincher_integration_active' => true,
'allow_wincher_integration' => null,
'elementor_integration_active' => true,
'jetpack_integration_active' => true,
'elementor_integration_active' => false,
'jetpack_integration_active' => false,
'woocommerce_seo_installed' => false,
'woocommerce_seo_active' => true,
'woocommerce_active' => false,
Expand All @@ -156,6 +159,13 @@ public function test_enqueue_assets() {
'mastodon_active' => false,
'is_multisite' => false,
'plugin_url' => 'https://www.example.com',
'googleSiteKit' => [
'isInstalled' => false,
'isActive' => true,
'afterSetup' => false,
'isConnected' => true,
'featureEnabled' => false,
],
]
);

Expand Down

0 comments on commit 4c3bbdd

Please sign in to comment.