|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Common\Product\Import\Csv\Processor\Attribute; |
|
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\Product\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 => 'attribute.type', |
|
38
|
|
|
1 => 'attribute.code', |
|
39
|
|
|
2 => 'product.lists.type', |
|
40
|
|
|
3 => 'attribute.type', |
|
41
|
|
|
4 => 'attribute.code', |
|
42
|
|
|
5 => 'product.lists.type', |
|
43
|
|
|
6 => 'attribute.type', |
|
44
|
|
|
7 => 'attribute.code', |
|
45
|
|
|
8 => 'product.lists.type', |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$data = array( |
|
49
|
|
|
0 => 'length', |
|
50
|
|
|
1 => '30', |
|
51
|
|
|
2 => 'variant', |
|
52
|
|
|
3 => 'width', |
|
53
|
|
|
4 => '29', |
|
54
|
|
|
5 => 'variant', |
|
55
|
|
|
6 => 'color', |
|
56
|
|
|
7 => 'white', |
|
57
|
|
|
8 => 'variant', |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
$product = $this->create( 'job_csv_test' ); |
|
61
|
|
|
|
|
62
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Attribute\Standard( $this->context, $mapping, $this->endpoint ); |
|
63
|
|
|
$object->process( $product, $data ); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$pos = 0; |
|
67
|
|
|
$listItems = $product->getListItems(); |
|
68
|
|
|
$expected = array( |
|
69
|
|
|
array( 'variant', 'length', '30' ), |
|
70
|
|
|
array( 'variant', 'width', '29' ), |
|
71
|
|
|
array( 'variant', 'color', 'white' ), |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertEquals( 3, count( $listItems ) ); |
|
75
|
|
|
|
|
76
|
|
|
foreach( $listItems as $listItem ) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->assertEquals( 1, $listItem->getStatus() ); |
|
79
|
|
|
$this->assertEquals( 'attribute', $listItem->getDomain() ); |
|
80
|
|
|
$this->assertEquals( $expected[$pos][0], $listItem->getType() ); |
|
81
|
|
|
$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getType() ); |
|
82
|
|
|
$this->assertEquals( $expected[$pos][2], $listItem->getRefItem()->getCode() ); |
|
83
|
|
|
$pos++; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
public function testProcessMultiple() |
|
89
|
|
|
{ |
|
90
|
|
|
$mapping = array( |
|
91
|
|
|
0 => 'attribute.type', |
|
92
|
|
|
1 => 'attribute.code', |
|
93
|
|
|
2 => 'product.lists.type', |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
$data = array( |
|
97
|
|
|
0 => 'color', |
|
98
|
|
|
1 => "white\nblack\naimeos", |
|
99
|
|
|
2 => 'variant', |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
$product = $this->create( 'job_csv_test' ); |
|
103
|
|
|
|
|
104
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Catalog\Standard( $this->context, $mapping, $this->endpoint ); |
|
105
|
|
|
$object->process( $product, $data ); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
$pos = 0; |
|
109
|
|
|
$codes = array( 'white', 'black', 'aimeos' ); |
|
110
|
|
|
|
|
111
|
|
|
foreach( $product->getListItems() as $listItems ) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->assertEquals( 3, count( $listItems ) ); |
|
114
|
|
|
|
|
115
|
|
|
foreach( $listItems as $listItem ) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->assertEquals( 1, $listItem->getStatus() ); |
|
118
|
|
|
$this->assertEquals( 'attribute', $listItem->getDomain() ); |
|
119
|
|
|
$this->assertEquals( 'variant', $listItem->getType() ); |
|
120
|
|
|
$this->assertEquals( $codes[$pos], $listItem->getRefItem()->getCode() ); |
|
121
|
|
|
$pos++; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
public function testProcessUpdate() |
|
128
|
|
|
{ |
|
129
|
|
|
$mapping = array( |
|
130
|
|
|
0 => 'attribute.type', |
|
131
|
|
|
1 => 'attribute.code', |
|
132
|
|
|
); |
|
133
|
|
|
|
|
134
|
|
|
$data = array( |
|
135
|
|
|
0 => 'length', |
|
136
|
|
|
1 => '30', |
|
137
|
|
|
); |
|
138
|
|
|
|
|
139
|
|
|
$dataUpdate = array( |
|
140
|
|
|
0 => 'width', |
|
141
|
|
|
1 => '29', |
|
142
|
|
|
); |
|
143
|
|
|
|
|
144
|
|
|
$product = $this->create( 'job_csv_test' ); |
|
145
|
|
|
|
|
146
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Attribute\Standard( $this->context, $mapping, $this->endpoint ); |
|
147
|
|
|
$object->process( $product, $data ); |
|
|
|
|
|
|
148
|
|
|
$object->process( $product, $dataUpdate ); |
|
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
$listItems = $product->getListItems(); |
|
152
|
|
|
$listItem = reset( $listItems ); |
|
153
|
|
|
|
|
154
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
155
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertEquals( 'width', $listItem->getRefItem()->getType() ); |
|
158
|
|
|
$this->assertEquals( '29', $listItem->getRefItem()->getCode() ); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
public function testProcessDelete() |
|
163
|
|
|
{ |
|
164
|
|
|
$mapping = array( |
|
165
|
|
|
0 => 'attribute.type', |
|
166
|
|
|
1 => 'attribute.code', |
|
167
|
|
|
); |
|
168
|
|
|
|
|
169
|
|
|
$data = array( |
|
170
|
|
|
0 => 'length', |
|
171
|
|
|
1 => '30', |
|
172
|
|
|
); |
|
173
|
|
|
|
|
174
|
|
|
$product = $this->create( 'job_csv_test' ); |
|
175
|
|
|
|
|
176
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Attribute\Standard( $this->context, $mapping, $this->endpoint ); |
|
177
|
|
|
$object->process( $product, $data ); |
|
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Attribute\Standard( $this->context, [], $this->endpoint ); |
|
180
|
|
|
$object->process( $product, [] ); |
|
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
$listItems = $product->getListItems(); |
|
184
|
|
|
|
|
185
|
|
|
$this->assertEquals( 0, count( $listItems ) ); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
public function testProcessEmpty() |
|
190
|
|
|
{ |
|
191
|
|
|
$mapping = array( |
|
192
|
|
|
0 => 'attribute.type', |
|
193
|
|
|
1 => 'attribute.code', |
|
194
|
|
|
2 => 'attribute.type', |
|
195
|
|
|
3 => 'attribute.code', |
|
196
|
|
|
); |
|
197
|
|
|
|
|
198
|
|
|
$data = array( |
|
199
|
|
|
0 => '', |
|
200
|
|
|
1 => '', |
|
201
|
|
|
2 => 'length', |
|
202
|
|
|
3 => '30', |
|
203
|
|
|
); |
|
204
|
|
|
|
|
205
|
|
|
$product = $this->create( 'job_csv_test' ); |
|
206
|
|
|
|
|
207
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Attribute\Standard( $this->context, $mapping, $this->endpoint ); |
|
208
|
|
|
$object->process( $product, $data ); |
|
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
$listItems = $product->getListItems(); |
|
212
|
|
|
|
|
213
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
public function testProcessListtypes() |
|
218
|
|
|
{ |
|
219
|
|
|
$mapping = array( |
|
220
|
|
|
0 => 'attribute.type', |
|
221
|
|
|
1 => 'attribute.code', |
|
222
|
|
|
2 => 'product.lists.type', |
|
223
|
|
|
3 => 'attribute.type', |
|
224
|
|
|
4 => 'attribute.code', |
|
225
|
|
|
5 => 'product.lists.type', |
|
226
|
|
|
); |
|
227
|
|
|
|
|
228
|
|
|
$data = array( |
|
229
|
|
|
0 => 'length', |
|
230
|
|
|
1 => '32', |
|
231
|
|
|
2 => 'custom', |
|
232
|
|
|
3 => 'width', |
|
233
|
|
|
4 => '30', |
|
234
|
|
|
5 => 'default', |
|
235
|
|
|
); |
|
236
|
|
|
|
|
237
|
|
|
$this->context->getConfig()->set( 'controller/common/product/import/csv/processor/attribute/listtypes', array( 'default' ) ); |
|
238
|
|
|
|
|
239
|
|
|
$product = $this->create( 'job_csv_test' ); |
|
240
|
|
|
|
|
241
|
|
|
$object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Attribute\Standard( $this->context, $mapping, $this->endpoint ); |
|
242
|
|
|
|
|
243
|
|
|
$this->setExpectedException( '\Aimeos\Controller\Common\Exception' ); |
|
244
|
|
|
$object->process( $product, $data ); |
|
|
|
|
|
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* @param string $code |
|
250
|
|
|
*/ |
|
251
|
|
|
protected function create( $code ) |
|
252
|
|
|
{ |
|
253
|
|
|
$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->context ); |
|
254
|
|
|
return $manager->createItem()->setCode( $code ); |
|
255
|
|
|
} |
|
256
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: