43 private $fieldMapperMock;
48 private $dateFieldTypeMock;
53 private $additionalFieldsProvider;
58 private $dataProvider;
65 $this->builderMock = $this->createTestProxy(Builder::class);
66 $this->fieldMapperMock = $this->createMock(FieldMapperInterface::class);
67 $this->dataProvider = $this->createMock(DataProvider::class);
68 $this->attribute = $this->createMock(Attribute::class);
69 $this->additionalFieldsProvider = $this->createMock(AdditionalFieldsProviderInterface::class);
70 $this->dateFieldTypeMock = $this->createMock(Date::class);
74 ProductDataMapper::class,
76 'builder' => $this->builderMock,
77 'fieldMapper' => $this->fieldMapperMock,
78 'dateFieldType' => $this->dateFieldTypeMock,
79 'dataProvider' => $this->dataProvider,
80 'additionalFieldsProvider' => $this->additionalFieldsProvider,
92 $additionalFields = [
'some data'];
93 $this->builderMock->expects($this->once())
97 $this->builderMock->expects($this->any())
99 ->withConsecutive([$additionalFields])
100 ->will($this->returnSelf());
101 $this->builderMock->expects($this->any())
103 ->will($this->returnValue([]));
104 $this->additionalFieldsProvider->expects($this->once())
105 ->method(
'getFields')
107 ->willReturn([
$productId => $additionalFields]);
110 $this->assertEquals([
$productId], array_keys($documents));
120 $this->builderMock->expects($this->never())->method(
'addField');
121 $this->builderMock->expects($this->never())->method(
'build');
122 $this->additionalFieldsProvider->expects($this->once())
123 ->method(
'getFields')
127 $documents = $this->model->map([],
$storeId, []);
128 $this->assertEquals([], $documents);
144 $this->dataProvider->method(
'getSearchableAttribute')
147 $this->fieldMapperMock->method(
'getFieldName')
148 ->willReturnArgument(0);
149 $this->dateFieldTypeMock->method(
'formatDate')
150 ->willReturnArgument(1);
151 $this->additionalFieldsProvider->expects($this->once())
152 ->method(
'getFields')
156 $productId => [$attributeId => $attributeValue],
158 $documents = $this->model->map($documentData,
$storeId, $context);
159 $returnAttributeData[
'store_id'] =
$storeId;
160 $this->assertEquals($returnAttributeData, $documents[
$productId]);
171 $attributeValue = [
'o1',
'o2'];
172 $returnAttributeData = [
174 'options' => $attributeValue,
177 $this->dataProvider->expects($this->never())
178 ->method(
'getSearchableAttribute');
179 $this->fieldMapperMock->method(
'getFieldName')
180 ->willReturnArgument(0);
181 $this->additionalFieldsProvider->expects($this->once())
182 ->method(
'getFields')
188 $documents = $this->model->map($documentData,
$storeId, $context);
189 $this->assertEquals($returnAttributeData, $documents[
$productId]);
198 private function getAttribute(array
$attributeData): \PHPUnit_Framework_MockObject_MockObject
200 $attributeMock = $this->createMock(Attribute::class);
201 $attributeMock->method(
'getAttributeCode')->willReturn(
$attributeData[
'code']);
202 $attributeMock->method(
'getBackendType')->willReturn(
$attributeData[
'backendType']);
203 $attributeMock->method(
'getFrontendInput')->willReturn(
$attributeData[
'frontendInput']);
204 $attributeMock->method(
'getIsSearchable')->willReturn(
$attributeData[
'is_searchable']);
207 $optionMock = $this->createMock(AttributeOptionInterface::class);
208 $optionMock->method(
'getValue')->willReturn(
$option[
'value']);
209 $optionMock->method(
'getLabel')->willReturn(
$option[
'label']);
212 $attributeMock->method(
'getOptions')->willReturn(
$options);
214 return $attributeMock;
227 'code' =>
'description',
228 'backendType' =>
'text',
229 'frontendInput' =>
'text',
230 'is_searchable' =>
false,
234 [
'description' =>
'some text'],
239 'code' =>
'created_at',
240 'backendType' =>
'datetime',
241 'frontendInput' =>
'date',
242 'is_searchable' =>
false,
246 [
'created_at' =>
'00-00-00 00:00:00'],
249 'array single value' => [
252 'code' =>
'attribute_array',
253 'backendType' =>
'text',
254 'frontendInput' =>
'text',
255 'is_searchable' =>
false,
259 [
'attribute_array' =>
'one'],
261 'array multiple value' => [
264 'code' =>
'attribute_array',
265 'backendType' =>
'text',
266 'frontendInput' =>
'text',
267 'is_searchable' =>
false,
270 [10 =>
'one', 11 =>
'two', 12 =>
'three'],
271 [
'attribute_array' => [
'one',
'two',
'three']],
273 'array multiple decimal value' => [
276 'code' =>
'decimal_array',
277 'backendType' =>
'decimal',
278 'frontendInput' =>
'text',
279 'is_searchable' =>
false,
282 [10 =>
'0.1', 11 =>
'0.2', 12 =>
'0.3'],
283 [
'decimal_array' => [
'0.1',
'0.2',
'0.3']],
285 'array excluded from merge' => [
289 'backendType' =>
'int',
290 'frontendInput' =>
'select',
291 'is_searchable' =>
false,
293 [
'value' =>
'1',
'label' =>
'Enabled'],
294 [
'value' =>
'2',
'label' =>
'Disabled'],
297 [10 =>
'1', 11 =>
'2'],
300 'select without options' => [
304 'backendType' =>
'text',
305 'frontendInput' =>
'select',
306 'is_searchable' =>
false,
312 'unsearchable select with options' => [
316 'backendType' =>
'text',
317 'frontendInput' =>
'select',
318 'is_searchable' =>
false,
320 [
'value' =>
'44',
'label' =>
'red'],
321 [
'value' =>
'45',
'label' =>
'black'],
327 'searchable select with options' => [
331 'backendType' =>
'text',
332 'frontendInput' =>
'select',
333 'is_searchable' =>
true,
335 [
'value' =>
'44',
'label' =>
'red'],
336 [
'value' =>
'45',
'label' =>
'black'],
340 [
'color' =>
'44',
'color_value' =>
'red'],
342 'composite select with options' => [
346 'backendType' =>
'text',
347 'frontendInput' =>
'select',
348 'is_searchable' =>
true,
350 [
'value' =>
'44',
'label' =>
'red'],
351 [
'value' =>
'45',
'label' =>
'black'],
354 [10 =>
'44', 11 =>
'45'],
355 [
'color' => [
'44',
'45'],
'color_value' => [
'red',
'black']],
357 'multiselect without options' => [
360 'code' =>
'multicolor',
361 'backendType' =>
'text',
362 'frontendInput' =>
'multiselect',
363 'is_searchable' =>
false,
367 [
'multicolor' => [44, 45]],
369 'unsearchable multiselect with options' => [
372 'code' =>
'multicolor',
373 'backendType' =>
'text',
374 'frontendInput' =>
'multiselect',
375 'is_searchable' =>
false,
377 [
'value' =>
'44',
'label' =>
'red'],
378 [
'value' =>
'45',
'label' =>
'black'],
382 [
'multicolor' => [44, 45]],
384 'searchable multiselect with options' => [
387 'code' =>
'multicolor',
388 'backendType' =>
'text',
389 'frontendInput' =>
'multiselect',
390 'is_searchable' =>
true,
392 [
'value' =>
'44',
'label' =>
'red'],
393 [
'value' =>
'45',
'label' =>
'black'],
397 [
'multicolor' => [44, 45],
'multicolor_value' => [
'red',
'black']],
399 'composite multiselect with options' => [
402 'code' =>
'multicolor',
403 'backendType' =>
'text',
404 'frontendInput' =>
'multiselect',
405 'is_searchable' =>
true,
407 [
'value' =>
'44',
'label' =>
'red'],
408 [
'value' =>
'45',
'label' =>
'black'],
409 [
'value' =>
'46',
'label' =>
'green'],
412 [10 =>
'44,45', 11 =>
'45,46'],
413 [
'multicolor' => [44, 45, 46],
'multicolor_value' => [
'red',
'black',
'green']],
415 'excluded attribute' => [
419 'backendType' =>
'int',
420 'frontendInput' =>
'int',
421 'is_searchable' =>
false,
testGetMapAdditionalFieldsOnly()
testGetMap(int $productId, array $attributeData, $attributeValue, array $returnAttributeData)