1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018-2020 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Subscription\Item; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $values; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
$this->values = array( |
21
|
|
|
'subscription.id' => 15, |
22
|
|
|
'subscription.siteid' => 99, |
23
|
|
|
'subscription.ordbaseid' => 12, |
24
|
|
|
'subscription.ordprodid' => 123, |
25
|
|
|
'subscription.productid' => '456', |
26
|
|
|
'subscription.datenext' => '2000-01-01', |
27
|
|
|
'subscription.dateend' => '2100-01-01', |
28
|
|
|
'subscription.interval' => 'P1Y0M0W0D', |
29
|
|
|
'subscription.reason' => 0, |
30
|
|
|
'subscription.period' => 2, |
31
|
|
|
'subscription.status' => 1, |
32
|
|
|
'subscription.mtime' => '2018-01-01 00:00:02', |
33
|
|
|
'subscription.ctime' => '2018-01-01 00:00:01', |
34
|
|
|
'subscription.editor' => 'unitTestUser' |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$baseItem = \Aimeos\MShop::create( \TestHelperMShop::getContext(), 'order/base' )->createItem(); |
38
|
|
|
$this->object = new \Aimeos\MShop\Subscription\Item\Standard( $this->values, $baseItem ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
protected function tearDown() : void |
43
|
|
|
{ |
44
|
|
|
unset( $this->object ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testGetBaseItem() |
49
|
|
|
{ |
50
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $this->object->getBaseItem() ); |
51
|
|
|
$this->assertNull( ( new \Aimeos\MShop\Subscription\Item\Standard( $this->values ) )->getBaseItem() ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testGetId() |
56
|
|
|
{ |
57
|
|
|
$this->assertEquals( $this->values['subscription.id'], $this->object->getId() ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testSetId() |
62
|
|
|
{ |
63
|
|
|
$return = $this->object->setId( null ); |
64
|
|
|
|
65
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
66
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
67
|
|
|
$this->assertTrue( $this->object->isModified() ); |
68
|
|
|
|
69
|
|
|
$return = $this->object->setId( 15 ); |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
72
|
|
|
$this->assertEquals( 15, $this->object->getId() ); |
73
|
|
|
$this->assertFalse( $this->object->isModified() ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function testGetSiteId() |
78
|
|
|
{ |
79
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
public function testGetOrderBaseId() |
84
|
|
|
{ |
85
|
|
|
$this->assertEquals( $this->values['subscription.ordbaseid'], $this->object->getOrderBaseId() ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testSetOrderBaseId() |
90
|
|
|
{ |
91
|
|
|
$return = $this->object->setOrderBaseId( 15 ); |
92
|
|
|
|
93
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
94
|
|
|
$this->assertEquals( 15, $this->object->getOrderBaseId() ); |
95
|
|
|
$this->assertTrue( $this->object->isModified() ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testGetOrderProductId() |
100
|
|
|
{ |
101
|
|
|
$this->assertEquals( $this->values['subscription.ordprodid'], $this->object->getOrderProductId() ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testSetOrderProductId() |
106
|
|
|
{ |
107
|
|
|
$return = $this->object->setOrderProductId( 15 ); |
108
|
|
|
|
109
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
110
|
|
|
$this->assertEquals( 15, $this->object->getOrderProductId() ); |
111
|
|
|
$this->assertTrue( $this->object->isModified() ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testGetDateNext() |
116
|
|
|
{ |
117
|
|
|
$this->assertEquals( $this->values['subscription.datenext'], $this->object->getDateNext() ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testSetDateNext() |
122
|
|
|
{ |
123
|
|
|
$return = $this->object->setDateNext( '2018-01-01' ); |
124
|
|
|
|
125
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
126
|
|
|
$this->assertEquals( '2018-01-01', $this->object->getDateNext() ); |
127
|
|
|
$this->assertTrue( $this->object->isModified() ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
public function testGetDateEnd() |
132
|
|
|
{ |
133
|
|
|
$this->assertEquals( $this->values['subscription.dateend'], $this->object->getDateEnd() ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testSetDateEnd() |
138
|
|
|
{ |
139
|
|
|
$return = $this->object->setDateEnd( '2020-01-01' ); |
140
|
|
|
|
141
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
142
|
|
|
$this->assertEquals( '2020-01-01', $this->object->getDateEnd() ); |
143
|
|
|
$this->assertTrue( $this->object->isModified() ); |
144
|
|
|
|
145
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
146
|
|
|
$this->object->setDateEnd( '2008-34-12' ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
public function testGetInterval() |
151
|
|
|
{ |
152
|
|
|
$this->assertEquals( $this->values['subscription.interval'], $this->object->getInterval() ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
public function testSetInterval() |
157
|
|
|
{ |
158
|
|
|
$return = $this->object->setInterval( 'P0Y1M0W0D' ); |
159
|
|
|
|
160
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
161
|
|
|
$this->assertEquals( 'P0Y1M0W0D', $this->object->getInterval() ); |
162
|
|
|
$this->assertTrue( $this->object->isModified() ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
public function testGetPeriod() |
167
|
|
|
{ |
168
|
|
|
$this->assertEquals( $this->values['subscription.period'], $this->object->getPeriod() ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
public function testSetPeriod() |
173
|
|
|
{ |
174
|
|
|
$return = $this->object->setPeriod( 3 ); |
175
|
|
|
|
176
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
177
|
|
|
$this->assertEquals( 3, $this->object->getPeriod() ); |
178
|
|
|
$this->assertTrue( $this->object->isModified() ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testGetProductId() |
183
|
|
|
{ |
184
|
|
|
$this->assertEquals( $this->values['subscription.productid'], $this->object->getProductId() ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
public function testSetProductId() |
189
|
|
|
{ |
190
|
|
|
$return = $this->object->setProductId( '567' ); |
191
|
|
|
|
192
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
193
|
|
|
$this->assertEquals( '567', $this->object->getProductId() ); |
194
|
|
|
$this->assertTrue( $this->object->isModified() ); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
public function testGetReason() |
199
|
|
|
{ |
200
|
|
|
$this->assertEquals( $this->values['subscription.reason'], $this->object->getReason() ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function testSetReason() |
205
|
|
|
{ |
206
|
|
|
$return = $this->object->setReason( 1 ); |
207
|
|
|
|
208
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
209
|
|
|
$this->assertSame( 1, $this->object->getReason() ); |
210
|
|
|
$this->assertTrue( $this->object->isModified() ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
public function testSetReasonNull() |
215
|
|
|
{ |
216
|
|
|
$return = $this->object->setReason( null ); |
217
|
|
|
|
218
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
219
|
|
|
$this->assertSame( null, $this->object->getReason() ); |
220
|
|
|
$this->assertTrue( $this->object->isModified() ); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
public function testSetReasonString() |
225
|
|
|
{ |
226
|
|
|
$return = $this->object->setReason( '-1' ); |
227
|
|
|
|
228
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
229
|
|
|
$this->assertSame( -1, $this->object->getReason() ); |
230
|
|
|
$this->assertTrue( $this->object->isModified() ); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
public function testGetStatus() |
235
|
|
|
{ |
236
|
|
|
$this->assertEquals( $this->values['subscription.status'], $this->object->getStatus() ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
public function testSetStatus() |
241
|
|
|
{ |
242
|
|
|
$return = $this->object->setStatus( 0 ); |
243
|
|
|
|
244
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $return ); |
245
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
246
|
|
|
$this->assertTrue( $this->object->isModified() ); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
public function testGetTimeModified() |
251
|
|
|
{ |
252
|
|
|
$this->assertEquals( '2018-01-01 00:00:02', $this->object->getTimeModified() ); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
public function testGetTimeCreated() |
257
|
|
|
{ |
258
|
|
|
$this->assertEquals( '2018-01-01 00:00:01', $this->object->getTimeCreated() ); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
public function testGetEditor() |
263
|
|
|
{ |
264
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
|
268
|
|
|
public function testGetResourceType() |
269
|
|
|
{ |
270
|
|
|
$this->assertEquals( 'subscription', $this->object->getResourceType() ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
public function testIsModified() |
275
|
|
|
{ |
276
|
|
|
$this->assertFalse( $this->object->isModified() ); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
|
280
|
|
|
public function testFromArray() |
281
|
|
|
{ |
282
|
|
|
$item = new \Aimeos\MShop\Subscription\Item\Standard(); |
283
|
|
|
|
284
|
|
|
$list = $entries = array( |
285
|
|
|
'subscription.id' => 1, |
286
|
|
|
'subscription.ordbaseid' => 2, |
287
|
|
|
'subscription.ordprodid' => 3, |
288
|
|
|
'subscription.productid' => '456', |
289
|
|
|
'subscription.datenext' => '2019-01-01', |
290
|
|
|
'subscription.dateend' => '2020-01-01', |
291
|
|
|
'subscription.interval' => 'P1Y0M0W0D', |
292
|
|
|
'subscription.period' => 2, |
293
|
|
|
'subscription.reason' => 0, |
294
|
|
|
'subscription.status' => 1, |
295
|
|
|
); |
296
|
|
|
|
297
|
|
|
$item = $item->fromArray( $entries, true ); |
298
|
|
|
|
299
|
|
|
$this->assertEquals( [], $entries ); |
300
|
|
|
$this->assertEquals( $list['subscription.id'], $item->getId() ); |
301
|
|
|
$this->assertEquals( $list['subscription.ordbaseid'], $item->getOrderBaseId() ); |
302
|
|
|
$this->assertEquals( $list['subscription.ordprodid'], $item->getOrderProductId() ); |
303
|
|
|
$this->assertEquals( $list['subscription.productid'], $item->getProductId() ); |
304
|
|
|
$this->assertEquals( $list['subscription.datenext'], $item->getDateNext() ); |
305
|
|
|
$this->assertEquals( $list['subscription.dateend'], $item->getDateEnd() ); |
306
|
|
|
$this->assertEquals( $list['subscription.interval'], $item->getInterval() ); |
307
|
|
|
$this->assertEquals( $list['subscription.period'], $item->getPeriod() ); |
308
|
|
|
$this->assertEquals( $list['subscription.reason'], $item->getReason() ); |
309
|
|
|
$this->assertEquals( $list['subscription.status'], $item->getStatus() ); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
|
313
|
|
|
public function testToArray() |
314
|
|
|
{ |
315
|
|
|
$list = $this->object->toArray( true ); |
316
|
|
|
$this->assertEquals( count( $this->values ), count( $list ) ); |
317
|
|
|
|
318
|
|
|
$this->assertEquals( $this->object->getId(), $list['subscription.id'] ); |
319
|
|
|
$this->assertEquals( $this->object->getSiteId(), $list['subscription.siteid'] ); |
320
|
|
|
$this->assertEquals( $this->object->getOrderBaseId(), $list['subscription.ordbaseid'] ); |
321
|
|
|
$this->assertEquals( $this->object->getOrderProductId(), $list['subscription.ordprodid'] ); |
322
|
|
|
$this->assertEquals( $this->object->getProductId(), $list['subscription.productid'] ); |
323
|
|
|
$this->assertEquals( $this->object->getDateNext(), $list['subscription.datenext'] ); |
324
|
|
|
$this->assertEquals( $this->object->getDateEnd(), $list['subscription.dateend'] ); |
325
|
|
|
$this->assertEquals( $this->object->getInterval(), $list['subscription.interval'] ); |
326
|
|
|
$this->assertEquals( $this->object->getPeriod(), $list['subscription.period'] ); |
327
|
|
|
$this->assertEquals( $this->object->getReason(), $list['subscription.reason'] ); |
328
|
|
|
$this->assertEquals( $this->object->getStatus(), $list['subscription.status'] ); |
329
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['subscription.mtime'] ); |
330
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $list['subscription.ctime'] ); |
331
|
|
|
$this->assertEquals( $this->object->getEditor(), $list['subscription.editor'] ); |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
|