作者:abdeldaye
项目:pim-community-de
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, []]);
}
作者:abdeldaye
项目:pim-community-de
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\\"}}');
}
作者:a2xchi
项目:pim-community-de
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']]);
}
作者:a2xchi
项目:pim-community-de
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']]);
}
作者:abdeldaye
项目:pim-community-de
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']);
}
作者:a2xchi
项目:pim-community-de
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]]]]]);
}
作者:a2xchi
项目:pim-community-de
/**
* Normalize the variant group values
*
* @param GroupInterface $variantGroup
*
* @return array
*/
protected function normalizeVariantGroupValues(GroupInterface $variantGroup)
{
if (null === ($template = $variantGroup->getProductTemplate())) {
return [];
}
return $template->getValuesData();
}
作者:pierallar
项目:pim-community-de
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, []]);
}
作者:pierallar
项目:pim-community-de
/**
* 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);
}
}
作者:abdeldaye
项目:pim-community-de
/**
* @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());
}
}
}
作者:a2xchi
项目:pim-community-de
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);
}
作者:abdeldaye
项目:pim-community-de
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, []]);
}
作者:a2xchi
项目:pim-community-de
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);
}
作者:abdeldaye
项目:pim-community-de
/**
* 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;
}
作者:alexisfroge
项目:pim-community-de
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);
}
作者:a2xchi
项目:pim-community-de
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']]]]);
}
作者:alexisfroge
项目:pim-community-de
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\\"]}]}');
}
作者:a2xchi
项目:pim-community-de
/**
* 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']));
}
}
作者:abdeldaye
项目:pim-community-de
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);
}
作者:a2xchi
项目:pim-community-de
/**
* @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;
}