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

Add active plugin list to compatibility service #7933

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add active plugins array to compatibility data.
3 changes: 3 additions & 0 deletions includes/class-compatibility-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public function init_hooks() {
* @return void
*/
public function update_compatibility_data() {
$active_plugins = get_option( 'active_plugins', [] );

try {
$this->payments_api_client->update_compatibility_data(
[
'woopayments_version' => WCPAY_VERSION_NUMBER,
'woocommerce_version' => WC_VERSION,
'blog_theme' => get_stylesheet(),
'active_plugins' => $active_plugins,
]
);
} catch ( API_Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
Expand Down
57 changes: 57 additions & 0 deletions tests/unit/test-class-compatibility-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,72 @@ function( $theme ) use ( $stylesheet ) {
'woopayments_version' => WCPAY_VERSION_NUMBER,
'woocommerce_version' => WC_VERSION,
'blog_theme' => $stylesheet,
'active_plugins' => [
'woocommerce/woocommerce.php',
'woocommerce-payments/woocommerce-payments.php',
],
];

// Arrange/Assert: Set the expectations for update_compatibility_data.
add_filter( 'option_active_plugins', [ $this, 'active_plugins_filter_return' ] );

$this->mock_api_client
->expects( $this->once() )
->method( 'update_compatibility_data' )
->with( $expected );

// Act: Call the method we're testing.
$this->compatibility_service->update_compatibility_data();

remove_filter( 'option_active_plugins', [ $this, 'active_plugins_filter_return' ] );
}

public function test_update_compatibility_data_active_plugins_false() {
$stylesheet = 'my_theme_name';
add_filter(
'stylesheet',
function( $theme ) use ( $stylesheet ) {
return $stylesheet;
}
);

// Arrange: Create the expected value to be passed to update_compatibility_data.
$expected = [
'woopayments_version' => WCPAY_VERSION_NUMBER,
'woocommerce_version' => WC_VERSION,
'blog_theme' => $stylesheet,
'active_plugins' => [],
];

$this->break_active_plugins_option();

// Arrange/Assert: Set the expectations for update_compatibility_data.
$this->mock_api_client
->expects( $this->once() )
->method( 'update_compatibility_data' )
->with( $expected );

// Act: Call the method we're testing.
$this->compatibility_service->update_compatibility_data();

$this->fix_active_plugins_option();
}


public function active_plugins_filter_return() {
return [
'woocommerce/woocommerce.php',
'woocommerce-payments/woocommerce-payments.php',
];
}

private function break_active_plugins_option() {
update_option( 'temp_active_plugins', get_option( 'active_plugins' ) );
delete_option( 'active_plugins' );
}

private function fix_active_plugins_option() {
update_option( 'active_plugins', get_option( 'temp_active_plugins' ) );
delete_option( 'temp_active_plugins' );
}
}
Loading