Passed
Push — master ( a045db...b8904b )
by Aimeos
04:49
created

StandardTest::testSetChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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-2021
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 testSetStatusDeliveryNull()
201
	{
202
		$return = $this->object->setStatusDelivery( null );
203
204
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return );
205
		$this->assertNull( $this->object->getStatusDelivery() );
206
		$this->assertTrue( $this->object->isModified() );
207
	}
208
209
210
	public function testGetStatusPayment()
211
	{
212
		$this->assertEquals( $this->values['order.statuspayment'], $this->object->getStatusPayment() );
213
	}
214
215
216
	public function testSetStatusPayment()
217
	{
218
		$return = $this->object->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_DELETED );
219
220
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return );
221
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_DELETED, $this->object->getStatusPayment() );
222
		$this->assertTrue( $this->object->isModified() );
223
	}
224
225
226
	public function testSetStatusPaymentNull()
227
	{
228
		$return = $this->object->setStatusPayment( null );
229
230
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return );
231
		$this->assertNull( $this->object->getStatusPayment() );
232
		$this->assertTrue( $this->object->isModified() );
233
	}
234
235
236
	public function testGetRelatedId()
237
	{
238
		$this->assertEquals( $this->values['order.relatedid'], $this->object->getRelatedId() );
239
	}
240
241
242
	public function testSetRelatedId()
243
	{
244
		$return = $this->object->setRelatedId( 22 );
245
246
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $return );
247
		$this->assertEquals( '22', $this->object->getRelatedId() );
248
		$this->assertTrue( $this->object->isModified() );
249
	}
250
251
252
	public function testGetTimeModified()
253
	{
254
		$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() );
255
	}
256
257
258
	public function testGetTimeCreated()
259
	{
260
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
261
	}
262
263
264
	public function testGetEditor()
265
	{
266
		$this->assertEquals( 'unitTestUser', $this->object->editor() );
267
	}
268
269
270
	public function testGetResourceType()
271
	{
272
		$this->assertEquals( 'order', $this->object->getResourceType() );
273
	}
274
275
276
	public function testFromArray()
277
	{
278
		$item = new \Aimeos\MShop\Order\Item\Standard();
279
280
		$list = $entries = array(
281
			'order.id' => 1,
282
			'order.channel' => 'web',
283
			'order.baseid' => 2,
284
			'order.relatedid' => '3',
285
			'order.statusdelivery' => 4,
286
			'order.statuspayment' => 5,
287
			'order.datepayment' => '2000-01-01 00:00:00',
288
			'order.datedelivery' => '2001-01-01 00:00:00',
289
		);
290
291
		$item = $item->fromArray( $entries, true );
292
293
		$this->assertEquals( [], $entries );
294
		$this->assertEquals( '', $item->getSiteId() );
295
		$this->assertEquals( $list['order.id'], $item->getId() );
296
		$this->assertEquals( $list['order.channel'], $item->getChannel() );
297
		$this->assertEquals( $list['order.baseid'], $item->getBaseId() );
298
		$this->assertEquals( $list['order.relatedid'], $item->getRelatedId() );
299
		$this->assertEquals( $list['order.statusdelivery'], $item->getStatusDelivery() );
300
		$this->assertEquals( $list['order.statuspayment'], $item->getStatusPayment() );
301
		$this->assertEquals( $list['order.datepayment'], $item->getDatePayment() );
302
		$this->assertEquals( $list['order.datedelivery'], $item->getDateDelivery() );
303
	}
304
305
306
	public function testToArray()
307
	{
308
		$list = $this->object->toArray( true );
309
		$this->assertEquals( count( $this->values ), count( $list ) );
310
311
		$this->assertEquals( $this->object->getId(), $list['order.id'] );
312
		$this->assertEquals( $this->object->getSiteId(), $list['order.siteid'] );
313
		$this->assertEquals( $this->object->getChannel(), $list['order.channel'] );
314
		$this->assertEquals( $this->object->getStatusDelivery(), $list['order.statusdelivery'] );
315
		$this->assertEquals( $this->object->getStatusPayment(), $list['order.statuspayment'] );
316
		$this->assertEquals( $this->object->getDatePayment(), $list['order.datepayment'] );
317
		$this->assertEquals( $this->object->getDateDelivery(), $list['order.datedelivery'] );
318
		$this->assertEquals( $this->object->getBaseId(), $list['order.baseid'] );
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