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 testGetValues() { $expected = [1, 2, 3]; $this->source->expects($this->once())->method('getAllOptions')->with(true, true)->willReturn($expected); $this->attribute->expects($this->once())->method('getSource')->willReturn($this->source); $this->swatch->expects($this->once())->method('getData')->with('entity_attribute')->willReturn($this->attribute); $method = new \ReflectionMethod('Magento\\Swatches\\Model\\Form\\Element\\AbstractSwatch', 'getValues'); $method->setAccessible(true); $this->assertEquals($expected, $method->invoke($this->swatch)); }
protected function setUp() { parent::setUp(); $this->sourceCountryMock = $this->getMockBuilder(SourceCountry::class)->disableOriginalConstructor()->getMock(); $this->eavAttributeFactoryMock = $this->getMockBuilder(EavAttributeFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->eavAttributeMock = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock(); $this->websiteManagerMock = $this->getMockBuilder(WebsiteManager::class)->disableOriginalConstructor()->getMock(); $this->eavAttributeFactoryMock->expects($this->any())->method('create')->willReturn($this->eavAttributeMock); $this->eavAttributeMock->expects($this->any())->method('loadByCode')->willReturn($this->eavAttributeMock); }
public function testExecute() { $this->attributeMock->expects($this->any())->method('offsetGet')->with('attribute_code')->willReturn('color'); $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, 'color' => 43])->willReturn($this->productMock); $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 testExecute() { $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['frontend_label', null, 'test_frontend_label'], ['attribute_code', null, 'test_attribute_code'], ['new_attribute_set_name', null, 'test_attribute_set_name']]); $this->objectManagerMock->expects($this->exactly(2))->method('create')->willReturnMap([['Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], $this->attributeMock], ['Magento\\Eav\\Model\\Entity\\Attribute\\Set', [], $this->attributeSetMock]]); $this->attributeMock->expects($this->once())->method('loadByCode')->willReturnSelf(); $this->requestMock->expects($this->once())->method('has')->with('new_attribute_set_name')->willReturn(true); $this->attributeSetMock->expects($this->once())->method('setEntityTypeId')->willReturnSelf(); $this->attributeSetMock->expects($this->once())->method('load')->willReturnSelf(); $this->attributeSetMock->expects($this->once())->method('getId')->willReturn(false); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($this->resultJson); $this->resultJson->expects($this->once())->method('setJsonData')->willReturnSelf(); $this->assertInstanceOf(ResultJson::class, $this->getModel()->execute()); }
public function testGetAttributes() { $ids = [1]; $result = [['id' => 'id', 'label' => 'label', 'code' => 'code', 'options' => ['options']]]; $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->assertEquals($result, $this->attributeListModel->getAttributes($ids)); }
public function testUpdateAttributes() { $productIds = [1, 2, 2, 4]; $productIdsUnique = [0 => 1, 1 => 2, 3 => 4]; $attrData = [1]; $storeId = 1; $this->resource->expects($this->any())->method('updateAttributes')->with($productIds, $attrData, $storeId)->will($this->returnSelf()); $this->categoryIndexer->expects($this->any())->method('isScheduled')->will($this->returnValue(false)); $this->categoryIndexer->expects($this->any())->method('reindexList')->will($this->returnValue($productIds)); $this->prepareIndexer(); $this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttribute)); $this->eavAttribute->expects($this->any())->method('isIndexable')->will($this->returnValue(false)); $this->assertEquals($this->model, $this->model->updateAttributes($productIds, $attrData, $storeId)); $this->assertEquals($this->model->getDataByKey('product_ids'), $productIdsUnique); $this->assertEquals($this->model->getDataByKey('attributes_data'), $attrData); $this->assertEquals($this->model->getDataByKey('store_id'), $storeId); }
/** * @dataProvider validateDataProvider * * @param string $attributeValue * @param string|array $parsedValue * @param string $newValue * @param string $operator * @param array $input * @return void */ public function testValidateWithDatetimeValue($attributeValue, $parsedValue, $newValue, $operator, $input) { $this->product->setData('attribute', 'attribute_key'); $this->product->setData('value_parsed', $parsedValue); $this->product->setData('operator', $operator); $this->config->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource)); $this->eavAttributeResource->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(false)); $this->eavAttributeResource->expects($this->any())->method($input['method'])->will($this->returnValue($input['type'])); $this->productModel->expects($this->any())->method('hasData')->will($this->returnValue(true)); $this->productModel->expects($this->at(0))->method('getData')->will($this->returnValue(['1' => ['1' => $attributeValue]])); $this->productModel->expects($this->any())->method('getData')->will($this->returnValue($newValue)); $this->productModel->expects($this->any())->method('getId')->will($this->returnValue('1')); $this->productModel->expects($this->once())->method('getStoreId')->will($this->returnValue('1')); $this->productModel->expects($this->any())->method('getResource')->will($this->returnValue($this->productResource)); $this->productResource->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource)); $this->product->collectValidatedAttributes($this->productModel); $this->assertTrue($this->product->validate($this->productModel)); }
/** * @dataProvider dataIsSwatchAttribute */ public function testIsSwatchAttribute($times, $swatchType, $boolResult) { $this->attributeMock->method('hasData')->with('swatch_input_type')->willReturn(true); $this->attributeMock->expects($this->exactly($times))->method('getData')->with('swatch_input_type')->willReturn($swatchType); $result = $this->swatchHelperObject->isSwatchAttribute($this->attributeMock); if ($boolResult) { $this->assertTrue($result); } else { $this->assertFalse($result); } }
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); }
public function testExecuteNoPopup() { $attributesData = ['frontend_label' => '']; $this->request->expects($this->any())->method('getParam')->willReturnMap([['attribute_id', null, null], ['attribute', null, $attributesData], ['popup', null, false]]); $this->objectManagerMock->expects($this->any())->method('create')->with('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->willReturn($this->eavAttribute); $this->objectManagerMock->expects($this->any())->method('get')->with('Magento\\Backend\\Model\\Session')->willReturn($this->session); $this->eavAttribute->expects($this->once())->method('setEntityTypeId')->willReturnSelf(); $this->eavAttribute->expects($this->once())->method('addData')->with($attributesData)->willReturnSelf(); $this->registry->expects($this->any())->method('register')->with('entity_attribute', $this->eavAttribute); $this->resultPage->expects($this->any())->method('addBreadcrumb')->willReturnSelf(); $this->resultPage->expects($this->once())->method('setActiveMenu')->with('Magento_Catalog::catalog_attributes_attributes')->willReturnSelf(); $this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig); $this->resultPage->expects($this->once())->method('getLayout')->willReturn($this->layout); $this->resultPageFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->resultPage); $this->pageConfig->expects($this->any())->method('getTitle')->willReturn($this->pageTitle); $this->pageTitle->expects($this->any())->method('prepend')->willReturnSelf(); $this->eavAttribute->expects($this->any())->method('getName')->willReturn(null); $this->layout->expects($this->once())->method('getBlock')->willReturn($this->blockTemplate); $this->blockTemplate->expects($this->any())->method('setIsPopup')->willReturnSelf(); $this->assertSame($this->resultPage, $this->editController->execute()); }
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([])); }