Passed
Push — master ( c437df...9bb5b0 )
by Aimeos
06:36
created

StandardTest   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 296
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 121
c 4
b 0
f 0
dl 0
loc 296
rs 10
wmc 30

30 Methods

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