1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flagbit\Bundle\TableAttributeBundle\Test\Pim; |
4
|
|
|
|
5
|
|
|
use Akeneo\Pim\Enrichment\Bundle\Elasticsearch\Filter\Attribute\OptionFilter; |
6
|
|
|
use Akeneo\Pim\Enrichment\Component\Product\Comparator\Attribute\ScalarComparator; |
7
|
|
|
use Akeneo\Pim\Enrichment\Component\Product\Connector\ArrayConverter\FlatToStandard\ValueConverter\TextConverter as FlatToStandardTextConverter; |
8
|
|
|
use Akeneo\Pim\Enrichment\Component\Product\Connector\ArrayConverter\StandardToFlat\Product\ValueConverter\TextConverter as StandardToFlatTextConverter; |
9
|
|
|
use Akeneo\Pim\Enrichment\Component\Product\Query\Filter\FilterRegistry; |
10
|
|
|
use Akeneo\Pim\Enrichment\Component\Product\Updater\Setter\AttributeSetter; |
11
|
|
|
use Akeneo\Pim\Enrichment\Component\Product\Value\ScalarValue; |
12
|
|
|
use Akeneo\Pim\Structure\Component\Model\Attribute; |
13
|
|
|
use Akeneo\Pim\Structure\Component\Query\PublicApi\AttributeType\Attribute as PublicApiAttribute; |
14
|
|
|
use Akeneo\Pim\Structure\Component\Repository\AttributeRepositoryInterface; |
15
|
|
|
use Akeneo\Tool\Component\StorageUtils\Repository\IdentifiableObjectRepositoryInterface; |
16
|
|
|
use Flagbit\Bundle\TableAttributeBundle\AttributeType\TableType; |
17
|
|
|
use Flagbit\Bundle\TableAttributeBundle\Component\Product\Factory\Value\TableValueFactory; |
18
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
19
|
|
|
|
20
|
|
|
class PimTest extends KernelTestCase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
public function testFlatToStandardConverterRegisters() |
24
|
|
|
{ |
25
|
|
|
self::bootKernel(); |
26
|
|
|
$container = self::$container; |
27
|
|
|
|
28
|
|
|
$registryValueConverter = $container->get('pim_connector.array_converter.flat_to_standard.product.value_converter.registry'); |
29
|
|
|
|
30
|
|
|
$converter = $registryValueConverter->getConverter('flagbit_catalog_table'); |
31
|
|
|
|
32
|
|
|
self::assertInstanceOf(FlatToStandardTextConverter::class, $converter); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testStandardToFlatConverterRegisters() |
36
|
|
|
{ |
37
|
|
|
self::bootKernel(); |
38
|
|
|
$container = self::$container; |
39
|
|
|
|
40
|
|
|
$registryValueConverter = $container->get('pim_connector.array_converter.standard_to_flat.product.value_converter.registry'); |
41
|
|
|
|
42
|
|
|
$attribute = new Attribute(); |
43
|
|
|
$attribute->setAttributeType('flagbit_catalog_table'); |
44
|
|
|
|
45
|
|
|
$converter = $registryValueConverter->getConverter($attribute); |
46
|
|
|
|
47
|
|
|
self::assertInstanceOf(StandardToFlatTextConverter::class, $converter); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testAttributeComparedSuccessfully() |
51
|
|
|
{ |
52
|
|
|
self::bootKernel(); |
53
|
|
|
$container = self::$container; |
54
|
|
|
|
55
|
|
|
$registryComparator = $container->get('pim_catalog.comparator.registry'); |
56
|
|
|
|
57
|
|
|
$comparator = $registryComparator->getAttributeComparator('flagbit_catalog_table'); |
58
|
|
|
|
59
|
|
|
self::assertInstanceOf(ScalarComparator::class, $comparator); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testScalarValueCreated() |
63
|
|
|
{ |
64
|
|
|
self::bootKernel(); |
65
|
|
|
$container = self::$container; |
66
|
|
|
|
67
|
|
|
$valueFactory = $container->get('akeneo.pim.enrichment.factory.value'); |
68
|
|
|
|
69
|
|
|
$attribute = new PublicApiAttribute( |
70
|
|
|
'foo', |
71
|
|
|
'flagbit_catalog_table', |
72
|
|
|
[], |
73
|
|
|
false, |
74
|
|
|
false, |
75
|
|
|
null, |
76
|
|
|
null, |
77
|
|
|
'flagbit_catalog_table', |
78
|
|
|
[] |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$value = $valueFactory->createWithoutCheckingData($attribute, null, null, '{}'); |
82
|
|
|
|
83
|
|
|
self::assertEquals(ScalarValue::value('foo', '{}'), $value); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testProductUpdatedSuccessfully() |
87
|
|
|
{ |
88
|
|
|
self::bootKernel(); |
89
|
|
|
$container = self::$container; |
90
|
|
|
|
91
|
|
|
$repository = $this->createMock(IdentifiableObjectRepositoryInterface::class); |
92
|
|
|
|
93
|
|
|
$container->set('pim_catalog.repository.cached_attribute', $repository); |
94
|
|
|
|
95
|
|
|
$registryUpdater = $container->get('pim_catalog.updater.setter.registry'); |
96
|
|
|
|
97
|
|
|
$attribute = new Attribute(); |
98
|
|
|
$attribute->setAttributeType('flagbit_catalog_table'); |
99
|
|
|
|
100
|
|
|
$updater = $registryUpdater->getAttributeSetter($attribute); |
101
|
|
|
|
102
|
|
|
self::assertInstanceOf(AttributeSetter::class, $updater); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testSupportsTableMaskItem() |
106
|
|
|
{ |
107
|
|
|
self::bootKernel(); |
108
|
|
|
$container = self::$container; |
109
|
|
|
|
110
|
|
|
$maskItemGenerator = $container->get('akeneo.pim.enrichment.completeness.mask_item_generator.generator'); |
111
|
|
|
|
112
|
|
|
$tableMask = $maskItemGenerator->generate('code', TableType::FLAGBIT_CATALOG_TABLE, 'channel', 'locale', 'value'); |
113
|
|
|
|
114
|
|
|
self::assertSame(['code-channel-locale'], $tableMask); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testSupportsTableValueFactory() |
118
|
|
|
{ |
119
|
|
|
self::bootKernel(); |
120
|
|
|
$container = self::$container; |
121
|
|
|
|
122
|
|
|
$attribute = new PublicApiAttribute( |
123
|
|
|
'foo', |
124
|
|
|
'flagbit_catalog_table', |
125
|
|
|
[], |
126
|
|
|
false, |
127
|
|
|
false, |
128
|
|
|
null, |
129
|
|
|
null, |
130
|
|
|
'flagbit_catalog_table', |
131
|
|
|
[] |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
$valueFactory = $container->get('akeneo.pim.enrichment.factory.value'); |
135
|
|
|
|
136
|
|
|
$tableValue = $valueFactory->createByCheckingData($attribute, null, null, '{}'); |
137
|
|
|
|
138
|
|
|
self::assertInstanceOf(ScalarValue::class, $tableValue); |
139
|
|
|
self::assertSame('foo', $tableValue->getAttributeCode()); |
140
|
|
|
self::assertSame('{}', $tableValue->getData()); |
141
|
|
|
|
142
|
|
|
$tableValue = $valueFactory->createWithoutCheckingData($attribute, null, null, '{}'); |
143
|
|
|
|
144
|
|
|
self::assertInstanceOf(ScalarValue::class, $tableValue); |
145
|
|
|
self::assertSame('foo', $tableValue->getAttributeCode()); |
146
|
|
|
self::assertSame('{}', $tableValue->getData()); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @dataProvider queryBuildersProvider |
151
|
|
|
*/ |
152
|
|
|
public function testQueryBuilderFiltersCorrectly($operator, $service) |
153
|
|
|
{ |
154
|
|
|
self::bootKernel(); |
155
|
|
|
$container = self::$container; |
156
|
|
|
|
157
|
|
|
$attribute = new Attribute(); |
158
|
|
|
$attribute->setType('flagbit_catalog_table'); |
159
|
|
|
|
160
|
|
|
$repository = $this->createMock(AttributeRepositoryInterface::class); |
161
|
|
|
$repository->expects(self::once()) |
162
|
|
|
->method('findOneBy') |
163
|
|
|
->willReturn($attribute); |
164
|
|
|
|
165
|
|
|
$container->set('pim_catalog.repository.attribute', $repository); |
166
|
|
|
|
167
|
|
|
/** @var FilterRegistry $filterRegistry */ |
168
|
|
|
$filterRegistry = $container->get($service); |
169
|
|
|
|
170
|
|
|
$filter = $filterRegistry->getFilter('flagbit_catalog_table', $operator); |
171
|
|
|
|
172
|
|
|
self::assertInstanceOf(OptionFilter::class, $filter); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @dataProvider queryBuildersProvider |
177
|
|
|
*/ |
178
|
|
|
public function testQueryBuilderAttributeFiltersCorrectly($operator, $service) |
179
|
|
|
{ |
180
|
|
|
self::bootKernel(); |
181
|
|
|
$container = self::$container; |
182
|
|
|
|
183
|
|
|
$attribute = new Attribute(); |
184
|
|
|
$attribute->setType('flagbit_catalog_table'); |
185
|
|
|
|
186
|
|
|
/** @var FilterRegistry $filterRegistry */ |
187
|
|
|
$filterRegistry = $container->get($service); |
188
|
|
|
|
189
|
|
|
$filter = $filterRegistry->getAttributeFilter($attribute, $operator); |
190
|
|
|
|
191
|
|
|
self::assertInstanceOf(OptionFilter::class, $filter); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function queryBuildersProvider() |
195
|
|
|
{ |
196
|
|
|
return [ |
197
|
|
|
['IN', 'pim_catalog.query.filter.product_registry'], |
198
|
|
|
['EMPTY', 'pim_catalog.query.filter.product_registry'], |
199
|
|
|
['NOT EMPTY', 'pim_catalog.query.filter.product_registry'], |
200
|
|
|
['NOT IN', 'pim_catalog.query.filter.product_registry'], |
201
|
|
|
['IN', 'pim_catalog.query.filter.product_model_registry'], |
202
|
|
|
['EMPTY', 'pim_catalog.query.filter.product_model_registry'], |
203
|
|
|
['NOT EMPTY', 'pim_catalog.query.filter.product_model_registry'], |
204
|
|
|
['NOT IN', 'pim_catalog.query.filter.product_model_registry'], |
205
|
|
|
['IN', 'pim_catalog.query.filter.product_and_product_model_registry'], |
206
|
|
|
['EMPTY', 'pim_catalog.query.filter.product_and_product_model_registry'], |
207
|
|
|
['NOT EMPTY', 'pim_catalog.query.filter.product_and_product_model_registry'], |
208
|
|
|
['NOT IN', 'pim_catalog.query.filter.product_and_product_model_registry'], |
209
|
|
|
// service doesn't exist in community. See tests/Kernel/config/packages/test/ee-services.yml |
210
|
|
|
['IN', 'pimee_workflow.query.filter.product_proposal_registry'], |
211
|
|
|
['EMPTY', 'pimee_workflow.query.filter.product_proposal_registry'], |
212
|
|
|
['NOT EMPTY', 'pimee_workflow.query.filter.product_proposal_registry'], |
213
|
|
|
['NOT IN', 'pimee_workflow.query.filter.product_proposal_registry'], |
214
|
|
|
// service doesn't exist in community. See tests/Kernel/config/packages/test/ee-services.yml |
215
|
|
|
['IN', 'pimee_workflow.query.filter.published_product_registry'], |
216
|
|
|
['EMPTY', 'pimee_workflow.query.filter.published_product_registry'], |
217
|
|
|
['NOT EMPTY', 'pimee_workflow.query.filter.published_product_registry'], |
218
|
|
|
['NOT IN', 'pimee_workflow.query.filter.published_product_registry'], |
219
|
|
|
]; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|