Skip to content

Commit

Permalink
Write unit tests for GiftcardDataBuilder and multishipping Success cl…
Browse files Browse the repository at this point in the history
…asses (#2465)

* Write unit test for multishipping Success block

* Remove unused references

* Remove unused references

* Write unit test for GiftcardDataBuilder class
  • Loading branch information
candemiralp authored Jan 26, 2024
1 parent 17800b6 commit f5ae3ee
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Test/Unit/Block/Checkout/Multishipping/SuccessTest.php
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);
}
}
61 changes: 61 additions & 0 deletions Test/Unit/Gateway/Request/GiftcardDataBuilderTest.php
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']);
}
}

0 comments on commit f5ae3ee

Please sign in to comment.