diff --git a/integrations/parsely.php b/integrations/parsely.php index 8a3791b752..cf44d8cebd 100644 --- a/integrations/parsely.php +++ b/integrations/parsely.php @@ -41,15 +41,18 @@ 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 ( empty( $config ) ) { - return $original_credentials; - } - - return array( + // If config provided by VIP is empty then take original credentials else take + // credentials from config. + $credentials = empty( $config ) ? $original_credentials : 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 ); } } diff --git a/tests/integrations/test-parsely.php b/tests/integrations/test-parsely.php index 0956b376de..32905bbccf 100644 --- a/tests/integrations/test-parsely.php +++ b/tests/integrations/test-parsely.php @@ -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; @@ -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' => [ @@ -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 );