function it_throws_an_error_if_type_is_unknown(GroupInterface $group) { $group->setCode('mycode')->shouldBeCalled(); $group->getId()->willReturn(null); $values = ['code' => 'mycode', 'type' => 'UNKNOWN']; $this->shouldThrow(new \InvalidArgumentException('Type "UNKNOWN" does not exist'))->during('update', [$group, $values, []]); }
function it_provides_formatted_batch_config_for_the_job(GroupInterface $oroTshirt) { $oroTshirt->getCode()->willReturn('oro_tshirt'); $this->setGroup($oroTshirt); $this->setFilters([['id', 'IN', ['22', '7']]]); $this->getBatchConfig()->shouldReturn('{\\"filters\\":[[\\"id\\",\\"IN\\",[\\"22\\",\\"7\\"]]],\\"actions\\":{\\"field\\":\\"variant_group\\",\\"value\\":\\"oro_tshirt\\"}}'); }
function it_normalizes_groups($normalizer, $structureVersionProvider, $versionManager, $versionNormalizer, $localizedConverter, GroupInterface $tshirt, GroupTypeInterface $groupType, Version $oldestLog, Version $newestLog, ArrayCollection $products, ProductInterface $product, \ArrayIterator $productsIterator) { $options = ['decimal_separator' => ',', 'date_format' => 'dd/MM/yyyy']; $tshirt->getType()->willReturn($groupType); $groupType->isVariant()->willReturn(true); $variantNormalized = ['code' => 'my_variant', 'axis' => ['color', 'size'], 'type' => 'variant', 'values' => ['number' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'metric' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'prices' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'date' => ['data' => '2015-01-31', 'locale' => null, 'scope' => null]]]; $valuesLocalized = ['number' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'metric' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'prices' => ['data' => '12,50', 'locale' => null, 'scope' => null], 'date' => ['data' => '31/01/2015', 'locale' => null, 'scope' => null]]; $normalizer->normalize($tshirt, 'json', $options)->willReturn($variantNormalized); $localizedConverter->convertToLocalizedFormats($variantNormalized['values'], $options)->willReturn($valuesLocalized); $structureVersionProvider->getStructureVersion()->willReturn(1); $versionManager->getOldestLogEntry($tshirt)->willReturn($oldestLog); $versionManager->getNewestLogEntry($tshirt)->willReturn($newestLog); $versionNormalizer->normalize($oldestLog, 'internal_api')->willReturn('normalized_oldest_log'); $versionNormalizer->normalize($newestLog, 'internal_api')->willReturn('normalized_newest_log'); $products->getIterator()->willReturn($productsIterator); $productsIterator->rewind()->shouldBeCalled(); $productsCount = 1; $productsIterator->valid()->will(function () use(&$productsCount) { return $productsCount-- > 0; }); $productsIterator->next()->shouldBeCalled(); $productsIterator->current()->will(new ReturnPromise([$product])); $product->getId()->willReturn(42); $tshirt->getId()->willReturn(12); $tshirt->getProducts()->willReturn($products); $this->normalize($tshirt, 'internal_api', $options)->shouldReturn(['code' => 'my_variant', 'axis' => ['color', 'size'], 'type' => 'variant', 'values' => $valuesLocalized, 'products' => [42], 'meta' => ['id' => 12, 'form' => 'pim-variant-group-edit-form', 'structure_version' => 1, 'model_type' => 'variant_group', 'created' => 'normalized_oldest_log', 'updated' => 'normalized_newest_log']]); }
function it_provides_formatted_batch_config_for_the_job(GroupInterface $oroTshirt) { $oroTshirt->getCode()->willReturn('oro_tshirt'); $this->setGroup($oroTshirt); $this->setFilters([['id', 'IN', ['22', '7']]]); $this->getBatchConfig()->shouldReturn(['filters' => [['id', 'IN', ['22', '7']]], 'actions' => ['field' => 'variant_group', 'value' => 'oro_tshirt']]); }
function it_fails_if_the_group_code_is_not_found($groupRepository, ProductInterface $product, GroupInterface $pack, GroupTypeInterface $nonVariantType) { $groupRepository->findOneByIdentifier('not valid code')->willReturn(null); $pack->getType()->willReturn($nonVariantType); $nonVariantType->isVariant()->willReturn(false); $this->shouldThrow(InvalidArgumentException::expected('variant_group', 'existing variant group code', 'setter', 'variant_group', 'not valid code'))->during('setFieldData', [$product, 'variant_group', 'not valid code']); }
function it_normalize_products($productNormalizer, $versionNormalizer, $versionManager, $localeRepository, $structureVersionProvider, $formProvider, $localizedConverter, ProductInterface $mug, AssociationInterface $upsell, AssociationTypeInterface $groupType, GroupInterface $group, ArrayCollection $groups) { $options = ['decimal_separator' => ',', 'date_format' => 'dd/MM/yyyy']; $productNormalized = ['enabled' => true, 'categories' => ['kitchen'], 'family' => '', 'values' => ['normalized_property' => ['data' => 'a nice normalized property', 'locale' => null, 'scope' => null], 'number' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'metric' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'prices' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'date' => ['data' => '2015-01-31', 'locale' => null, 'scope' => null]]]; $valuesLocalized = ['normalized_property' => ['data' => 'a nice normalized property', 'locale' => null, 'scope' => null], 'number' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'metric' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'prices' => ['data' => '12,5', 'locale' => null, 'scope' => null], 'date' => ['data' => '31/01/2015', 'locale' => null, 'scope' => null]]; $productNormalizer->normalize($mug, 'json', $options)->willReturn($productNormalized); $localizedConverter->convertToLocalizedFormats($productNormalized['values'], $options)->willReturn($valuesLocalized); $mug->getId()->willReturn(12); $versionManager->getOldestLogEntry($mug)->willReturn('create_version'); $versionNormalizer->normalize('create_version', 'internal_api')->willReturn('normalized_create_version'); $versionManager->getNewestLogEntry($mug)->willReturn('update_version'); $versionNormalizer->normalize('update_version', 'internal_api')->willReturn('normalized_update_version'); $localeRepository->getActivatedLocaleCodes()->willReturn(['en_US', 'fr_FR']); $mug->getLabel('en_US')->willReturn('A nice Mug!'); $mug->getLabel('fr_FR')->willReturn('Un très beau Mug !'); $mug->getAssociations()->willReturn([$upsell]); $upsell->getAssociationType()->willReturn($groupType); $groupType->getCode()->willReturn('group'); $upsell->getGroups()->willReturn($groups); $groups->toArray()->willReturn([$group]); $group->getId()->willReturn(12); $structureVersionProvider->getStructureVersion()->willReturn(12); $formProvider->getForm($mug)->willReturn('product-edit-form'); $this->normalize($mug, 'internal_api', $options)->shouldReturn(['enabled' => true, 'categories' => ['kitchen'], 'family' => '', 'values' => $valuesLocalized, 'meta' => ['form' => 'product-edit-form', 'id' => 12, 'created' => 'normalized_create_version', 'updated' => 'normalized_update_version', 'model_type' => 'product', 'structure_version' => 12, 'label' => ['en_US' => 'A nice Mug!', 'fr_FR' => 'Un très beau Mug !'], 'associations' => ['group' => ['groupIds' => [12]]]]]); }
/** * Normalize the variant group values * * @param GroupInterface $variantGroup * * @return array */ protected function normalizeVariantGroupValues(GroupInterface $variantGroup) { if (null === ($template = $variantGroup->getProductTemplate())) { return []; } return $template->getValuesData(); }
function it_throws_an_exception_if_attribute_is_unknown($attributeRepository, GroupInterface $group) { $group->setCode('mycode')->shouldBeCalled(); $attributeRepository->findOneByIdentifier('foo')->willReturn(null); $group->getId()->willReturn(null); $values = ['code' => 'mycode', 'axis' => ['foo']]; $this->shouldThrow(new \InvalidArgumentException('Attribute "foo" does not exist'))->during('update', [$group, $values, []]); }
/** * Bind products * * @param GroupInterface $group * @param array $appendProducts * @param array $removeProducts */ protected function bindProducts(GroupInterface $group, array $appendProducts, array $removeProducts) { foreach ($appendProducts as $product) { $group->addProduct($product); } foreach ($removeProducts as $product) { $group->removeProduct($product); } }
/** * @param VariantGroupAxis $constraint * @param GroupInterface $variantGroup */ protected function validateAttributeAxis(VariantGroupAxis $constraint, GroupInterface $variantGroup) { $allowedTypes = [AttributeTypes::OPTION_SIMPLE_SELECT, AttributeTypes::REFERENCE_DATA_SIMPLE_SELECT]; foreach ($variantGroup->getAxisAttributes() as $attribute) { if (!in_array($attribute->getAttributeType(), $allowedTypes)) { $this->addInvalidAxisViolation($constraint, $variantGroup->getCode(), $attribute->getCode()); } } }
function it_validates_products_with_one_variant_group($context, $onlyOneVariantGroup, ProductInterface $mug, GroupInterface $mugVariantGroup, GroupInterface $otherGroup, GroupTypeInterface $variantType, GroupTypeInterface $groupType) { $mug->getGroups()->willReturn([$mugVariantGroup, $otherGroup]); $mugVariantGroup->getType()->willReturn($variantType); $otherGroup->getType()->willReturn($groupType); $variantType->isVariant()->willReturn(true); $groupType->isVariant()->willReturn(false); $context->buildViolation(Argument::any())->shouldNotBeCalled(); $this->validate($mug, $onlyOneVariantGroup); }
function it_throws_an_error_if_axis_is_updated(GroupInterface $variantGroup) { $variantGroup->setCode('mycode')->shouldBeCalled(); $variantGroup->getId()->willReturn(42); $attribute = new Attribute(); $attribute->setCode('other'); $variantGroup->getAxisAttributes()->willReturn(new ArrayCollection([$attribute])); $values = ['code' => 'mycode', 'axis' => ['main_color']]; $this->shouldThrow(new \InvalidArgumentException('Attributes: This property cannot be changed.'))->during('update', [$variantGroup, $values, []]); }
function it_supports_standard_normalization(GroupInterface $variantGroup, GroupTypeInterface $variantGroupType) { $variantGroup->getType()->willReturn($variantGroupType); $variantGroupType->isVariant()->willReturn(false); $this->supportsNormalization($variantGroup, 'standard')->shouldReturn(false); $variantGroupType->isVariant()->willReturn(true); $this->supportsNormalization($variantGroup, 'standard')->shouldReturn(true); $this->supportsNormalization(new \stdClass(), 'standard')->shouldReturn(false); $this->supportsNormalization($variantGroup, 'xml')->shouldReturn(false); $this->supportsNormalization($variantGroup, 'json')->shouldReturn(false); }
/** * Get missing axis codes of a product given a variant group * * @param ProductInterface $product * @param GroupInterface $variantGroup * * @return array */ protected function getMissingAxisCodes(ProductInterface $product, GroupInterface $variantGroup) { $missingAxisCodes = []; foreach ($variantGroup->getAxisAttributes() as $attribute) { $value = $product->getValue($attribute->getCode()); if (null === $value || null === $value->getData()) { $missingAxisCodes[] = $attribute->getCode(); } } return $missingAxisCodes; }
function it_throws_an_exception_if_media_of_variant_group_is_not_found($normalizer, $denormalizer, ArrayCollection $productValuesCollection, ArrayCollection $mediaCollection, ProductMediaInterface $media, GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, ProductValueInterface $productValue) { $variantGroup->getProductTemplate()->willReturn($productTemplate); $variantGroup->getCode()->willReturn('my_variant_group'); $productTemplate->getValuesData()->willReturn([$productValue]); $denormalizer->denormalize([$productValue], 'ProductValue[]', 'json')->willReturn($productValuesCollection); $productValuesCollection->filter(Argument::cetera())->willReturn($mediaCollection); $mediaCollection->toArray()->willReturn([$media]); $normalizer->normalize([$media], 'csv', ['field_name' => 'media', 'prepare_copy' => true, 'identifier' => 'my_variant_group'])->willThrow(new FileNotFoundException('upload/path/img.jpg')); $this->shouldThrow(new InvalidItemException('The file "upload/path/img.jpg" does not exist', ['item' => 'my_variant_group', 'uploadDirectory' => 'upload/path/']))->duringProcess($variantGroup); }
function it_provides_formatted_batch_config_for_the_job(GroupInterface $officeGroup, GroupInterface $bedroomGroup, ArrayCollection $groupCollection) { $officeGroup->getCode()->willReturn('office_room'); $bedroomGroup->getCode()->willReturn('bedroom'); $groupCollection->add($officeGroup); $groupCollection->add($bedroomGroup); $this->setGroups($groupCollection); $groupCollection->map(Argument::type('closure'))->willReturn($groupCollection); $groupCollection->toArray()->willReturn(['office_room', 'bedroom']); $this->setFilters([['id', 'IN', ['22', '7']]]); $this->getBatchConfig()->shouldReturn(['filters' => [['id', 'IN', ['22', '7']]], 'actions' => [['field' => 'groups', 'value' => ['office_room', 'bedroom']]]]); }
function it_provides_formatted_batch_config_for_the_job(GroupInterface $officeGroup, GroupInterface $bedroomGroup, ArrayCollection $groupCollection) { $officeGroup->getCode()->willReturn('office_room'); $bedroomGroup->getCode()->willReturn('bedroom'); $groupCollection->add($officeGroup); $groupCollection->add($bedroomGroup); $this->setGroups($groupCollection); $groupCollection->map(Argument::type('closure'))->willReturn($groupCollection); $groupCollection->toArray()->willReturn(['office_room', 'bedroom']); $this->setFilters([['id', 'IN', ['22', '7']]]); $this->getBatchConfig()->shouldReturn('{\\"filters\\":[[\\"id\\",\\"IN\\",[\\"22\\",\\"7\\"]]],\\"actions\\":[{\\"field\\":\\"groups\\",\\"value\\":[\\"office_room\\",\\"bedroom\\"]}]}'); }
/** * Fetch medias in local filesystem * * @param GroupInterface $variantGroup * @param string $directory */ protected function fetchMedia(GroupInterface $variantGroup, $directory) { if (null === ($productTemplate = $variantGroup->getProductTemplate())) { return; } $identifier = $variantGroup->getCode(); $this->variantGroupUpdater->update($variantGroup, ['values' => $productTemplate->getValuesData()]); $this->mediaFetcher->fetchAll($productTemplate->getValues(), $directory, $identifier); foreach ($this->mediaFetcher->getErrors() as $error) { $this->stepExecution->addWarning($error['message'], [], new DataInvalidItem($error['media'])); } }
function it_returns_non_eligible_attributes($attributeRepository, GroupInterface $group, ProductTemplateInterface $template, AttributeInterface $length, AttributeInterface $name, AttributeInterface $color, AttributeInterface $identifier, Collection $collection) { $group->getProductTemplate()->willReturn($template); $group->getAxisAttributes()->willReturn($collection); $collection->toArray()->willReturn([$length]); $template->getValuesData()->willReturn(['name' => 'foo', 'color' => 'bar']); $attributeRepository->findOneByIdentifier('name')->willReturn($name); $attributeRepository->findOneByIdentifier('color')->willReturn($color); $attributeRepository->findBy(['unique' => true])->willReturn([$name, $identifier]); $attributes = [$length, $name, $color, $identifier]; $this->getNonEligibleAttributes($group)->shouldReturn($attributes); }
/** * @param GroupInterface $group * * @return array */ protected function getFormOptionsForEdition(GroupInterface $group) { $axesIds = array_map(function (AttributeInterface $attribute) { return $attribute->getId(); }, $group->getAxisAttributes()->toArray()); $options = ['data' => $group->getAxisAttributes(), 'disabled' => true, 'read_only' => true, 'query_builder' => function (AttributeRepositoryInterface $repository) use($axesIds) { $qb = $repository->findAllAxesQB(); $qb->andWhere('a.id IN (:ids)'); $qb->setParameter('ids', $axesIds); return $qb; }]; return $options; }
function it_does_not_copy_values_to_products_when_template_is_empty(GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, Collection $productCollection, ProductInterface $productOne, ProductInterface $productTwo, $productTplApplier, $stepExecution) { $variantGroup->getId()->willReturn(42); $stepExecution->incrementSummaryInfo('process')->shouldBeCalled(); $variantGroup->getProductTemplate()->willReturn($productTemplate); $productTemplate->getValuesData()->willReturn([]); $variantGroup->getProducts()->willReturn($productCollection); $productCollection->isEmpty()->willReturn(false); $productCollection->toArray()->willReturn([$productOne, $productTwo]); $productCollection->count()->willReturn(2); $productTplApplier->apply($productTemplate, [$productOne, $productTwo])->shouldNotBeCalled(); $this->write([$variantGroup]); }
/** * Validate variant group product template values * * @param GroupInterface $variantGroup * @param Constraint $constraint */ protected function validateProductTemplateValues(GroupInterface $variantGroup, Constraint $constraint) { $template = $variantGroup->getProductTemplate(); $valuesData = $template->getValuesData(); $forbiddenAttrCodes = $this->attributeRepository->findUniqueAttributeCodes(); foreach ($variantGroup->getAxisAttributes() as $axisAttribute) { $forbiddenAttrCodes[] = $axisAttribute->getCode(); } $invalidAttrCodes = array_intersect($forbiddenAttrCodes, array_keys($valuesData)); if (count($invalidAttrCodes) > 0) { $this->context->buildViolation($constraint->message, ['%group%' => $variantGroup->getCode(), '%attributes%' => $this->formatValues($invalidAttrCodes)])->addViolation(); } }
function it_adds_a_violation_when_validates_a_product_with_missing_value_for_an_axe_of_its_variant_group($context, ProductInterface $product, GroupInterface $tShirtVariantGroup, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeValue, ProductValueInterface $identifierValue, HasVariantAxes $constraint, ConstraintViolationBuilderInterface $violation) { $tShirtVariantGroup->getCode()->willReturn('tshirt'); $tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]); $sizeAttribute->getCode()->willReturn('size'); $colorAttribute->getCode()->willReturn('color'); $product->getIdentifier()->willReturn($identifierValue); $product->getVariantGroup()->willReturn($tShirtVariantGroup); $product->getValue('size')->willReturn($sizeValue); $product->getValue('color')->willReturn(null); $sizeValue->getData()->willReturn('XL'); $context->buildViolation('The product "%product%" is in the variant group "%variant%" but it misses the following axes: %axes%.', ['%product%' => $identifierValue, '%variant%' => 'tshirt', '%axes%' => 'color'])->shouldBeCalled()->willReturn($violation); $this->validate($product, $constraint); }
/** * {@inheritdoc} */ protected function normalizeVariantGroupValues(GroupInterface $group, $format, array $context) { if (!$group->getType()->isVariant() || null === $group->getProductTemplate()) { return []; } $valuesData = $group->getProductTemplate()->getValuesData(); $values = $this->valuesDenormalizer->denormalize($valuesData, 'ProductValue[]', 'json'); $normalizedValues = []; foreach ($values as $value) { $normalizedValues = array_replace($normalizedValues, $this->serializer->normalize($value, $format, ['entity' => 'product'] + $context)); } ksort($normalizedValues); return $normalizedValues; }
function it_normalizes_a_product_associations_in_standard_format_only(ProductInterface $product, AssociationInterface $association1, AssociationInterface $association2, AssociationTypeInterface $associationType1, AssociationTypeInterface $associationType2, GroupInterface $group1, ProductInterface $productAssociated) { $group1->getCode()->willReturn('group_code'); $associationType1->getCode()->willReturn('XSELL'); $association1->getAssociationType()->willReturn($associationType1); $association1->getGroups()->willReturn([$group1]); $association1->getProducts()->willReturn([]); $productAssociated->getReference()->willReturn('product_code'); $associationType2->getCode()->willReturn('PACK'); $association2->getAssociationType()->willReturn($associationType2); $association2->getGroups()->willReturn([]); $association2->getProducts()->willReturn([$productAssociated]); $product->getAssociations()->willReturn([$association1, $association2]); $this->normalize($product, 'standard')->shouldReturn(['PACK' => ['groups' => [], 'products' => ['product_code']], 'XSELL' => ['groups' => ['group_code'], 'products' => []]]); }
function it_saves_a_variant_group_and_copies_values_to_products($optionsResolver, $objectManager, $templateApplier, $eventDispatcher, GroupInterface $group, GroupType $type, ProductInterface $product, ProductTemplateInterface $template, ArrayCollection $products) { $optionsResolver->resolveSaveOptions(['copy_values_to_products' => true])->willReturn(['flush' => true, 'copy_values_to_products' => true, 'add_products' => [], 'remove_products' => []]); $group->getType()->willReturn($type); $group->getCode()->willReturn('my_code'); $objectManager->persist($group)->shouldBeCalled(); $objectManager->flush()->shouldBeCalled(); $type->isVariant()->willReturn(true); $group->getProductTemplate()->willReturn($template); $group->getProducts()->willReturn($products); $products->toArray()->willReturn([$product]); $templateApplier->apply($template, [$product])->shouldBeCalled(); $eventDispatcher->dispatch(StorageEvents::PRE_SAVE, Argument::cetera())->shouldBeCalled(); $eventDispatcher->dispatch(StorageEvents::POST_SAVE, Argument::cetera())->shouldBeCalled(); $this->save($group, ['copy_values_to_products' => true]); }
function it_sets_groups_field($groupRepository, ProductInterface $product, GroupInterface $pack, GroupInterface $cross, GroupInterface $up, GroupTypeInterface $nonVariantType) { $groupRepository->findOneByIdentifier('pack')->willReturn($pack); $groupRepository->findOneByIdentifier('cross')->willReturn($cross); $product->getGroups()->willReturn([$up]); $up->getType()->willReturn($nonVariantType); $nonVariantType->isVariant()->willReturn(false); $product->removeGroup($up)->shouldBeCalled(); $pack->getType()->willReturn($nonVariantType); $nonVariantType->isVariant()->willReturn(false); $cross->getType()->willReturn($nonVariantType); $nonVariantType->isVariant()->willReturn(false); $product->addGroup($pack)->shouldBeCalled(); $product->addGroup($cross)->shouldBeCalled(); $this->setFieldData($product, 'groups', ['pack', 'cross']); }
/** * Get non eligible attributes to a product template * * @param GroupInterface $variantGroup * * @return AttributeInterface[] */ public function getNonEligibleAttributes(GroupInterface $variantGroup) { $attributes = $variantGroup->getAxisAttributes()->toArray(); $template = $variantGroup->getProductTemplate(); if (null !== $template) { foreach (array_keys($template->getValuesData()) as $attributeCode) { $attributes[] = $this->attributeRepository->findOneByIdentifier($attributeCode); } } $uniqueAttributes = $this->attributeRepository->findBy(['unique' => true]); foreach ($uniqueAttributes as $attribute) { if (!in_array($attribute, $attributes)) { $attributes[] = $attribute; } } return $attributes; }
function it_normalizes_the_associations_of_the_product(ProductInterface $product, AssociationInterface $association1, AssociationInterface $association2, AssociationTypeInterface $type1, AssociationTypeInterface $type2, ProductInterface $productAssociated1, ProductInterface $productAssociated2, ProductInterface $productAssociated3, GroupInterface $groupAssociated1, GroupInterface $groupAssociated2) { $type1->getCode()->willReturn('wahou the type'); $type2->getCode()->willReturn('such a type'); $groupAssociated1->getCode()->willReturn('group 1'); $groupAssociated2->getCode()->willReturn('group 2'); $productAssociated1->getReference()->willReturn('product 1'); $productAssociated2->getReference()->willReturn('product 2'); $productAssociated3->getReference()->willReturn('product 3'); $association1->getAssociationType()->willReturn($type1); $association2->getAssociationType()->willReturn($type2); $association1->getGroups()->willReturn([$groupAssociated1]); $association2->getGroups()->willReturn([$groupAssociated1, $groupAssociated2]); $association1->getProducts()->willReturn([]); $association2->getProducts()->willReturn([$productAssociated1, $productAssociated2, $productAssociated3]); $product->getAssociations()->willReturn([$association1, $association2]); $this->normalize($product, 'json')->shouldReturn(['such a type' => ['groups' => ['group 1', 'group 2'], 'products' => ['product 1', 'product 2', 'product 3']], 'wahou the type' => ['groups' => ['group 1'], 'products' => []]]); }
function it_normalize_products($productNormalizer, $versionNormalizer, $versionManager, $localeRepository, $structureVersionProvider, $formProvider, ProductInterface $mug, AssociationInterface $upsell, AssociationTypeInterface $groupType, GroupInterface $group, ArrayCollection $groups) { $productNormalizer->normalize($mug, 'json', [])->willReturn(['normalized_property' => 'a nice normalized property']); $mug->getId()->willReturn(12); $versionManager->getOldestLogEntry($mug)->willReturn('create_version'); $versionNormalizer->normalize('create_version', 'internal_api')->willReturn('normalized_create_version'); $versionManager->getNewestLogEntry($mug)->willReturn('update_version'); $versionNormalizer->normalize('update_version', 'internal_api')->willReturn('normalized_update_version'); $localeRepository->getActivatedLocaleCodes()->willReturn(['en_US', 'fr_FR']); $mug->getLabel('en_US')->willReturn('A nice Mug!'); $mug->getLabel('fr_FR')->willReturn('Un très beau Mug !'); $mug->getAssociations()->willReturn([$upsell]); $upsell->getAssociationType()->willReturn($groupType); $groupType->getCode()->willReturn('group'); $upsell->getGroups()->willReturn($groups); $groups->toArray()->willReturn([$group]); $group->getId()->willReturn(12); $structureVersionProvider->getStructureVersion()->willReturn(12); $formProvider->getForm($mug)->willReturn('product-edit-form'); $this->normalize($mug, 'internal_api', [])->shouldReturn(['normalized_property' => 'a nice normalized property', 'meta' => ['form' => 'product-edit-form', 'id' => 12, 'created' => 'normalized_create_version', 'updated' => 'normalized_update_version', 'model_type' => 'product', 'structure_version' => 12, 'label' => ['en_US' => 'A nice Mug!', 'fr_FR' => 'Un très beau Mug !'], 'associations' => ['group' => ['groupIds' => [12]]]]]); }