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\Supplier\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
|
|
|
'supplier.id' => 541, |
23
|
|
|
'supplier.siteid' => 99, |
24
|
|
|
'supplier.label' => 'unitObject', |
25
|
|
|
'supplier.code' => 'unitCode', |
26
|
|
|
'supplier.position' => 1, |
27
|
|
|
'supplier.status' => 4, |
28
|
|
|
'supplier.mtime' => '2011-01-01 00:00:02', |
29
|
|
|
'supplier.ctime' => '2011-01-01 00:00:01', |
30
|
|
|
'supplier.editor' => 'unitTestUser' |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$addresses = array( |
34
|
|
|
new \Aimeos\MShop\Supplier\Item\Address\Standard( 'supplier.address.', ['supplier.address.position' => 0] ), |
35
|
|
|
new \Aimeos\MShop\Supplier\Item\Address\Standard( 'supplier.address.', ['supplier.address.position' => 1] ), |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$this->object = new \Aimeos\MShop\Supplier\Item\Standard( $this->values, [], [], $addresses ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
protected function tearDown() : void |
43
|
|
|
{ |
44
|
|
|
$this->object = null; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testGetId() |
49
|
|
|
{ |
50
|
|
|
$this->assertEquals( 541, $this->object->getId() ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testSetId() |
55
|
|
|
{ |
56
|
|
|
$return = $this->object->setId( null ); |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $return ); |
59
|
|
|
$this->assertNull( $this->object->getId() ); |
60
|
|
|
$this->assertTrue( $this->object->isModified() ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testGetSiteId() |
65
|
|
|
{ |
66
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testGetLabel() |
71
|
|
|
{ |
72
|
|
|
$this->assertEquals( 'unitObject', $this->object->getLabel() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testSetLabel() |
77
|
|
|
{ |
78
|
|
|
$return = $this->object->setLabel( 'newName' ); |
79
|
|
|
|
80
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $return ); |
81
|
|
|
$this->assertEquals( 'newName', $this->object->getLabel() ); |
82
|
|
|
$this->assertTrue( $this->object->isModified() ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testGetCode() |
87
|
|
|
{ |
88
|
|
|
$this->assertEquals( 'unitCode', $this->object->getCode() ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testSetCode() |
93
|
|
|
{ |
94
|
|
|
$return = $this->object->setCode( 'newCode' ); |
95
|
|
|
|
96
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $return ); |
97
|
|
|
$this->assertEquals( 'newCode', $this->object->getCode() ); |
98
|
|
|
$this->assertTrue( $this->object->isModified() ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testGetPosition() |
103
|
|
|
{ |
104
|
|
|
$this->assertEquals( 1, $this->object->getPosition() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testSetPosition() |
109
|
|
|
{ |
110
|
|
|
$return = $this->object->setPosition( 0 ); |
111
|
|
|
|
112
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $return ); |
113
|
|
|
$this->assertEquals( 0, $this->object->getPosition() ); |
114
|
|
|
$this->assertTrue( $this->object->isModified() ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testGetStatus() |
119
|
|
|
{ |
120
|
|
|
$this->assertEquals( 4, $this->object->getStatus() ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testSetStatus() |
125
|
|
|
{ |
126
|
|
|
$return = $this->object->setStatus( 0 ); |
127
|
|
|
|
128
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $return ); |
129
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
130
|
|
|
$this->assertTrue( $this->object->isModified() ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testGetTimeModified() |
135
|
|
|
{ |
136
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function testGetTimeCreated() |
141
|
|
|
{ |
142
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
public function testGetEditor() |
147
|
|
|
{ |
148
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->editor() ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testIsAvailable() |
153
|
|
|
{ |
154
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
155
|
|
|
$this->object->setAvailable( false ); |
156
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
public function testIsAvailableOnStatus() |
161
|
|
|
{ |
162
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
163
|
|
|
$this->object->setStatus( 0 ); |
164
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
165
|
|
|
$this->object->setStatus( -1 ); |
166
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function testIsModified() |
171
|
|
|
{ |
172
|
|
|
$this->assertFalse( $this->object->isModified() ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
public function testGetAddressItems() |
177
|
|
|
{ |
178
|
|
|
$i = 0; |
179
|
|
|
$list = $this->object->getAddressItems(); |
180
|
|
|
$this->assertEquals( 2, count( $list ) ); |
181
|
|
|
|
182
|
|
|
foreach( $list as $item ) |
183
|
|
|
{ |
184
|
|
|
$this->assertEquals( $i++, $item->getPosition() ); |
185
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Address\Iface::class, $item ); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
public function testGetResourceType() |
191
|
|
|
{ |
192
|
|
|
$this->assertEquals( 'supplier', $this->object->getResourceType() ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
public function testFromArray() |
197
|
|
|
{ |
198
|
|
|
$item = new \Aimeos\MShop\Supplier\Item\Standard(); |
199
|
|
|
|
200
|
|
|
$list = $entries = array( |
201
|
|
|
'supplier.id' => 1, |
202
|
|
|
'supplier.code' => 'test', |
203
|
|
|
'supplier.label' => 'test item', |
204
|
|
|
'supplier.position' => 1, |
205
|
|
|
'supplier.status' => 0, |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
$item = $item->fromArray( $entries, true ); |
209
|
|
|
|
210
|
|
|
$this->assertEquals( [], $entries ); |
211
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
212
|
|
|
$this->assertEquals( $list['supplier.id'], $item->getId() ); |
213
|
|
|
$this->assertEquals( $list['supplier.code'], $item->getCode() ); |
214
|
|
|
$this->assertEquals( $list['supplier.label'], $item->getLabel() ); |
215
|
|
|
$this->assertEquals( $list['supplier.status'], $item->getStatus() ); |
216
|
|
|
$this->assertEquals( $list['supplier.position'], $item->getPosition() ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
public function testToArray() |
221
|
|
|
{ |
222
|
|
|
$arrayObject = $this->object->toArray( true ); |
223
|
|
|
|
224
|
|
|
$this->assertEquals( count( $this->values ), count( $arrayObject ) ); |
225
|
|
|
|
226
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['supplier.id'] ); |
227
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['supplier.siteid'] ); |
228
|
|
|
$this->assertEquals( $this->object->getLabel(), $arrayObject['supplier.label'] ); |
229
|
|
|
$this->assertEquals( $this->object->getCode(), $arrayObject['supplier.code'] ); |
230
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['supplier.status'] ); |
231
|
|
|
$this->assertEquals( $this->object->getPosition(), $arrayObject['supplier.position'] ); |
232
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['supplier.ctime'] ); |
233
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['supplier.mtime'] ); |
234
|
|
|
$this->assertEquals( $this->object->editor(), $arrayObject['supplier.editor'] ); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|