|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2020 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Common\Product\Import\Csv\Processor\Supplier; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private static $product; |
|
15
|
|
|
private $context; |
|
16
|
|
|
private $endpoint; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
public static function setUpBeforeClass() : void |
|
20
|
|
|
{ |
|
21
|
|
|
$manager = \Aimeos\MShop\Product\Manager\Factory::create( \TestHelperCntl::getContext() ); |
|
22
|
|
|
|
|
23
|
|
|
$item = $manager->createItem(); |
|
24
|
|
|
$item->setCode( 'job_csv_prod' ); |
|
25
|
|
|
$item->setType( 'default' ); |
|
26
|
|
|
$item->setStatus( 1 ); |
|
27
|
|
|
|
|
28
|
|
|
self::$product = $manager->saveItem( $item ); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public static function tearDownAfterClass() : void |
|
33
|
|
|
{ |
|
34
|
|
|
$manager = \Aimeos\MShop\Product\Manager\Factory::create( \TestHelperCntl::getContext() ); |
|
35
|
|
|
$manager->deleteItem( self::$product->getId() ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
protected function setUp() : void |
|
40
|
|
|
{ |
|
41
|
|
|
\Aimeos\MShop::cache( true ); |
|
42
|
|
|
|
|
43
|
|
|
$this->context = \TestHelperCntl::getContext(); |
|
44
|
|
|
$this->endpoint = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Done( $this->context, [] ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
protected function tearDown() : void |
|
49
|
|
|
{ |
|
50
|
|
|
\Aimeos\MShop::cache( false ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function testProcess() |
|
55
|
|
|
{ |
|
56
|
|
|
$mapping = array( |
|
57
|
|
|
0 => 'supplier.lists.type', |
|
58
|
|
|
1 => 'supplier.code', |
|
59
|
|
|
2 => 'supplier.lists.type', |
|
60
|
|
|
3 => 'supplier.code', |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$data = array( |
|
64
|
|
|
0 => 'default', |
|
65
|
|
|
1 => 'job_csv_test', |
|
66
|
|
|
2 => 'promotion', |
|
67
|
|
|
3 => 'job_csv_test', |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$this->create( 'job_csv_test' ); |
|
71
|
|
|
|
|
72
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Supplier\Standard( $this->context, $mapping, $this->endpoint ); |
|
73
|
|
|
$object->process( self::$product, $data ); |
|
74
|
|
|
|
|
75
|
|
|
$supplier = $this->get( 'job_csv_test' ); |
|
76
|
|
|
$this->delete( $supplier ); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$pos = 0; |
|
80
|
|
|
$listItems = $supplier->getListItems(); |
|
81
|
|
|
$expected = array( |
|
82
|
|
|
array( 'default', 'job_csv_prod' ), |
|
83
|
|
|
array( 'promotion', 'job_csv_prod' ), |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertEquals( 2, count( $listItems ) ); |
|
87
|
|
|
|
|
88
|
|
|
foreach( $listItems as $listItem ) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->assertEquals( 1, $listItem->getStatus() ); |
|
91
|
|
|
$this->assertEquals( 'product', $listItem->getDomain() ); |
|
92
|
|
|
$this->assertEquals( $expected[$pos][0], $listItem->getType() ); |
|
93
|
|
|
$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getCode() ); |
|
94
|
|
|
$pos++; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
public function testProcessMultiple() |
|
100
|
|
|
{ |
|
101
|
|
|
$mapping = array( |
|
102
|
|
|
0 => 'supplier.lists.type', |
|
103
|
|
|
1 => 'supplier.code', |
|
104
|
|
|
2 => 'supplier.lists.type', |
|
105
|
|
|
3 => 'supplier.code', |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
$data = array( |
|
109
|
|
|
0 => 'default', |
|
110
|
|
|
1 => "job_csv_test\njob_csv_test2", |
|
111
|
|
|
2 => 'promotion', |
|
112
|
|
|
3 => "job_csv_test\njob_csv_test2", |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
|
|
$this->create( 'job_csv_test' ); |
|
116
|
|
|
$this->create( 'job_csv_test2' ); |
|
117
|
|
|
|
|
118
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Supplier\Standard( $this->context, $mapping, $this->endpoint ); |
|
119
|
|
|
$object->process( self::$product, $data ); |
|
120
|
|
|
|
|
121
|
|
|
$supplier = $this->get( 'job_csv_test' ); |
|
122
|
|
|
$supplier2 = $this->get( 'job_csv_test2' ); |
|
123
|
|
|
|
|
124
|
|
|
$this->delete( $supplier ); |
|
|
|
|
|
|
125
|
|
|
$this->delete( $supplier2 ); |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
$pos = 0; |
|
129
|
|
|
$types = array( 'default', 'promotion', 'default', 'promotion' ); |
|
130
|
|
|
|
|
131
|
|
|
foreach( array( $supplier->getListItems(), $supplier2->getListItems() ) as $listItems ) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->assertEquals( 2, count( $listItems ) ); |
|
134
|
|
|
|
|
135
|
|
|
foreach( $listItems as $listItem ) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->assertEquals( 1, $listItem->getStatus() ); |
|
138
|
|
|
$this->assertEquals( 'product', $listItem->getDomain() ); |
|
139
|
|
|
$this->assertEquals( $types[$pos], $listItem->getType() ); |
|
140
|
|
|
$this->assertEquals( 'job_csv_prod', $listItem->getRefItem()->getCode() ); |
|
141
|
|
|
$pos++; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
public function testProcessUpdate() |
|
148
|
|
|
{ |
|
149
|
|
|
$mapping = array( |
|
150
|
|
|
0 => 'supplier.lists.type', |
|
151
|
|
|
1 => 'supplier.code', |
|
152
|
|
|
); |
|
153
|
|
|
|
|
154
|
|
|
$data = array( |
|
155
|
|
|
0 => 'default', |
|
156
|
|
|
1 => 'job_csv_test', |
|
157
|
|
|
); |
|
158
|
|
|
|
|
159
|
|
|
$dataUpdate = array( |
|
160
|
|
|
0 => 'promotion', |
|
161
|
|
|
1 => 'job_csv_test', |
|
162
|
|
|
); |
|
163
|
|
|
|
|
164
|
|
|
$this->create( 'job_csv_test' ); |
|
165
|
|
|
|
|
166
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Supplier\Standard( $this->context, $mapping, $this->endpoint ); |
|
167
|
|
|
$object->process( self::$product, $data ); |
|
168
|
|
|
$object->process( self::$product, $dataUpdate ); |
|
169
|
|
|
|
|
170
|
|
|
$supplier = $this->get( 'job_csv_test' ); |
|
171
|
|
|
$this->delete( $supplier ); |
|
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
$listItems = $supplier->getListItems(); |
|
175
|
|
|
$listItem = $listItems->first(); |
|
176
|
|
|
|
|
177
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
178
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
|
179
|
|
|
|
|
180
|
|
|
$this->assertEquals( 'job_csv_prod', $listItem->getRefItem()->getCode() ); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
public function testProcessDelete() |
|
185
|
|
|
{ |
|
186
|
|
|
$mapping = array( |
|
187
|
|
|
0 => 'supplier.lists.type', |
|
188
|
|
|
1 => 'supplier.code', |
|
189
|
|
|
); |
|
190
|
|
|
|
|
191
|
|
|
$data = array( |
|
192
|
|
|
0 => 'default', |
|
193
|
|
|
1 => 'job_csv_test', |
|
194
|
|
|
); |
|
195
|
|
|
|
|
196
|
|
|
$this->create( 'job_csv_test' ); |
|
197
|
|
|
|
|
198
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Supplier\Standard( $this->context, $mapping, $this->endpoint ); |
|
199
|
|
|
$object->process( self::$product, $data ); |
|
200
|
|
|
|
|
201
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Supplier\Standard( $this->context, [], $this->endpoint ); |
|
202
|
|
|
$object->process( self::$product, [] ); |
|
203
|
|
|
|
|
204
|
|
|
$supplier = $this->get( 'job_csv_test' ); |
|
205
|
|
|
$this->delete( $supplier ); |
|
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
$listItems = $supplier->getListItems(); |
|
209
|
|
|
|
|
210
|
|
|
$this->assertEquals( 0, count( $listItems ) ); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
public function testProcessEmpty() |
|
215
|
|
|
{ |
|
216
|
|
|
$mapping = array( |
|
217
|
|
|
0 => 'supplier.lists.type', |
|
218
|
|
|
1 => 'supplier.code', |
|
219
|
|
|
2 => 'supplier.lists.type', |
|
220
|
|
|
3 => 'supplier.code', |
|
221
|
|
|
); |
|
222
|
|
|
|
|
223
|
|
|
$data = array( |
|
224
|
|
|
0 => '', |
|
225
|
|
|
1 => '', |
|
226
|
|
|
2 => 'default', |
|
227
|
|
|
3 => 'job_csv_test', |
|
228
|
|
|
); |
|
229
|
|
|
|
|
230
|
|
|
$this->create( 'job_csv_test' ); |
|
231
|
|
|
|
|
232
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Supplier\Standard( $this->context, $mapping, $this->endpoint ); |
|
233
|
|
|
$object->process( self::$product, $data ); |
|
234
|
|
|
|
|
235
|
|
|
$supplier = $this->get( 'job_csv_test' ); |
|
236
|
|
|
$this->delete( $supplier ); |
|
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
$listItems = $supplier->getListItems(); |
|
240
|
|
|
|
|
241
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
public function testProcessListtypes() |
|
246
|
|
|
{ |
|
247
|
|
|
$mapping = array( |
|
248
|
|
|
0 => 'supplier.lists.type', |
|
249
|
|
|
1 => 'supplier.code', |
|
250
|
|
|
2 => 'supplier.lists.type', |
|
251
|
|
|
3 => 'supplier.code', |
|
252
|
|
|
); |
|
253
|
|
|
|
|
254
|
|
|
$data = array( |
|
255
|
|
|
0 => 'promotion', |
|
256
|
|
|
1 => 'job_csv_test', |
|
257
|
|
|
2 => 'default', |
|
258
|
|
|
3 => 'job_csv_test', |
|
259
|
|
|
); |
|
260
|
|
|
|
|
261
|
|
|
$this->context->getConfig()->set( 'controller/common/product/import/csv/processor/supplier/listtypes', array( 'default' ) ); |
|
262
|
|
|
|
|
263
|
|
|
$this->create( 'job_csv_test' ); |
|
264
|
|
|
|
|
265
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Supplier\Standard( $this->context, $mapping, $this->endpoint ); |
|
266
|
|
|
|
|
267
|
|
|
$this->expectException( '\Aimeos\Controller\Common\Exception' ); |
|
268
|
|
|
$object->process( self::$product, $data ); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @param string $code |
|
274
|
|
|
*/ |
|
275
|
|
|
protected function create( $code ) |
|
276
|
|
|
{ |
|
277
|
|
|
$manager = \Aimeos\MShop\Supplier\Manager\Factory::create( $this->context ); |
|
278
|
|
|
|
|
279
|
|
|
$item = $manager->createItem(); |
|
280
|
|
|
$item->setCode( $code ); |
|
281
|
|
|
|
|
282
|
|
|
$manager->insertItem( $item ); |
|
283
|
|
|
|
|
284
|
|
|
return $item; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
|
|
288
|
|
|
protected function delete( \Aimeos\MShop\Supplier\Item\Iface $catItem ) |
|
289
|
|
|
{ |
|
290
|
|
|
$manager = \Aimeos\MShop\Supplier\Manager\Factory::create( $this->context ); |
|
291
|
|
|
$listManager = $manager->getSubManager( 'lists' ); |
|
292
|
|
|
|
|
293
|
|
|
$listManager->deleteItems( $catItem->getListItems( 'product' )->keys()->toArray() ); |
|
294
|
|
|
$manager->deleteItem( $catItem->getId() ); |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @param string $code |
|
300
|
|
|
*/ |
|
301
|
|
|
protected function get( $code ) |
|
302
|
|
|
{ |
|
303
|
|
|
$manager = \Aimeos\MShop\Supplier\Manager\Factory::create( $this->context ); |
|
304
|
|
|
|
|
305
|
|
|
$search = $manager->createSearch(); |
|
306
|
|
|
$search->setConditions( $search->compare( '==', 'supplier.code', $code ) ); |
|
307
|
|
|
|
|
308
|
|
|
if( ( $item = $manager->searchItems( $search, ['product'] )->first() ) === null ) { |
|
309
|
|
|
throw new \RuntimeException( sprintf( 'No supplier item for code "%1$s"', $code ) ); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
return $item; |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.