1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Order\Item; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $values; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->values = array( |
22
|
|
|
'order.id' => 15, |
23
|
|
|
'order.siteid' => 99, |
24
|
|
|
'order.channel' => 'web', |
25
|
|
|
'order.invoiceno' => 'INV-0014', |
26
|
|
|
'order.statusdelivery' => \Aimeos\MShop\Order\Item\Base::STAT_PENDING, |
27
|
|
|
'order.statuspayment' => \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED, |
28
|
|
|
'order.datepayment' => '2004-12-01 12:34:56', |
29
|
|
|
'order.datedelivery' => '2004-01-03 12:34:56', |
30
|
|
|
'order.relatedid' => '123', |
31
|
|
|
'order.baseid' => 4, |
32
|
|
|
'order.mtime' => '2011-01-01 00:00:02', |
33
|
|
|
'order.ctime' => '2011-01-01 00:00:01', |
34
|
|
|
'order.editor' => 'unitTestUser' |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$baseItem = \Aimeos\MShop::create( \TestHelper::context(), 'order/base' )->create(); |
38
|
|
|
$this->object = new \Aimeos\MShop\Order\Item\Standard( $this->values, $baseItem ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
protected function tearDown() : void |
43
|
|
|
{ |
44
|
|
|
unset( $this->object ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testGetBaseItem() |
49
|
|
|
{ |
50
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $this->object->getBaseItem() ); |
51
|
|
|
$this->assertNull( ( new \Aimeos\MShop\Order\Item\Standard( $this->values ) )->getBaseItem() ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testSetBaseItem() |
56
|
|
|
{ |
57
|
|
|
$item = new \Aimeos\MShop\Order\Item\Standard( $this->values ); |
|
|
|
|
58
|
|
|
$baseItem = \Aimeos\MShop::create( \TestHelper::context(), 'order/base' )->create(); |
59
|
|
|
|
60
|
|
|
$result = $this->object->setBaseItem( $baseItem ); |
61
|
|
|
|
62
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $result ); |
63
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $result->getBaseItem() ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testGetId() |
68
|
|
|
{ |
69
|
|
|
$this->assertEquals( $this->values['order.id'], $this->object->getId() ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
public function testSetId() |
74
|
|
|
{ |
75
|
|
|
$return = $this->object->setId( null ); |
76
|
|
|
|
77
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
78
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
79
|
|
|
$this->assertTrue( $this->object->isModified() ); |
80
|
|
|
|
81
|
|
|
$return = $this->object->setId( 15 ); |
82
|
|
|
|
83
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
84
|
|
|
$this->assertEquals( 15, $this->object->getId() ); |
85
|
|
|
$this->assertFalse( $this->object->isModified() ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testGetSiteId() |
90
|
|
|
{ |
91
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
public function testGetOrderNumber() |
96
|
|
|
{ |
97
|
|
|
$this->assertEquals( $this->values['order.id'], $this->object->getOrderNumber() ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testGetOrderNumberCustom() |
102
|
|
|
{ |
103
|
|
|
\Aimeos\MShop\Order\Item\Base::macro( 'ordernumber', function( \Aimeos\MShop\Order\Item\Iface $item ) { |
104
|
|
|
return 'order-' . $item->getId() . 'Z'; |
105
|
|
|
} ); |
106
|
|
|
|
107
|
|
|
$this->assertEquals( 'order-' . $this->values['order.id'] . 'Z', $this->object->getOrderNumber() ); |
108
|
|
|
|
109
|
|
|
\Aimeos\MShop\Order\Item\Base::macro( 'ordernumber', function( \Aimeos\MShop\Order\Item\Iface $item ) { |
110
|
|
|
return $item->getId(); |
111
|
|
|
} ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testGetBaseId() |
116
|
|
|
{ |
117
|
|
|
$this->assertEquals( $this->values['order.baseid'], $this->object->getBaseId() ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testSetBaseId() |
122
|
|
|
{ |
123
|
|
|
$return = $this->object->setBaseId( 15 ); |
124
|
|
|
|
125
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
126
|
|
|
$this->assertEquals( 15, $this->object->getBaseId() ); |
127
|
|
|
$this->assertTrue( $this->object->isModified() ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
public function testGetInvoiceNumber() |
132
|
|
|
{ |
133
|
|
|
$this->assertEquals( $this->values['order.invoiceno'], $this->object->getInvoiceNumber() ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testSetInvoiceNumber() |
138
|
|
|
{ |
139
|
|
|
$return = $this->object->setInvoiceNumber( 'INV-01010' ); |
140
|
|
|
|
141
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
142
|
|
|
$this->assertEquals( 'INV-01010', $this->object->getInvoiceNumber() ); |
143
|
|
|
$this->assertTrue( $this->object->isModified() ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
public function testGetChannel() |
148
|
|
|
{ |
149
|
|
|
$this->assertEquals( $this->values['order.channel'], $this->object->getChannel() ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
public function testSetChannel() |
154
|
|
|
{ |
155
|
|
|
$return = $this->object->setChannel( 'phone' ); |
156
|
|
|
|
157
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
158
|
|
|
$this->assertEquals( 'phone', $this->object->getChannel() ); |
159
|
|
|
$this->assertTrue( $this->object->isModified() ); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
public function testGetDateDelivery() |
164
|
|
|
{ |
165
|
|
|
$this->assertEquals( $this->values['order.datedelivery'], $this->object->getDateDelivery() ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
public function testSetDateDelivery() |
170
|
|
|
{ |
171
|
|
|
$return = $this->object->setDateDelivery( '2008-04-12 12:34:56' ); |
172
|
|
|
|
173
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
174
|
|
|
$this->assertEquals( '2008-04-12 12:34:56', $this->object->getDateDelivery() ); |
175
|
|
|
$this->assertTrue( $this->object->isModified() ); |
176
|
|
|
|
177
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
178
|
|
|
$this->object->setDateDelivery( '2008-34-12' ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testGetDatePayment() |
183
|
|
|
{ |
184
|
|
|
$this->assertEquals( $this->values['order.datepayment'], $this->object->getDatePayment() ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
public function testSetDatePayment() |
189
|
|
|
{ |
190
|
|
|
$return = $this->object->setDatePayment( '2008-04-12 12:34:56' ); |
191
|
|
|
|
192
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
193
|
|
|
$this->assertEquals( '2008-04-12 12:34:56', $this->object->getDatePayment() ); |
194
|
|
|
$this->assertTrue( $this->object->isModified() ); |
195
|
|
|
|
196
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
197
|
|
|
$this->object->setDatePayment( '2008-34-12' ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
public function testGetStatusDelivery() |
202
|
|
|
{ |
203
|
|
|
$this->assertEquals( $this->values['order.statusdelivery'], $this->object->getStatusDelivery() ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testSetStatusDelivery() |
208
|
|
|
{ |
209
|
|
|
$return = $this->object->setStatusDelivery( \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS ); |
210
|
|
|
|
211
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
212
|
|
|
$this->assertEquals( \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS, $this->object->getStatusDelivery() ); |
213
|
|
|
$this->assertTrue( $this->object->isModified() ); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
public function testGetStatusPayment() |
218
|
|
|
{ |
219
|
|
|
$this->assertEquals( $this->values['order.statuspayment'], $this->object->getStatusPayment() ); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
public function testSetStatusPayment() |
224
|
|
|
{ |
225
|
|
|
$return = $this->object->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_DELETED ); |
226
|
|
|
|
227
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
228
|
|
|
$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_DELETED, $this->object->getStatusPayment() ); |
229
|
|
|
$this->assertTrue( $this->object->isModified() ); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
233
|
|
|
public function testGetRelatedId() |
234
|
|
|
{ |
235
|
|
|
$this->assertEquals( $this->values['order.relatedid'], $this->object->getRelatedId() ); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
|
239
|
|
|
public function testSetRelatedId() |
240
|
|
|
{ |
241
|
|
|
$return = $this->object->setRelatedId( 22 ); |
242
|
|
|
|
243
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return ); |
244
|
|
|
$this->assertEquals( '22', $this->object->getRelatedId() ); |
245
|
|
|
$this->assertTrue( $this->object->isModified() ); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
public function testGetTimeModified() |
250
|
|
|
{ |
251
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
|
255
|
|
|
public function testGetTimeCreated() |
256
|
|
|
{ |
257
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
|
261
|
|
|
public function testGetEditor() |
262
|
|
|
{ |
263
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->editor() ); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
|
267
|
|
|
public function testGetResourceType() |
268
|
|
|
{ |
269
|
|
|
$this->assertEquals( 'order', $this->object->getResourceType() ); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
|
273
|
|
|
public function testFromArray() |
274
|
|
|
{ |
275
|
|
|
$item = new \Aimeos\MShop\Order\Item\Standard(); |
276
|
|
|
|
277
|
|
|
$list = $entries = array( |
278
|
|
|
'order.id' => 1, |
279
|
|
|
'order.invoiceno' => 'INV-1', |
280
|
|
|
'order.channel' => 'web', |
281
|
|
|
'order.baseid' => 2, |
282
|
|
|
'order.relatedid' => '3', |
283
|
|
|
'order.statusdelivery' => 4, |
284
|
|
|
'order.statuspayment' => 5, |
285
|
|
|
'order.datepayment' => '2000-01-01 00:00:00', |
286
|
|
|
'order.datedelivery' => '2001-01-01 00:00:00', |
287
|
|
|
); |
288
|
|
|
|
289
|
|
|
$item = $item->fromArray( $entries, true ); |
290
|
|
|
|
291
|
|
|
$this->assertEquals( [], $entries ); |
292
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
293
|
|
|
$this->assertEquals( $list['order.id'], $item->getId() ); |
294
|
|
|
$this->assertEquals( $list['order.invoiceno'], $item->getInvoiceNumber() ); |
295
|
|
|
$this->assertEquals( $list['order.channel'], $item->getChannel() ); |
296
|
|
|
$this->assertEquals( $list['order.baseid'], $item->getBaseId() ); |
297
|
|
|
$this->assertEquals( $list['order.relatedid'], $item->getRelatedId() ); |
298
|
|
|
$this->assertEquals( $list['order.statusdelivery'], $item->getStatusDelivery() ); |
299
|
|
|
$this->assertEquals( $list['order.statuspayment'], $item->getStatusPayment() ); |
300
|
|
|
$this->assertEquals( $list['order.datepayment'], $item->getDatePayment() ); |
301
|
|
|
$this->assertEquals( $list['order.datedelivery'], $item->getDateDelivery() ); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
public function testToArray() |
306
|
|
|
{ |
307
|
|
|
$list = $this->object->toArray( true ); |
308
|
|
|
$this->assertEquals( count( $this->values ), count( $list ) ); |
309
|
|
|
|
310
|
|
|
$this->assertEquals( $this->object->getId(), $list['order.id'] ); |
311
|
|
|
$this->assertEquals( $this->object->getSiteId(), $list['order.siteid'] ); |
312
|
|
|
$this->assertEquals( $this->object->getBaseId(), $list['order.baseid'] ); |
313
|
|
|
$this->assertEquals( $this->object->getChannel(), $list['order.channel'] ); |
314
|
|
|
$this->assertEquals( $this->object->getInvoiceNumber(), $list['order.invoiceno'] ); |
315
|
|
|
$this->assertEquals( $this->object->getStatusDelivery(), $list['order.statusdelivery'] ); |
316
|
|
|
$this->assertEquals( $this->object->getStatusPayment(), $list['order.statuspayment'] ); |
317
|
|
|
$this->assertEquals( $this->object->getDatePayment(), $list['order.datepayment'] ); |
318
|
|
|
$this->assertEquals( $this->object->getDateDelivery(), $list['order.datedelivery'] ); |
319
|
|
|
$this->assertEquals( $this->object->getRelatedId(), $list['order.relatedid'] ); |
320
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['order.mtime'] ); |
321
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $list['order.ctime'] ); |
322
|
|
|
$this->assertEquals( $this->object->editor(), $list['order.editor'] ); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
|
326
|
|
|
public function testIsModified() |
327
|
|
|
{ |
328
|
|
|
$this->assertFalse( $this->object->isModified() ); |
329
|
|
|
} |
330
|
|
|
} |
331
|
|
|
|