6 declare(strict_types=1);
17 as FieldTypeConverterInterface;
19 as IndexTypeConverterInterface;
41 private $groupRepository;
46 private $searchCriteriaBuilder;
51 private $fieldTypeConverter;
56 private $indexTypeConverter;
61 private $attributeAdapterProvider;
66 private $categoryList;
71 private $fieldNameResolver;
80 $this->groupRepository = $this->getMockBuilder(GroupRepositoryInterface::class)
81 ->disableOriginalConstructor()
83 $this->searchCriteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class)
84 ->disableOriginalConstructor()
86 $this->fieldTypeConverter = $this->getMockBuilder(FieldTypeConverterInterface::class)
87 ->disableOriginalConstructor()
89 $this->indexTypeConverter = $this->getMockBuilder(IndexTypeConverterInterface::class)
90 ->disableOriginalConstructor()
92 $this->attributeAdapterProvider = $this->getMockBuilder(AttributeProvider::class)
93 ->disableOriginalConstructor()
94 ->setMethods([
'getByAttributeCode',
'getByAttribute'])
96 $this->fieldNameResolver = $this->getMockBuilder(FieldNameResolver::class)
97 ->disableOriginalConstructor()
98 ->setMethods([
'getFieldName'])
100 $this->categoryList = $this->getMockBuilder(CategoryListInterface::class)
101 ->disableOriginalConstructor()
107 \
Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\DynamicField::class,
109 'groupRepository' => $this->groupRepository,
110 'searchCriteriaBuilder' => $this->searchCriteriaBuilder,
111 'fieldTypeConverter' => $this->fieldTypeConverter,
112 'indexTypeConverter' => $this->indexTypeConverter,
113 'attributeAdapterProvider' => $this->attributeAdapterProvider,
114 'categoryList' => $this->categoryList,
115 'fieldNameResolver' => $this->fieldNameResolver,
136 ->disableOriginalConstructor()
138 $this->searchCriteriaBuilder->expects($this->any())
141 $categorySearchResults = $this->getMockBuilder(CategorySearchResultsInterface::class)
142 ->disableOriginalConstructor()
143 ->setMethods([
'getItems'])
144 ->getMockForAbstractClass();
145 $groupSearchResults = $this->getMockBuilder(GroupSearchResultsInterface::class)
146 ->disableOriginalConstructor()
147 ->setMethods([
'getItems'])
148 ->getMockForAbstractClass();
149 $group = $this->getMockBuilder(GroupInterface::class)
150 ->disableOriginalConstructor()
151 ->setMethods([
'getId'])
152 ->getMockForAbstractClass();
153 $group->expects($this->any())
156 $groupSearchResults->expects($this->any())
159 $category = $this->getMockBuilder(CategoryInterface::class)
160 ->disableOriginalConstructor()
161 ->setMethods([
'getId'])
162 ->getMockForAbstractClass();
165 ->willReturn($categoryId);
166 $categorySearchResults->expects($this->any())
169 $this->categoryList->expects($this->any())
171 ->willReturn($categorySearchResults);
173 $categoryAttributeMock = $this->getMockBuilder(AttributeAdapter::class)
174 ->disableOriginalConstructor()
175 ->setMethods([
'getAttributeCode'])
177 $categoryAttributeMock->expects($this->any())
178 ->method(
'getAttributeCode')
179 ->willReturn(
'category');
180 $positionAttributeMock = $this->getMockBuilder(AttributeAdapter::class)
181 ->disableOriginalConstructor()
182 ->setMethods([
'getAttributeCode'])
184 $positionAttributeMock->expects($this->any())
185 ->method(
'getAttributeCode')
186 ->willReturn(
'position');
188 $this->fieldNameResolver->expects($this->any())
189 ->method(
'getFieldName')
190 ->will($this->returnCallback(
192 static $callCount = [];
197 return 'category_name_' . $categoryId;
199 return 'position_' . $categoryId;
201 return 'price_' . $categoryId .
'_1';
205 $priceAttributeMock = $this->getMockBuilder(AttributeAdapter::class)
206 ->disableOriginalConstructor()
207 ->setMethods([
'getAttributeCode'])
209 $priceAttributeMock->expects($this->any())
210 ->method(
'getAttributeCode')
211 ->willReturn(
'price');
212 $this->indexTypeConverter->expects($this->any())
214 ->willReturn(
'no_index');
215 $this->groupRepository->expects($this->any())
217 ->willReturn($groupSearchResults);
218 $this->attributeAdapterProvider->expects($this->any())
219 ->method(
'getByAttributeCode')
220 ->with($this->anything())
221 ->will($this->returnCallback(
222 function (
$code) use (
223 $categoryAttributeMock,
224 $positionAttributeMock,
227 static $callCount = [];
228 $callCount[
$code] = !isset($callCount[
$code]) ? 1 : ++$callCount[
$code];
230 if (
$code ===
'position') {
231 return $positionAttributeMock;
233 return $categoryAttributeMock;
235 return $priceAttributeMock;
239 $this->fieldTypeConverter->expects($this->any())
241 ->with($this->anything())
242 ->will($this->returnCallback(
243 function (
$type) use ($complexType) {
244 static $callCount = [];
245 $callCount[
$type] = !isset($callCount[
$type]) ? 1 : ++$callCount[
$type];
247 if (
$type ===
'string') {
250 if (
$type ===
'string') {
262 $this->provider->getFields([
'websiteId' => 1])
277 'category_name_1' => [
279 'index' =>
'no_index' 283 'index' =>
'no_index' 296 'category_name_1' => [
298 'index' =>
'no_index' 302 'index' =>
'no_index' 315 'category_name_1' => [
317 'index' =>
'no_index' 321 'index' =>
'no_index'
elseif(isset( $params[ 'redirect_parent']))
testGetAllAttributesTypes( $complexType, $categoryId, $groupId, $expected)