function it_checks_unicity_of_product_value(Product $product1, Product $product2, ColumnInfo $columnInfo1, ColumnInfo $columnInfo2, AttributeInterface $attribute1, AttributeInterface $attribute2, ProductValueInterface $productValue1, ProductValueInterface $productValue2, ProductValueInterface $productValue3, ProductValueInterface $productValue4, ValidatorInterface $validator, ConstraintViolationListInterface $constraint) { $values = [['sku' => 'AKNTS_BPXL', 'test_unique_attribute' => '1200000011a'], ['sku' => '17727158', 'test_unique_attribute' => '1200000011a']]; $columnInfo1->getLabel()->willReturn("sku"); $columnInfo1->getName()->willReturn("sku"); $columnInfo1->getLocale()->willReturn(null); $columnInfo1->getScope()->willReturn(null); $columnInfo1->getAttribute()->willReturn($attribute1); $columnInfo2->getLabel()->willReturn("test_unique_attribute"); $columnInfo2->getName()->willReturn("test_unique_attribute"); $columnInfo2->getLocale()->willReturn(null); $columnInfo2->getScope()->willReturn(null); $columnInfo2->getAttribute()->willReturn($attribute2); $attribute1->isUnique()->willReturn(true); $attribute1->getAttributeType()->willReturn('pim_catalog_text'); $attribute1->getCode()->willReturn('sku'); $attribute2->isUnique()->willReturn(true); $attribute2->getAttributeType()->willReturn('pim_catalog_identifier'); $attribute2->getCode()->willReturn('test_unique_attribute'); $columnsInfo = [$columnInfo1, $columnInfo2]; $product1->getValue("sku", null, null)->shouldBeCalled()->willReturn($productValue1); $product1->getValue("test_unique_attribute", null, null)->shouldBeCalled()->willReturn($productValue2); $product2->getValue("sku", null, null)->shouldBeCalled()->willReturn($productValue3); $product2->getValue("test_unique_attribute", null, null)->shouldBeCalled()->willReturn($productValue4); $product1->__toString()->willReturn('product1'); $product2->__toString()->willReturn('product2'); $productValue1->getAttribute()->willReturn($attribute1); $productValue2->getAttribute()->willReturn($attribute2); $productValue3->getAttribute()->willReturn($attribute1); $productValue4->getAttribute()->willReturn($attribute2); $productValue1->getData()->willReturn("AKNTS_BPXL"); $productValue2->getData()->willReturn("1200000011a"); $productValue3->getData()->willReturn("17727158"); $productValue4->getData()->willReturn("1200000011a"); $productValue1->__toString()->willReturn("AKNTS_BPXL"); $productValue2->__toString()->willReturn("1200000011a"); $productValue3->__toString()->willReturn("17727158"); $productValue4->__toString()->willReturn("1200000011a"); $validator->validate('17727158', Argument::any())->shouldBeCalled()->willReturn($constraint); $validator->validate('1200000011a', Argument::any())->shouldBeCalled()->willReturn($constraint); $validator->validate('AKNTS_BPXL', Argument::any())->shouldBeCalled()->willReturn($constraint); $validator->validate($product1, Argument::any())->shouldBeCalled()->willReturn($constraint); $validator->validate($product2, Argument::any())->shouldBeCalled()->willReturn($constraint); $constraint->count()->willReturn(0); $errors = ['17727158' => [['The value "1200000011a" for unique attribute "test_unique_attribute" was already read in this file']]]; $this->validate($product1, $columnsInfo, $values[0])->shouldReturn([]); $this->validate($product2, $columnsInfo, $values[1])->shouldReturn($errors); }
function let(ChannelManager $channelManager, MediaManager $mediaManager, ProductValueNormalizer $productValueNormalizer, CategoryMappingManager $categoryMappingManager, AssociationTypeManager $associationTypeManager, MappingCollection $storeViewMapping, MappingCollection $categoryMapping, MappingCollection $attributeMapping, Product $product, ProductValue $productValue, ProductValue $imageValue, Channel $channel, Locale $localeFR, Locale $localeEN, Category $category, ExportableLocaleFilter $localeFilter) { $this->beConstructedWith($channelManager, $mediaManager, $productValueNormalizer, $categoryMappingManager, $associationTypeManager, $localeFilter, 1, 4, 1, 'currency', 'magento_url'); $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'pimGrouped' => 'pim_grouped', 'created_date' => new \DateTime(), 'updated_date' => new \DateTime(), 'defaultStoreView' => 'default', 'smallImageAttribute' => 'small_image_attribute', 'baseImageAttribute' => 'image_attribute', 'thumbnailAttribute' => 'image_attribute', 'urlKey' => false, 'skuFirst' => false]; $attributeMapping->getTarget('visibility')->willReturn('visibility'); $attributeMapping->getTarget('created_at')->willReturn('created_at'); $attributeMapping->getTarget('updated_at')->willReturn('updated_at'); $attributeMapping->getTarget('status')->willReturn('status'); $attributeMapping->getTarget('categories')->willReturn('categories'); $attributeMapping->getTarget('url_key')->willReturn('url_key'); $attributeMapping->getSource('name')->willReturn('my-name'); $channelManager->getChannelByCode('channel')->willReturn($channel); $channel->getLocales()->willReturn([$localeEN, $localeFR]); $localeEN->getCode()->willReturn('default_locale'); $localeFR->getCode()->willReturn('fr_FR'); $channel->getCode()->willReturn('channel_code'); $channel->getCategory()->willReturn($category); $product->getCategories()->willReturn([$category]); $product->getIdentifier()->willReturn('sku-000'); $product->getCreated()->willReturn($this->globalContext['created_date']); $product->getUpdated()->willReturn($this->globalContext['updated_date']); $product->getValues()->willReturn(new ArrayCollection([$productValue, $imageValue])); $product->getValue('my-name', Argument::any(), Argument::any())->willReturn('my-name'); $storeViewMapping->getTarget('default_locale')->willReturn('default_locale'); $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr'); $categoryMappingManager->getIdFromCategory($category, 'magento_url', $categoryMapping)->willReturn(2); $productValueNormalizer->normalize($productValue, Argument::cetera())->willReturn(['value' => 'productValueNormalized']); $productValueNormalizer->normalize($imageValue, Argument::cetera())->willReturn(null); }
function let(Group $group, Product $product1, Product $product2, Product $product3, Attribute $attribute1, Attribute $attribute2, AttributeOption $attributeOption11, AttributeOption $attributeOption12, AttributeOption $attributeOption21, AttributeOption $attributeOption22, ProductValue $productValueOption11, ProductValue $productValueOption12, ProductValue $productValueOption21, ProductValue $productValueOption22, ProductValue $productValuePrice1, ProductPrice $productPrice1, ProductValue $productValuePrice2, ProductPrice $productPrice2, ProductValue $productValuePrice3, ProductPrice $productPrice3, MappingCollection $attributeMapping) { $this->beConstructedWith('locale', 'currency'); $group->getAttributes()->willReturn([$attribute1, $attribute2]); //get attribute options $attribute1->getOptions()->willReturn([$attributeOption11, $attributeOption12]); $attribute1->getCode()->willReturn('attribute_1'); $attributeOption11->getAttribute()->willReturn($attribute1); $attributeOption11->getCode()->willReturn('attribute_1_option_1'); $productValueOption11->getData()->willReturn($attributeOption11); $attributeOption12->getAttribute()->willReturn($attribute1); $attributeOption12->getCode()->willReturn('attribute_1_option_2'); $productValueOption12->getData()->willReturn($attributeOption12); $attribute2->getOptions()->willReturn([$attributeOption21, $attributeOption22]); $attribute2->getCode()->willReturn('attribute_2'); $attributeOption21->getAttribute()->willReturn($attribute2); $attributeOption21->getCode()->willReturn('attribute_2_option_1'); $productValueOption21->getData()->willReturn($attributeOption21); $attributeOption22->getAttribute()->willReturn($attribute2); $attributeOption22->getCode()->willReturn('attribute_2_option_2'); $productValueOption22->getData()->willReturn($attributeOption22); //Get product prices $product1->getValue('price', 'locale')->willReturn($productValuePrice1); $product1->getIdentifier()->willReturn('product_1'); $productValuePrice1->getPrice('currency')->willReturn($productPrice1); $productPrice1->getData()->willReturn(5.0); $product2->getValue('price', 'locale')->willReturn($productValuePrice2); $product2->getIdentifier()->willReturn('product_2'); $productValuePrice2->getPrice('currency')->willReturn($productPrice2); $productPrice2->getData()->willReturn(15.0); $product3->getValue('price', 'locale')->willReturn($productValuePrice3); $product3->getIdentifier()->willReturn('product_3'); $productValuePrice3->getPrice('currency')->willReturn($productPrice3); $productPrice3->getData()->willReturn(10.0); $attributeMapping->getSource('attribute_1')->willReturn('attribute_1'); $attributeMapping->getSource('attribute_2')->willReturn('attribute_2'); $attributeMapping->getTarget('attribute_1')->willReturn('attribute_1'); $attributeMapping->getTarget('attribute_2')->willReturn('attribute_2'); }
/** * {@inheritDoc} */ public function getValue($attributeCode, $localeCode = NULL, $scopeCode = NULL) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getValue', array($attributeCode, $localeCode, $scopeCode)); return parent::getValue($attributeCode, $localeCode, $scopeCode); }