mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge pull request #3268 from woocommerce/PCP-4427-fix-the-branded-only-detection
Fix the branded-only detection (4427)
This commit is contained in:
commit
fe055a0137
4 changed files with 50 additions and 56 deletions
|
@ -15,26 +15,28 @@ use WooCommerce\PayPalCommerce\Settings\Enum\InstallationPathEnum;
|
||||||
* Class that includes detection logic for Branded Experience.
|
* Class that includes detection logic for Branded Experience.
|
||||||
*/
|
*/
|
||||||
class ActivationDetector {
|
class ActivationDetector {
|
||||||
|
/**
|
||||||
|
* The expected slug that identifies the "core-profiler" installation path.
|
||||||
|
*/
|
||||||
|
private const ATTACHMENT_CORE_PROFILER = 'payments_settings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects from which path the plugin was installed.
|
* Detects from which path the plugin was installed.
|
||||||
*
|
*
|
||||||
* @return string The installation path.
|
* @return string The installation path.
|
||||||
*/
|
*/
|
||||||
public function detect_activation_path(): string {
|
public function detect_activation_path() : string {
|
||||||
$slug = 'woocommerce-paypal-payments';
|
/**
|
||||||
|
* Get the custom attachment detail which was added by WooCommerce
|
||||||
|
*
|
||||||
|
* @see PaymentProviders::attach_extension_suggestion()
|
||||||
|
*/
|
||||||
|
$branded_option = get_option( 'woocommerce_paypal_branded' );
|
||||||
|
|
||||||
$onboarding_data = (array) get_option( 'woocommerce_onboarding_profile', array() );
|
if ( self::ATTACHMENT_CORE_PROFILER === $branded_option ) {
|
||||||
if ( ! empty( $onboarding_data['business_extensions'] ) && is_array( $onboarding_data['business_extensions'] ) && in_array( $slug, $onboarding_data['business_extensions'], true )
|
|
||||||
) {
|
|
||||||
return InstallationPathEnum::CORE_PROFILER;
|
return InstallationPathEnum::CORE_PROFILER;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nox_data = (array) get_option( 'woocommerce_payments_nox_profile', array() );
|
|
||||||
if ( ! empty( $nox_data['extensions']['attached'] ) && is_array( $nox_data['extensions']['attached'] ) && in_array( $slug, array_column( $nox_data['extensions']['attached'], 'slug' ), true )
|
|
||||||
) {
|
|
||||||
return InstallationPathEnum::PAYMENT_SETTINGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
return InstallationPathEnum::DIRECT;
|
return InstallationPathEnum::DIRECT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/PHPUnit/bootstrap.php" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
bootstrap="tests/PHPUnit/bootstrap.php"
|
<coverage processUncoveredFiles="true">
|
||||||
backupGlobals="false"
|
<include>
|
||||||
colors="true"
|
<directory suffix=".php">./src</directory>
|
||||||
convertErrorsToExceptions="true"
|
<directory suffix=".php">./modules/</directory>
|
||||||
convertNoticesToExceptions="true"
|
</include>
|
||||||
convertWarningsToExceptions="true"
|
</coverage>
|
||||||
>
|
<testsuites>
|
||||||
<filter>
|
<testsuite name="unit">
|
||||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
<directory suffix="Test.php">./tests/PHPUnit</directory>
|
||||||
<directory suffix=".php">./src</directory>
|
</testsuite>
|
||||||
<directory suffix=".php">./modules/</directory>
|
</testsuites>
|
||||||
</whitelist>
|
|
||||||
</filter>
|
|
||||||
<testsuites>
|
|
||||||
<testsuite name="unit">
|
|
||||||
<directory suffix="Test.php">./tests/PHPUnit</directory>
|
|
||||||
</testsuite>
|
|
||||||
</testsuites>
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
21
phpunit.xml.dist.bak
Normal file
21
phpunit.xml.dist.bak
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit
|
||||||
|
bootstrap="tests/PHPUnit/bootstrap.php"
|
||||||
|
backupGlobals="false"
|
||||||
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
>
|
||||||
|
<filter>
|
||||||
|
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory suffix=".php">./src</directory>
|
||||||
|
<directory suffix=".php">./modules/</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="unit">
|
||||||
|
<directory suffix="Test.php">./tests/PHPUnit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
|
@ -11,42 +11,20 @@ use function Brain\Monkey\Functions\when;
|
||||||
|
|
||||||
class ActivationDetectorTest extends TestCase {
|
class ActivationDetectorTest extends TestCase {
|
||||||
|
|
||||||
public function test_returns_direct_if_not_attached_via_woocommerce_paths() {
|
public function test_returns_direct_if_not_installed_via_woocommerce_paths() {
|
||||||
when( 'get_option' )->justReturn( [] );
|
when( 'get_option' )->justReturn( [] );
|
||||||
$detector = new ActivationDetector();
|
$detector = new ActivationDetector();
|
||||||
|
|
||||||
$this->assertEquals( InstallationPathEnum::DIRECT, $detector->detect_activation_path() );
|
$this->assertEquals( InstallationPathEnum::DIRECT, $detector->detect_activation_path() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_returns_core_profiler_if_attached_via_core_profiler() {
|
public function test_returns_core_profiler_if_installed_via_woocommerce_path() {
|
||||||
expect( 'get_option' )
|
expect( 'get_option' )
|
||||||
->with( 'woocommerce_onboarding_profile', array() )
|
->with( 'woocommerce_paypal_branded' )
|
||||||
->andReturn( [
|
->andReturn('payments_settings' );
|
||||||
'business_extensions' => [
|
|
||||||
'woocommerce-paypal-payments'
|
|
||||||
],
|
|
||||||
] );
|
|
||||||
|
|
||||||
$detector = new ActivationDetector();
|
$detector = new ActivationDetector();
|
||||||
|
|
||||||
$this->assertEquals( InstallationPathEnum::CORE_PROFILER, $detector->detect_activation_path() );
|
$this->assertEquals( InstallationPathEnum::CORE_PROFILER, $detector->detect_activation_path() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_returns_payment_settings_if_attached_via_payments_settings_page() {
|
|
||||||
expect( 'get_option' )
|
|
||||||
->with( 'woocommerce_payments_nox_profile', array() )
|
|
||||||
->andReturn( [
|
|
||||||
'extensions' => [
|
|
||||||
'attached' => [
|
|
||||||
[
|
|
||||||
'slug' => 'woocommerce-paypal-payments',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
],
|
|
||||||
] );
|
|
||||||
|
|
||||||
$detector = new ActivationDetector();
|
|
||||||
|
|
||||||
$this->assertEquals( InstallationPathEnum::PAYMENT_SETTINGS, $detector->detect_activation_path() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue