|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Rule\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
|
|
|
'rule.id' => 123, |
|
22
|
|
|
'rule.siteid' => 99, |
|
23
|
|
|
'rule.label' => 'unitTestRule', |
|
24
|
|
|
'rule.type' => 'catalog', |
|
25
|
|
|
'rule.provider' => 'provider', |
|
26
|
|
|
'rule.config' => array( 'limit' => '40' ), |
|
27
|
|
|
'rule.datestart' => null, |
|
28
|
|
|
'rule.dateend' => null, |
|
29
|
|
|
'rule.position' => 0, |
|
30
|
|
|
'rule.status' => 1, |
|
31
|
|
|
'rule.mtime' => '2011-01-01 00:00:02', |
|
32
|
|
|
'rule.ctime' => '2011-01-01 00:00:01', |
|
33
|
|
|
'rule.editor' => 'unitTestUser' |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
$this->object = new \Aimeos\MShop\Rule\Item\Standard( $this->values ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
protected function tearDown() : void |
|
41
|
|
|
{ |
|
42
|
|
|
unset( $this->object ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function testGetId() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->assertEquals( 123, $this->object->getId() ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
public function testSetId() |
|
53
|
|
|
{ |
|
54
|
|
|
$return = $this->object->setId( null ); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
57
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
|
58
|
|
|
$this->assertEquals( true, $this->object->isModified() ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
public function testGetSiteId() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
public function testGetType() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->assertEquals( 'catalog', $this->object->getType() ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function testSetType() |
|
75
|
|
|
{ |
|
76
|
|
|
$return = $this->object->setType( 'test' ); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
79
|
|
|
$this->assertEquals( 'test', $this->object->getType() ); |
|
80
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
public function testGetLabel() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->assertEquals( 'unitTestRule', $this->object->getLabel() ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
public function testSetLabel() |
|
91
|
|
|
{ |
|
92
|
|
|
$return = $this->object->setLabel( 'anotherLabel' ); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
95
|
|
|
$this->assertEquals( 'anotherLabel', $this->object->getLabel() ); |
|
96
|
|
|
$this->assertEquals( true, $this->object->isModified() ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
public function testGetProvider() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->assertEquals( 'provider', $this->object->getProvider() ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
public function testSetProvider() |
|
107
|
|
|
{ |
|
108
|
|
|
$return = $this->object->setProvider( 'newProvider' ); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
111
|
|
|
$this->assertEquals( 'newProvider', $this->object->getProvider() ); |
|
112
|
|
|
$this->assertEquals( true, $this->object->isModified() ); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
public function testSetProviderInvalid() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->expectException( \Aimeos\MShop\Rule\Exception::class ); |
|
119
|
|
|
$this->object->setProvider( ',newProvider' ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
public function testGetConfig() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->assertEquals( array( 'limit'=>'40' ), $this->object->getConfig() ); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
public function testGetConfigValue() |
|
130
|
|
|
{ |
|
131
|
|
|
$this->assertEquals( '40', $this->object->getConfigValue( 'limit' ) ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
public function testSetConfig() |
|
136
|
|
|
{ |
|
137
|
|
|
$return = $this->object->setConfig( array( 'threshold' => '20.00' ) ); |
|
138
|
|
|
|
|
139
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
140
|
|
|
$this->assertEquals( array( 'threshold'=>'20.00' ), $this->object->getConfig() ); |
|
141
|
|
|
$this->assertEquals( true, $this->object->isModified() ); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
public function testGetDateStart() |
|
146
|
|
|
{ |
|
147
|
|
|
$this->assertEquals( null, $this->object->getDateStart() ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
public function testSetDateStart() |
|
152
|
|
|
{ |
|
153
|
|
|
$return = $this->object->setDateStart( '2010-04-22 06:22:22' ); |
|
154
|
|
|
|
|
155
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
156
|
|
|
$this->assertEquals( '2010-04-22 06:22:22', $this->object->getDateStart() ); |
|
157
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
public function testGetDateEnd() |
|
162
|
|
|
{ |
|
163
|
|
|
$this->assertEquals( null, $this->object->getDateEnd() ); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
public function testSetDateEnd() |
|
168
|
|
|
{ |
|
169
|
|
|
$return = $this->object->setDateEnd( '2010-05-22 06:22' ); |
|
170
|
|
|
|
|
171
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
172
|
|
|
$this->assertEquals( '2010-05-22 06:22:00', $this->object->getDateEnd() ); |
|
173
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
public function testGetPosition() |
|
178
|
|
|
{ |
|
179
|
|
|
$this->assertEquals( 0, $this->object->getPosition() ); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
public function testSetPosition() |
|
184
|
|
|
{ |
|
185
|
|
|
$return = $this->object->setPosition( 1 ); |
|
186
|
|
|
|
|
187
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
188
|
|
|
$this->assertEquals( 1, $this->object->getPosition() ); |
|
189
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
public function testGetStatus() |
|
194
|
|
|
{ |
|
195
|
|
|
$this->assertEquals( 1, $this->object->getStatus() ); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
public function testSetStatus() |
|
200
|
|
|
{ |
|
201
|
|
|
$return = $this->object->setStatus( 0 ); |
|
202
|
|
|
|
|
203
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Rule\Item\Iface::class, $return ); |
|
204
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
|
205
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
public function testGetTimeModified() |
|
210
|
|
|
{ |
|
211
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
public function testGetTimeCreated() |
|
216
|
|
|
{ |
|
217
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
public function testGetEditor() |
|
222
|
|
|
{ |
|
223
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
public function testGetResourceType() |
|
228
|
|
|
{ |
|
229
|
|
|
$this->assertEquals( 'rule', $this->object->getResourceType() ); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
|
|
233
|
|
|
public function testFromArray() |
|
234
|
|
|
{ |
|
235
|
|
|
$item = new \Aimeos\MShop\Rule\Item\Standard(); |
|
236
|
|
|
|
|
237
|
|
|
$list = $entries = array( |
|
238
|
|
|
'rule.id' => 1, |
|
239
|
|
|
'rule.type' => 'test', |
|
240
|
|
|
'rule.label' => 'test item', |
|
241
|
|
|
'rule.provider' => 'FreeShipping', |
|
242
|
|
|
'rule.datestart' => '2000-01-01 00:00:00', |
|
243
|
|
|
'rule.dateend' => '2001-01-01 00:00:00', |
|
244
|
|
|
'rule.config' => array( 'test' ), |
|
245
|
|
|
'rule.status' => 0, |
|
246
|
|
|
); |
|
247
|
|
|
|
|
248
|
|
|
$item = $item->fromArray( $entries, true ); |
|
249
|
|
|
|
|
250
|
|
|
$this->assertEquals( [], $entries ); |
|
251
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
|
252
|
|
|
$this->assertEquals( $list['rule.id'], $item->getId() ); |
|
253
|
|
|
$this->assertEquals( $list['rule.type'], $item->getType() ); |
|
254
|
|
|
$this->assertEquals( $list['rule.label'], $item->getLabel() ); |
|
255
|
|
|
$this->assertEquals( $list['rule.provider'], $item->getProvider() ); |
|
256
|
|
|
$this->assertEquals( $list['rule.datestart'], $item->getDateStart() ); |
|
257
|
|
|
$this->assertEquals( $list['rule.dateend'], $item->getDateEnd() ); |
|
258
|
|
|
$this->assertEquals( $list['rule.config'], $item->getConfig() ); |
|
259
|
|
|
$this->assertEquals( $list['rule.status'], $item->getStatus() ); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
|
|
263
|
|
|
public function testToArray() |
|
264
|
|
|
{ |
|
265
|
|
|
$arrayObject = $this->object->toArray( true ); |
|
266
|
|
|
|
|
267
|
|
|
$this->assertEquals( count( $this->values ), count( $arrayObject ) ); |
|
268
|
|
|
|
|
269
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['rule.id'] ); |
|
270
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['rule.siteid'] ); |
|
271
|
|
|
$this->assertEquals( $this->object->getType(), $arrayObject['rule.type'] ); |
|
272
|
|
|
$this->assertEquals( $this->object->getLabel(), $arrayObject['rule.label'] ); |
|
273
|
|
|
$this->assertEquals( $this->object->getProvider(), $arrayObject['rule.provider'] ); |
|
274
|
|
|
$this->assertEquals( $this->object->getDateStart(), $arrayObject['rule.datestart'] ); |
|
275
|
|
|
$this->assertEquals( $this->object->getDateEnd(), $arrayObject['rule.dateend'] ); |
|
276
|
|
|
$this->assertEquals( $this->object->getConfig(), $arrayObject['rule.config'] ); |
|
277
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['rule.status'] ); |
|
278
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['rule.ctime'] ); |
|
279
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['rule.mtime'] ); |
|
280
|
|
|
$this->assertEquals( $this->object->getEditor(), $arrayObject['rule.editor'] ); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
|
|
284
|
|
|
public function testIsAvailable() |
|
285
|
|
|
{ |
|
286
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
287
|
|
|
$this->object->setAvailable( false ); |
|
288
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
|
|
292
|
|
|
public function testIsAvailableOnStatus() |
|
293
|
|
|
{ |
|
294
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
295
|
|
|
$this->object->setStatus( 0 ); |
|
296
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
297
|
|
|
$this->object->setStatus( -1 ); |
|
298
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|