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

Adds "is_managed" key in Parse.ly Integration if integration is managed by VIP #4802

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions integrations/parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor

@alecgeatches alecgeatches Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion - may be better to check for the keys you need explicitly (site_id and api_secret) rather than any $config value. If $config currently or in the future accepts other configuration keys, this code would set both values to null if any other configuration key is set.

Suggested change
$credentials = empty( $config ) ? $original_credentials : array(
$credentials = ( isset( $config[ 'site_id' ] ) && isset( $config[ 'api_secret' ] ) ? array( ... ) : $original_credentials;

(note this implementation switches the order of the array values and $original_credentials)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$original_credentials means credentials that we got from plugin so I think its fine to return as it is without any extra checks to keep things simple. Later we can improve if needed.

'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
Loading