mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +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 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.
|
||||
*
|
||||
* @return string The installation path.
|
||||
*/
|
||||
public function detect_activation_path(): string {
|
||||
$slug = 'woocommerce-paypal-payments';
|
||||
public function detect_activation_path() : string {
|
||||
/**
|
||||
* 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 ( ! empty( $onboarding_data['business_extensions'] ) && is_array( $onboarding_data['business_extensions'] ) && in_array( $slug, $onboarding_data['business_extensions'], true )
|
||||
) {
|
||||
if ( self::ATTACHMENT_CORE_PROFILER === $branded_option ) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
<?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">
|
||||
<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">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./src</directory>
|
||||
<directory suffix=".php">./modules/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="unit">
|
||||
<directory suffix="Test.php">./tests/PHPUnit</directory>
|
||||
|
|
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 {
|
||||
|
||||
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( [] );
|
||||
$detector = new ActivationDetector();
|
||||
|
||||
$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' )
|
||||
->with( 'woocommerce_onboarding_profile', array() )
|
||||
->andReturn( [
|
||||
'business_extensions' => [
|
||||
'woocommerce-paypal-payments'
|
||||
],
|
||||
] );
|
||||
->with( 'woocommerce_paypal_branded' )
|
||||
->andReturn('payments_settings' );
|
||||
|
||||
$detector = new ActivationDetector();
|
||||
|
||||
$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