|
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\Controller\Common\Supplier\Import\Csv\Processor\Media; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $endpoint; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
19
|
|
|
{ |
|
20
|
|
|
\Aimeos\MShop::cache( true ); |
|
21
|
|
|
|
|
22
|
|
|
$this->context = \TestHelperCntl::getContext(); |
|
23
|
|
|
$this->endpoint = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Done( $this->context, [] ); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
protected function tearDown() : void |
|
28
|
|
|
{ |
|
29
|
|
|
\Aimeos\MShop::cache( false ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
public function testProcess() |
|
34
|
|
|
{ |
|
35
|
|
|
$mapping = array( |
|
36
|
|
|
0 => 'media.languageid', |
|
37
|
|
|
1 => 'media.label', |
|
38
|
|
|
2 => 'media.mimetype', |
|
39
|
|
|
3 => 'media.preview', |
|
40
|
|
|
4 => 'media.url', |
|
41
|
|
|
5 => 'media.status', |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$data = array( |
|
45
|
|
|
0 => 'de', |
|
46
|
|
|
1 => 'test image', |
|
47
|
|
|
2 => 'image/jpeg', |
|
48
|
|
|
3 => 'path/to/preview', |
|
49
|
|
|
4 => 'path/to/file', |
|
50
|
|
|
5 => 1, |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
$supplier = $this->create( 'job_csv_test' ); |
|
54
|
|
|
|
|
55
|
|
|
$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint ); |
|
56
|
|
|
$object->process( $supplier, $data ); |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$listItems = $supplier->getListItems(); |
|
60
|
|
|
$listItem = $listItems->first(); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
|
63
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertEquals( 1, $listItem->getStatus() ); |
|
66
|
|
|
$this->assertEquals( 0, $listItem->getPosition() ); |
|
67
|
|
|
$this->assertEquals( 'media', $listItem->getDomain() ); |
|
68
|
|
|
$this->assertEquals( 'default', $listItem->getType() ); |
|
69
|
|
|
|
|
70
|
|
|
$refItem = $listItem->getRefItem(); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals( 1, $refItem->getStatus() ); |
|
73
|
|
|
$this->assertEquals( 'default', $refItem->getType() ); |
|
74
|
|
|
$this->assertEquals( 'test image', $refItem->getLabel() ); |
|
75
|
|
|
$this->assertEquals( 'image/jpeg', $refItem->getMimetype() ); |
|
76
|
|
|
$this->assertEquals( 'path/to/preview', $refItem->getPreview() ); |
|
77
|
|
|
$this->assertEquals( 'path/to/file', $refItem->getUrl() ); |
|
78
|
|
|
$this->assertEquals( 'de', $refItem->getLanguageId() ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
public function testProcessMultiple() |
|
83
|
|
|
{ |
|
84
|
|
|
$mapping = array( |
|
85
|
|
|
0 => 'media.url', |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$data = array( |
|
89
|
|
|
0 => "path/to/0\npath/to/1\npath/to/2\npath/to/3", |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
$supplier = $this->create( 'job_csv_test' ); |
|
93
|
|
|
|
|
94
|
|
|
$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint ); |
|
95
|
|
|
$object->process( $supplier, $data ); |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
$pos = 0; |
|
99
|
|
|
$listItems = $supplier->getListItems(); |
|
100
|
|
|
$expected = array( 'path/to/0', 'path/to/1', 'path/to/2', 'path/to/3' ); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertEquals( 4, count( $listItems ) ); |
|
103
|
|
|
|
|
104
|
|
|
foreach( $listItems as $listItem ) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->assertEquals( $expected[$pos], $listItem->getRefItem()->getUrl() ); |
|
107
|
|
|
$pos++; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
public function testProcessMultipleFields() |
|
113
|
|
|
{ |
|
114
|
|
|
$mapping = array( |
|
115
|
|
|
0 => 'media.url', |
|
116
|
|
|
1 => 'media.url', |
|
117
|
|
|
2 => 'media.url', |
|
118
|
|
|
3 => 'media.url', |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
$data = array( |
|
122
|
|
|
0 => 'path/to/0', |
|
123
|
|
|
1 => 'path/to/1', |
|
124
|
|
|
2 => 'path/to/2', |
|
125
|
|
|
3 => 'path/to/3', |
|
126
|
|
|
); |
|
127
|
|
|
|
|
128
|
|
|
$supplier = $this->create( 'job_csv_test' ); |
|
129
|
|
|
|
|
130
|
|
|
$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint ); |
|
131
|
|
|
$object->process( $supplier, $data ); |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
$pos = 0; |
|
135
|
|
|
$listItems = $supplier->getListItems(); |
|
136
|
|
|
|
|
137
|
|
|
$this->assertEquals( 4, count( $listItems ) ); |
|
138
|
|
|
|
|
139
|
|
|
foreach( $listItems as $listItem ) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->assertEquals( $data[$pos], $listItem->getRefItem()->getUrl() ); |
|
142
|
|
|
$pos++; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
public function testProcessUpdate() |
|
148
|
|
|
{ |
|
149
|
|
|
$mapping = array( |
|
150
|
|
|
0 => 'media.url', |
|
151
|
|
|
1 => 'media.languageid', |
|
152
|
|
|
); |
|
153
|
|
|
|
|
154
|
|
|
$data = array( |
|
155
|
|
|
0 => 'path/to/file', |
|
156
|
|
|
1 => 'de', |
|
157
|
|
|
); |
|
158
|
|
|
|
|
159
|
|
|
$dataUpdate = array( |
|
160
|
|
|
0 => 'path/to/new', |
|
161
|
|
|
1 => '', |
|
162
|
|
|
); |
|
163
|
|
|
|
|
164
|
|
|
$supplier = $this->create( 'job_csv_test' ); |
|
165
|
|
|
|
|
166
|
|
|
$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint ); |
|
167
|
|
|
$object->process( $supplier, $data ); |
|
168
|
|
|
$object->process( $supplier, $dataUpdate ); |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
$listItems = $supplier->getListItems(); |
|
172
|
|
|
$listItem = $listItems->first(); |
|
173
|
|
|
|
|
174
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
175
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
|
176
|
|
|
|
|
177
|
|
|
$this->assertEquals( 'path/to/new', $listItem->getRefItem()->getUrl() ); |
|
178
|
|
|
$this->assertEquals( null, $listItem->getRefItem()->getLanguageId() ); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
public function testProcessDelete() |
|
183
|
|
|
{ |
|
184
|
|
|
$mapping = array( |
|
185
|
|
|
0 => 'media.url', |
|
186
|
|
|
); |
|
187
|
|
|
|
|
188
|
|
|
$data = array( |
|
189
|
|
|
0 => '/path/to/file', |
|
190
|
|
|
); |
|
191
|
|
|
|
|
192
|
|
|
$supplier = $this->create( 'job_csv_test' ); |
|
193
|
|
|
|
|
194
|
|
|
$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint ); |
|
195
|
|
|
$object->process( $supplier, $data ); |
|
196
|
|
|
|
|
197
|
|
|
$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Media\Standard( $this->context, [], $this->endpoint ); |
|
198
|
|
|
$object->process( $supplier, [] ); |
|
199
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
$listItems = $supplier->getListItems(); |
|
202
|
|
|
|
|
203
|
|
|
$this->assertEquals( 0, count( $listItems ) ); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
public function testProcessEmpty() |
|
208
|
|
|
{ |
|
209
|
|
|
$mapping = array( |
|
210
|
|
|
0 => 'media.url', |
|
211
|
|
|
1 => 'media.url', |
|
212
|
|
|
); |
|
213
|
|
|
|
|
214
|
|
|
$data = array( |
|
215
|
|
|
0 => 'path/to/file', |
|
216
|
|
|
1 => '', |
|
217
|
|
|
); |
|
218
|
|
|
|
|
219
|
|
|
$supplier = $this->create( 'job_csv_test' ); |
|
220
|
|
|
|
|
221
|
|
|
$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint ); |
|
222
|
|
|
$object->process( $supplier, $data ); |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
$listItems = $supplier->getListItems(); |
|
226
|
|
|
|
|
227
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
public function testProcessListtypes() |
|
232
|
|
|
{ |
|
233
|
|
|
$mapping = array( |
|
234
|
|
|
0 => 'media.url', |
|
235
|
|
|
1 => 'supplier.lists.type', |
|
236
|
|
|
2 => 'media.url', |
|
237
|
|
|
3 => 'supplier.lists.type', |
|
238
|
|
|
); |
|
239
|
|
|
|
|
240
|
|
|
$data = array( |
|
241
|
|
|
0 => 'path/to/file', |
|
242
|
|
|
1 => 'test', |
|
243
|
|
|
2 => 'path/to/file2', |
|
244
|
|
|
3 => 'default', |
|
245
|
|
|
); |
|
246
|
|
|
|
|
247
|
|
|
$this->context->getConfig()->set( 'controller/common/supplier/import/csv/processor/media/listtypes', array( 'default' ) ); |
|
248
|
|
|
|
|
249
|
|
|
$supplier = $this->create( 'job_csv_test' ); |
|
250
|
|
|
|
|
251
|
|
|
$object = new \Aimeos\Controller\Common\Supplier\Import\Csv\Processor\Media\Standard( $this->context, $mapping, $this->endpoint ); |
|
252
|
|
|
|
|
253
|
|
|
$this->expectException( '\Aimeos\Controller\Common\Exception' ); |
|
254
|
|
|
$object->process( $supplier, $data ); |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @param string $code |
|
260
|
|
|
*/ |
|
261
|
|
|
protected function create( $code ) |
|
262
|
|
|
{ |
|
263
|
|
|
$manager = \Aimeos\MShop\Supplier\Manager\Factory::create( $this->context ); |
|
264
|
|
|
|
|
265
|
|
|
$item = $manager->createItem(); |
|
266
|
|
|
$item->setCode( $code ); |
|
267
|
|
|
|
|
268
|
|
|
return $item; |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
|
|
|