Skip to content

Commit

Permalink
➕ ADDS: "is_managed" key in Parse.ly Integration if the plugin is man…
Browse files Browse the repository at this point in the history
…aged by VIP
  • Loading branch information
mehmoodak committed Aug 21, 2023
1 parent cf0f5e1 commit 701ec7e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
18 changes: 12 additions & 6 deletions integrations/parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ public function load(): void {
* @return array
*/
public function wp_parsely_credentials_callback( $original_credentials ) {
$config = $this->get_config();
$config = $this->get_config();
$credentials = array();

// If config provided by VIP is empty then take original credentials else take config.
if ( empty( $config ) ) {
return $original_credentials;
$credentials = $original_credentials;
} else {
$credentials = array(
'site_id' => $config['site_id'] ?? null,
'api_secret' => $config['api_secret'] ?? null,
);
}

return array(
'site_id' => $config['site_id'] ?? null,
'api_secret' => $config['api_secret'] ?? null,
);
// Adds `is_managed` flag to indicate that platform is managing this integration
// and we have to hide the credential banner warning or more.
return array_merge( array( 'is_managed' => true ), $credentials );
}
}
15 changes: 9 additions & 6 deletions tests/integrations/test-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use WP_UnitTestCase;

use function Automattic\Test\Utils\get_class_method_as_public;
use function Automattic\Test\Utils\get_class_property_as_public;
use function Automattic\Test\Utils\is_parsely_disabled;
use function Automattic\VIP\WP_Parsely_Integration\maybe_load_plugin;
Expand Down Expand Up @@ -37,18 +36,21 @@ public function test__load_call_is_defining_the_enabled_constant_and_adding_filt
$this->assertFalse( has_filter( 'wp_parsely_credentials' ) );
}

public function test__wp_parsely_credentials_callback_returns_original_credentials_of_the_integration(): void {
public function test__wp_parsely_credentials_callback_returns_original_credentials_of_the_integration_if_platform_config_is_empty(): void {
$parsely_integration = new ParselyIntegration( $this->slug );
get_class_property_as_public( Integration::class, 'options' )->setValue( $parsely_integration, [
'config' => [],
] );

$callback_value = get_class_method_as_public( ParselyIntegration::class, 'wp_parsely_credentials_callback' )->invoke( $parsely_integration, [ 'original' ] );
$callback_value = $parsely_integration->wp_parsely_credentials_callback( [ 'credential_1' => 'value' ] );

$this->assertEquals( [ 'original' ], $callback_value );
$this->assertEquals( [
'is_managed' => true,
'credential_1' => 'value',
], $callback_value );
}

public function test__wp_parsely_credentials_callback_returns_platform_credentials_of_the_integration(): void {
public function test__wp_parsely_credentials_callback_returns_platform_credentials_of_the_integration_if_platform_config_exists(): void {
$parsely_integration = new ParselyIntegration( $this->slug );
get_class_property_as_public( Integration::class, 'options' )->setValue( $parsely_integration, [
'config' => [
Expand All @@ -57,9 +59,10 @@ public function test__wp_parsely_credentials_callback_returns_platform_credentia
],
] );

$callback_value = get_class_method_as_public( ParselyIntegration::class, 'wp_parsely_credentials_callback' )->invoke( $parsely_integration, array() );
$callback_value = $parsely_integration->wp_parsely_credentials_callback( array() );

$this->assertEquals( [
'is_managed' => true,
'site_id' => 'value',
'api_secret' => null,
], $callback_value );
Expand Down

0 comments on commit 701ec7e

Please sign in to comment.