/
StandardTest.php
229 lines (164 loc) · 6.3 KB
/
StandardTest.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Metaways Infosystems GmbH, 2011
* @copyright Aimeos (aimeos.org), 2015-2018
*/
namespace Aimeos\MShop\Order\Item\Base;
class StandardTest extends \PHPUnit\Framework\TestCase
{
private $locale;
private $object;
private $values;
protected function setUp()
{
$context = \TestHelperMShop::getContext();
$this->values = array(
'order.base.id' => 1,
'order.base.siteid' => 99,
'order.base.customerid' => 'testuser',
'order.base.comment' => 'this is a comment from unittest',
'order.base.mtime' => '2011-01-01 00:00:02',
'order.base.ctime' => '2011-01-01 00:00:01',
'order.base.editor' => 'unitTestUser'
);
$price = \Aimeos\MShop\Price\Manager\Factory::create( $context )->createItem();
$this->locale = \Aimeos\MShop\Locale\Manager\Factory::create( $context )->createItem();
$this->object = new \Aimeos\MShop\Order\Item\Base\Standard( $price, $this->locale, $this->values );
}
protected function tearDown()
{
unset( $this->locale, $this->object, $this->values );
}
public function testGetId()
{
$this->assertEquals( 1, $this->object->getId() );
}
public function testSetId()
{
$return = $this->object->setId( null );
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return );
$this->assertEquals( null, $this->object->getId() );
$this->assertTrue( $this->object->isModified() );
$return = $this->object->setId( 5 );
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return );
$this->assertEquals( 5, $this->object->getId() );
$this->assertFalse( $this->object->isModified() );
$this->setExpectedException( \Aimeos\MShop\Exception::class );
$this->object->setId( 6 );
}
public function testSetId2()
{
$this->setExpectedException( \Aimeos\MShop\Exception::class );
$this->object->setId( 'test' );
}
public function testGetSiteId()
{
$this->assertEquals( 99, $this->object->getSiteId() );
}
public function testGetCustomerId()
{
$this->assertEquals( 'testuser', $this->object->getCustomerId() );
}
public function testSetCustomerId()
{
$return = $this->object->setCustomerId( '44' );
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return );
$this->assertEquals( '44', $this->object->getCustomerId() );
$this->assertTrue( $this->object->isModified() );
}
public function testGetLocale()
{
$this->assertEquals( $this->locale, $this->object->getLocale() );
}
public function testSetLocale()
{
$locale = \Aimeos\MShop\Locale\Manager\Factory::create( \TestHelperMShop::getContext() )->createItem();
$return = $this->object->setLocale( $locale );
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return );
$this->assertEquals( $locale, $this->object->getLocale() );
$this->assertTrue( $this->object->isModified() );
}
public function testGetPrice()
{
$priceItem = $this->object->getPrice();
$this->assertEquals( $priceItem->getCurrencyId(), 'EUR' );
$this->assertEquals( $priceItem->getTaxRate(), '0.00' );
$this->assertEquals( $priceItem->getRebate(), '0.00' );
$this->assertEquals( $priceItem->getCosts(), '0.00' );
$this->assertEquals( $priceItem->getValue(), '0.00' );
}
public function testGetComment()
{
$this->assertEquals( 'this is a comment from unittest', $this->object->getComment() );
}
public function testSetComment()
{
$return = $this->object->setComment( 'New unit test comment' );
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return );
$this->assertEquals( 'New unit test comment', $this->object->getComment() );
$this->assertTrue( $this->object->isModified() );
}
public function testGetTimeModified()
{
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() );
}
public function testGetTimeCreated()
{
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
}
public function testGetEditor()
{
$this->assertEquals( 'unitTestUser', $this->object->getEditor() );
}
public function testFromArray()
{
$item = new \Aimeos\MShop\Order\Item\Base\Standard( new \Aimeos\MShop\Price\Item\Standard(), new \Aimeos\MShop\Locale\Item\Standard() );
$list = $entries = array(
'order.base.id' => 1,
'order.base.comment' => 'test comment',
'order.base.languageid' => 'de',
'order.base.customerid' => 3,
);
$item = $item->fromArray( $entries, true );
$this->assertEquals( [], $entries );
$this->assertEquals( $list['order.base.id'], $item->getId() );
$this->assertEquals( $list['order.base.customerid'], $item->getCustomerId() );
$this->assertEquals( $list['order.base.languageid'], $item->getLocale()->getLanguageId() );
$this->assertEquals( $list['order.base.comment'], $item->getComment() );
}
public function testToArray()
{
$list = $this->object->toArray( true );
$price = $this->object->getPrice();
$this->assertEquals( $this->object->getId(), $list['order.base.id'] );
$this->assertEquals( $this->object->getSiteId(), $list['order.base.siteid'] );
$this->assertEquals( $this->object->getCustomerId(), $list['order.base.customerid'] );
$this->assertEquals( $this->object->getLocale()->getLanguageId(), $list['order.base.languageid'] );
$this->assertEquals( $this->object->getComment(), $list['order.base.comment'] );
$this->assertEquals( $this->object->getTimeCreated(), $list['order.base.ctime'] );
$this->assertEquals( $this->object->getTimeModified(), $list['order.base.mtime'] );
$this->assertEquals( $this->object->getEditor(), $list['order.base.editor'] );
$this->assertEquals( $price->getValue(), $list['order.base.price'] );
$this->assertEquals( $price->getCosts(), $list['order.base.costs'] );
$this->assertEquals( $price->getRebate(), $list['order.base.rebate'] );
$this->assertEquals( $price->getCurrencyId(), $list['order.base.currencyid'] );
}
public function testIsModified()
{
$this->assertFalse( $this->object->isModified() );
}
public function testFinish()
{
$return = $this->object->finish();
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $return );
}
public function testGetResourceType()
{
$this->assertEquals( 'order/base', $this->object->getResourceType() );
}
public function testSerialize()
{
$this->assertTrue( is_string( serialize( $this->object ) ) );
}
}