public function testAroundRenderFalse() { $attributeMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $this->filterMock->expects($this->atLeastOnce())->method('getAttributeModel')->willReturn($attributeMock); $this->filterMock->expects($this->once())->method('hasAttributeModel')->willReturn(true); $this->swatchHelperMock->expects($this->once())->method('isSwatchAttribute')->with($attributeMock)->willReturn(false); $result = $this->plugin->aroundRender($this->filterRendererMock, $this->closureMock, $this->filterMock); $this->assertEquals($result, $this->filterMock); }
protected function canReplaceImageWithSwatch($expected) { $this->swatchesHelperMock->expects($this->once())->method('isSwatchAttribute')->with($this->attributeMock)->willReturn($expected['isSwatchAttribute']); $this->attributeMock->expects($this->exactly($expected['getUsedInProductListing_count']))->method('getUsedInProductListing')->willReturn($expected['getUsedInProductListing']); $this->attributeMock->expects($this->exactly($expected['getIsFilterable_count']))->method('getIsFilterable')->willReturn($expected['getIsFilterable']); if ($expected['update_product_preview_image__count'] == 1) { $this->attributeMock->method('getData')->with('update_product_preview_image')->willReturn($expected['update_product_preview_image']); } }
public function testExecuteNullProduct() { $this->productMock->expects($this->once())->method('load')->with(59)->willReturn($this->productMock); $this->productModelFactoryMock->expects($this->once())->method('create')->willReturn($this->productMock); $this->swatchHelperMock->expects($this->once())->method('getAttributesFromConfigurable')->with($this->productMock)->willReturn([$this->attributeMock]); $this->swatchHelperMock->expects($this->once())->method('loadVariationByFallback')->with($this->productMock, ['size' => 454])->willReturn(null); $this->swatchHelperMock->expects($this->once())->method('getProductMediaGallery')->with($this->productMock)->willReturn($this->mediaGallery); $this->jsonMock->expects($this->once())->method('setData')->with($this->mediaGallery)->will($this->returnSelf()); $result = $this->controller->execute(); $this->assertInstanceOf('\\Magento\\Framework\\Controller\\Result\\Json', $result); }
public function testGetAttributes() { $ids = [1, 2, 3]; $result = [['id' => 'id', 'label' => 'label', 'code' => 'code', 'options' => ['options'], 'canCreateOption' => false]]; $this->collectionMock->expects($this->any())->method('addFieldToFilter')->with('main_table.attribute_id', $ids); $this->attributeMock->expects($this->once())->method('getId')->will($this->returnValue('id')); $this->attributeMock->expects($this->once())->method('getFrontendLabel')->will($this->returnValue('label')); $this->attributeMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue('code')); $source = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource', [], [], '', false); $source->expects($this->once())->method('getAllOptions')->with(false)->will($this->returnValue(['options'])); $this->attributeMock->expects($this->once())->method('getSource')->will($this->returnValue($source)); $this->swatchHelper->expects($this->once())->method('isSwatchAttribute')->with($this->attributeMock)->willReturn(true); $this->assertEquals($result, $this->attributeListModel->getAttributes($ids)); }
public function testAfterGetUsedProductCollection() { $subject = $this->getMock('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false); $result = $this->getMock('\\Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Product\\Collection', ['getEntity', 'addAttributeToSelect'], [], '', false); $collectionEntity = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', ['getType'], [], '', false); $collectionEntity->expects($this->once())->method('getType')->willReturn('catalog'); $result->expects($this->once())->method('getEntity')->willReturn($collectionEntity); $attribute = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $this->eavConfig->expects($this->once())->method('getEntityAttributeCodes')->with('catalog')->willReturn(['size', 'color', 'swatch1']); $this->eavConfig->expects($this->exactly(3))->method('getAttribute')->willReturn($attribute); $this->swatchHelper->expects($this->exactly(3))->method('isVisualSwatch')->with($attribute)->willReturn(true); $result->expects($this->once())->method('addAttributeToSelect')->with($this->identicalTo(['image', 'size', 'color', 'swatch1']))->willReturn($result); $result = $this->pluginModel->afterGetUsedProductCollection($subject, $result); $this->assertInstanceOf('\\Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Product\\Collection', $result); }
/** * @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData */ public function testGetJsonSwatchUsedInProductListing() { $products = [1 => 'testA', 3 => 'testB']; $expected = ['type' => null, 'value' => 'hello', 'label' => $products[3]]; $this->prepareGetJsonSwatchConfig(); $this->configurable->setProduct($this->product); $this->swatchHelper->expects($this->once())->method('getSwatchAttributesAsArray')->with($this->product)->willReturn([1 => ['options' => $products, 'use_product_image_for_swatch' => true, 'used_in_product_listing' => true, 'attribute_code' => 'code']]); $this->swatchHelper->expects($this->once())->method('getSwatchesByOptionsId')->with([1, 3])->willReturn([3 => ['type' => $expected['type'], 'value' => $expected['value']]]); $this->jsonEncoder->expects($this->once())->method('encode'); $this->configurable->getJsonSwatchConfig(); }
public function testGetJsonSwatchConfigWithoutVisualImageType() { $this->configurable->setProduct($this->product); $this->swatchHelper->expects($this->once())->method('getSwatchAttributesAsArray')->with($this->product)->willReturn([1 => ['options' => [1 => 'testA', 3 => 'testB'], 'use_product_image_for_swatch' => true, 'attribute_code' => 'code']]); $this->swatchHelper->expects($this->once())->method('getSwatchesByOptionsId')->with([1, 3])->willReturn([3 => ['type' => Swatch::SWATCH_TYPE_VISUAL_IMAGE, 'value' => 'hello']]); $this->swatchHelper->expects($this->once())->method('loadFirstVariationWithSwatchImage')->with($this->product, ['code' => 3])->willReturn($this->product); $this->swatchMediaHelper->expects($this->exactly(2))->method('getSwatchAttributeImage')->withConsecutive(['swatch_image', 'hello'], ['swatch_thumb', 'hello'])->willReturn('/path'); $this->product->expects($this->exactly(4))->method('getData')->withConsecutive(['swatch_image'], ['image'], ['swatch_image'], ['image'])->will($this->onConsecutiveCalls(null, null, null, null)); $this->imageHelper->expects($this->never())->method('init'); $this->imageHelper->expects($this->never())->method('resize'); $this->jsonEncoder->expects($this->once())->method('encode'); $this->configurable->getJsonSwatchConfig(); }
public function testAfterAfterSaveNotSwatchAttribute() { $this->abstractSource->expects($this->once())->method('getAllOptions')->willReturn($this->allOptions); $this->swatch->expects($this->once())->method('getId')->willReturn(1); $this->swatch->expects($this->once())->method('save'); $this->swatch->expects($this->once())->method('isDeleted')->with(false); $this->swatch->expects($this->exactly(2))->method('setData')->withConsecutive(['type', Swatch::SWATCH_TYPE_TEXTUAL], ['value', null]); $this->collection->expects($this->exactly(2))->method('addFieldToFilter')->withConsecutive(['option_id', self::OPTION_ID], ['store_id', self::OPTION_ID])->willReturnSelf(); $this->collection->expects($this->once())->method('getFirstItem')->willReturn($this->swatch); $this->collectionFactory->expects($this->once())->method('create')->willReturn($this->collection); $this->attribute->expects($this->at(0))->method('getData')->with('option')->willReturn($this->optionIds); $this->attribute->expects($this->at(1))->method('getSource')->willReturn($this->abstractSource); $this->attribute->expects($this->at(2))->method('getData')->with('swatch/value')->willReturn([self::STORE_ID => [self::OPTION_ID => null]]); $this->attribute->expects($this->at(3))->method('getData')->with('option/delete/' . self::OPTION_ID)->willReturn(false); $this->swatchHelper->expects($this->exactly(2))->method('isSwatchAttribute')->with($this->attribute)->will($this->onConsecutiveCalls(true, false)); $this->swatchHelper->expects($this->once())->method('isVisualSwatch')->with($this->attribute)->willReturn(false); $this->swatchHelper->expects($this->once())->method('isTextSwatch')->with($this->attribute)->willReturn(true); $this->eavAttribute->afterAfterSave($this->attribute); }