diff --git a/modules/ppcp-settings/src/Service/BrandedExperience/ActivationDetector.php b/modules/ppcp-settings/src/Service/BrandedExperience/ActivationDetector.php index 48c38e91d..f33390a60 100644 --- a/modules/ppcp-settings/src/Service/BrandedExperience/ActivationDetector.php +++ b/modules/ppcp-settings/src/Service/BrandedExperience/ActivationDetector.php @@ -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; } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f8faa3dbc..557f0eb11 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,14 @@ - - - - ./src - ./modules/ - - - - - ./tests/PHPUnit - - + + + + ./src + ./modules/ + + + + + ./tests/PHPUnit + + diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak new file mode 100644 index 000000000..f8faa3dbc --- /dev/null +++ b/phpunit.xml.dist.bak @@ -0,0 +1,21 @@ + + + + + ./src + ./modules/ + + + + + ./tests/PHPUnit + + + diff --git a/tests/PHPUnit/Settings/Service/BrandedExperience/ActivationDetectorTest.php b/tests/PHPUnit/Settings/Service/BrandedExperience/ActivationDetectorTest.php index a7d6f60b0..fd40fbda8 100644 --- a/tests/PHPUnit/Settings/Service/BrandedExperience/ActivationDetectorTest.php +++ b/tests/PHPUnit/Settings/Service/BrandedExperience/ActivationDetectorTest.php @@ -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() ); - } }