public function testResolve()
 {
     $documentIds = [1, 2, 3];
     $attributeSetIds = [4, 5];
     $requestName = 'request_name';
     $this->attributeSetFinder->expects($this->once())->method('findAttributeSetIdsByProductIds')->with($documentIds)->willReturn($attributeSetIds);
     $searchCriteria = $this->getMock(SearchCriteriaInterface::class);
     $this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with('attribute_set_id', $attributeSetIds, 'in')->willReturnSelf();
     $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
     $attributeFirst = $this->getMock(ProductAttributeInterface::class);
     $attributeFirst->expects($this->once())->method('getAttributeCode')->willReturn('code_1');
     $attributeSecond = $this->getMock(ProductAttributeInterface::class);
     $attributeSecond->expects($this->once())->method('getAttributeCode')->willReturn('code_2');
     $searchResult = $this->getMock(ProductAttributeSearchResultsInterface::class);
     $searchResult->expects($this->once())->method('getItems')->willReturn([$attributeFirst, $attributeSecond]);
     $this->productAttributeRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($searchResult);
     $bucketFirst = $this->getMock(BucketInterface::class);
     $bucketFirst->expects($this->once())->method('getField')->willReturn('code_1');
     $bucketSecond = $this->getMock(BucketInterface::class);
     $bucketSecond->expects($this->once())->method('getField')->willReturn('some_another_code');
     $bucketThird = $this->getMock(BucketInterface::class);
     $bucketThird->expects($this->once())->method('getName')->willReturn('custom_not_attribute_field');
     $this->request->expects($this->once())->method('getAggregation')->willReturn([$bucketFirst, $bucketSecond, $bucketThird]);
     $this->request->expects($this->once())->method('getName')->willReturn($requestName);
     $this->config->expects($this->once())->method('get')->with($requestName)->willReturn(['aggregations' => ['custom_not_attribute_field' => []]]);
     $this->assertEquals([$bucketFirst, $bucketThird], $this->aggregationResolver->resolve($this->request, $documentIds));
 }
Пример #2
0
 public function testPrepareDataSource()
 {
     $name = 'some_name';
     $initialData = ['data' => ['items' => [['attribute1_1_code' => 'attribute1_1_option2'], ['attribute2_1_code' => 'attribute2_1_option3'], ['attribute3_1_code' => 'attribute3_1_option3', 'attribute3_2_code' => 'attribute3_2_option1']]]];
     $attributes = [$this->createAttributeMock('attribute1_1_code', 'attribute1_1_label', [$this->createAttributeOptionMock('attribute1_1_option1', 'attribute1_1_option1_label'), $this->createAttributeOptionMock('attribute1_1_option2', 'attribute1_1_option2_label')]), $this->createAttributeMock('attribute2_1_code', 'attribute2_1_label', [$this->createAttributeOptionMock('attribute2_1_option1', 'attribute2_1_option1_label'), $this->createAttributeOptionMock('attribute2_1_option2', 'attribute2_1_option2_label')]), $this->createAttributeMock('attribute3_1_code', 'attribute3_1_label', [$this->createAttributeOptionMock('attribute3_1_option1', 'attribute3_1_option1_label'), $this->createAttributeOptionMock('attribute3_1_option2', 'attribute3_1_option2_label'), $this->createAttributeOptionMock('attribute3_1_option3', 'attribute3_1_option3_label')]), $this->createAttributeMock('attribute3_2_code', 'attribute3_2_label', [$this->createAttributeOptionMock('attribute3_2_option1', 'attribute3_2_option1_label'), $this->createAttributeOptionMock('attribute3_2_option2', 'attribute3_2_option2_label'), $this->createAttributeOptionMock('attribute3_2_option3', 'attribute3_2_option3_label')]), $this->createAttributeMock('attribute4_1_code', 'attribute4_1_label')];
     $resultData = ['data' => ['items' => [['attribute1_1_code' => 'attribute1_1_option2', $name => 'attribute1_1_label: attribute1_1_option2_label'], ['attribute2_1_code' => 'attribute2_1_option3', $name => ''], ['attribute3_1_code' => 'attribute3_1_option3', 'attribute3_2_code' => 'attribute3_2_option1', $name => 'attribute3_1_label: attribute3_1_option3_label,' . ' attribute3_2_label: attribute3_2_option1_label']]]];
     $this->attributesColumn->setData('name', $name);
     $this->attributeRepositoryMock->expects(static::any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultsMock);
     $this->searchResultsMock->expects(static::any())->method('getItems')->willReturn($attributes);
     $this->assertSame($resultData, $this->attributesColumn->prepareDataSource($initialData));
 }
 public function testGenerateVariation()
 {
     $data = ['someKey' => 'someValue'];
     $attributeOption = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Option', [], [], '', false);
     $attributeOption->expects($this->once())->method('getData')->willReturn(['key' => 'value']);
     $attribute = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
     $attribute->expects($this->any())->method('getOptions')->willReturn([$attributeOption]);
     $attribute->expects($this->once())->method('getAttributeCode')->willReturn(10);
     $this->option->expects($this->any())->method('getAttributeId')->willReturn(1);
     $this->attributeRepository->expects($this->once())->method('get')->with(1)->willReturn($attribute);
     $this->option->expects($this->any())->method('getData')->willReturn($data);
     $expectedAttributes = [1 => ['someKey' => 'someValue', 'options' => [['key' => 'value']], 'attribute_code' => 10]];
     $this->productVariationBuilder->expects($this->once())->method('create')->with($this->product, $expectedAttributes)->willReturn(['someObject']);
     $expected = ['someObject'];
     $this->assertEquals($expected, $this->model->generateVariation($this->product, [$this->option]));
 }
 /**
  * Mock for options save
  *
  * @param MockObject $attribute
  * @param MockObject $product
  * @param $attributeId
  * @param $sku
  * @param $id
  * @return void
  */
 private function processSaveOptions(MockObject $attribute, MockObject $product, $attributeId, $sku, $id)
 {
     $attribute->expects(static::once())->method('getAttributeId')->willReturn($attributeId);
     $eavAttribute = $this->getMock(ProductAttributeInterface::class);
     $this->productAttributeRepository->expects(static::once())->method('get')->with($attributeId)->willReturn($eavAttribute);
     $attribute->expects(static::once())->method('loadByProductAndAttribute')->with($product, $eavAttribute)->willReturnSelf();
     $this->optionRepository->expects(static::once())->method('save')->with($sku, $attribute)->willReturn($id);
 }
 /**
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Products "5" and "4" have the same set of attribute values.
  */
 public function testAroundSaveWithLinksWithDuplicateAttributes()
 {
     $links = [4, 5];
     $attributeCode = 'color';
     $attributeId = 23;
     $this->option->expects(static::once())->method('getAttributeId')->willReturn($attributeId);
     $this->product->expects(static::once())->method('getTypeId')->willReturn(Configurable::TYPE_CODE);
     $this->result->expects(static::once())->method('getExtensionAttributes')->willReturn($this->extensionAttributes);
     $this->extensionAttributes->expects(static::once())->method('getConfigurableProductOptions')->willReturn([$this->option]);
     $this->extensionAttributes->expects(static::once())->method('getConfigurableProductLinks')->willReturn($links);
     $this->productAttributeRepository->expects(static::once())->method('get')->willReturn($this->eavAttribute);
     $this->eavAttribute->expects(static::once())->method('getAttributeCode')->willReturn($attributeCode);
     $product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->setMethods(['load', 'getData', '__wakeup'])->getMock();
     $this->productFactory->expects(static::exactly(2))->method('create')->willReturn($product);
     $product->expects(static::exactly(2))->method('load')->willReturnSelf();
     $product->expects(static::exactly(4))->method('getData')->with($attributeCode)->willReturn($attributeId);
     $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product);
 }
Пример #6
0
 /**
  * @covers \Magento\ConfigurableProduct\Helper\Product\Options\Factory::create
  */
 public function testCreate()
 {
     $attributeId = 90;
     $valueIndex = 12;
     $item = ['attribute_id' => $attributeId, 'values' => [['value_index' => $valueIndex]]];
     $data = [$item];
     $attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->setMethods(['setValues', 'setData', '__wakeup'])->getMock();
     $this->attributeFactory->expects(static::once())->method('create')->willReturn($attribute);
     $eavAttribute = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock();
     $this->productAttributeRepository->expects(static::once())->method('get')->with($attributeId)->willReturn($eavAttribute);
     $this->configurable->expects(static::once())->method('canUseAttribute')->with($eavAttribute)->willReturn(true);
     $option = $this->getMock(OptionValueInterface::class);
     $option->expects(static::once())->method('setValueIndex')->with($valueIndex)->willReturnSelf();
     $this->optionValueFactory->expects(static::once())->method('create')->willReturn($option);
     $attribute->expects(static::once())->method('setData')->with($item);
     $attribute->expects(static::once())->method('setValues')->with([$option]);
     $result = $this->factory->create($data);
     static::assertSame([$attribute], $result);
 }
Пример #7
0
 public function testModifyData()
 {
     $sourceData = ['1' => ['product' => [ProductAttributeInterface::CODE_PRICE => '19.99']]];
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->any())->method('getId')->willReturn(1);
     $this->productMock->expects($this->once())->method('getAttributeSetId')->willReturn(4);
     $this->productMock->expects($this->once())->method('getData')->with(ProductAttributeInterface::CODE_PRICE)->willReturn('19.9900');
     $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
     $this->attributeGroupRepositoryMock->expects($this->any())->method('getList')->willReturn($this->searchCriteriaMock);
     $this->searchCriteriaMock->expects($this->once())->method('getItems')->willReturn([$this->attributeGroupMock]);
     $this->sortOrderBuilderMock->expects($this->once())->method('setField')->willReturnSelf();
     $this->sortOrderBuilderMock->expects($this->once())->method('setAscendingDirection')->willReturnSelf();
     $dataObjectMock = $this->getMock('\\Magento\\Framework\\Api\\AbstractSimpleObject', [], [], '', false);
     $this->sortOrderBuilderMock->expects($this->once())->method('create')->willReturn($dataObjectMock);
     $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->once())->method('addSortOrder')->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
     $this->attributeRepositoryMock->expects($this->once())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultsMock);
     $this->eavAttributeMock->expects($this->any())->method('getAttributeGroupCode')->willReturn('product-details');
     $this->eavAttributeMock->expects($this->once())->method('getApplyTo')->willReturn([]);
     $this->eavAttributeMock->expects($this->once())->method('getFrontendInput')->willReturn('price');
     $this->eavAttributeMock->expects($this->any())->method('getAttributeCode')->willReturn(ProductAttributeInterface::CODE_PRICE);
     $this->searchResultsMock->expects($this->once())->method('getItems')->willReturn([$this->eavAttributeMock]);
     $this->storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('en_US');
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
     $this->currencyMock->expects($this->once())->method('toCurrency')->willReturn('19.99');
     $this->currencyLocaleMock->expects($this->once())->method('getCurrency')->willReturn($this->currencyMock);
     $this->assertEquals($sourceData, $this->eav->modifyData([]));
 }