/**
  * @dataProvider getConstructData
  */
 public function testConstruct($label, $expectedName, $expectedPropertyPath, array $expectedSuffixes = array())
 {
     $info = new ColumnInfo($label);
     $this->assertEquals($label, $info->getLabel());
     $this->assertEquals($expectedName, $info->getName());
     $this->assertEquals($expectedPropertyPath, $info->getPropertyPath());
     $this->assertEquals($expectedSuffixes, $info->getSuffixes());
 }
 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 it_validates_a_property_from_an_entity_which_has_error($validator, ProductInterface $product, ColumnInfo $columnInfo, ConstraintViolationList $violationList, ConstraintViolationInterface $violation, \ArrayIterator $iterator)
 {
     $product->getReference()->willReturn('sku-001');
     $columnInfo->getPropertyPath()->willReturn('name');
     $columnInfo->getLabel()->willReturn('Product name');
     $validator->validateProperty($product, 'name')->willReturn($violationList);
     $violationList->count()->willReturn(1);
     $violationList->getIterator()->willReturn($iterator);
     $iterator->rewind()->willReturn(null);
     $iterator->append($violation);
     $validReturns = [true, false];
     $iterator->valid()->will(function () use(&$validReturns) {
         $isValid = current($validReturns);
         next($validReturns);
         return $isValid;
     });
     $iterator->next()->willReturn(null);
     $iterator->current()->willReturn($violation);
     $violation->getMessageTemplate()->willReturn('An error occurs during validation');
     $violation->getMessageParameters()->willReturn([]);
     $this->validate($product, [$columnInfo], [], ['An error already here'])->shouldReturn(['Product name' => [['An error occurs during validation', []]], 0 => 'An error already here']);
 }
 function it_transform_an_existing_product($guesser, $columnInfoTransformer, $attributeCache, $doctrine, $associationReader, $templateUpdater, $productRepository, AttributeInterface $attributeSku, AttributeInterface $attributeDesc, ColumnInfo $columnInfoSku, ColumnInfo $columnInfoFamily, ColumnInfo $columnInfoGroups, ColumnInfo $columnInfoCategories, ColumnInfo $columnInfoAssocGroups, ColumnInfo $columnInfoAssocProducts, ColumnInfo $columnInfoDesc, IdentifiableObjectRepositoryInterface $productRepository, ProductInterface $product, ObjectManager $objectManager, ClassMetadata $productMetadata, RelationTransformer $relationFamily, RelationTransformer $relationGroups, RelationTransformer $relationCategories, ClassMetadata $productValueMetadata, DefaultTransformer $defaultTransformer, ProductValueInterface $valueSku, ProductValueInterface $valueDesc, GroupInterface $variantGroup, ProductTemplateInterface $productTemplate)
 {
     // initialize attributes
     $columnInfoTransformer->transform('Pim\\Bundle\\CatalogBundle\\Model\\Product', ['sku', 'family', 'groups', 'categories', 'SUBSTITUTION-groups', 'SUBSTITUTION-products', 'description-en_US-mobile'])->shouldBeCalled()->willReturn([$columnInfoSku, $columnInfoFamily, $columnInfoGroups, $columnInfoCategories, $columnInfoAssocGroups, $columnInfoAssocProducts, $columnInfoDesc]);
     $columnInfoSku->getName()->willReturn('sku');
     $columnInfoSku->getPropertyPath()->willReturn('sku');
     $columnInfoSku->getLabel()->willReturn('sku');
     $columnInfoSku->getSuffixes()->willReturn([]);
     $columnInfoFamily->getName()->willReturn('family');
     $columnInfoFamily->getPropertyPath()->willReturn('family');
     $columnInfoFamily->getLabel()->willReturn('family');
     $columnInfoFamily->getSuffixes()->willReturn([]);
     // TODO : we should introduce a variant_group column after PIM-2458
     $columnInfoGroups->getName()->willReturn('groups');
     $columnInfoGroups->getPropertyPath()->willReturn('groups');
     $columnInfoGroups->getLabel()->willReturn('groups');
     $columnInfoGroups->getSuffixes()->willReturn([]);
     $columnInfoCategories->getName()->willReturn('categories');
     $columnInfoCategories->getPropertyPath()->willReturn('categories');
     $columnInfoCategories->getLabel()->willReturn('categories');
     $columnInfoCategories->getSuffixes()->willReturn([]);
     $columnInfoAssocGroups->getName()->willReturn('SUBSTITUTION');
     $columnInfoAssocGroups->getPropertyPath()->willReturn('sUBSTITUTION');
     $columnInfoAssocGroups->getLabel()->willReturn('SUBSTITUTION-groups');
     $columnInfoAssocGroups->getSuffixes()->willReturn(['groups']);
     $columnInfoAssocProducts->getName()->willReturn('SUBSTITUTION');
     $columnInfoAssocProducts->getPropertyPath()->willReturn('sUBSTITUTION');
     $columnInfoAssocProducts->getLabel()->willReturn('SUBSTITUTION-products');
     $columnInfoAssocProducts->getSuffixes()->willReturn(['products']);
     $columnInfoDesc->getName()->willReturn('description');
     $columnInfoDesc->getPropertyPath()->willReturn('description');
     $columnInfoDesc->getLabel()->willReturn('description');
     $columnInfoDesc->getSuffixes()->willReturn([]);
     $attributeCache->getAttributes([$columnInfoSku, $columnInfoFamily, $columnInfoGroups, $columnInfoCategories, $columnInfoAssocGroups, $columnInfoAssocProducts, $columnInfoDesc])->willReturn(['sku' => $attributeSku, 'description' => $attributeDesc]);
     $columnInfoSku->setAttribute($attributeSku)->shouldBeCalled();
     $attributeSku->getAttributeType()->willReturn('pim_catalog_identifier');
     $columnInfoFamily->setAttribute(null)->shouldBeCalled();
     $columnInfoGroups->setAttribute(null)->shouldBeCalled();
     $columnInfoCategories->setAttribute(null)->shouldBeCalled();
     $columnInfoDesc->setAttribute($attributeDesc)->shouldBeCalled();
     // find entity
     $attributeSku->getCode()->willReturn('sku');
     $productRepository->findOneByIdentifier('AKNTS')->willReturn($product);
     // set product properties
     $doctrine->getManagerForClass('Pim\\Bundle\\CatalogBundle\\Model\\Product')->willReturn($objectManager);
     $objectManager->getClassMetadata('Pim\\Bundle\\CatalogBundle\\Model\\Product')->willReturn($productMetadata);
     $guesser->getTransformerInfo($columnInfoFamily, $productMetadata)->willReturn([$relationFamily, ['class' => 'Pim\\Bundle\\CatalogBundle\\Entity\\Family', 'multiple' => false]]);
     $guesser->getTransformerInfo($columnInfoGroups, $productMetadata)->willReturn([$relationGroups, ['class' => 'Pim\\Bundle\\CatalogBundle\\Entity\\Group', 'multiple' => true]]);
     $guesser->getTransformerInfo($columnInfoCategories, $productMetadata)->willReturn([$relationCategories, ['class' => 'Pim\\Bundle\\CatalogBundle\\Entity\\Category', 'multiple' => true]]);
     // set product values
     $attributeCache->getRequiredAttributeCodes($product)->willReturn(['sku', 'description']);
     $doctrine->getManagerForClass('Pim\\Bundle\\CatalogBundle\\Model\\ProductValue')->willReturn($objectManager);
     $objectManager->getClassMetadata('Pim\\Bundle\\CatalogBundle\\Model\\ProductValue')->willReturn($productValueMetadata);
     $guesser->getTransformerInfo($columnInfoSku, $productValueMetadata)->willReturn([$defaultTransformer, []]);
     $guesser->getTransformerInfo($columnInfoDesc, $productValueMetadata)->willReturn([$defaultTransformer, []]);
     $columnInfoSku->getLocale()->willReturn(null);
     $columnInfoSku->getScope()->willReturn(null);
     $columnInfoDesc->getLocale()->willReturn('en_US');
     $columnInfoDesc->getScope()->willReturn('mobile');
     $product->getValue('sku', null, null)->willReturn($valueSku);
     $product->getValue('description', 'de_DE', 'mobile')->willReturn($valueDesc);
     // set variant group values
     $product->getVariantGroup()->willReturn($variantGroup);
     $variantGroup->getProductTemplate()->willReturn($productTemplate);
     $templateUpdater->update($productTemplate, [$product])->shouldBeCalled();
     // set associations
     $product->getReference()->willReturn('AKNTS');
     $associationReader->addItem(['association_type' => 'SUBSTITUTION', 'owner' => 'AKNTS', 'products' => 'AKNTS_WPS,AKNTS_PBS,AKNTS_PWS'])->shouldBeCalled();
     $this->transform('Pim\\Bundle\\CatalogBundle\\Model\\Product', ['sku' => 'AKNTS', 'family' => 'tshirts', 'groups' => 'akeneo_tshirt', 'categories' => 'tshirts,goodies', 'SUBSTITUTION-groups' => '', 'SUBSTITUTION-products' => 'AKNTS_WPS,AKNTS_PBS,AKNTS_PWS', 'description-en_US-mobile' => '<p>Akeneo T-Shirt</p>']);
 }