-
Notifications
You must be signed in to change notification settings - Fork 54
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 #348 from mollie/1.21.0
1.21.0
- Loading branch information
Showing
13 changed files
with
204 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mollie\Payment\GraphQL\Resolver\Cart; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
class PaymentMethodMeta implements \Magento\Framework\GraphQl\Query\ResolverInterface | ||
{ | ||
/** | ||
* @var \Magento\Framework\View\Asset\Repository | ||
*/ | ||
private $assetRepository; | ||
|
||
public function __construct( | ||
\Magento\Framework\View\Asset\Repository $assertRepository | ||
) { | ||
$this->assetRepository = $assertRepository; | ||
} | ||
|
||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
$method = $value['code']; | ||
if (strpos($method, 'mollie_method') !== 0) { | ||
return ['image' => null]; | ||
} | ||
|
||
$cleanCode = str_replace('mollie_methods_', '', $method); | ||
|
||
return [ | ||
'image' => $this->assetRepository->getUrl('Mollie_Payment::images/methods/' . $cleanCode . '.svg'), | ||
]; | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
Test/Integration/GraphQL/Resolver/Cart/PaymentMethodMetaTest.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,68 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mollie\Payment\Test\Integration\GraphQL\Resolver\Cart; | ||
|
||
use Magento\Framework\App\ProductMetadataInterface; | ||
use Mollie\Payment\GraphQL\Resolver\Cart\PaymentMethodMeta; | ||
use Mollie\Payment\Test\Integration\IntegrationTestCase; | ||
|
||
class PaymentMethodMetaTest extends IntegrationTestCase | ||
{ | ||
protected function setUpWithoutVoid() | ||
{ | ||
$version = $this->objectManager->get(ProductMetadataInterface::class)->getVersion(); | ||
if (version_compare($version, '2.3', '<=')) { | ||
$this->markTestSkipped('This test only works on Magento 2.3 and higher.'); | ||
} | ||
} | ||
|
||
public function testReturnsAnEmptyResponseForNonMollieMethods() | ||
{ | ||
$instance = $this->objectManager->create(PaymentMethodMeta::class); | ||
|
||
$result = $this->callResolve($instance, ['code' => 'checkmo']); | ||
|
||
$this->assertNull($result['image']); | ||
} | ||
|
||
public function testReturnsTheImageForMollieMethods() | ||
{ | ||
$instance = $this->objectManager->create(PaymentMethodMeta::class); | ||
|
||
$result = $this->callResolve($instance, ['code' => 'mollie_methods_ideal']); | ||
|
||
$this->assertStringContainsString('Mollie_Payment/images/methods/ideal.svg', $result['image']); | ||
} | ||
|
||
public function callResolve(PaymentMethodMeta $instance, $value = null, $args = null) | ||
{ | ||
return $instance->resolve( | ||
$this->objectManager->create(\Magento\Framework\GraphQl\Config\Element\Field::class, [ | ||
'name' => 'testfield', | ||
'type' => 'string', | ||
'required' => false, | ||
'isList' => false, | ||
]), | ||
$this->objectManager->create(\Magento\Framework\GraphQl\Query\Resolver\ContextInterface::class), | ||
$this->objectManager->create(\Magento\Framework\GraphQl\Schema\Type\ResolveInfo::class, [ | ||
'values' => [], | ||
'fieldName' => 'testfield', | ||
'fieldNodes' => [], | ||
'returnType' => 'string', | ||
'parentType' => new \GraphQL\Type\Definition\ObjectType(['name' => 'testfield']), | ||
'path' => [], | ||
'schema' => $this->objectManager->create(\GraphQL\Type\Schema::class, ['config' => []]), | ||
'fragments' => [], | ||
'rootValue' => '', | ||
'operation' => null, | ||
'variableValues' => [], | ||
]), | ||
$value, | ||
$args | ||
); | ||
} | ||
} |
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
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