Merge branch 'trunk' into PCP-726-add-oxxo-apm-alternative-payment

This commit is contained in:
Alex P 2022-07-26 16:59:27 +03:00
commit 1049fda586
49 changed files with 1586 additions and 668 deletions

View file

@ -46,6 +46,7 @@ class IdentityTokenTest extends TestCase
public function testGenerateForCustomerReturnsToken()
{
$id = 1;
define( 'PPCP_FLAG_SUBSCRIPTION', true );
$token = Mockery::mock(Token::class);
$token
@ -60,6 +61,7 @@ class IdentityTokenTest extends TestCase
$this->settings->shouldReceive('has')->andReturn(true);
$this->settings->shouldReceive('get')->andReturn(true);
$this->customer_repository->shouldReceive('customer_id_for_user')->andReturn('prefix1');
expect('update_user_meta')->with($id, 'ppcp_customer_id', 'prefix1');
$rawResponse = [
'body' => '{"client_token":"abc123", "expires_in":3600}',
@ -97,6 +99,7 @@ class IdentityTokenTest extends TestCase
public function testGenerateForCustomerFailsBecauseWpError()
{
$id = 1;
$token = Mockery::mock(Token::class);
$token
->expects('token')->andReturn('bearer');
@ -111,7 +114,8 @@ class IdentityTokenTest extends TestCase
$this->logger->shouldReceive('debug');
$this->settings->shouldReceive('has')->andReturn(true);
$this->settings->shouldReceive('get')->andReturn(true);
$this->customer_repository->shouldReceive('customer_id_for_user');
$this->customer_repository->shouldReceive('customer_id_for_user')->andReturn('prefix1');
expect('update_user_meta')->with($id, 'ppcp_customer_id', 'prefix1');
$this->expectException(RuntimeException::class);
$this->sut->generate_for_user(1);
@ -119,6 +123,7 @@ class IdentityTokenTest extends TestCase
public function testGenerateForCustomerFailsBecauseResponseCodeIsNot200()
{
$id = 1;
$token = Mockery::mock(Token::class);
$token
->expects('token')->andReturn('bearer');
@ -137,7 +142,8 @@ class IdentityTokenTest extends TestCase
$this->logger->shouldReceive('debug');
$this->settings->shouldReceive('has')->andReturn(true);
$this->settings->shouldReceive('get')->andReturn(true);
$this->customer_repository->shouldReceive('customer_id_for_user');
$this->customer_repository->shouldReceive('customer_id_for_user')->andReturn('prefix1');
expect('update_user_meta')->with($id, 'ppcp_customer_id', 'prefix1');
$this->expectException(PayPalApiException::class);
$this->sut->generate_for_user(1);

View file

@ -1046,8 +1046,6 @@ class OrderEndpointTest extends TestCase
$payer = Mockery::mock(Payer::class);
$payer->expects('email_address')->andReturn('email@email.com');
$payerName = Mockery::mock(PayerName::class);
$payer->expects('name')->andReturn($payerName);
$payer->expects('to_array')->andReturn(['payer']);
$result = $testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE, $payer);
$this->assertEquals($expectedOrder, $result);
@ -1138,8 +1136,6 @@ class OrderEndpointTest extends TestCase
$payer = Mockery::mock(Payer::class);
$payer->expects('email_address')->andReturn('email@email.com');
$payerName = Mockery::mock(PayerName::class);
$payer->expects('name')->andReturn($payerName);
$payer->expects('to_array')->andReturn(['payer']);
$testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING, $payer);
}
@ -1229,8 +1225,6 @@ class OrderEndpointTest extends TestCase
$this->expectException(RuntimeException::class);
$payer = Mockery::mock(Payer::class);
$payer->expects('email_address')->andReturn('email@email.com');
$payerName = Mockery::mock(PayerName::class);
$payer->expects('name')->andReturn($payerName);
$payer->expects('to_array')->andReturn(['payer']);
$testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE, $payer);
}

View file

@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\TestCase;
use WooCommerce\PayPalCommerce\WcGateway\CardBillingMode;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\WooCommerce\Logging\Logger\NullLogger;
@ -152,6 +153,7 @@ class CreateOrderEndpointTest extends TestCase
$session_handler = Mockery::mock(SessionHandler::class);
$settings = Mockery::mock(Settings::class);
$early_order_handler = Mockery::mock(EarlyOrderHandler::class);
$settings->shouldReceive('has')->andReturnFalse();
$testee = new CreateOrderEndpoint(
$request_data,
@ -163,6 +165,7 @@ class CreateOrderEndpointTest extends TestCase
$settings,
$early_order_handler,
false,
CardBillingMode::MINIMAL_INPUT,
new NullLogger()
);
return array($payer_factory, $testee);

View file

@ -23,6 +23,8 @@ use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
class RenewalHandlerTest extends TestCase
{
@ -48,6 +50,11 @@ class RenewalHandlerTest extends TestCase
$this->shippingPreferenceFactory = Mockery::mock(ShippingPreferenceFactory::class);
$this->payerFactory = Mockery::mock(PayerFactory::class);
$this->environment = new Environment(new Dictionary([]));
$authorizedPaymentProcessor = Mockery::mock(AuthorizedPaymentsProcessor::class);
$settings = Mockery::mock(Settings::class);
$settings
->shouldReceive('has')
->andReturnFalse();
$this->logger->shouldReceive('error')->andReturnUsing(function ($msg) {
throw new Exception($msg);
@ -61,7 +68,9 @@ class RenewalHandlerTest extends TestCase
$this->purchaseUnitFactory,
$this->shippingPreferenceFactory,
$this->payerFactory,
$this->environment
$this->environment,
$settings,
$authorizedPaymentProcessor
);
}

View file

@ -3,14 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use Psr\Log\NullLogger;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
@ -37,7 +30,6 @@ class WcGatewayTest extends TestCase
private $settingsRenderer;
private $funding_source_renderer;
private $orderProcessor;
private $authorizedOrdersProcessor;
private $settings;
private $refundProcessor;
private $onboardingState;
@ -45,10 +37,7 @@ class WcGatewayTest extends TestCase
private $subscriptionHelper;
private $environment;
private $paymentTokenRepository;
private $shipping_preference_factory;
private $logger;
private $paymentsEndpoint;
private $orderEndpoint;
private $apiShopCountry;
public function setUp(): void {
@ -60,7 +49,6 @@ class WcGatewayTest extends TestCase
$this->settingsRenderer = Mockery::mock(SettingsRenderer::class);
$this->orderProcessor = Mockery::mock(OrderProcessor::class);
$this->authorizedOrdersProcessor = Mockery::mock(AuthorizedPaymentsProcessor::class);
$this->settings = Mockery::mock(Settings::class);
$this->sessionHandler = Mockery::mock(SessionHandler::class);
$this->refundProcessor = Mockery::mock(RefundProcessor::class);
@ -69,10 +57,7 @@ class WcGatewayTest extends TestCase
$this->subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
$this->environment = Mockery::mock(Environment::class);
$this->paymentTokenRepository = Mockery::mock(PaymentTokenRepository::class);
$this->shipping_preference_factory = Mockery::mock(ShippingPreferenceFactory::class);
$this->logger = Mockery::mock(LoggerInterface::class);
$this->paymentsEndpoint = Mockery::mock(PaymentsEndpoint::class);
$this->orderEndpoint = Mockery::mock(OrderEndpoint::class);
$this->funding_source_renderer = new FundingSourceRenderer($this->settings);
$this->apiShopCountry = 'DE';
@ -87,6 +72,7 @@ class WcGatewayTest extends TestCase
$this->settings->shouldReceive('has')->andReturnFalse();
$this->logger->shouldReceive('info');
$this->logger->shouldReceive('error');
}
private function createGateway()
@ -95,7 +81,6 @@ class WcGatewayTest extends TestCase
$this->settingsRenderer,
$this->funding_source_renderer,
$this->orderProcessor,
$this->authorizedOrdersProcessor,
$this->settings,
$this->sessionHandler,
$this->refundProcessor,
@ -105,10 +90,7 @@ class WcGatewayTest extends TestCase
PayPalGateway::ID,
$this->environment,
$this->paymentTokenRepository,
$this->shipping_preference_factory,
$this->logger,
$this->paymentsEndpoint,
$this->orderEndpoint,
$this->apiShopCountry
);
}
@ -173,8 +155,10 @@ class WcGatewayTest extends TestCase
when('wc_get_checkout_url')
->justReturn($redirectUrl);
expect('wc_add_notice')
->with('Couldn\'t find order to process','error');
$this->sessionHandler
->shouldReceive('destroy_session_data');
expect('wc_add_notice');
$this->assertEquals(
[
@ -195,7 +179,6 @@ class WcGatewayTest extends TestCase
->andReturnFalse();
$this->orderProcessor
->expects('last_error')
->twice()
->andReturn($lastError);
$this->subscriptionHelper->shouldReceive('has_subscription')->with($orderId)->andReturn(true);
$this->subscriptionHelper->shouldReceive('is_subscription_change_payment')->andReturn(true);
@ -206,6 +189,8 @@ class WcGatewayTest extends TestCase
expect('wc_get_order')
->with($orderId)
->andReturn($wcOrder);
$this->sessionHandler
->shouldReceive('destroy_session_data');
expect('wc_add_notice')
->with($lastError, 'error');

View file

@ -27,6 +27,7 @@ class PayUponInvoiceHelperTest extends TestCase
['1942-02-31', false],
['01-01-1942', false],
['1942-01-01', true],
['0001-01-01', false],
];
}

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
class WC_Payment_Gateway
{
protected function get_option(string $key) : string {
public function get_option(string $key, $empty_value = null) {
return $key;
}
@ -19,4 +19,4 @@ class WC_Payment_Gateway
public function process_admin_options() {
}
}
}