Skip to content

Commit

Permalink
Merge pull request #473 from mollie/release/2.4.0
Browse files Browse the repository at this point in the history
Release/2.4.0
  • Loading branch information
Marvin-Magmodules committed Dec 17, 2021
2 parents 15e3da3 + 3a3a6a4 commit 1bdeb41
Show file tree
Hide file tree
Showing 33 changed files with 324 additions and 32 deletions.
5 changes: 3 additions & 2 deletions Controller/Adminhtml/Action/Apikey.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Store\Model\ScopeInterface;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Helper\Tests as TestsHelper;

Expand Down Expand Up @@ -108,11 +109,11 @@ protected function _isAllowed()
private function getKey(string $type): string
{
if (!$this->request->getParam($type . '_key') || $this->request->getParam($type . '_key') == '******') {
$value = $this->scopeConfig->getValue('payment/mollie_general/apikey_' . $type);
$value = $this->scopeConfig->getValue('payment/mollie_general/apikey_' . $type, ScopeInterface::SCOPE_STORE);

return $this->encryptor->decrypt($value);
}

return $this->request->getParam('test_key');
return $this->request->getParam($type . '_key');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function execute(Observer $observer)
return;
}

if ($order->getState() === Order::STATE_NEW &&
if ($order->getState() === Order::STATE_PENDING_PAYMENT &&
$order->getStatus() === $this->config->orderStatusPending($order->getStoreId())
) {
$this->checkoutSession->restoreQuote();
}
}
}
}
2 changes: 1 addition & 1 deletion Service/Order/DeletePaymentReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function delete($reference)
if (is_numeric($reference)) {
$criteria->addFilter(Order::CUSTOMER_ID, $reference);
} else {
$criteria->addFilter(Order::CUSTOMER_ID, ['null' => true]);
$criteria->addFilter(Order::CUSTOMER_ID, '', 'null');
$criteria->addFilter(Order::CUSTOMER_EMAIL, $reference);
}

Expand Down
7 changes: 7 additions & 0 deletions Test/Integration/BackendControllerTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

if (version_compare(\PHPUnit\Runner\Version::id(), '9.0', '>=')) {
require __DIR__ . '/PHPUnit/BackendControllerTestCaseVersion9AndHigher.php';
} else {
require __DIR__ . '/PHPUnit/BackendControllerTestCaseVersion8AndLower.php';
}
154 changes: 154 additions & 0 deletions Test/Integration/Controller/Adminhtml/Action/ApikeyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration\Controller\Adminhtml\Action;

use Magento\Framework\Encryption\Encryptor;
use Mollie\Api\Endpoints\MethodEndpoint;
use Mollie\Payment\Helper\Tests;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Test\Integration\BackendControllerTestCase;

class ApikeyTest extends BackendControllerTestCase
{
public function testValidatesTheTestKey()
{
$this->mockMollieMethodsEndpointForRequestKeys('test_apikey123456789101112131415161718', '');

$this->dispatch('backend/mollie/action/apikey');

$result = json_decode($this->getResponse()->getContent(), true);

$this->assertStringContainsString('Test API-key: Success!', $result['msg']);
$this->assertStringContainsString('Live API-key: Empty value', $result['msg']);
$this->assertTrue($result['success']);
}

public function testValidatesTheLiveKey()
{
$this->mockMollieMethodsEndpointForRequestKeys('', 'live_apikey123456789101112131415161718');

$this->dispatch('backend/mollie/action/apikey');

$result = json_decode($this->getResponse()->getContent(), true);

$this->assertStringContainsString('Test API-key: Empty value', $result['msg']);
$this->assertStringContainsString('Live API-key: Success!', $result['msg']);
$this->assertTrue($result['success']);
}

public function testFallsBackOnTheConfigurationForTest()
{
$encryptorMock = $this->createMock(Encryptor::class);

$encryptorMock->method('decrypt')->willReturnCallback(function ($input) use (&$count) {
$count++;
if ($count == 2) {
return 'test_apikey123456789101112131415161718';
}

if ($count === 3) {
return '';
}

return $input;
});

$this->mockMollieMethodsEndpointForConfigurationKeys('test_apikey123456789101112131415161718', '');

$this->_objectManager->addSharedInstance($encryptorMock, Encryptor::class);

$this->dispatch('backend/mollie/action/apikey');

$result = json_decode($this->getResponse()->getContent(), true);

$this->assertStringContainsString('Test API-key: Success!', $result['msg']);
$this->assertStringContainsString('Live API-key: Empty value', $result['msg']);
$this->assertTrue($result['success']);
}

public function testFallsBackOnTheConfigurationForLive()
{
$count = 0;
$encryptorMock = $this->createMock(Encryptor::class);
$encryptorMock->method('decrypt')->willReturnCallback(function ($input) use (&$count) {
$count++;
if ($count == 2) {
return '';
}

if ($count === 3) {
return 'live_apikey123456789101112131415161718';
}

return $input;
});

$this->mockMollieMethodsEndpointForConfigurationKeys('', 'live_apikey123456789101112131415161718');

$this->_objectManager->addSharedInstance($encryptorMock, Encryptor::class);

$this->dispatch('backend/mollie/action/apikey');

$result = json_decode($this->getResponse()->getContent(), true);

$this->assertStringContainsString('Test API-key: Empty value', $result['msg']);
$this->assertStringContainsString('Live API-key: Success!', $result['msg']);
$this->assertTrue($result['success']);
}

protected function mockMollieMethodsEndpointForRequestKeys(string $testApiKey, string $liveApiKey): void
{
$mollieModel = $this->_objectManager->get(Mollie::class);
$mollieModelMock = $this->createMock(Mollie::class);
foreach (array_filter([$testApiKey, $liveApiKey]) as $key) {
$api = $mollieModel->loadMollieApi($key);

$api->methods = $this->createMock(MethodEndpoint::class);
$api->methods->method('all')->willReturn([]);

$mollieModelMock->method('loadMollieApi')->with($key)->willReturn($api);
}

$tests = $this->_objectManager->create(Tests::class, [
'mollieModel' => $mollieModelMock,
'tests' => [],
]);

$this->_objectManager->addSharedInstance($tests, Tests::class);

$this->getRequest()->setParams([
'test_key' => $testApiKey,
'live_key' => $liveApiKey,
]);
}

protected function mockMollieMethodsEndpointForConfigurationKeys(string $testApiKey, string $liveApiKey): void
{
$mollieModel = $this->_objectManager->get(Mollie::class);
$mollieModelMock = $this->createMock(Mollie::class);
foreach (array_filter([$testApiKey, $liveApiKey]) as $key) {
$api = $mollieModel->loadMollieApi($key);

$api->methods = $this->createMock(MethodEndpoint::class);
$api->methods->method('all')->willReturn([]);

$mollieModelMock->method('loadMollieApi')->with($key)->willReturn($api);
}

$tests = $this->_objectManager->create(Tests::class, [
'mollieModel' => $mollieModelMock,
'tests' => [],
]);

$this->_objectManager->addSharedInstance($tests, Tests::class);

$this->getRequest()->setParams([
'test_key' => '',
'live_key' => '',
]);
}
}
53 changes: 53 additions & 0 deletions Test/Integration/Etc/Config/MethodsConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration\Etc\Config;

use Magento\Config\Model\Config\Structure;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class MethodsConfigurationTest extends IntegrationTestCase
{
public function methods()
{
return [
['mollie_methods_applepay'],
['mollie_methods_bancontact'],
['mollie_methods_banktransfer'],
['mollie_methods_belfius'],
['mollie_methods_creditcard'],
['mollie_methods_directdebit'],
['mollie_methods_eps'],
['mollie_methods_giftcard'],
['mollie_methods_giropay'],
['mollie_methods_ideal'],
['mollie_methods_kbc'],
['mollie_methods_klarnapaylater'],
['mollie_methods_klarnapaynow'],
['mollie_methods_klarnasliceit'],
['mollie_methods_voucher'],
['mollie_methods_mybank'],
['mollie_methods_paypal'],
['mollie_methods_paysafecard'],
['mollie_methods_przelewy24'],
['mollie_methods_sofort'],
];
}

/**
* @dataProvider methods
* @magentoAppArea adminhtml
*/
public function testHasTheCorrectValidationForExpireDays($method)
{
/** @var Structure $config */
$config = $this->objectManager->get(Structure::class);

$value = $config->getElementByConfigPath('payment/' . $method . '/days_before_expire');

$this->assertStringContainsString('digits-range-1-365', $value->getAttribute('frontend_class'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration;

use Magento\TestFramework\TestCase\AbstractBackendController;

class BackendControllerTestCase extends AbstractBackendController
{
protected function setUp()
{
parent::setup();

$this->setUpWithoutVoid();
}

protected function setUpWithoutVoid()
{
}

public function assertStringContainsString($expected, $actual, $message = null)
{
$this->assertContains($expected, $actual, $message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration;

use Magento\TestFramework\TestCase\AbstractBackendController;

class BackendControllerTestCase extends AbstractBackendController
{
protected function setUp(): void
{
parent::setup();

$this->setUpWithoutVoid();
}

protected function setUpWithoutVoid()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ protected function setUp()
protected function setUpWithoutVoid()
{
}

public function assertStringContainsString($expected, $actual, $message = null)
{
$this->assertContains($expected, $actual, $message);
}
}
16 changes: 15 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mollie/magento2",
"description": "Mollie Payment Module for Magento 2",
"version": "2.3.0",
"version": "2.4.0",
"keywords": [
"mollie",
"payment",
Expand Down Expand Up @@ -46,6 +46,20 @@
"require": {
"mollie/mollie-api-php": "^2.1",
"magento/framework": ">=102.0.3",
"magento/module-backend": ">=100.3.3",
"magento/module-catalog": ">=100.3.3",
"magento/module-checkout": ">=100.3.3",
"magento/module-config": ">=100.3.3",
"magento/module-customer": ">=100.3.3",
"magento/module-eav": ">=100.3.3",
"magento/module-payment": ">=100.3.3",
"magento/module-quote": ">=100.3.3",
"magento/module-sales": ">=100.3.3",
"magento/module-sales-rule": ">=100.3.3",
"magento/module-store": ">=100.3.3",
"magento/module-tax": ">=100.3.3",
"magento/module-ui": ">=100.3.3",
"magento/module-vault": ">=100.3.3",
"php": ">=7.1",
"ext-json": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/methods/applepay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<field id="days_before_expire" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Days to expire</label>
<frontend_class>validate-digits-range digits-range-1-100</frontend_class>
<frontend_class>validate-digits-range digits-range-1-365</frontend_class>
<config_path>payment/mollie_methods_applepay/days_before_expire</config_path>
<depends>
<field id="active">1</field>
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/methods/bancontact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<field id="days_before_expire" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Days to expire</label>
<frontend_class>validate-digits-range digits-range-1-100</frontend_class>
<frontend_class>validate-digits-range digits-range-1-365</frontend_class>
<config_path>payment/mollie_methods_bancontact/days_before_expire</config_path>
<depends>
<field id="active">1</field>
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/methods/banktransfer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<field id="days_before_expire" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Days to expire</label>
<frontend_class>validate-digits-range digits-range-1-100</frontend_class>
<frontend_class>validate-digits-range digits-range-1-365</frontend_class>
<config_path>payment/mollie_methods_banktransfer/days_before_expire</config_path>
<depends>
<field id="active">1</field>
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/methods/belfius.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<field id="days_before_expire" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Days to expire</label>
<frontend_class>validate-digits-range digits-range-1-100</frontend_class>
<frontend_class>validate-digits-range digits-range-1-365</frontend_class>
<config_path>payment/mollie_methods_belfius/days_before_expire</config_path>
<depends>
<field id="active">1</field>
Expand Down
Loading

0 comments on commit 1bdeb41

Please sign in to comment.