mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Fix merge conflicts
This commit is contained in:
commit
baee53e90f
60 changed files with 3162 additions and 366 deletions
|
@ -43,9 +43,8 @@ class ItemFactoryTest extends TestCase
|
|||
->expects('get_cart_contents')
|
||||
->andReturn($items);
|
||||
|
||||
expect('wp_strip_all_tags')
|
||||
->with('description')
|
||||
->andReturn('description');
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
$session = Mockery::mock(\WC_Session::class);
|
||||
|
@ -99,9 +98,8 @@ class ItemFactoryTest extends TestCase
|
|||
->expects('get_cart_contents')
|
||||
->andReturn($items);
|
||||
|
||||
expect('wp_strip_all_tags')
|
||||
->with('description')
|
||||
->andReturn('description');
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
$session = Mockery::mock(\WC_Session::class);
|
||||
|
@ -130,9 +128,9 @@ class ItemFactoryTest extends TestCase
|
|||
$product
|
||||
->expects('is_virtual')
|
||||
->andReturn(false);
|
||||
expect('wp_strip_all_tags')
|
||||
->with('description')
|
||||
->andReturn('description');
|
||||
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||
$item
|
||||
|
@ -190,9 +188,8 @@ class ItemFactoryTest extends TestCase
|
|||
->expects('is_virtual')
|
||||
->andReturn(true);
|
||||
|
||||
expect('wp_strip_all_tags')
|
||||
->with('description')
|
||||
->andReturn('description');
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||
$item
|
||||
|
@ -245,9 +242,8 @@ class ItemFactoryTest extends TestCase
|
|||
->expects('is_virtual')
|
||||
->andReturn(true);
|
||||
|
||||
expect('wp_strip_all_tags')
|
||||
->with($description)
|
||||
->andReturn(mb_substr( $description, 0, 127 ));
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||
$item
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
|
|||
|
||||
use Exception;
|
||||
use Mockery;
|
||||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Exception\ValidationException;
|
||||
use WooCommerce\PayPalCommerce\Button\Validation\CheckoutFormValidator;
|
||||
|
@ -13,6 +14,8 @@ use function Brain\Monkey\Functions\expect;
|
|||
|
||||
class ValidateCheckoutEndpointTest extends TestCase
|
||||
{
|
||||
use MockeryPHPUnitIntegration;
|
||||
|
||||
private $requestData;
|
||||
private $formValidator;
|
||||
private $logger;
|
||||
|
|
14
tests/PHPUnit/Helper/RedirectorStub.php
Normal file
14
tests/PHPUnit/Helper/RedirectorStub.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Helper;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Http\RedirectorInterface;
|
||||
|
||||
class RedirectorStub implements RedirectorInterface
|
||||
{
|
||||
public function redirect(string $location): void
|
||||
{
|
||||
throw new StubRedirectionException($location);
|
||||
}
|
||||
}
|
41
tests/PHPUnit/Helper/SettingsStub.php
Normal file
41
tests/PHPUnit/Helper/SettingsStub.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Helper;
|
||||
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
class SettingsStub extends Settings
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data) {
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function get($id) {
|
||||
if ( ! $this->has( $id ) ) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return $this->data[$id];
|
||||
}
|
||||
|
||||
public function has($id) {
|
||||
return array_key_exists( $id, $this->data );
|
||||
}
|
||||
|
||||
public function set($id, $value) {
|
||||
$this->data[$id] = $value;
|
||||
}
|
||||
|
||||
public function persist() {
|
||||
}
|
||||
}
|
10
tests/PHPUnit/Helper/StubRedirectionException.php
Normal file
10
tests/PHPUnit/Helper/StubRedirectionException.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Helper;
|
||||
|
||||
use Exception;
|
||||
|
||||
class StubRedirectionException extends Exception
|
||||
{
|
||||
}
|
|
@ -3,10 +3,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\CompositeCachingServiceProvider;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\DelegatingContainer;
|
||||
use WooCommerce\PayPalCommerce\Helper\RedirectorStub;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
|
@ -58,13 +59,28 @@ class ModularTestCase extends TestCase
|
|||
*/
|
||||
protected function bootstrapModule(array $overriddenServices = []): ContainerInterface
|
||||
{
|
||||
$overridingContainer = new DelegatingContainer(new CompositeCachingServiceProvider([
|
||||
new ServiceProvider($overriddenServices, []),
|
||||
]));
|
||||
$overriddenServices = array_merge([
|
||||
'http.redirector' => function () {
|
||||
return new RedirectorStub();
|
||||
}
|
||||
], $overriddenServices);
|
||||
|
||||
$module = new class ($overriddenServices) implements ModuleInterface {
|
||||
public function __construct(array $services) {
|
||||
$this->services = $services;
|
||||
}
|
||||
|
||||
public function setup(): ServiceProviderInterface{
|
||||
return new ServiceProvider($this->services, []);
|
||||
}
|
||||
|
||||
public function run(ContainerInterface $c): void {
|
||||
}
|
||||
};
|
||||
|
||||
$rootDir = ROOT_DIR;
|
||||
$bootstrap = require ("$rootDir/bootstrap.php");
|
||||
$appContainer = $bootstrap($rootDir, $overridingContainer);
|
||||
$appContainer = $bootstrap($rootDir, [], [$module]);
|
||||
|
||||
return $appContainer;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,10 @@ class WcGatewayTest extends TestCase
|
|||
$this->environment = Mockery::mock(Environment::class);
|
||||
$this->paymentTokenRepository = Mockery::mock(PaymentTokenRepository::class);
|
||||
$this->logger = Mockery::mock(LoggerInterface::class);
|
||||
$this->funding_source_renderer = new FundingSourceRenderer($this->settings);
|
||||
$this->funding_source_renderer = new FundingSourceRenderer(
|
||||
$this->settings,
|
||||
['venmo' => 'Venmo', 'paylater' => 'Pay Later', 'blik' => 'BLIK']
|
||||
);
|
||||
$this->apiShopCountry = 'DE';
|
||||
|
||||
$this->onboardingState->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
|
||||
|
@ -271,6 +274,8 @@ class WcGatewayTest extends TestCase
|
|||
return [
|
||||
[null, 'PayPal', 'Pay via PayPal.'],
|
||||
['venmo', 'Venmo', 'Pay via Venmo.'],
|
||||
['paylater', 'Pay Later', 'Pay via Pay Later.'],
|
||||
['blik', 'BLIK (via PayPal)', 'Pay via BLIK.'],
|
||||
['qwerty', 'PayPal', 'Pay via PayPal.'],
|
||||
];
|
||||
}
|
||||
|
|
60
tests/PHPUnit/WcGateway/Settings/LocationsTest.php
Normal file
60
tests/PHPUnit/WcGateway/Settings/LocationsTest.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Helper\SettingsStub;
|
||||
use WooCommerce\PayPalCommerce\ModularTestCase;
|
||||
|
||||
class LocationsTest extends ModularTestCase
|
||||
{
|
||||
private $appContainer;
|
||||
|
||||
private $settings;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->settings = new SettingsStub([]);
|
||||
|
||||
$this->appContainer = $this->bootstrapModule([
|
||||
'wcgateway.settings' => function () {
|
||||
return $this->settings;
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider payLaterButtonLocationsData
|
||||
*/
|
||||
public function testPayLaterButtonLocations(array $selectedLocations, array $expectedResult) {
|
||||
$this->settings->set('smart_button_locations', $selectedLocations);
|
||||
|
||||
$result = $this->appContainer->get('wcgateway.settings.pay-later.button-locations');
|
||||
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function payLaterButtonLocationsData()
|
||||
{
|
||||
yield [
|
||||
['product', 'cart', 'checkout', 'mini-cart'],
|
||||
[
|
||||
'product' => 'Single Product',
|
||||
'cart' => 'Cart',
|
||||
'checkout' => 'Checkout',
|
||||
'mini-cart' => 'Mini Cart',
|
||||
],
|
||||
];
|
||||
yield [
|
||||
['cart', 'checkout'],
|
||||
[
|
||||
'cart' => 'Cart',
|
||||
'checkout' => 'Checkout',
|
||||
],
|
||||
];
|
||||
yield [
|
||||
[],
|
||||
[],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
|
|||
use Requests_Utility_CaseInsensitiveDictionary;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\Helper\RedirectorStub;
|
||||
use WooCommerce\PayPalCommerce\Helper\StubRedirectionException;
|
||||
use WooCommerce\PayPalCommerce\ModularTestCase;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use Mockery;
|
||||
|
@ -50,7 +52,8 @@ class SettingsListenerTest extends ModularTestCase
|
|||
$signup_link_cache,
|
||||
$signup_link_ids,
|
||||
$pui_status_cache,
|
||||
$dcc_status_cache
|
||||
$dcc_status_cache,
|
||||
new RedirectorStub()
|
||||
);
|
||||
|
||||
$_GET['section'] = PayPalGateway::ID;
|
||||
|
@ -85,6 +88,8 @@ class SettingsListenerTest extends ModularTestCase
|
|||
$dcc_status_cache->shouldReceive('has')
|
||||
->andReturn(false);
|
||||
|
||||
$this->expectException(StubRedirectionException::class);
|
||||
|
||||
$testee->listen();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,10 @@ class PurchaseUnitTest extends TestCase
|
|||
|
||||
$this->puFactory = $this->container->get( 'api.factory.purchase-unit' );
|
||||
assert($this->puFactory instanceof PurchaseUnitFactory);
|
||||
|
||||
add_filter('woocommerce_get_base_location', function () {
|
||||
return 'AQ';
|
||||
});
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
|
@ -195,6 +199,7 @@ class PurchaseUnitTest extends TestCase
|
|||
$product->set_regular_price((string) $data['price']);
|
||||
$product->set_tax_status('taxable');
|
||||
$product->set_tax_class('');
|
||||
$product->set_virtual(true);
|
||||
|
||||
$product->save();
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ class ValidationTest extends TestCase
|
|||
'terms-field'=>'1',
|
||||
'terms'=>'on',
|
||||
]);
|
||||
|
||||
self::assertTrue(true); // no assertions warnings
|
||||
}
|
||||
|
||||
public function testInvalid()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue