1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
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() |
21
|
|
|
{ |
22
|
|
|
$context = \TestHelperMShop::getContext(); |
23
|
|
|
|
24
|
|
|
$this->values = array( |
25
|
|
|
'order.base.id' => 1, |
26
|
|
|
'order.base.siteid' => 99, |
27
|
|
|
'order.base.customerid' => 'testuser', |
28
|
|
|
'order.base.comment' => 'this is a comment from unittest', |
29
|
|
|
'order.base.mtime' => '2011-01-01 00:00:02', |
30
|
|
|
'order.base.ctime' => '2011-01-01 00:00:01', |
31
|
|
|
'order.base.editor' => 'unitTestUser' |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
$price = \Aimeos\MShop\Price\Manager\Factory::create( $context )->createItem(); |
35
|
|
|
$this->locale = \Aimeos\MShop\Locale\Manager\Factory::create( $context )->createItem(); |
36
|
|
|
$this->object = new \Aimeos\MShop\Order\Item\Base\Standard( $price, $this->locale, $this->values ); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
protected function tearDown() |
41
|
|
|
{ |
42
|
|
|
unset( $this->locale, $this->object, $this->values ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testGetId() |
47
|
|
|
{ |
48
|
|
|
$this->assertEquals( 1, $this->object->getId() ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function testSetId() |
53
|
|
|
{ |
54
|
|
|
$return = $this->object->setId( null ); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
57
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
58
|
|
|
$this->assertTrue( $this->object->isModified() ); |
59
|
|
|
|
60
|
|
|
$return = $this->object->setId( 5 ); |
61
|
|
|
|
62
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
63
|
|
|
$this->assertEquals( 5, $this->object->getId() ); |
64
|
|
|
$this->assertFalse( $this->object->isModified() ); |
65
|
|
|
|
66
|
|
|
$this->setExpectedException( \Aimeos\MShop\Exception::class ); |
67
|
|
|
$this->object->setId( 6 ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testSetId2() |
72
|
|
|
{ |
73
|
|
|
$this->setExpectedException( \Aimeos\MShop\Exception::class ); |
74
|
|
|
$this->object->setId( 'test' ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testGetSiteId() |
79
|
|
|
{ |
80
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
public function testGetCustomerId() |
85
|
|
|
{ |
86
|
|
|
$this->assertEquals( 'testuser', $this->object->getCustomerId() ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testSetCustomerId() |
91
|
|
|
{ |
92
|
|
|
$return = $this->object->setCustomerId( '44' ); |
93
|
|
|
|
94
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
95
|
|
|
$this->assertEquals( '44', $this->object->getCustomerId() ); |
96
|
|
|
$this->assertTrue( $this->object->isModified() ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
public function testGetLocale() |
101
|
|
|
{ |
102
|
|
|
$this->assertEquals( $this->locale, $this->object->getLocale() ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testSetLocale() |
107
|
|
|
{ |
108
|
|
|
$locale = \Aimeos\MShop\Locale\Manager\Factory::create( \TestHelperMShop::getContext() )->createItem(); |
109
|
|
|
$return = $this->object->setLocale( $locale ); |
110
|
|
|
|
111
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
112
|
|
|
$this->assertEquals( $locale, $this->object->getLocale() ); |
113
|
|
|
$this->assertTrue( $this->object->isModified() ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
public function testGetPrice() |
118
|
|
|
{ |
119
|
|
|
$priceItem = $this->object->getPrice(); |
120
|
|
|
|
121
|
|
|
$this->assertEquals( $priceItem->getCurrencyId(), 'EUR' ); |
122
|
|
|
$this->assertEquals( $priceItem->getTaxRate(), '0.00' ); |
123
|
|
|
$this->assertEquals( $priceItem->getRebate(), '0.00' ); |
124
|
|
|
$this->assertEquals( $priceItem->getCosts(), '0.00' ); |
125
|
|
|
$this->assertEquals( $priceItem->getValue(), '0.00' ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testGetComment() |
130
|
|
|
{ |
131
|
|
|
$this->assertEquals( 'this is a comment from unittest', $this->object->getComment() ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
public function testSetComment() |
136
|
|
|
{ |
137
|
|
|
$return = $this->object->setComment( 'New unit test comment' ); |
138
|
|
|
|
139
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
140
|
|
|
$this->assertEquals( 'New unit test comment', $this->object->getComment() ); |
141
|
|
|
$this->assertTrue( $this->object->isModified() ); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
public function testGetTimeModified() |
146
|
|
|
{ |
147
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
public function testGetTimeCreated() |
152
|
|
|
{ |
153
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
public function testGetEditor() |
158
|
|
|
{ |
159
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
public function testFromArray() |
164
|
|
|
{ |
165
|
|
|
$item = new \Aimeos\MShop\Order\Item\Base\Standard( new \Aimeos\MShop\Price\Item\Standard(), new \Aimeos\MShop\Locale\Item\Standard() ); |
166
|
|
|
|
167
|
|
|
$list = $entries = array( |
168
|
|
|
'order.base.id' => 1, |
169
|
|
|
'order.base.comment' => 'test comment', |
170
|
|
|
'order.base.languageid' => 'de', |
171
|
|
|
'order.base.customerid' => 3, |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
$item = $item->fromArray( $entries, true ); |
175
|
|
|
|
176
|
|
|
$this->assertEquals( [], $entries ); |
177
|
|
|
$this->assertEquals( $list['order.base.id'], $item->getId() ); |
178
|
|
|
$this->assertEquals( $list['order.base.customerid'], $item->getCustomerId() ); |
179
|
|
|
$this->assertEquals( $list['order.base.languageid'], $item->getLocale()->getLanguageId() ); |
180
|
|
|
$this->assertEquals( $list['order.base.comment'], $item->getComment() ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
public function testToArray() |
185
|
|
|
{ |
186
|
|
|
$list = $this->object->toArray( true ); |
187
|
|
|
$price = $this->object->getPrice(); |
188
|
|
|
|
189
|
|
|
$this->assertEquals( $this->object->getId(), $list['order.base.id'] ); |
190
|
|
|
$this->assertEquals( $this->object->getSiteId(), $list['order.base.siteid'] ); |
191
|
|
|
$this->assertEquals( $this->object->getCustomerId(), $list['order.base.customerid'] ); |
192
|
|
|
$this->assertEquals( $this->object->getLocale()->getLanguageId(), $list['order.base.languageid'] ); |
193
|
|
|
$this->assertEquals( $this->object->getComment(), $list['order.base.comment'] ); |
194
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $list['order.base.ctime'] ); |
195
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['order.base.mtime'] ); |
196
|
|
|
$this->assertEquals( $this->object->getEditor(), $list['order.base.editor'] ); |
197
|
|
|
|
198
|
|
|
$this->assertEquals( $price->getValue(), $list['order.base.price'] ); |
199
|
|
|
$this->assertEquals( $price->getCosts(), $list['order.base.costs'] ); |
200
|
|
|
$this->assertEquals( $price->getRebate(), $list['order.base.rebate'] ); |
201
|
|
|
$this->assertEquals( $price->getCurrencyId(), $list['order.base.currencyid'] ); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
public function testIsModified() |
206
|
|
|
{ |
207
|
|
|
$this->assertFalse( $this->object->isModified() ); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
public function testFinish() |
212
|
|
|
{ |
213
|
|
|
$return = $this->object->finish(); |
214
|
|
|
|
215
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return ); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
public function testGetResourceType() |
220
|
|
|
{ |
221
|
|
|
$this->assertEquals( 'order/base', $this->object->getResourceType() ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
public function testSerialize() |
226
|
|
|
{ |
227
|
|
|
$this->assertTrue( is_string( serialize( $this->object ) ) ); |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|