-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write unit tests for GiftcardDataBuilder and multishipping Success cl…
…asses (#2465) * Write unit test for multishipping Success block * Remove unused references * Remove unused references * Write unit test for GiftcardDataBuilder class
- Loading branch information
1 parent
17800b6
commit f5ae3ee
Showing
2 changed files
with
134 additions
and
0 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,73 @@ | ||
<?php | ||
/** | ||
* | ||
* Adyen Payment module (https://www.adyen.com/) | ||
* | ||
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/) | ||
* See LICENSE.txt for license details. | ||
* | ||
* Author: Adyen <magento@adyen.com> | ||
*/ | ||
|
||
namespace Adyen\Payment\Test\Unit\Block\Checkout\Multishipping; | ||
|
||
use Adyen\Payment\Block\Checkout\Multishipping\Success; | ||
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
use Magento\Framework\Session\SessionManager; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Magento\Sales\Api\Data\OrderSearchResultInterface; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
|
||
class SuccessTest extends AbstractAdyenTestCase | ||
{ | ||
private $successBlock; | ||
private $contextMock; | ||
private $sessionMock; | ||
private $orderRepositoryMock; | ||
private $searchCriteriaBuilderMock; | ||
private $orderSearchResultMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->sessionMock = $this->createGeneratedMock(SessionManager::class, [ | ||
'getOrderIds' | ||
]); | ||
$this->sessionMock->method('getOrderIds')->willReturn(['1' => 1, '2' => 2]); | ||
|
||
$this->contextMock = $this->createMock(Context::class); | ||
$this->contextMock->method('getSession')->willReturn($this->sessionMock); | ||
|
||
$this->orderSearchResultMock = $this->createMock(OrderSearchResultInterface::class); | ||
$this->orderSearchResultMock->method('getItems')->willReturn([]); | ||
|
||
$this->orderRepositoryMock = $this->createMock(OrderRepositoryInterface::class); | ||
$this->orderRepositoryMock->method('getList')->willReturn($this->orderSearchResultMock); | ||
$this->searchCriteriaBuilderMock = $this->createMock(SearchCriteriaBuilder::class); | ||
$this->searchCriteriaBuilderMock->method('addFilter')->willReturnSelf(); | ||
$this->searchCriteriaBuilderMock->method('create')->willReturn( | ||
$this->createMock(SearchCriteriaInterface::class) | ||
); | ||
|
||
$payments = [ | ||
['result_code' => 'Authorised'], | ||
['result_code' => 'IdentifyShopper', 'action' => 'DUMMY_ACTION_OBJECT'] | ||
]; | ||
|
||
$objectManager = new ObjectManager($this); | ||
$this->successBlock = $objectManager->getObject(Success::class, [ | ||
'paymentResponseEntities' => $payments, | ||
'context' => $this->contextMock, | ||
'orderRepository' => $this->orderRepositoryMock, | ||
'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock | ||
]); | ||
} | ||
|
||
public function testRenderAction() | ||
{ | ||
$result = $this->successBlock->renderAction(); | ||
$this->assertTrue($result); | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
/** | ||
* | ||
* Adyen Payment module (https://www.adyen.com/) | ||
* | ||
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/) | ||
* See LICENSE.txt for license details. | ||
* | ||
* Author: Adyen <magento@adyen.com> | ||
*/ | ||
|
||
namespace Adyen\Payment\Test\Gateway\Request; | ||
|
||
use Adyen\Payment\Gateway\Request\GiftcardDataBuilder; | ||
use Adyen\Payment\Model\ResourceModel\StateData\Collection; | ||
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Payment\Gateway\Data\PaymentDataObject; | ||
use Magento\Sales\Model\Order; | ||
use Magento\Sales\Model\Order\Payment; | ||
|
||
class GiftcardDataBuilderTest extends AbstractAdyenTestCase | ||
{ | ||
private $giftcardDataBuilder; | ||
private $adyenStateDataCollectionMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->adyenStateDataCollectionMock = $this->createMock(Collection::class); | ||
|
||
$objectManager = new ObjectManager($this); | ||
$this->giftcardDataBuilder = $objectManager->getObject(GiftcardDataBuilder::class, [ | ||
'adyenStateData' => $this->adyenStateDataCollectionMock | ||
]); | ||
} | ||
|
||
public function testBuild() | ||
{ | ||
$orderMock = $this->createMock(Order::class); | ||
$orderMock->method('getQuoteId')->willReturn(1); | ||
|
||
$paymentMock = $this->createMock(Payment::class); | ||
$paymentMock->method('getOrder')->willReturn($orderMock); | ||
|
||
$buildSubject = [ | ||
'payment' => $this->createConfiguredMock(PaymentDataObject::class, [ | ||
'getPayment' => $paymentMock | ||
]) | ||
]; | ||
|
||
$stateDataMock = [ | ||
['entity_id' => 1, 'state_data' => '{"paymentMethod":{"type":"giftcard","brand":"genericgiftcard"}}'] | ||
]; | ||
|
||
$this->adyenStateDataCollectionMock->method('getStateDataRowsWithQuoteId')->willReturnSelf(); | ||
$this->adyenStateDataCollectionMock->method('getData')->willReturn($stateDataMock); | ||
|
||
$request = $this->giftcardDataBuilder->build($buildSubject); | ||
$this->assertArrayHasKey('giftcardRequestParameters', $request['body']); | ||
} | ||
} |