|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Flagbit\Bundle\TableAttributeBundle\Test\Pim; |
|
4
|
|
|
|
|
5
|
|
|
use Akeneo\Component\StorageUtils\Repository\IdentifiableObjectRepositoryInterface; |
|
6
|
|
|
use Pim\Bundle\CatalogBundle\Elasticsearch\Filter\Attribute\OptionFilter; |
|
7
|
|
|
use Pim\Bundle\CatalogBundle\Entity\Attribute; |
|
8
|
|
|
use Pim\Component\Catalog\Comparator\Attribute\ScalarComparator; |
|
9
|
|
|
use Pim\Component\Catalog\Query\Filter\FilterRegistry; |
|
10
|
|
|
use Pim\Component\Catalog\Repository\AttributeRepositoryInterface; |
|
11
|
|
|
use Pim\Component\Catalog\Updater\Setter\AttributeSetter; |
|
12
|
|
|
use Pim\Component\Catalog\Value\ScalarValue; |
|
13
|
|
|
use Pim\Component\Connector\ArrayConverter\FlatToStandard\Product\ValueConverter\TextConverter as FlatToStandardTextConverter; |
|
14
|
|
|
use Pim\Component\Connector\ArrayConverter\StandardToFlat\Product\ValueConverter\TextConverter as StandardToFlatTextConverter; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
16
|
|
|
|
|
17
|
|
|
class PimTest extends KernelTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
public function testFlatToStandardConverterRegisters() |
|
21
|
|
|
{ |
|
22
|
|
|
self::bootKernel(); |
|
23
|
|
|
$container = self::$kernel->getContainer(); |
|
24
|
|
|
|
|
25
|
|
|
$registryValueConverter = $container->get('pim_connector.array_converter.flat_to_standard.product.value_converter.registry'); |
|
26
|
|
|
|
|
27
|
|
|
$converter = $registryValueConverter->getConverter('flagbit_catalog_table'); |
|
28
|
|
|
|
|
29
|
|
|
self::assertInstanceOf(FlatToStandardTextConverter::class, $converter); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testStandardToFlatConverterRegisters() |
|
33
|
|
|
{ |
|
34
|
|
|
self::bootKernel(); |
|
35
|
|
|
$container = self::$kernel->getContainer(); |
|
36
|
|
|
|
|
37
|
|
|
$registryValueConverter = $container->get('pim_connector.array_converter.standard_to_flat.product.value_converter.registry'); |
|
38
|
|
|
|
|
39
|
|
|
$attribute = new Attribute(); |
|
40
|
|
|
$attribute->setAttributeType('flagbit_catalog_table'); |
|
41
|
|
|
|
|
42
|
|
|
$converter = $registryValueConverter->getConverter($attribute); |
|
43
|
|
|
|
|
44
|
|
|
self::assertInstanceOf(StandardToFlatTextConverter::class, $converter); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testAttributeComparedSuccessfully() |
|
48
|
|
|
{ |
|
49
|
|
|
self::bootKernel(); |
|
50
|
|
|
$container = self::$kernel->getContainer(); |
|
51
|
|
|
|
|
52
|
|
|
$registryComparator = $container->get('pim_catalog.comparator.registry'); |
|
53
|
|
|
|
|
54
|
|
|
$comparator = $registryComparator->getAttributeComparator('flagbit_catalog_table'); |
|
55
|
|
|
|
|
56
|
|
|
self::assertInstanceOf(ScalarComparator::class, $comparator); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testScalarValueCreated() |
|
60
|
|
|
{ |
|
61
|
|
|
self::bootKernel(); |
|
62
|
|
|
$container = self::$kernel->getContainer(); |
|
63
|
|
|
|
|
64
|
|
|
$valueFactory = $container->get('pim_catalog.factory.value'); |
|
65
|
|
|
|
|
66
|
|
|
$attribute = new Attribute(); |
|
67
|
|
|
$attribute->setAttributeType('flagbit_catalog_table'); |
|
68
|
|
|
$attribute->setLocalizable(false); |
|
69
|
|
|
$attribute->setScopable(false); |
|
70
|
|
|
|
|
71
|
|
|
$value = $valueFactory->create($attribute, null, null, '{}'); |
|
72
|
|
|
|
|
73
|
|
|
self::assertInstanceOf(ScalarValue::class, $value); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testProductUpdatedSuccessfully() |
|
77
|
|
|
{ |
|
78
|
|
|
self::bootKernel(); |
|
79
|
|
|
$container = self::$kernel->getContainer(); |
|
80
|
|
|
|
|
81
|
|
|
$repository = $this->createMock(IdentifiableObjectRepositoryInterface::class); |
|
82
|
|
|
|
|
83
|
|
|
$container->set('pim_catalog.repository.cached_attribute', $repository); |
|
84
|
|
|
|
|
85
|
|
|
$registryUpdater = $container->get('pim_catalog.updater.setter.registry'); |
|
86
|
|
|
|
|
87
|
|
|
$attribute = new Attribute(); |
|
88
|
|
|
$attribute->setAttributeType('flagbit_catalog_table'); |
|
89
|
|
|
|
|
90
|
|
|
$updater = $registryUpdater->getAttributeSetter($attribute); |
|
91
|
|
|
|
|
92
|
|
|
self::assertInstanceOf(AttributeSetter::class, $updater); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @dataProvider queryBuildersProvider |
|
97
|
|
|
*/ |
|
98
|
|
|
public function testQueryBuilderFiltersCorrectly($operator, $service) |
|
99
|
|
|
{ |
|
100
|
|
|
self::bootKernel(); |
|
101
|
|
|
$container = self::$kernel->getContainer(); |
|
102
|
|
|
|
|
103
|
|
|
$attribute = new Attribute(); |
|
104
|
|
|
$attribute->setType('flagbit_catalog_table'); |
|
105
|
|
|
|
|
106
|
|
|
$repository = $this->createMock(AttributeRepositoryInterface::class); |
|
107
|
|
|
$repository->expects(self::once()) |
|
108
|
|
|
->method('findOneBy') |
|
109
|
|
|
->willReturn($attribute); |
|
110
|
|
|
|
|
111
|
|
|
$container->set('pim_catalog.repository.attribute', $repository); |
|
112
|
|
|
|
|
113
|
|
|
/** @var FilterRegistry $filterRegistry */ |
|
114
|
|
|
$filterRegistry = $container->get($service); |
|
115
|
|
|
|
|
116
|
|
|
$filter = $filterRegistry->getFilter('flagbit_catalog_table', $operator); |
|
117
|
|
|
|
|
118
|
|
|
self::assertInstanceOf(OptionFilter::class, $filter); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function queryBuildersProvider() |
|
122
|
|
|
{ |
|
123
|
|
|
return [ |
|
124
|
|
|
['IN', 'pim_catalog.query.filter.product_registry'], |
|
125
|
|
|
['EMPTY', 'pim_catalog.query.filter.product_registry'], |
|
126
|
|
|
['NOT EMPTY', 'pim_catalog.query.filter.product_registry'], |
|
127
|
|
|
['NOT IN', 'pim_catalog.query.filter.product_registry'], |
|
128
|
|
|
['IN', 'pim_catalog.query.filter.product_model_registry'], |
|
129
|
|
|
['EMPTY', 'pim_catalog.query.filter.product_model_registry'], |
|
130
|
|
|
['NOT EMPTY', 'pim_catalog.query.filter.product_model_registry'], |
|
131
|
|
|
['NOT IN', 'pim_catalog.query.filter.product_model_registry'], |
|
132
|
|
|
['IN', 'pim_catalog.query.filter.product_and_product_model_registry'], |
|
133
|
|
|
['EMPTY', 'pim_catalog.query.filter.product_and_product_model_registry'], |
|
134
|
|
|
['NOT EMPTY', 'pim_catalog.query.filter.product_and_product_model_registry'], |
|
135
|
|
|
['NOT IN', 'pim_catalog.query.filter.product_and_product_model_registry'], |
|
136
|
|
|
]; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|