/**
  * Test related methods
  */
 public function testGuessUpdates()
 {
     $attribute = new Attribute();
     $attribute->setCode('my_attribute');
     $value = new ProductValue();
     $value->setAttribute($attribute);
     $product = new Product();
     $product->addValue($value);
     $guesser = new ProductValueUpdateGuesser();
     $em = $this->getEntityManagerMock();
     $updates = $guesser->guessUpdates($em, $value, UpdateGuesserInterface::ACTION_UPDATE_ENTITY);
     $this->assertEquals(1, count($updates));
     $this->assertEquals($product, $updates[0]);
     $attribute = new Attribute();
     $attribute->setCode('my_price');
     $price = new ProductPrice();
     $value = new ProductValue();
     $value->setAttribute($attribute);
     $value->addPrice($price);
     $product = new Product();
     $product->addValue($value);
     $updates = $guesser->guessUpdates($em, $price, UpdateGuesserInterface::ACTION_UPDATE_ENTITY);
     $this->assertEquals(1, count($updates));
     $this->assertEquals($product, $updates[0]);
 }
 /**
  * Check product values
  *
  * @param Product $product   the product
  * @param array   $valueKeys the expected value keys (attCode + locale + scope)
  *
  * @return boolean
  */
 protected function assertValues($product, $valueKeys)
 {
     $nbValues = count($valueKeys);
     $values = $product->getValues();
     $this->assertEquals(count($values), $nbValues);
     foreach ($values as $value) {
         $key = $value->getAttribute()->getCode() . $value->getLocale() . $value->getScope();
         $this->assertTrue(in_array($key, $valueKeys));
     }
 }
 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);
 }
 /**
  * Test getter for media
  */
 public function testGetMedia()
 {
     $this->product->addValue($this->getValueMock($this->getAttributeMock(null, 'pim_catalog_identifier', 'sku')));
     $this->product->addValue($this->getValueMock($this->getAttributeMock(null, 'pim_catalog_text', 'name')));
     $this->product->addValue($this->getValueMock($this->getAttributeMock(null, 'pim_catalog_image', 'view'), $view = $this->getMediaMock()));
     $this->product->addValue($this->getValueMock($this->getAttributeMock(null, 'pim_catalog_file', 'manual'), $manual = $this->getMediaMock()));
     $this->assertEquals(array($view, $manual), $this->product->getMedia());
 }
 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');
 }
 function it_throws_an_exception_if_something_went_wrong_during_normalization($webservice, $attributeMappingMerger, $categoryMappingMerger, $productNormalizer, $mappingCollection, Product $product, Channel $channel, Family $family, MetricConverter $metricConverter, AbstractAttribute $skuAttribute, ProductValue $sku)
 {
     $categoryMappingMerger->getMapping()->willReturn($mappingCollection);
     $attributeMappingMerger->getMapping()->willReturn($mappingCollection);
     $product->getFamily()->shouldBeCalled()->willReturn($family);
     $family->getCode()->shouldBeCalled()->willReturn('family_code');
     $webservice->getAttributeSetId('family_code')->shouldBeCalled()->willReturn('4');
     $product->getIdentifier()->shouldBeCalled()->willReturn($sku);
     $sku->getData()->willReturn('sku-000');
     $sku->getAttribute()->willReturn($skuAttribute);
     $skuAttribute->getCode()->willReturn('SKU');
     $product->getId()->willReturn(12);
     $product->getLabel()->willReturn('my product');
     $metricConverter->convert($product, $channel)->shouldBeCalled();
     $productNormalizer->normalize(Argument::type('\\Pim\\Bundle\\CatalogBundle\\Model\\Product'), 'MagentoArray', Argument::type('array'))->shouldBeCalled()->willThrow('\\Pim\\Bundle\\MagentoConnectorBundle\\Normalizer\\Exception\\NormalizeException');
     $this->shouldThrow('\\Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->duringProcess($product);
 }
 /**
  * @param Product $product
  *
  * @Given /^I should be on the (product "([^"]*)") edit page$/
  */
 public function iShouldBeOnTheProductEditPage(Product $product)
 {
     $expectedAddress = $this->getPage('Product edit')->getUrl(array('id' => $product->getId()));
     $this->assertAddress($expectedAddress);
 }
 /**
  * @param Product $product
  *
  * @Given /^I should be on the (product "([^"]*)") edit page$/
  */
 public function iShouldBeOnTheProductEditPage(Product $product)
 {
     $this->spin(function () use($product) {
         $expectedAddress = $this->getPage('Product edit')->getUrl(['id' => $product->getId()]);
         $this->assertAddress($expectedAddress);
         return true;
     });
     $this->getMainContext()->spin(function () {
         return $this->getCurrentPage()->find('css', '.product-label');
     });
 }
 function it_throws_an_exception_if_a_soap_call_error_occured_during_normalization($groupRepository, $webservice, $group, $configurableNormalizer, Product $product, Family $family)
 {
     $groupRepository->getVariantGroupIds()->willReturn([0, 1]);
     $product->getGroups()->willReturn([$group]);
     $product->getFamily()->shouldBeCalled()->willReturn($family);
     $group->getCode()->willReturn('abcd');
     $family->getCode()->willReturn('family_code');
     $configurable = ['group' => $group, 'products' => [$product]];
     $webservice->getConfigurablesStatus(['1' => $configurable])->shouldBeCalled()->willReturn([['sku' => 'conf-adcb']]);
     $webservice->getAttributeSetId('family_code')->shouldBeCalled()->willReturn('attrSet_code');
     $configurableNormalizer->normalize($configurable, 'MagentoArray', Argument::any())->willThrow('Pim\\Bundle\\MagentoConnectorBundle\\Webservice\\SoapCallException');
     $this->shouldThrow('\\Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->duringProcess([$product]);
 }
 /**
  * {@inheritDoc}
  */
 public function setNormalizedData($normalizedData)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setNormalizedData', array($normalizedData));
     return parent::setNormalizedData($normalizedData);
 }