mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
* Fix tests
This commit is contained in:
parent
ef5fc4b3d4
commit
4027f4a77e
5 changed files with 61 additions and 6 deletions
|
@ -43,10 +43,19 @@ class PaymentsTest extends TestCase
|
|||
'status' => 'CREATED',
|
||||
]
|
||||
);
|
||||
$captures = [$capture];
|
||||
$authorizations = [$authorization];
|
||||
$refund = \Mockery::mock(Refund::class);
|
||||
$refund->shouldReceive('to_array')->andReturn(
|
||||
[
|
||||
'id' => 'refund',
|
||||
'status' => 'CREATED',
|
||||
]
|
||||
);
|
||||
|
||||
$testee = new Payments($authorizations, $captures);
|
||||
$authorizations = [$authorization];
|
||||
$captures = [$capture];
|
||||
$refunds = [$refund];
|
||||
|
||||
$testee = new Payments($authorizations, $captures, $refunds);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
|
@ -62,6 +71,12 @@ class PaymentsTest extends TestCase
|
|||
'status' => 'CREATED',
|
||||
],
|
||||
],
|
||||
'refunds' => [
|
||||
[
|
||||
'id' => 'refund',
|
||||
'status' => 'CREATED',
|
||||
],
|
||||
],
|
||||
],
|
||||
$testee->to_array()
|
||||
);
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Refund;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use Mockery;
|
||||
|
||||
|
@ -18,11 +19,15 @@ class PaymentsFactoryTest extends TestCase
|
|||
$authorization->shouldReceive('to_array')->andReturn(['id' => 'foo', 'status' => 'CREATED']);
|
||||
$capture = Mockery::mock(Capture::class);
|
||||
$capture->shouldReceive('to_array')->andReturn(['id' => 'capture', 'status' => 'CREATED']);
|
||||
$refund = Mockery::mock(Refund::class);
|
||||
$refund->shouldReceive('to_array')->andReturn(['id' => 'refund', 'status' => 'CREATED']);
|
||||
|
||||
$authorizationsFactory = Mockery::mock(AuthorizationFactory::class);
|
||||
$authorizationsFactory->shouldReceive('from_paypal_response')->andReturn($authorization);
|
||||
$captureFactory = Mockery::mock(CaptureFactory::class);
|
||||
$captureFactory->shouldReceive('from_paypal_response')->andReturn($capture);
|
||||
$refundFactory = Mockery::mock(RefundFactory::class);
|
||||
$refundFactory->shouldReceive('from_paypal_response')->andReturn($refund);
|
||||
$response = (object)[
|
||||
'authorizations' => [
|
||||
(object)['id' => 'foo', 'status' => 'CREATED'],
|
||||
|
@ -30,9 +35,12 @@ class PaymentsFactoryTest extends TestCase
|
|||
'captures' => [
|
||||
(object)['id' => 'capture', 'status' => 'CREATED'],
|
||||
],
|
||||
'refunds' => [
|
||||
(object)['id' => 'refund', 'status' => 'CREATED'],
|
||||
],
|
||||
];
|
||||
|
||||
$testee = new PaymentsFactory($authorizationsFactory, $captureFactory);
|
||||
$testee = new PaymentsFactory($authorizationsFactory, $captureFactory, $refundFactory);
|
||||
$result = $testee->from_paypal_response($response);
|
||||
|
||||
$this->assertInstanceOf(Payments::class, $result);
|
||||
|
@ -44,6 +52,9 @@ class PaymentsFactoryTest extends TestCase
|
|||
'captures' => [
|
||||
['id' => 'capture', 'status' => 'CREATED'],
|
||||
],
|
||||
'refunds' => [
|
||||
['id' => 'refund', 'status' => 'CREATED'],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expectedToArray, $result->to_array());
|
||||
}
|
||||
|
|
|
@ -43,11 +43,32 @@ class FeesRendererTest extends TestCase
|
|||
],
|
||||
]);
|
||||
|
||||
$wcOrder->expects('get_meta')
|
||||
->with(PayPalGateway::REFUND_FEES_META_KEY)
|
||||
->andReturn([
|
||||
'gross_amount' => [
|
||||
'currency_code' => 'USD',
|
||||
'value' => '20.52',
|
||||
],
|
||||
'paypal_fee' => [
|
||||
'currency_code' => 'USD',
|
||||
'value' => '0.51',
|
||||
],
|
||||
'net_amount' => [
|
||||
'currency_code' => 'USD',
|
||||
'value' => '50.01',
|
||||
],
|
||||
]);
|
||||
|
||||
$result = $this->renderer->render($wcOrder);
|
||||
$this->assertStringContainsString('Fee', $result);
|
||||
$this->assertStringContainsString('0.41', $result);
|
||||
$this->assertStringContainsString('Payout', $result);
|
||||
$this->assertStringContainsString('10.01', $result);
|
||||
$this->assertStringContainsString('PayPal Refund Fee', $result);
|
||||
$this->assertStringContainsString('0.51', $result);
|
||||
$this->assertStringContainsString('PayPal Refund', $result);
|
||||
$this->assertStringContainsString('50.01', $result);
|
||||
}
|
||||
|
||||
public function testRenderWithoutNet() {
|
||||
|
@ -62,6 +83,10 @@ class FeesRendererTest extends TestCase
|
|||
],
|
||||
]);
|
||||
|
||||
$wcOrder->expects('get_meta')
|
||||
->with(PayPalGateway::REFUND_FEES_META_KEY)
|
||||
->andReturn([]);
|
||||
|
||||
$result = $this->renderer->render($wcOrder);
|
||||
$this->assertStringContainsString('Fee', $result);
|
||||
$this->assertStringContainsString('0.41', $result);
|
||||
|
@ -78,6 +103,10 @@ class FeesRendererTest extends TestCase
|
|||
->with(PayPalGateway::FEES_META_KEY)
|
||||
->andReturn($meta);
|
||||
|
||||
$wcOrder->expects('get_meta')
|
||||
->with(PayPalGateway::REFUND_FEES_META_KEY)
|
||||
->andReturn([]);
|
||||
|
||||
$this->assertSame('', $this->renderer->render($wcOrder));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue