コード例 #1
0
 /**
  * Validate a more complex value that doesn't store the data itself
  *
  * @param ProductValueInterface $value
  * @param Constraint            $constraint
  */
 protected function validateComplexValue(ProductValueInterface $value, Constraint $constraint)
 {
     if ($value->getAttribute()) {
         $backendType = $value->getAttribute()->getBackendType();
         if ('prices' === $backendType) {
             $this->validatePrices($value, $constraint);
         } elseif ('media' === $backendType) {
             $this->validateMedia($value, $constraint);
         } elseif ('metric' === $backendType) {
             $this->validateMetric($value, $constraint);
         }
     }
 }
コード例 #2
0
 /**
  * @param ProductValueInterface $productValue
  * @param null                  $format
  * @param array                 $context
  *
  * @return mixed
  */
 protected function getSimpleValue(ProductValueInterface $productValue, $format = null, array $context = [])
 {
     $attributeType = $productValue->getAttribute()->getAttributeType();
     $context['is_decimals_allowed'] = $productValue->getAttribute()->isDecimalsAllowed();
     // if decimals_allowed is false, we return an integer
     // if true, we return a string to avoid to loose precision (http://floating-point-gui.de)
     if (AttributeTypes::NUMBER === $attributeType && null !== $productValue->getData() && is_numeric($productValue->getData())) {
         return $productValue->getAttribute()->isDecimalsAllowed() ? number_format($productValue->getData(), static::DECIMAL_PRECISION, '.', '') : (int) $productValue->getData();
     }
     if (in_array($attributeType, [AttributeTypes::OPTION_SIMPLE_SELECT, AttributeTypes::REFERENCE_DATA_SIMPLE_SELECT])) {
         return $productValue->getData()->getCode();
     }
     return $this->serializer->normalize($productValue->getData(), $format, $context);
 }
コード例 #3
0
 function it_allows_to_get_errors_if_the_copy_went_wrong($mediaFetcher, $filesystemProvider, $fileExporterPath, FileInfoInterface $fileInfo, FileInfoInterface $fileInfo2, ArrayCollection $productValuesCollection, \ArrayIterator $valuesIterator, ProductValueInterface $productValue, ProductValueInterface $productValue2, AttributeInterface $attribute, FilesystemInterface $filesystem)
 {
     $fileInfo->getStorage()->willReturn('storageAlias');
     $fileInfo->getKey()->willReturn('a/b/c/d/product.jpg');
     $fileInfo->getOriginalFilename()->willReturn('my product.jpg');
     $fileInfo2->getStorage()->willReturn('storageAlias');
     $fileInfo2->getKey()->willReturn('wrong-path.jpg');
     $fileInfo2->getOriginalFilename()->willReturn('my-second-media.jpg');
     $productValue->getAttribute()->willReturn($attribute);
     $productValue->getMedia()->willReturn($fileInfo);
     $productValue->getLocale()->willReturn('en_US');
     $productValue->getScope()->willReturn(null);
     $productValue2->getAttribute()->willReturn($attribute);
     $productValue2->getMedia()->willReturn($fileInfo2);
     $productValue2->getLocale()->willReturn('fr_FR');
     $productValue2->getScope()->willReturn('ecommerce');
     $attribute->getAttributeType()->willReturn('pim_catalog_image');
     $attribute->getCode()->willReturn('my_picture');
     $productValuesCollection->getIterator()->willReturn($valuesIterator);
     $valuesIterator->rewind()->shouldBeCalled();
     $valuesCount = 2;
     $valuesIterator->valid()->will(function () use(&$valuesCount) {
         return $valuesCount-- > 0;
     });
     $valuesIterator->next()->shouldBeCalled();
     $valuesIterator->current()->will(new ReturnPromise([$productValue, $productValue2]));
     $filesystemProvider->getFilesystem('storageAlias')->willReturn($filesystem);
     $mediaFetcher->fetch($filesystem, 'a/b/c/d/product.jpg', ['filePath' => $this->directory . 'files/the_sku/my_picture/en_US/', 'filename' => 'my product.jpg'])->willThrow(new FileTransferException());
     $fileExporterPath->generate(['locale' => 'en_US', 'scope' => null], ['identifier' => 'the_sku', 'code' => 'my_picture'])->willReturn('files/the_sku/my_picture/en_US/');
     $mediaFetcher->fetch($filesystem, 'wrong-path.jpg', ['filePath' => $this->directory . 'files/the_sku/my_picture/fr_FR/ecommerce/', 'filename' => 'my-second-media.jpg'])->willThrow(new \LogicException('Something went wrong.'));
     $fileExporterPath->generate(['locale' => 'fr_FR', 'scope' => 'ecommerce'], ['identifier' => 'the_sku', 'code' => 'my_picture'])->willReturn('files/the_sku/my_picture/fr_FR/ecommerce/');
     $this->fetchAll($productValuesCollection, $this->directory, 'the_sku');
     $this->getErrors()->shouldBeEqualTo([['message' => 'The media has not been found or is not currently available', 'media' => ['from' => 'a/b/c/d/product.jpg', 'to' => ['filePath' => $this->directory . 'files/the_sku/my_picture/en_US/', 'filename' => 'my product.jpg'], 'storage' => 'storageAlias']], ['message' => 'The media has not been copied. Something went wrong.', 'media' => ['from' => 'wrong-path.jpg', 'to' => ['filePath' => $this->directory . 'files/the_sku/my_picture/fr_FR/ecommerce/', 'filename' => 'my-second-media.jpg'], 'storage' => 'storageAlias']]]);
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function prepareValueFormAlias(ProductValueInterface $value)
 {
     if ($value->getAttribute()->isWysiwygEnabled()) {
         return 'pim_wysiwyg';
     }
     return parent::prepareValueFormAlias($value);
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function prepareValueFormData(ProductValueInterface $value)
 {
     if (!is_null($value->getData())) {
         return $value->getData();
     }
     return $this->metricFactory->createMetric($value->getAttribute()->getMetricFamily());
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function prepareValueFormOptions(ProductValueInterface $value)
 {
     $referenceDataConf = $this->referenceDataRegistry->get($value->getAttribute()->getReferenceDataName());
     $options = parent::prepareValueFormOptions($value);
     $options['class'] = $referenceDataConf->getClass();
     return $options;
 }
コード例 #7
0
 function let(AttributeConstraintGuesser $guesser, ProductValueInterface $value, AttributeInterface $color, AttributeOptionInterface $red)
 {
     $value->getAttribute()->willReturn($color);
     $value->getData()->willReturn(new ArrayCollection([$red]));
     $color->getBackendType()->willReturn(AttributeTypes::BACKEND_TYPE_OPTIONS);
     $this->beConstructedWith(AttributeTypes::BACKEND_TYPE_OPTIONS, 'pim_ajax_entity', $guesser);
 }
コード例 #8
0
 function it_normalizes_the_properties_of_the_product($filter, $serializer, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, FamilyInterface $family, ArrayCollection $values, \ArrayIterator $iterator, ProductValueInterface $identifier)
 {
     $values->getIterator()->willReturn($iterator);
     $family->getCode()->willReturn('my_family');
     $product->getFamily()->willReturn($family);
     $product->getGroupCodes()->willReturn([]);
     $product->getVariantGroup()->willReturn(null);
     $product->getCategoryCodes()->willReturn([]);
     $product->isEnabled()->willReturn(true);
     $value->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('name');
     $product->getIdentifier()->willReturn($identifier);
     $identifier->getData()->willReturn('my_code');
     $product->getValues()->willReturn($values);
     $filter->filterCollection($values, 'pim.transform.product_value.structured', Argument::type('array'))->shouldBeCalled()->willReturn($values);
     $iterator->rewind()->willReturn(null);
     $valueCount = 1;
     $iterator->valid()->will(function () use(&$valueCount) {
         return $valueCount-- > 0;
     });
     $iterator->current()->willReturn($value);
     $iterator->next()->willReturn(null);
     $context = ['filter_types' => ['pim.transform.product_value.structured']];
     $serializer->normalize($value, 'standard', $context)->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']);
     $created = new \DateTime('2010-06-23');
     $product->getCreated()->willReturn($created);
     $serializer->normalize($created, 'standard')->willReturn('2010-06-23T00:00:00+01:00');
     $updated = new \DateTime('2010-06-23 23:00:00');
     $product->getUpdated()->willReturn($updated);
     $serializer->normalize($updated, 'standard')->willReturn('2010-06-23T23:00:00+01:00');
     $this->normalize($product, 'standard', $context)->shouldReturn(['identifier' => 'my_code', 'family' => 'my_family', 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]], 'created' => '2010-06-23T00:00:00+01:00', 'updated' => '2010-06-23T23:00:00+01:00']);
 }
コード例 #9
0
 function it_adds_multiple_product_values_children_in_the_same_group(ProductValueInterface $valueOne, AttributeInterface $attributeOne, ProductValueInterface $valueTwo, AttributeInterface $attributeTwo, AttributeGroup $group, FormView $valueFormView, $viewUpdaterRegistry)
 {
     $valueOne->getAttribute()->willReturn($attributeOne);
     $valueOne->isRemovable()->willReturn(true);
     $valueOne->getLocale()->willReturn(null);
     $valueOne->getEntity()->willReturn(null);
     $attributeOne->getGroup()->willReturn($group);
     $attributeOne->getId()->willReturn(42);
     $attributeOne->getCode()->willReturn('name');
     $attributeOne->getLabel()->willReturn('Name');
     $attributeOne->getSortOrder()->willReturn(10);
     $attributeOne->getAttributeType()->willReturn('pim_catalog_text');
     $attributeOne->isLocalizable()->willReturn(false);
     $attributeOne->isScopable()->willReturn(false);
     $valueTwo->getAttribute()->willReturn($attributeTwo);
     $valueTwo->isRemovable()->willReturn(true);
     $valueTwo->getLocale()->willReturn(null);
     $valueTwo->getEntity()->willReturn(null);
     $attributeTwo->getGroup()->willReturn($group);
     $attributeTwo->getId()->willReturn(47);
     $attributeTwo->getCode()->willReturn('description');
     $attributeTwo->getLabel()->willReturn('Description');
     $attributeTwo->getSortOrder()->willReturn(15);
     $attributeTwo->getAttributeType()->willReturn('pim_catalog_text');
     $attributeTwo->isLocalizable()->willReturn(false);
     $attributeTwo->isScopable()->willReturn(false);
     $group->getId()->willReturn(1);
     $group->getCode()->willReturn('general');
     $group->getLabel()->willReturn('General');
     $this->addChildren($valueOne, $valueFormView);
     $this->addChildren($valueTwo, $valueFormView);
     $viewUpdaterRegistry->getUpdaters()->willReturn([]);
     $resultView = [1 => ['label' => 'General', 'attributes' => ['name' => ['id' => 42, 'isRemovable' => true, 'code' => 'name', 'label' => 'Name', 'sortOrder' => 10, 'allowValueCreation' => false, 'locale' => null, 'value' => $valueFormView], 'description' => ['id' => 47, 'isRemovable' => true, 'code' => 'description', 'label' => 'Description', 'sortOrder' => 15, 'allowValueCreation' => false, 'locale' => null, 'value' => $valueFormView]]]];
     $this->getView()->shouldReturn($resultView);
 }
コード例 #10
0
 function it_returns_flat_data_with_media($channelManager, Filesystem $filesystem, ChannelInterface $channel, LocaleInterface $locale, ProductInterface $product, FileInfoInterface $media1, FileInfoInterface $media2, ProductValueInterface $value1, ProductValueInterface $value2, AttributeInterface $attribute, ProductValueInterface $identifierValue, AttributeInterface $identifierAttribute, $serializer, $productBuilder)
 {
     $localeCodes = ['en_US'];
     $channel->getLocales()->willReturn(new ArrayCollection([$locale]));
     $channel->getLocaleCodes()->willReturn($localeCodes);
     $productBuilder->addMissingProductValues($product, [$channel], [$locale])->shouldBeCalled();
     $media1->getKey()->willReturn('key/to/media1.jpg');
     $media2->getKey()->willReturn('key/to/media2.jpg');
     $value1->getAttribute()->willReturn($attribute);
     $value1->getMedia()->willReturn($media1);
     $value2->getAttribute()->willReturn($attribute);
     $value2->getMedia()->willReturn($media2);
     $attribute->getAttributeType()->willReturn('pim_catalog_image');
     $product->getValues()->willReturn([$value1, $value2, $identifierValue]);
     $identifierValue->getAttribute()->willReturn($identifierAttribute);
     $identifierAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
     $product->getIdentifier()->willReturn($identifierValue);
     $identifierValue->getData()->willReturn('data');
     $filesystem->has('key/to/media1.jpg')->willReturn(true);
     $filesystem->has('key/to/media2.jpg')->willReturn(true);
     $serializer->normalize($media1, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value1])->willReturn(['normalized_media1']);
     $serializer->normalize($media2, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value2])->willReturn(['normalized_media2']);
     $serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => $localeCodes, 'decimal_separator' => '.', 'date_format' => 'yyyy-MM-dd'])->willReturn(['normalized_product']);
     $channelManager->getChannelByCode('foobar')->willReturn($channel);
     $this->setChannel('foobar');
     $this->process($product)->shouldReturn(['media' => [['normalized_media1'], ['normalized_media2']], 'product' => ['normalized_product']]);
 }
コード例 #11
0
 function it_adds_missing_product_values_from_family_on_new_product($valuesResolver, FamilyInterface $family, ProductInterface $product, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, ProductValueInterface $skuValue)
 {
     $sku->getCode()->willReturn('sku');
     $sku->getAttributeType()->willReturn('pim_catalog_identifier');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $name->getCode()->willReturn('name');
     $name->getAttributeType()->willReturn('pim_catalog_text');
     $name->isLocalizable()->willReturn(true);
     $name->isScopable()->willReturn(false);
     $desc->getCode()->willReturn('description');
     $desc->getAttributeType()->willReturn('pim_catalog_text');
     $desc->isLocalizable()->willReturn(true);
     $desc->isScopable()->willReturn(true);
     // get expected attributes
     $product->getAttributes()->willReturn([$sku]);
     $family->getAttributes()->willReturn([$sku, $name, $desc]);
     $product->getFamily()->willReturn($family);
     // get eligible values
     $valuesResolver->resolveEligibleValues(['sku' => $sku, 'name' => $name, 'description' => $desc], null, null)->willReturn([['attribute' => 'sku', 'type' => 'pim_catalog_identifier', 'locale' => null, 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => null], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'print'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'print']]);
     // get existing values
     $skuValue->getAttribute()->willReturn($sku);
     $skuValue->getLocale()->willReturn(null);
     $skuValue->getScope()->willReturn(null);
     $product->getValues()->willReturn([$skuValue]);
     // add 6 new values : 4 desc (locales x scopes) + 2 name (locales
     $product->addValue(Argument::any())->shouldBeCalledTimes(6);
     $this->addMissingProductValues($product);
 }
コード例 #12
0
 /**
  * @param ProductValueInterface $productValue
  *
  * @return string
  */
 protected function getUniqueValueCode(ProductValueInterface $productValue)
 {
     $attributeCode = $productValue->getAttribute()->getCode();
     $uniqueValueCode = $attributeCode;
     $uniqueValueCode .= null !== $productValue->getLocale() ? $productValue->getLocale() : '';
     $uniqueValueCode .= null !== $productValue->getScope() ? $productValue->getScope() : '';
     return $uniqueValueCode;
 }
コード例 #13
0
 function it_denormalizes_data_into_reference_data($resolver, AttributeInterface $attribute, ReferenceDataInterface $battlecruiser, ReferenceDataRepository $referenceDataRepo, ProductValueInterface $productValue)
 {
     $attribute->getReferenceDataName()->willReturn('starship');
     $productValue->getAttribute()->willReturn($attribute);
     $resolver->resolve('starship')->willReturn($referenceDataRepo);
     $referenceDataRepo->findOneBy(['code' => 'battlecruiser'])->willReturn($battlecruiser);
     $this->denormalize('battlecruiser', 'pim_reference_data_simpleselect', 'csv', ['value' => $productValue])->shouldReturn($battlecruiser);
 }
コード例 #14
0
 public function it_suports_media_attribute(ProductValueInterface $productValue, AttributeInterface $attribute)
 {
     $productValue->getAttribute()->willReturn($attribute);
     $attribute->getBackendType()->willReturn('media');
     $this->supportsValue($productValue)->shouldReturn(true);
     $attribute->getBackendType()->willReturn('other');
     $this->supportsValue($productValue)->shouldReturn(false);
 }
 function it_denormalizes_a_collection_of_reference_data_values($refDataDenormalizer, AttributeInterface $attribute, ReferenceDataInterface $refData1, ReferenceDataInterface $refData2, ProductValueInterface $productValue)
 {
     $productValue->getAttribute()->willReturn($attribute);
     $context = ['value' => $productValue];
     $refDataDenormalizer->denormalize('battlecruiser', 'pim_reference_data_multiselect', null, $context)->shouldBeCalled()->willReturn($refData1);
     $refDataDenormalizer->denormalize('destroyer', 'pim_reference_data_multiselect', null, $context)->shouldBeCalled()->willReturn($refData2);
     $this->denormalize('battlecruiser,destroyer', 'pim_reference_data_multiselect', null, $context)->shouldHaveCount(2);
 }
コード例 #16
0
 public function it_suports_metric_attribute(ProductValueInterface $productValue, AttributeInterface $attribute)
 {
     $productValue->getAttribute()->willReturn($attribute);
     $attribute->getAttributeType()->willReturn('pim_catalog_metric');
     $this->supportsValue($productValue)->shouldReturn(true);
     $attribute->getAttributeType()->willReturn('other');
     $this->supportsValue($productValue)->shouldReturn(false);
 }
コード例 #17
0
 function it_denormalizes_attribute_option($repository, ProductValueInterface $productValueInterface, AttributeInterface $color, AttributeOptionInterface $red)
 {
     $data = '1';
     $context['value'] = $productValueInterface;
     $productValueInterface->getAttribute()->shouldBeCalled()->willReturn($color);
     $color->getCode()->willReturn('color');
     $repository->findOneByIdentifier('color.1')->shouldBeCalled()->willReturn($red);
     $this->denormalize($data, 'className', null, $context)->shouldReturn($red);
 }
 public function it_succesfully_checks_complete_attribute(ProductValueInterface $value, ChannelInterface $channel, LocaleInterface $locale, ProductValueCompleteCheckerInterface $completenessChecker, AttributeInterface $attribute)
 {
     $value->getAttribute()->willReturn($attribute);
     $value->getData()->willReturn('foo');
     $this->addProductValueChecker($completenessChecker);
     $completenessChecker->supportsValue($value)->willReturn(true);
     $completenessChecker->isComplete($value, $channel, $locale)->willReturn(true);
     $this->isComplete($value, $channel, $locale)->shouldReturn(true);
 }
コード例 #19
0
 function it_adds_violation_when_validates_non_string_product_value($context, IsString $stringConstraint, ProductValueInterface $productValue, AttributeInterface $attribute, ConstraintViolationBuilderInterface $violation)
 {
     $productValue->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('foo');
     $attribute->getBackendType()->willReturn('integer');
     $productValue->getInteger()->willReturn(666);
     $context->buildViolation($stringConstraint->message, ['%attribute%' => 'foo', '%givenType%' => 'integer'])->shouldBeCalled()->willReturn($violation);
     $this->validate($productValue, $stringConstraint);
 }
 function it_doesnt_remove_value_when_the_attribute_is_not_locale_specific(FormEvent $event, FormInterface $form, FormInterface $field, FormInterface $rootForm, ProductValueInterface $nameValue, AttributeInterface $nameAttribute)
 {
     $event->getForm()->willReturn($form);
     $event->getData()->willReturn(['name' => $nameValue]);
     $nameValue->getAttribute()->willReturn($nameAttribute);
     $nameAttribute->isLocaleSpecific()->willReturn(false);
     $form->remove('name')->shouldNotBeCalled();
     $this->preSetData($event);
 }
 function it_denormalizes_a_collection_of_reference_data_values($refDataDenormalizer, AttributeInterface $attribute, ReferenceDataInterface $refData1, ReferenceDataInterface $refData2, ProductValueInterface $productValue, ObjectRepository $repository)
 {
     $productValue->getAttribute()->willReturn($attribute);
     $attribute->getReferenceDataName()->willReturn('reference');
     $context = ['value' => $productValue];
     $refDataDenormalizer->resolve('reference')->willReturn($repository);
     $repository->findOneBy(['code' => 'battlecruiser'])->willReturn($refData1);
     $repository->findOneBy(['code' => 'destroyer'])->willReturn($refData2);
     $this->denormalize('battlecruiser, destroyer', 'pim_reference_data_multiselect', null, $context)->shouldHaveCount(2);
 }
コード例 #22
0
 function it_normalizes_collection_of_product_values_in_standard_format($serializer, ProductValueInterface $textValue, AttributeInterface $text, ProductValueInterface $priceValue, AttributeInterface $price)
 {
     $textValue->getAttribute()->willReturn($text);
     $priceValue->getAttribute()->willReturn($price);
     $text->getCode()->willReturn('text');
     $price->getCode()->willReturn('price');
     $serializer->normalize($textValue, 'standard', [])->shouldBeCalled()->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']);
     $serializer->normalize($priceValue, 'standard', [])->shouldBeCalled()->willReturn(['locale' => 'en_US', 'scope' => 'ecommerce', 'value' => [['amount' => '12.50', 'currency' => 'USD'], ['amount' => '15.00', 'currency' => 'EUR']]]);
     $this->normalize([$textValue, $priceValue], 'standard')->shouldReturn(['text' => [['locale' => null, 'scope' => null, 'value' => 'foo']], 'price' => [['locale' => 'en_US', 'scope' => 'ecommerce', 'value' => [['amount' => '12.50', 'currency' => 'USD'], ['amount' => '15.00', 'currency' => 'EUR']]]]]);
 }
コード例 #23
0
 function it_normalizes_product_values_into_json($serializer, ProductValueInterface $nameValue, ProductValueInterface $colorValue, AttributeInterface $name, AttributeInterface $color)
 {
     $nameValue->getAttribute()->willReturn($name);
     $colorValue->getAttribute()->willReturn($color);
     $name->getCode()->willReturn('name');
     $color->getCode()->willReturn('color');
     $serializer->normalize($nameValue, 'json', [])->shouldBeCalled()->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']);
     $serializer->normalize($colorValue, 'json', [])->shouldBeCalled()->willReturn(['locale' => 'en_US', 'scope' => 'ecommerce', 'value' => 'red']);
     $this->normalize([$nameValue, $colorValue], 'json')->shouldReturn(['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']], 'color' => [['locale' => 'en_US', 'scope' => 'ecommerce', 'value' => 'red']]]);
 }
コード例 #24
0
 function it_doesnt_support_multi_targets_constraint($guesser, $factory, ClassMetadata $metadata, ProductValueInterface $value, AttributeInterface $attribute, Constraint $multiTargets, Constraint $validNumber)
 {
     $factory->createMetadata(Argument::any())->willReturn($metadata);
     $value->getAttribute()->willReturn($attribute);
     $attribute->getBackendType()->willReturn('varchar');
     $attribute->getCode()->willReturn('myCode');
     $guesser->guessConstraints($attribute)->willReturn([$multiTargets]);
     $multiTargets->getTargets()->willReturn([Constraint::PROPERTY_CONSTRAINT, Constraint::CLASS_CONSTRAINT]);
     $this->shouldThrow(new \LogicException('No support provided for constraint on many targets'))->duringGetMetadataFor($value);
 }
コード例 #25
0
 function it_normalizes_value_with_decimal_support_backend(ProductValueInterface $value, AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('code');
     $attribute->getBackendType()->willReturn('decimal');
     $attribute->isLocalizable()->willReturn(false);
     $attribute->isScopable()->willReturn(false);
     $value->getData()->willReturn('42.42');
     $value->getAttribute()->willReturn($attribute);
     $this->normalize($value, 'mongodb_json', [])->shouldReturn(['code' => 42.42]);
 }
コード例 #26
0
 function it_normalizes_constraint_violation(ConstraintViolationInterface $violation, ProductInterface $product, ProductValueInterface $productValue, AttributeInterface $attribute)
 {
     $product->getValues()->willReturn(['price' => $productValue]);
     $productValue->getLocale()->willReturn(null);
     $productValue->getScope()->willReturn(null);
     $productValue->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('price');
     $violation->getPropertyPath()->willReturn('values[price].float');
     $violation->getMessage()->willReturn('The price should be above 10.');
     $this->normalize($violation, 'internal_api', ['product' => $product])->shouldReturn(['attribute' => 'price', 'locale' => null, 'scope' => null, 'message' => 'The price should be above 10.']);
 }
コード例 #27
0
 /**
  * The metric is built by many ordered calls, one for the data column, one for the unit column
  *
  * @param ProductValueInterface $value
  * @param string                $dataOrUnit
  *
  * @return MetricInterface
  */
 protected function addFromManyFields(ProductValueInterface $value, $dataOrUnit)
 {
     // TODO come from original implementation, really FRAGIL because depends on many ordered calls
     if (null === ($metric = $value->getMetric())) {
         $metric = $this->factory->createMetric($value->getAttribute()->getMetricFamily());
         $metric->setData($dataOrUnit);
     } else {
         $metric->setUnit($dataOrUnit);
     }
     return $metric;
 }
コード例 #28
0
 function it_denormalizes_a_new_metric_from_a_single_field_and_set_data_and_unit(ProductValueInterface $metricValue, MetricInterface $metric, AttributeInterface $weight, $metricFactory)
 {
     $context = ['value' => $metricValue];
     $metricValue->getMetric()->willReturn(null);
     $metricValue->getAttribute()->willReturn($weight);
     $weight->getMetricFamily()->willReturn('Weight');
     $metricFactory->createMetric('Weight')->willReturn($metric);
     $metric->setData('100')->shouldBeCalled();
     $metric->setUnit('KILOGRAM')->shouldBeCalled();
     $this->denormalize('100 KILOGRAM', 'className', null, $context)->shouldReturn($metric);
 }
コード例 #29
0
 function it_adds_violations_if_value_is_scopable_and_its_scope_does_not_exist($context, $channelRepository, ProductValueInterface $value, AttributeInterface $scopableAttribute, ScopableValue $constraint, ConstraintViolationBuilderInterface $violation)
 {
     $value->getAttribute()->willReturn($scopableAttribute);
     $scopableAttribute->isScopable()->willReturn(true);
     $value->getScope()->willReturn('inexistingChannel');
     $scopableAttribute->getCode()->willReturn('attributeCode');
     $channelRepository->findOneByIdentifier('inexistingChannel')->willReturn(null);
     $violationData = ['%attribute%' => 'attributeCode', '%channel%' => 'inexistingChannel'];
     $context->buildViolation($constraint->inexistingScopeMessage, $violationData)->shouldBeCalled()->willReturn($violation);
     $this->validate($value, $constraint);
 }
コード例 #30
0
 function it_normalizes_date($serializer, ProductValueInterface $productValue, AttributeInterface $attribute)
 {
     $productValue->getData()->willReturn('2000-10-28');
     $productValue->getScope()->willReturn(null);
     $productValue->getLocale()->willReturn(null);
     $attribute->getAttributeType()->willReturn(AttributeTypes::DATE);
     $attribute->isDecimalsAllowed()->willReturn(false);
     $productValue->getAttribute()->willReturn($attribute);
     $serializer->normalize('2000-10-28', 'json', ['decimals_allowed' => false])->willReturn('2000-10-28');
     $this->normalize($productValue, 'json', ['decimals_allowed' => false])->shouldReturn(['locale' => null, 'scope' => null, 'data' => '2000-10-28']);
 }