woocommerce-paypal-payments/tests/PHPUnit/Button/Helper/ThreeDSecureTest.php

141 lines
5.3 KiB
PHP
Raw Normal View History

2020-07-15 11:15:20 +03:00
<?php
declare(strict_types=1);
2020-09-14 07:51:45 +03:00
namespace WooCommerce\PayPalCommerce\Button\Helper;
2020-07-15 11:15:20 +03:00
2021-09-21 12:20:54 +02:00
use Psr\Log\LoggerInterface;
2020-09-14 07:51:45 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Entity\CardAuthenticationResult;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
2023-11-23 14:53:47 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\CardAuthenticationResultFactory;
2020-09-14 07:51:45 +03:00
use WooCommerce\PayPalCommerce\TestCase;
2020-07-15 11:15:20 +03:00
class ThreeDSecureTest extends TestCase
{
/**
* @dataProvider dataForTestDefault
* @param Order $order
* @param int $expected
*/
public function testDefault(int $expected, string $liabilityShift, string $authenticationResult, string $enrollment)
{
2023-11-23 14:53:47 +01:00
$authResult = \Mockery::mock(CardAuthenticationResult::class);
$authResult->shouldReceive('liability_shift')->andReturn($liabilityShift);
$authResult->shouldReceive('authentication_result')->andReturn($authenticationResult);
$authResult->shouldReceive('enrollment_status')->andReturn($enrollment);
$authResult->shouldReceive('to_array')->andReturn(['foo' => 'bar',]);
2023-10-20 15:16:30 +02:00
2023-11-23 14:53:47 +01:00
$authenticationResultFactory = \Mockery::mock(CardAuthenticationResultFactory::class);
$authenticationResultFactory->shouldReceive('from_paypal_response')
->andReturn($authResult);
$source = \Mockery::mock(PaymentSource::class);
2023-10-20 15:16:30 +02:00
$authentication_result = (object)[
'brand' => 'visa',
2023-11-23 14:53:47 +01:00
'authentication_result' => (object)array(
'liability_shift' => $liabilityShift,
'authentication_result' => $authenticationResult,
'enrollment_status' => $enrollment
),
2023-10-20 15:16:30 +02:00
];
2023-11-23 14:53:47 +01:00
$source->shouldReceive('properties')->andReturn($authentication_result);
$order = \Mockery::mock(Order::class);
$order->shouldReceive('payment_source')->andReturn($source);
2023-10-20 15:16:30 +02:00
2023-11-23 14:53:47 +01:00
$logger = \Mockery::mock(LoggerInterface::class);
$logger->shouldReceive('info');
2021-09-21 12:20:54 +02:00
2023-11-23 14:53:47 +01:00
$testee = new ThreeDSecure($authenticationResultFactory, $logger);
2020-08-31 11:12:59 +03:00
$result = $testee->proceed_with_order($order);
2020-07-15 11:15:20 +03:00
$this->assertEquals($expected, $result);
}
public function dataForTestDefault() : array
{
$matrix = [
'test_1' => [
2025-03-24 14:09:19 +01:00
ThreeDSecure::PROCEED,
2020-07-15 11:15:20 +03:00
CardAuthenticationResult::LIABILITY_SHIFT_POSSIBLE,
CardAuthenticationResult::AUTHENTICATION_RESULT_YES,
CardAuthenticationResult::ENROLLMENT_STATUS_YES,
],
'test_2' => [
ThreeDSecure::REJECT,
CardAuthenticationResult::LIABILITY_SHIFT_NO,
CardAuthenticationResult::AUTHENTICATION_RESULT_NO,
CardAuthenticationResult::ENROLLMENT_STATUS_YES,
],
'test_3' => [
ThreeDSecure::REJECT,
CardAuthenticationResult::LIABILITY_SHIFT_NO,
CardAuthenticationResult::AUTHENTICATION_RESULT_REJECTED,
CardAuthenticationResult::ENROLLMENT_STATUS_YES,
],
'test_4' => [
2025-03-24 14:09:19 +01:00
ThreeDSecure::PROCEED,
2020-07-15 11:15:20 +03:00
CardAuthenticationResult::LIABILITY_SHIFT_POSSIBLE,
CardAuthenticationResult::AUTHENTICATION_RESULT_ATTEMPTED,
CardAuthenticationResult::ENROLLMENT_STATUS_YES,
],
'test_5' => [
ThreeDSecure::RETRY,
CardAuthenticationResult::LIABILITY_SHIFT_UNKNOWN,
CardAuthenticationResult::AUTHENTICATION_RESULT_UNABLE,
CardAuthenticationResult::ENROLLMENT_STATUS_YES,
],
'test_6' => [
ThreeDSecure::RETRY,
CardAuthenticationResult::LIABILITY_SHIFT_NO,
CardAuthenticationResult::AUTHENTICATION_RESULT_UNABLE,
CardAuthenticationResult::ENROLLMENT_STATUS_YES,
],
'test_7' => [
ThreeDSecure::RETRY,
CardAuthenticationResult::LIABILITY_SHIFT_UNKNOWN,
CardAuthenticationResult::AUTHENTICATION_RESULT_CHALLENGE_REQUIRED,
CardAuthenticationResult::ENROLLMENT_STATUS_YES,
],
'test_8' => [
ThreeDSecure::RETRY,
CardAuthenticationResult::LIABILITY_SHIFT_NO,
'',
CardAuthenticationResult::ENROLLMENT_STATUS_YES,
],
'test_9' => [
2025-03-24 14:09:19 +01:00
ThreeDSecure::PROCEED,
2020-07-15 11:15:20 +03:00
CardAuthenticationResult::LIABILITY_SHIFT_NO,
'',
CardAuthenticationResult::ENROLLMENT_STATUS_NO,
],
'test_10' => [
2025-03-24 14:09:19 +01:00
ThreeDSecure::PROCEED,
2020-07-15 11:15:20 +03:00
CardAuthenticationResult::LIABILITY_SHIFT_NO,
'',
CardAuthenticationResult::ENROLLMENT_STATUS_UNAVAILABLE,
],
'test_11' => [
ThreeDSecure::RETRY,
CardAuthenticationResult::LIABILITY_SHIFT_UNKNOWN,
'',
CardAuthenticationResult::ENROLLMENT_STATUS_UNAVAILABLE,
],
'test_12' => [
2025-03-24 14:09:19 +01:00
ThreeDSecure::PROCEED,
2020-07-15 11:15:20 +03:00
CardAuthenticationResult::LIABILITY_SHIFT_NO,
'',
CardAuthenticationResult::ENROLLMENT_STATUS_BYPASS,
],
'test_13' => [
ThreeDSecure::RETRY,
CardAuthenticationResult::LIABILITY_SHIFT_UNKNOWN,
'',
'',
],
];
return $matrix;
}
2021-09-21 12:20:54 +02:00
}