-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from omise/release-v3.4.0
Bump v3.4.0
- Loading branch information
Showing
9 changed files
with
287 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Omise\Payment\Test\Unit; | ||
|
||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Omise\Payment\Model\Config\Config; | ||
use Magento\Store\Api\Data\StoreInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
|
||
class ConfigTest extends TestCase | ||
{ | ||
private $storeManagerMock; | ||
private $scopeConfigMock; | ||
private $storeMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->scopeConfigMock = m::mock(ScopeConfigInterface::class); | ||
$this->storeManagerMock = m::mock(StoreManagerInterface::class); | ||
$this->storeMock = m::mock(StoreInterface::class); | ||
} | ||
|
||
/** | ||
* @dataProvider isDynamicWebhooksEnabledProvider | ||
* @covers Omise\Payment\Model\Config\Config | ||
*/ | ||
public function testIsDynamicWebhooksEnabled($webhookEnabled, $dynamicWebhooksEnabled, $expected) | ||
{ | ||
$this->scopeConfigMock->shouldReceive('getValue') | ||
->with('general/locale/code', m::any(), m::any()) | ||
->andReturn('en'); | ||
|
||
$this->scopeConfigMock->shouldReceive('getValue') | ||
->with('payment/omise/sandbox_status', m::any(), m::any()) | ||
->andReturn(1); | ||
|
||
$this->scopeConfigMock->shouldReceive('getValue') | ||
->with('payment/omise/test_public_key', m::any(), m::any()) | ||
->andReturn('pkey_test_xx'); | ||
|
||
$this->scopeConfigMock->shouldReceive('getValue') | ||
->with('payment/omise/test_secret_key', m::any(), m::any()) | ||
->andReturn('pkey_test_xx'); | ||
|
||
$this->scopeConfigMock->shouldReceive('getValue') | ||
->with('payment/omise/dynamic_webhooks', m::any(), m::any()) | ||
->andReturn($dynamicWebhooksEnabled); | ||
|
||
$this->scopeConfigMock->shouldReceive('getValue') | ||
->with('payment/omise/webhook_status', m::any(), m::any()) | ||
->andReturn($webhookEnabled); | ||
|
||
$this->storeMock->shouldReceive('getId')->andReturn(1); | ||
$this->storeManagerMock->shouldReceive('getStore')->andReturn($this->storeMock); | ||
|
||
$config = new Config($this->scopeConfigMock, $this->storeManagerMock); | ||
$result = $config->isDynamicWebhooksEnabled(); | ||
$this->assertEquals($result, $expected); | ||
} | ||
|
||
/** | ||
* Data provider for testIsDynamicWebhooksEnabled method | ||
*/ | ||
public function isDynamicWebhooksEnabledProvider() | ||
{ | ||
return [ | ||
[ | ||
'webhookEnabled' => 1, | ||
'dynamicWebhooksEnabled' => 1, | ||
'expected' => true, | ||
], | ||
[ | ||
'webhookEnabled' => 1, | ||
'dynamicWebhooksEnabled' => 1, | ||
'expected' => true, | ||
], | ||
[ | ||
'webhookEnabled' => 0, | ||
'dynamicWebhooksEnabled' => 1, | ||
'expected' => false, | ||
], | ||
[ | ||
'webhookEnabled' => 0, | ||
'dynamicWebhooksEnabled' => 0, | ||
'expected' => false, | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
namespace Omise\Payment\Test\Unit; | ||
|
||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Omise\Payment\Gateway\Request\PaymentDataBuilder; | ||
use Omise\Payment\Helper\OmiseHelper; | ||
use Omise\Payment\Helper\OmiseMoney; | ||
use Omise\Payment\Model\Config\Cc; | ||
use Magento\Framework\ObjectManager\ConfigInterface; | ||
use Magento\Framework\ObjectManager\FactoryInterface; | ||
use Magento\Sales\Api\Data\OrderPaymentInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Store\Api\Data\StoreInterface; | ||
use Omise\Payment\Model\Config\Installment; | ||
use Omise\Payment\Model\Config\Promptpay; | ||
|
||
class PaymentDataBuilderTest extends TestCase | ||
{ | ||
private $omiseMoneyMock; | ||
private $ccConfigMock; | ||
private $paymentDataMock; | ||
private $paymentMock; | ||
private $orderMock; | ||
private $factoryMock; | ||
private $configMock; | ||
private $storeManagerMock; | ||
private $storeMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->factoryMock = m::mock(FactoryInterface::class); | ||
$this->configMock = m::mock(ConfigInterface::class); | ||
$this->omiseMoneyMock = m::mock(OmiseMoney::class); | ||
$this->ccConfigMock = m::mock(Cc::class); | ||
$this->paymentMock = m::mock(OrderPaymentInterface::class); | ||
$this->paymentDataMock = m::mock(PaymentDataObjectInterface::class); | ||
$this->orderMock = m::mock(OrderInterface::class); | ||
$this->storeManagerMock = m::mock(StoreManagerInterface::class); | ||
$this->storeMock = m::mock(StoreInterface::class); | ||
} | ||
|
||
/** | ||
* @covers Omise\Payment\Gateway\Request\PaymentDataBuilder | ||
*/ | ||
public function testConstants() | ||
{ | ||
$this->assertEquals('webhook_endpoints', PaymentDataBuilder::WEBHOOKS_ENDPOINT); | ||
$this->assertEquals('amount', PaymentDataBuilder::AMOUNT); | ||
$this->assertEquals('currency', PaymentDataBuilder::CURRENCY); | ||
$this->assertEquals('description', PaymentDataBuilder::DESCRIPTION); | ||
$this->assertEquals('metadata', PaymentDataBuilder::METADATA); | ||
$this->assertEquals('zero_interest_installments', PaymentDataBuilder::ZERO_INTEREST_INSTALLMENTS); | ||
} | ||
|
||
/** | ||
* @dataProvider buildDataProvider | ||
* @covers Omise\Payment\Gateway\Request\PaymentDataBuilder | ||
*/ | ||
public function testBuild($paymentMethod, $expectedMetadata) | ||
{ | ||
$amount = 1000; | ||
$currency = 'THB'; | ||
$orderId = 123; | ||
$storeId = 1; | ||
$storeName = 'opn-store'; | ||
$storeBaseUrl = 'https://omise.co/'; | ||
$secureFormEnabled = true; | ||
|
||
new ObjectManager($this->factoryMock, $this->configMock); | ||
|
||
$this->paymentMock->shouldReceive('getMethod')->andReturn($paymentMethod); | ||
$this->paymentMock->shouldReceive('getAdditionalInformation')->andReturn('installment_mbb'); | ||
|
||
$this->ccConfigMock->shouldReceive('getSecureForm')->andReturn($secureFormEnabled); | ||
$this->ccConfigMock->shouldReceive('isDynamicWebhooksEnabled')->andReturn(true); | ||
|
||
$this->omiseMoneyMock->shouldReceive('setAmountAndCurrency')->andReturn($this->omiseMoneyMock); | ||
$this->omiseMoneyMock->shouldReceive('toSubunit')->andReturn($amount * 100); | ||
|
||
$this->storeMock->shouldReceive('getName')->andReturn($storeName); | ||
$this->storeMock->shouldReceive('getBaseUrl')->andReturn($storeBaseUrl); | ||
|
||
$this->storeManagerMock->shouldReceive('getStore')->andReturn($this->storeMock); | ||
$this->configMock->shouldReceive('getPreference'); | ||
$this->factoryMock->shouldReceive('create')->andReturn($this->storeManagerMock); | ||
|
||
$this->orderMock->shouldReceive('getCurrencyCode')->andReturn($currency); | ||
$this->orderMock->shouldReceive('getGrandTotalAmount')->andReturn($amount); | ||
$this->orderMock->shouldReceive('getOrderIncrementId')->andReturn($orderId); | ||
$this->orderMock->shouldReceive('getStoreId')->andReturn($storeId); | ||
|
||
$this->paymentDataMock->shouldReceive('getOrder')->andReturn($this->orderMock); | ||
$this->paymentDataMock->shouldReceive('getPayment')->andReturn($this->paymentMock); | ||
|
||
$model = new PaymentDataBuilder($this->ccConfigMock, $this->omiseMoneyMock); | ||
$result = $model->build(['payment' => $this->paymentDataMock]); | ||
|
||
$this->assertEquals(100000, $result['amount']); | ||
$this->assertEquals('THB', $result['currency']); | ||
$this->assertEquals([ | ||
'https://omise.co/omise/callback/webhook' | ||
], $result['webhook_endpoints']); | ||
$this->assertEquals($expectedMetadata, $result['metadata']); | ||
|
||
if ($paymentMethod === Installment::CODE) { | ||
$this->assertEquals(true, $result['zero_interest_installments']); | ||
} | ||
} | ||
|
||
/** | ||
* Data provider for testBuild method | ||
*/ | ||
public function buildDataProvider() | ||
{ | ||
return [ | ||
[ | ||
'paymentMethod' => Cc::CODE, | ||
'expectedMetadata' => [ | ||
'order_id' => 123, | ||
'store_id' => 1, | ||
'store_name' => 'opn-store', | ||
'secure_form_enabled' => true | ||
], | ||
], | ||
[ | ||
'paymentMethod' => Installment::CODE, | ||
'expectedMetadata' => [ | ||
'order_id' => 123, | ||
'store_id' => 1, | ||
'store_name' => 'opn-store', | ||
], | ||
], | ||
[ | ||
'paymentMethod' => Promptpay::CODE, | ||
'expectedMetadata' => [ | ||
'order_id' => 123, | ||
'store_id' => 1, | ||
'store_name' => 'opn-store', | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
"email": "[email protected]" | ||
} | ||
], | ||
"version": "3.3.1", | ||
"version": "3.4.0", | ||
"minimum-stability": "stable", | ||
"type": "magento2-module", | ||
"license": "MIT", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.