1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2022 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Order\Item\Base\Service\Transaction; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $values; |
16
|
|
|
private $price; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->values = array( |
22
|
|
|
'order.base.service.transaction.id' => 3, |
23
|
|
|
'order.base.service.transaction.siteid' => 99, |
24
|
|
|
'order.base.service.transaction.parentid' => 42, |
25
|
|
|
'order.base.service.transaction.type' => 'payment', |
26
|
|
|
'order.base.service.transaction.currencyid' => 'EUR', |
27
|
|
|
'order.base.service.transaction.price' => '9.00', |
28
|
|
|
'order.base.service.transaction.costs' => '1.00', |
29
|
|
|
'order.base.service.transaction.rebate' => '3.00', |
30
|
|
|
'order.base.service.transaction.taxvalue' => '2.000', |
31
|
|
|
'order.base.service.transaction.taxflag' => true, |
32
|
|
|
'order.base.service.transaction.config' => ['tx' => 123], |
33
|
|
|
'order.base.service.transaction.status' => -1, |
34
|
|
|
'order.base.service.transaction.mtime' => '2020-12-31 23:59:59', |
35
|
|
|
'order.base.service.transaction.ctime' => '2011-01-01 00:00:01', |
36
|
|
|
'order.base.service.transaction.editor' => 'unitTestUser' |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$this->price = \Aimeos\MShop::create( \TestHelper::context(), 'price' )->create()->setValue( '100' ); |
40
|
|
|
$this->object = new \Aimeos\MShop\Order\Item\Base\Service\Transaction\Standard( $this->price, $this->values ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
protected function tearDown() : void |
45
|
|
|
{ |
46
|
|
|
unset( $this->object ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function testGetId() |
51
|
|
|
{ |
52
|
|
|
$this->assertEquals( 3, $this->object->getId() ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function testSetId() |
57
|
|
|
{ |
58
|
|
|
$return = $this->object->setId( null ); |
59
|
|
|
|
60
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Transaction\Iface::class, $return ); |
61
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
62
|
|
|
$this->assertTrue( $this->object->isModified() ); |
63
|
|
|
|
64
|
|
|
$return = $this->object->setId( 99 ); |
65
|
|
|
|
66
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Transaction\Iface::class, $return ); |
67
|
|
|
$this->assertEquals( 99, $this->object->getId() ); |
68
|
|
|
$this->assertFalse( $this->object->isModified() ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testGetSiteId() |
73
|
|
|
{ |
74
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testSetSiteId() |
79
|
|
|
{ |
80
|
|
|
$this->object->setSiteId( 100 ); |
81
|
|
|
$this->assertEquals( 100, $this->object->getSiteId() ); |
82
|
|
|
$this->assertTrue( $this->object->isModified() ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testGetParentId() |
87
|
|
|
{ |
88
|
|
|
$this->assertEquals( 42, $this->object->getParentId() ); |
89
|
|
|
$this->assertFalse( $this->object->isModified() ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testSetParentId() |
94
|
|
|
{ |
95
|
|
|
$return = $this->object->setParentId( 98 ); |
96
|
|
|
|
97
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Transaction\Iface::class, $return ); |
98
|
|
|
$this->assertEquals( 98, $this->object->getParentId() ); |
99
|
|
|
$this->assertTrue( $this->object->isModified() ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testGetType() |
104
|
|
|
{ |
105
|
|
|
$this->assertEquals( 'payment', $this->object->getType() ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
public function testSetType() |
110
|
|
|
{ |
111
|
|
|
$return = $this->object->setType( 'refund' ); |
112
|
|
|
|
113
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Transaction\Iface::class, $return ); |
114
|
|
|
$this->assertEquals( 'refund', $this->object->getType() ); |
115
|
|
|
$this->assertTrue( $this->object->isModified() ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testGetPrice() |
120
|
|
|
{ |
121
|
|
|
$this->assertEquals( $this->price, $this->object->getPrice() ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
public function testSetPrice() |
126
|
|
|
{ |
127
|
|
|
$price = \Aimeos\MShop::create( \TestHelper::context(), 'price' )->create()->setValue( '1.00' ); |
128
|
|
|
$return = $this->object->setPrice( $price ); |
129
|
|
|
|
130
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Transaction\Iface::class, $return ); |
131
|
|
|
$this->assertEquals( $price, $this->object->getPrice() ); |
132
|
|
|
$this->assertTrue( $this->object->isModified() ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
public function testGetConfig() |
137
|
|
|
{ |
138
|
|
|
$this->assertEquals( ['tx' => 123], $this->object->getConfig() ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testSetConfig() |
143
|
|
|
{ |
144
|
|
|
$return = $this->object->setConfig( ['ref' => 321] ); |
145
|
|
|
|
146
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Transaction\Iface::class, $return ); |
147
|
|
|
$this->assertEquals( ['ref' => 321], $this->object->getConfig() ); |
148
|
|
|
$this->assertTrue( $this->object->isModified() ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testGetTimeModified() |
153
|
|
|
{ |
154
|
|
|
$this->assertEquals( '2020-12-31 23:59:59', $this->object->getTimeModified() ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testGetTimeCreated() |
159
|
|
|
{ |
160
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testGetEditor() |
165
|
|
|
{ |
166
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->editor() ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function testGetResourceType() |
171
|
|
|
{ |
172
|
|
|
$this->assertEquals( 'order/base/service/transaction', $this->object->getResourceType() ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
public function testFromArray() |
177
|
|
|
{ |
178
|
|
|
$item = new \Aimeos\MShop\Order\Item\Base\Service\Transaction\Standard( $this->price ); |
179
|
|
|
|
180
|
|
|
$list = $entries = [ |
181
|
|
|
'order.base.service.transaction.id' => 1, |
182
|
|
|
'order.base.service.transaction.parentid' => 3, |
183
|
|
|
'order.base.service.transaction.type' => 'payment', |
184
|
|
|
'order.base.service.transaction.currencyid' => 'USD', |
185
|
|
|
'order.base.service.transaction.price' => '9.00', |
186
|
|
|
'order.base.service.transaction.costs' => '1.00', |
187
|
|
|
'order.base.service.transaction.rebate' => '3.00', |
188
|
|
|
'order.base.service.transaction.taxvalue' => '2.0000', |
189
|
|
|
'order.base.service.transaction.taxflag' => true, |
190
|
|
|
'order.base.service.transaction.config' => ['tx' => 123], |
191
|
|
|
'order.base.service.transaction.status' => -1, |
192
|
|
|
]; |
193
|
|
|
|
194
|
|
|
$item = $item->fromArray( $entries, true ); |
195
|
|
|
|
196
|
|
|
$this->assertEquals( [], $entries ); |
197
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
198
|
|
|
$this->assertEquals( $list['order.base.service.transaction.id'], $item->getId() ); |
199
|
|
|
$this->assertEquals( $list['order.base.service.transaction.parentid'], $item->getParentId() ); |
200
|
|
|
$this->assertEquals( $list['order.base.service.transaction.type'], $item->getType() ); |
201
|
|
|
$this->assertEquals( $list['order.base.service.transaction.currencyid'], $item->getPrice()->getCurrencyId() ); |
202
|
|
|
$this->assertEquals( $list['order.base.service.transaction.price'], $item->getPrice()->getValue() ); |
203
|
|
|
$this->assertEquals( $list['order.base.service.transaction.costs'], $item->getPrice()->getCosts() ); |
204
|
|
|
$this->assertEquals( $list['order.base.service.transaction.rebate'], $item->getPrice()->getRebate() ); |
205
|
|
|
$this->assertEquals( $list['order.base.service.transaction.taxvalue'], $item->getPrice()->getTaxvalue() ); |
206
|
|
|
$this->assertEquals( $list['order.base.service.transaction.taxflag'], $item->getPrice()->getTaxflag() ); |
207
|
|
|
$this->assertEquals( $list['order.base.service.transaction.config'], $item->getConfig() ); |
208
|
|
|
$this->assertEquals( $list['order.base.service.transaction.status'], $item->getStatus() ); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
|
212
|
|
|
public function testToArray() |
213
|
|
|
{ |
214
|
|
|
$list = $this->object->toArray( true ); |
215
|
|
|
|
216
|
|
|
$this->assertEquals( count( $this->values ), count( $list ) ); |
217
|
|
|
|
218
|
|
|
$this->assertEquals( $this->object->getId(), $list['order.base.service.transaction.id'] ); |
219
|
|
|
$this->assertEquals( $this->object->getSiteId(), $list['order.base.service.transaction.siteid'] ); |
220
|
|
|
$this->assertEquals( $this->object->getParentId(), $list['order.base.service.transaction.parentid'] ); |
221
|
|
|
$this->assertEquals( $this->object->getType(), $list['order.base.service.transaction.type'] ); |
222
|
|
|
$this->assertEquals( $this->object->getPrice()->getCurrencyId(), $list['order.base.service.transaction.currencyid'] ); |
223
|
|
|
$this->assertEquals( $this->object->getPrice()->getValue(), $list['order.base.service.transaction.price'] ); |
224
|
|
|
$this->assertEquals( $this->object->getPrice()->getCosts(), $list['order.base.service.transaction.costs'] ); |
225
|
|
|
$this->assertEquals( $this->object->getPrice()->getRebate(), $list['order.base.service.transaction.rebate'] ); |
226
|
|
|
$this->assertEquals( $this->object->getPrice()->getTaxvalue(), $list['order.base.service.transaction.taxvalue'] ); |
227
|
|
|
$this->assertEquals( $this->object->getPrice()->getTaxflag(), $list['order.base.service.transaction.taxflag'] ); |
228
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['order.base.service.transaction.mtime'] ); |
229
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $list['order.base.service.transaction.ctime'] ); |
230
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['order.base.service.transaction.mtime'] ); |
231
|
|
|
$this->assertEquals( $this->object->editor(), $list['order.base.service.transaction.editor'] ); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function testIsModified() |
235
|
|
|
{ |
236
|
|
|
$this->assertFalse( $this->object->isModified() ); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|