|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $endpoint; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() |
|
19
|
|
|
{ |
|
20
|
|
|
\Aimeos\MShop\Factory::setCache( true ); |
|
21
|
|
|
|
|
22
|
|
|
$this->context = \TestHelperCntl::getContext(); |
|
23
|
|
|
$this->endpoint = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Done( $this->context, [] ); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
protected function tearDown() |
|
28
|
|
|
{ |
|
29
|
|
|
\Aimeos\MShop\Factory::setCache( false ); |
|
30
|
|
|
\Aimeos\MShop\Factory::clear(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function testProcess() |
|
35
|
|
|
{ |
|
36
|
|
|
$mapping = array( |
|
37
|
|
|
0 => 'text.type', |
|
38
|
|
|
1 => 'text.content', |
|
39
|
|
|
2 => 'text.label', |
|
40
|
|
|
3 => 'text.languageid', |
|
41
|
|
|
4 => 'text.status', |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$data = array( |
|
45
|
|
|
0 => 'name', |
|
46
|
|
|
1 => 'Job CSV test', |
|
47
|
|
|
2 => 'test text', |
|
48
|
|
|
3 => 'de', |
|
49
|
|
|
4 => 1, |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$catalog = $this->create( 'job_csv_test' ); |
|
53
|
|
|
|
|
54
|
|
|
$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint ); |
|
55
|
|
|
$object->process( $catalog, $data ); |
|
56
|
|
|
|
|
57
|
|
|
$catalog = $this->get( 'job_csv_test' ); |
|
58
|
|
|
$this->delete( $catalog ); |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$listItems = $catalog->getListItems(); |
|
62
|
|
|
$listItem = reset( $listItems ); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
|
65
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertEquals( 1, $listItem->getStatus() ); |
|
68
|
|
|
$this->assertEquals( 0, $listItem->getPosition() ); |
|
69
|
|
|
$this->assertEquals( 'text', $listItem->getDomain() ); |
|
70
|
|
|
$this->assertEquals( 'default', $listItem->getType() ); |
|
71
|
|
|
|
|
72
|
|
|
$refItem = $listItem->getRefItem(); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertEquals( 1, $refItem->getStatus() ); |
|
75
|
|
|
$this->assertEquals( 'name', $refItem->getType() ); |
|
76
|
|
|
$this->assertEquals( 'catalog', $refItem->getDomain() ); |
|
77
|
|
|
$this->assertEquals( 'test text', $refItem->getLabel() ); |
|
78
|
|
|
$this->assertEquals( 'Job CSV test', $refItem->getContent() ); |
|
79
|
|
|
$this->assertEquals( 'de', $refItem->getLanguageId() ); |
|
80
|
|
|
$this->assertEquals( 1, $refItem->getStatus() ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
public function testProcessMultiple() |
|
85
|
|
|
{ |
|
86
|
|
|
$mapping = array( |
|
87
|
|
|
0 => 'text.type', |
|
88
|
|
|
1 => 'text.content', |
|
89
|
|
|
2 => 'text.type', |
|
90
|
|
|
3 => 'text.content', |
|
91
|
|
|
4 => 'text.type', |
|
92
|
|
|
5 => 'text.content', |
|
93
|
|
|
6 => 'text.type', |
|
94
|
|
|
7 => 'text.content', |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
|
|
$data = array( |
|
98
|
|
|
0 => 'name', |
|
99
|
|
|
1 => 'Job CSV test', |
|
100
|
|
|
2 => 'short', |
|
101
|
|
|
3 => 'Short: Job CSV test', |
|
102
|
|
|
4 => 'long', |
|
103
|
|
|
5 => 'Long: Job CSV test', |
|
104
|
|
|
6 => 'long', |
|
105
|
|
|
7 => 'Long: Job CSV test 2', |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
$catalog = $this->create( 'job_csv_test' ); |
|
109
|
|
|
|
|
110
|
|
|
$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint ); |
|
111
|
|
|
$object->process( $catalog, $data ); |
|
112
|
|
|
|
|
113
|
|
|
$catalog = $this->get( 'job_csv_test' ); |
|
114
|
|
|
$this->delete( $catalog ); |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
$pos = 0; |
|
118
|
|
|
$listItems = $catalog->getListItems(); |
|
119
|
|
|
$expected = array( |
|
120
|
|
|
0 => array( 'name', 'Job CSV test' ), |
|
121
|
|
|
1 => array( 'short', 'Short: Job CSV test' ), |
|
122
|
|
|
2 => array( 'long', 'Long: Job CSV test' ), |
|
123
|
|
|
3 => array( 'long', 'Long: Job CSV test 2' ), |
|
124
|
|
|
); |
|
125
|
|
|
|
|
126
|
|
|
$this->assertEquals( 4, count( $listItems ) ); |
|
127
|
|
|
|
|
128
|
|
|
foreach( $listItems as $listItem ) |
|
129
|
|
|
{ |
|
130
|
|
|
$this->assertEquals( $expected[$pos][0], $listItem->getRefItem()->getType() ); |
|
131
|
|
|
$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getContent() ); |
|
132
|
|
|
$pos++; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
public function testProcessUpdate() |
|
138
|
|
|
{ |
|
139
|
|
|
$mapping = array( |
|
140
|
|
|
0 => 'text.type', |
|
141
|
|
|
1 => 'text.content', |
|
142
|
|
|
); |
|
143
|
|
|
|
|
144
|
|
|
$data = array( |
|
145
|
|
|
0 => 'name', |
|
146
|
|
|
1 => 'Job CSV test', |
|
147
|
|
|
); |
|
148
|
|
|
|
|
149
|
|
|
$dataUpdate = array( |
|
150
|
|
|
0 => 'short', |
|
151
|
|
|
1 => 'Short: Job CSV test', |
|
152
|
|
|
); |
|
153
|
|
|
|
|
154
|
|
|
$catalog = $this->create( 'job_csv_test' ); |
|
155
|
|
|
|
|
156
|
|
|
$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint ); |
|
157
|
|
|
$object->process( $catalog, $data ); |
|
158
|
|
|
|
|
159
|
|
|
$catalog = $this->get( 'job_csv_test' ); |
|
160
|
|
|
|
|
161
|
|
|
$object->process( $catalog, $dataUpdate ); |
|
162
|
|
|
|
|
163
|
|
|
$catalog = $this->get( 'job_csv_test' ); |
|
164
|
|
|
$this->delete( $catalog ); |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
$listItems = $catalog->getListItems(); |
|
168
|
|
|
$listItem = reset( $listItems ); |
|
169
|
|
|
|
|
170
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
171
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
|
172
|
|
|
|
|
173
|
|
|
$this->assertEquals( 'short', $listItem->getRefItem()->getType() ); |
|
174
|
|
|
$this->assertEquals( 'Short: Job CSV test', $listItem->getRefItem()->getContent() ); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
public function testProcessDelete() |
|
179
|
|
|
{ |
|
180
|
|
|
$mapping = array( |
|
181
|
|
|
0 => 'text.type', |
|
182
|
|
|
1 => 'text.content', |
|
183
|
|
|
); |
|
184
|
|
|
|
|
185
|
|
|
$data = array( |
|
186
|
|
|
0 => 'name', |
|
187
|
|
|
1 => 'Job CSV test', |
|
188
|
|
|
); |
|
189
|
|
|
|
|
190
|
|
|
$catalog = $this->create( 'job_csv_test' ); |
|
191
|
|
|
|
|
192
|
|
|
$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint ); |
|
193
|
|
|
$object->process( $catalog, $data ); |
|
194
|
|
|
|
|
195
|
|
|
$catalog = $this->get( 'job_csv_test' ); |
|
196
|
|
|
|
|
197
|
|
|
$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, [], $this->endpoint ); |
|
198
|
|
|
$object->process( $catalog, [] ); |
|
199
|
|
|
|
|
200
|
|
|
$catalog = $this->get( 'job_csv_test' ); |
|
201
|
|
|
$this->delete( $catalog ); |
|
202
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
$listItems = $catalog->getListItems(); |
|
205
|
|
|
|
|
206
|
|
|
$this->assertEquals( 0, count( $listItems ) ); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
public function testProcessEmpty() |
|
211
|
|
|
{ |
|
212
|
|
|
$mapping = array( |
|
213
|
|
|
0 => 'text.type', |
|
214
|
|
|
1 => 'text.content', |
|
215
|
|
|
2 => 'text.type', |
|
216
|
|
|
3 => 'text.content', |
|
217
|
|
|
); |
|
218
|
|
|
|
|
219
|
|
|
$data = array( |
|
220
|
|
|
0 => 'name', |
|
221
|
|
|
1 => 'Job CSV test', |
|
222
|
|
|
2 => '', |
|
223
|
|
|
3 => '', |
|
224
|
|
|
); |
|
225
|
|
|
|
|
226
|
|
|
$catalog = $this->create( 'job_csv_test' ); |
|
227
|
|
|
|
|
228
|
|
|
$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint ); |
|
229
|
|
|
$object->process( $catalog, $data ); |
|
230
|
|
|
|
|
231
|
|
|
$catalog = $this->get( 'job_csv_test' ); |
|
232
|
|
|
$this->delete( $catalog ); |
|
233
|
|
|
|
|
234
|
|
|
|
|
235
|
|
|
$listItems = $catalog->getListItems(); |
|
236
|
|
|
|
|
237
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
public function testProcessListtypes() |
|
242
|
|
|
{ |
|
243
|
|
|
$mapping = array( |
|
244
|
|
|
0 => 'text.type', |
|
245
|
|
|
1 => 'text.content', |
|
246
|
|
|
2 => 'catalog.lists.type', |
|
247
|
|
|
3 => 'text.type', |
|
248
|
|
|
4 => 'text.content', |
|
249
|
|
|
5 => 'catalog.lists.type', |
|
250
|
|
|
); |
|
251
|
|
|
|
|
252
|
|
|
$data = array( |
|
253
|
|
|
0 => 'name', |
|
254
|
|
|
1 => 'test name', |
|
255
|
|
|
2 => 'test', |
|
256
|
|
|
3 => 'short', |
|
257
|
|
|
4 => 'test short', |
|
258
|
|
|
5 => 'default', |
|
259
|
|
|
); |
|
260
|
|
|
|
|
261
|
|
|
$this->context->getConfig()->set( 'controller/common/catalog/import/csv/processor/text/listtypes', array( 'default' ) ); |
|
262
|
|
|
|
|
263
|
|
|
$catalog = $this->create( 'job_csv_test' ); |
|
264
|
|
|
|
|
265
|
|
|
$object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Text\Standard( $this->context, $mapping, $this->endpoint ); |
|
266
|
|
|
$object->process( $catalog, $data ); |
|
267
|
|
|
|
|
268
|
|
|
$catalog = $this->get( 'job_csv_test' ); |
|
269
|
|
|
$this->delete( $catalog ); |
|
270
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
$listItems = $catalog->getListItems(); |
|
273
|
|
|
$listItem = reset( $listItems ); |
|
274
|
|
|
|
|
275
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
276
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
|
277
|
|
|
|
|
278
|
|
|
$this->assertEquals( 'default', $listItem->getType() ); |
|
279
|
|
|
$this->assertEquals( 'short', $listItem->getRefItem()->getType() ); |
|
280
|
|
|
$this->assertEquals( 'test short', $listItem->getRefItem()->getContent() ); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* @param string $code |
|
286
|
|
|
*/ |
|
287
|
|
|
protected function create( $code ) |
|
288
|
|
|
{ |
|
289
|
|
|
$manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context ); |
|
290
|
|
|
|
|
291
|
|
|
$item = $manager->createItem(); |
|
292
|
|
|
$item->setCode( $code ); |
|
293
|
|
|
|
|
294
|
|
|
return $manager->insertItem( $item ); |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
|
|
298
|
|
|
protected function delete( \Aimeos\MShop\Catalog\Item\Iface $catalog ) |
|
299
|
|
|
{ |
|
300
|
|
|
$textManager = \Aimeos\MShop\Text\Manager\Factory::createManager( $this->context ); |
|
301
|
|
|
$manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context ); |
|
302
|
|
|
$listManager = $manager->getSubManager( 'lists' ); |
|
303
|
|
|
|
|
304
|
|
|
foreach( $catalog->getListItems('text') as $listItem ) |
|
305
|
|
|
{ |
|
306
|
|
|
$textManager->deleteItem( $listItem->getRefItem()->getId() ); |
|
307
|
|
|
$listManager->deleteItem( $listItem->getId() ); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
$manager->deleteItem( $catalog->getId() ); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @param string $code |
|
316
|
|
|
*/ |
|
317
|
|
|
protected function get( $code ) |
|
318
|
|
|
{ |
|
319
|
|
|
$manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context ); |
|
320
|
|
|
return $manager->findItem( $code, ['text'] ); |
|
321
|
|
|
} |
|
322
|
|
|
} |