-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathStateDataTest.php
137 lines (114 loc) · 4.59 KB
/
StateDataTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2023 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Test\Unit\Helper;
use Adyen\Payment\Helper\StateData;
use Adyen\Payment\Model\ResourceModel\StateData as StateDataResourceModel;
use Adyen\Payment\Model\ResourceModel\StateData\Collection as StateDataCollection;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Adyen\Payment\Model\StateDataFactory;
class StateDataTest extends AbstractAdyenTestCase
{
private $stateDataHelper;
private $stateDataCollectionMock;
private $stateDataFactoryMock;
private $stateDataResourceModelMock;
protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);
$this->stateDataCollectionMock = $this->createMock(StateDataCollection::class);
$this->stateDataResourceModelMock = $this->createMock(StateDataResourceModel::class);
$stateDataMock = $this->createMock(\Adyen\Payment\Model\StateData::class);
$this->stateDataFactoryMock = $this->createGeneratedMock(StateDataFactory::class, ['create']);
$this->stateDataFactoryMock->method('create')->willReturn($stateDataMock);
$this->stateDataHelper = $this->objectManager->getObject(StateData::class, [
'stateDataCollection' => $this->stateDataCollectionMock,
'stateDataResourceModel' => $this->stateDataResourceModelMock,
'stateDataFactory' => $this->stateDataFactoryMock
]);
}
public function testSaveStateDataSuccessful()
{
$stateData = '{"stateData":"dummyData"}';
$quoteId = 1;
$stateDataMock = $this->createConfiguredMock(\Adyen\Payment\Model\StateData::class, [
'getData' => ['entity_id' => 1, 'quote_id' => 1]
]);
$this->stateDataCollectionMock->method('addFieldToFilter')->willReturnSelf();
$this->stateDataCollectionMock->method('getFirstItem')->willReturn($stateDataMock);
$this->stateDataResourceModelMock->expects($this->once())->method('save');
$this->stateDataHelper->saveStateData($stateData, $quoteId);
}
public function testRemoveStateDataSuccessful()
{
$stateDataId = 1;
$quoteId = 1;
$stateDataMock = $this->createConfiguredMock(\Adyen\Payment\Model\StateData::class, [
'getData' => ['entity_id' => 1, 'quote_id' => 1]
]);
$this->stateDataCollectionMock->method('addFieldToFilter')->willReturnSelf();
$this->stateDataCollectionMock->method('getFirstItem')->willReturn($stateDataMock);
$this->assertTrue($this->stateDataHelper->removeStateData($stateDataId, $quoteId));
}
public function testRemoveStateDataException()
{
$this->expectException(NoSuchEntityException::class);
$stateDataId = 1;
$quoteId = 1;
$stateDataMock = $this->createConfiguredMock(\Adyen\Payment\Model\StateData::class, [
'getData' => null
]);
$this->stateDataCollectionMock->method('addFieldToFilter')->willReturnSelf();
$this->stateDataCollectionMock->method('getFirstItem')->willReturn($stateDataMock);
$this->stateDataHelper->removeStateData($stateDataId, $quoteId);
}
/**
* @dataProvider storedPaymentMethodIdProvider
*/
public function testGetStoredPaymentMethodId($stateData, $expectedResult)
{
$this->assertEquals(
$expectedResult,
$this->stateDataHelper->getStoredPaymentMethodIdFromStateData($stateData)
);
}
public static function storedPaymentMethodIdProvider(): array
{
$mockStoredPaymentMethodId = hash('md5', time());
return [
[
'stateData' => [
'paymentMethod' => [
'storedPaymentMethodId' => $mockStoredPaymentMethodId
]
],
'expectedResult' => $mockStoredPaymentMethodId
],
[
'stateData' => [
'paymentMethod' => [
'storedPaymentMethodId' => null
]
],
'expectedResult' => null
],
[
'stateData' => [
'paymentMethod' => [
'type' => 'scheme'
]
],
'expectedResult' => null
]
];
}
}