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\Base; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $locale; |
16
|
|
|
private $object; |
17
|
|
|
private $values; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() : void |
21
|
|
|
{ |
22
|
|
|
$context = \TestHelper::context(); |
23
|
|
|
|
24
|
|
|
$this->values = array( |
25
|
|
|
'order.base.id' => 1, |
26
|
|
|
'order.base.siteid' => '1.99.', |
27
|
|
|
'order.base.customerid' => 'testuser', |
28
|
|
|
'order.base.customerref' => 'ABC-1234', |
29
|
|
|
'order.base.comment' => 'this is a comment from unittest', |
30
|
|
|
'order.base.mtime' => '2011-01-01 00:00:02', |
31
|
|
|
'order.base.ctime' => '2011-01-01 00:00:01', |
32
|
|
|
'order.base.editor' => 'unitTestUser' |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$price = \Aimeos\MShop::create( $context, 'price' )->create()->setValue( 0 ); |
36
|
|
|
$this->locale = \Aimeos\MShop::create( $context, 'locale' )->create(); |
37
|
|
|
$this->object = new \Aimeos\MShop\Order\Item\Base\Standard( $price, $this->locale, $this->values ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
protected function tearDown() : void |
42
|
|
|
{ |
43
|
|
|
unset( $this->locale, $this->object, $this->values ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function testJsonSerialize() |
48
|
|
|
{ |
49
|
|
|
$result = json_decode( json_encode( $this->object ), true ); |
50
|
|
|
|
51
|
|
|
$this->assertEquals( 1, $result['order.base.id'] ); |
52
|
|
|
$this->assertEquals( '1.99.', $result['order.base.siteid'] ); |
53
|
|
|
$this->assertArrayHasKey( 'price', $result ); |
54
|
|
|
$this->assertArrayHasKey( 'locale', $result ); |
55
|
|
|
$this->assertArrayHasKey( 'customer', $result ); |
56
|
|
|
$this->assertArrayHasKey( 'coupons', $result ); |
57
|
|
|
$this->assertArrayHasKey( 'products', $result ); |
58
|
|
|
$this->assertArrayHasKey( 'services', $result ); |
59
|
|
|
$this->assertArrayHasKey( 'addresses', $result ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function testGetId() |
64
|
|
|
{ |
65
|
|
|
$this->assertEquals( 1, $this->object->getId() ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testSetId() |
70
|
|
|
{ |
71
|
|
|
$return = $this->object->setId( null ); |
72
|
|
|
|
73
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
74
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
75
|
|
|
$this->assertTrue( $this->object->isModified() ); |
76
|
|
|
|
77
|
|
|
$return = $this->object->setId( 5 ); |
78
|
|
|
|
79
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
80
|
|
|
$this->assertEquals( 5, $this->object->getId() ); |
81
|
|
|
$this->assertFalse( $this->object->isModified() ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testGetSiteId() |
86
|
|
|
{ |
87
|
|
|
$this->assertEquals( '1.99.', $this->object->getSiteId() ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testGetCustomerId() |
92
|
|
|
{ |
93
|
|
|
$this->assertEquals( 'testuser', $this->object->getCustomerId() ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
public function testSetCustomerId() |
98
|
|
|
{ |
99
|
|
|
$return = $this->object->setCustomerId( '44' ); |
100
|
|
|
|
101
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
102
|
|
|
$this->assertEquals( '44', $this->object->getCustomerId() ); |
103
|
|
|
$this->assertTrue( $this->object->isModified() ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
public function testGetCustomerReference() |
108
|
|
|
{ |
109
|
|
|
$this->assertEquals( 'ABC-1234', $this->object->getCustomerReference() ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testSetCustomerReference() |
114
|
|
|
{ |
115
|
|
|
$return = $this->object->setCustomerReference( 'XYZ-9876' ); |
116
|
|
|
|
117
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
118
|
|
|
$this->assertEquals( 'XYZ-9876', $this->object->getCustomerReference() ); |
119
|
|
|
$this->assertTrue( $this->object->isModified() ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
public function testGetLocale() |
124
|
|
|
{ |
125
|
|
|
$this->assertEquals( $this->locale, $this->object->locale() ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testSetLocale() |
130
|
|
|
{ |
131
|
|
|
$locale = \Aimeos\MShop::create( \TestHelper::context(), 'locale' )->create(); |
132
|
|
|
$return = $this->object->setLocale( $locale ); |
133
|
|
|
|
134
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
135
|
|
|
$this->assertEquals( $locale, $this->object->locale() ); |
136
|
|
|
$this->assertTrue( $this->object->isModified() ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function testGetPrice() |
141
|
|
|
{ |
142
|
|
|
$priceItem = $this->object->getPrice(); |
143
|
|
|
|
144
|
|
|
$this->assertEquals( $priceItem->getCurrencyId(), 'EUR' ); |
145
|
|
|
$this->assertEquals( $priceItem->getTaxRate(), '0.00' ); |
146
|
|
|
$this->assertEquals( $priceItem->getRebate(), '0.00' ); |
147
|
|
|
$this->assertEquals( $priceItem->getCosts(), '0.00' ); |
148
|
|
|
$this->assertEquals( $priceItem->getValue(), '0.00' ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testGetComment() |
153
|
|
|
{ |
154
|
|
|
$this->assertEquals( 'this is a comment from unittest', $this->object->getComment() ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testSetComment() |
159
|
|
|
{ |
160
|
|
|
$return = $this->object->setComment( 'New unit test comment' ); |
161
|
|
|
|
162
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
163
|
|
|
$this->assertEquals( 'New unit test comment', $this->object->getComment() ); |
164
|
|
|
$this->assertTrue( $this->object->isModified() ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function testGetTimeModified() |
169
|
|
|
{ |
170
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
public function testGetTimeCreated() |
175
|
|
|
{ |
176
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
public function testGetEditor() |
181
|
|
|
{ |
182
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->editor() ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testFromArray() |
187
|
|
|
{ |
188
|
|
|
$item = new \Aimeos\MShop\Order\Item\Base\Standard( new \Aimeos\MShop\Price\Item\Standard(), new \Aimeos\MShop\Locale\Item\Standard() ); |
189
|
|
|
|
190
|
|
|
$list = $entries = array( |
191
|
|
|
'order.base.id' => 1, |
192
|
|
|
'order.base.customerref' => 'testref', |
193
|
|
|
'order.base.comment' => 'test comment', |
194
|
|
|
'order.base.languageid' => 'de', |
195
|
|
|
'order.base.customerid' => 3, |
196
|
|
|
); |
197
|
|
|
|
198
|
|
|
$item = $item->fromArray( $entries, true ); |
199
|
|
|
|
200
|
|
|
$this->assertEquals( [], $entries ); |
201
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
202
|
|
|
$this->assertEquals( $list['order.base.id'], $item->getId() ); |
203
|
|
|
$this->assertEquals( $list['order.base.customerid'], $item->getCustomerId() ); |
204
|
|
|
$this->assertEquals( $list['order.base.languageid'], $item->locale()->getLanguageId() ); |
205
|
|
|
$this->assertEquals( $list['order.base.customerref'], $item->getCustomerReference() ); |
206
|
|
|
$this->assertEquals( $list['order.base.comment'], $item->getComment() ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
public function testToArray() |
211
|
|
|
{ |
212
|
|
|
$list = $this->object->toArray( true ); |
213
|
|
|
$price = $this->object->getPrice(); |
214
|
|
|
|
215
|
|
|
$this->assertEquals( $this->object->getId(), $list['order.base.id'] ); |
216
|
|
|
$this->assertEquals( $this->object->getSiteId(), $list['order.base.siteid'] ); |
217
|
|
|
$this->assertEquals( $this->object->getCustomerId(), $list['order.base.customerid'] ); |
218
|
|
|
$this->assertEquals( $this->object->locale()->getLanguageId(), $list['order.base.languageid'] ); |
219
|
|
|
$this->assertEquals( $this->object->getCustomerReference(), $list['order.base.customerref'] ); |
220
|
|
|
$this->assertEquals( $this->object->getComment(), $list['order.base.comment'] ); |
221
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $list['order.base.ctime'] ); |
222
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['order.base.mtime'] ); |
223
|
|
|
$this->assertEquals( $this->object->editor(), $list['order.base.editor'] ); |
224
|
|
|
|
225
|
|
|
$this->assertEquals( $price->getValue(), $list['order.base.price'] ); |
226
|
|
|
$this->assertEquals( $price->getCosts(), $list['order.base.costs'] ); |
227
|
|
|
$this->assertEquals( $price->getRebate(), $list['order.base.rebate'] ); |
228
|
|
|
$this->assertEquals( $price->getCurrencyId(), $list['order.base.currencyid'] ); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
public function testIsModified() |
233
|
|
|
{ |
234
|
|
|
$this->assertFalse( $this->object->isModified() ); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
public function testSetModified() |
239
|
|
|
{ |
240
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Base\Iface', $this->object->setModified() ); |
241
|
|
|
$this->assertEquals( true, $this->object->isModified() ); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
|
245
|
|
|
public function testFinish() |
246
|
|
|
{ |
247
|
|
|
$return = $this->object->finish(); |
248
|
|
|
|
249
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
|
253
|
|
|
public function testGetResourceType() |
254
|
|
|
{ |
255
|
|
|
$this->assertEquals( 'order/base', $this->object->getResourceType() ); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
public function testSerialize() |
260
|
|
|
{ |
261
|
|
|
$this->assertTrue( is_string( serialize( $this->object ) ) ); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|