-
Notifications
You must be signed in to change notification settings - Fork 53
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 #473 from mollie/release/2.4.0
Release/2.4.0
- Loading branch information
Showing
33 changed files
with
324 additions
and
32 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,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
154
Test/Integration/Controller/Adminhtml/Action/ApikeyTest.php
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,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' => '', | ||
]); | ||
} | ||
} |
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,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')); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Test/Integration/PHPUnit/BackendControllerTestCaseVersion8AndLower.php
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,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); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Test/Integration/PHPUnit/BackendControllerTestCaseVersion9AndHigher.php
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,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() | ||
{ | ||
} | ||
} |
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
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
Oops, something went wrong.