function it_validates_extensions_with_product_media($context, File $constraint, ProductMediaInterface $productMedia) { $constraint->allowedExtensions = ['gif', 'jpg']; $productMedia->getFile()->willReturn(new \SplFileInfo(__DIR__ . '/../../../../../../features/Context/fixtures/akeneo.jpg')); $context->addViolation(Argument::any())->shouldNotBeCalled(); $this->validate($productMedia, $constraint); }
public function it_succesfully_checks_complete_media(ProductValueInterface $value, ChannelInterface $channel, LocaleInterface $locale, ProductMediaInterface $media) { $value->getMedia()->willReturn(null); $this->isComplete($value, $channel, $locale)->shouldReturn(false); $value->getMedia()->willReturn([]); $this->isComplete($value, $channel, $locale)->shouldReturn(false); $media->__toString()->willReturn(''); $value->getMedia()->willReturn($media); $this->isComplete($value, $channel, $locale)->shouldReturn(false); $media->__toString()->willReturn('other'); $value->getMedia()->willReturn($media); $this->isComplete($value, $channel, $locale)->shouldReturn(true); }
function it_returns_flat_data_with_media(ChannelInterface $channel, $channelManager, ProductInterface $product, ProductMediaInterface $media1, ProductMediaInterface $media2, ProductValueInterface $value1, ProductValueInterface $value2, AttributeInterface $attribute, $serializer) { $media1->getFilename()->willReturn('media_name'); $media1->getOriginalFilename()->willReturn('media_original_name'); $media2->getFilename()->willReturn('media_name'); $media2->getOriginalFilename()->willReturn('media_original_name'); $value1->getAttribute()->willReturn($attribute); $value1->getData()->willReturn($media1); $value2->getAttribute()->willReturn($attribute); $value2->getData()->willReturn($media2); $attribute->getAttributeType()->willReturn('pim_catalog_image'); $product->getValues()->willReturn([$value1, $value2]); $serializer->normalize([$media1, $media2], 'flat', ['field_name' => 'media', 'prepare_copy' => true])->willReturn(['normalized_media1', 'normalized_media2']); $serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => ''])->willReturn(['normalized_product']); $channelManager->getChannelByCode('foobar')->willReturn($channel); $this->setChannel('foobar'); $this->process($product)->shouldReturn(['media' => ['normalized_media1', 'normalized_media2'], 'product' => ['normalized_product']]); }
function it_copies_when_a_product_value_has_a_media_but_not_the_target_value($builder, $mediaManager, $attrValidatorHelper, ProductMediaInterface $fromMedia, ProductMediaInterface $toMedia, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product, ProductValueInterface $fromProductValue, ProductValueInterface $toProductValue) { $fromLocale = 'fr_FR'; $toLocale = 'fr_FR'; $toScope = 'mobile'; $fromScope = 'mobile'; $fromAttribute->getCode()->willReturn('fromAttributeCode'); $toAttribute->getCode()->willReturn('toAttributeCode'); $attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled(); $attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled(); $fromMedia->getOriginalFilename()->shouldBeCalled()->willReturn('picture.jpg'); $fromProductValue->getMedia()->willReturn($fromMedia); $product->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue); $product->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null); $builder->addProductValue($product, $toAttribute, $toLocale, $toScope)->willReturn($toProductValue); $toProductValue->getMedia()->willReturn($toMedia); $mediaManager->generateFilenamePrefix($product, $fromProductValue)->willReturn('prefix-to-file'); $mediaManager->duplicate($fromMedia, $toMedia, 'prefix-to-file')->shouldBeCalled(); $this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]); }
function it_returns_flat_data_with_media($serializer, $channelManager, $dateformatProvider, $numberFormatProvider, ChannelInterface $channel, ProductInterface $product, ProductMediaInterface $media1, ProductMediaInterface $media2, ProductValueInterface $value1, ProductValueInterface $value2, AttributeInterface $attribute) { $dateformatProvider->getFormat('en_US')->willReturn('n/j/y'); $numberFormatProvider->getFormat('en_US')->willReturn(['decimal_separator' => '.']); $this->configureOptions('en_US'); $media1->getFilename()->willReturn('media_name'); $media1->getOriginalFilename()->willReturn('media_original_name'); $media2->getFilename()->willReturn('media_name'); $media2->getOriginalFilename()->willReturn('media_original_name'); $value1->getAttribute()->willReturn($attribute); $value1->getData()->willReturn($media1); $value2->getAttribute()->willReturn($attribute); $value2->getData()->willReturn($media2); $attribute->getAttributeType()->willReturn('pim_catalog_image'); $product->getValues()->willReturn([$value1, $value2]); $serializer->normalize([$media1, $media2], 'flat', ['field_name' => 'media', 'prepare_copy' => true])->willReturn(['normalized_media1', 'normalized_media2']); $serializer->normalize($product, 'flat', ['scopeCode' => 'mobile', 'localeCodes' => '', 'decimal_separator' => '.', 'date_format' => 'n/j/y'])->willReturn(['normalized_product']); $channelManager->getChannelByCode('mobile')->willReturn($channel); $this->setChannelCode('mobile'); $this->process($product)->shouldReturn(['media' => ['normalized_media1', 'normalized_media2'], 'product' => ['normalized_product']]); }
/** * {@inheritdoc} */ public function setMedia(ProductMediaInterface $media) { $media->setValue($this); $this->media = $media; return $this; }
function it_marks_product_as_updated_when_a_product_media_is_updated(EntityManager $em, UnitOfWork $uow, ProductInterface $product, ProductValueInterface $value, ProductMediaInterface $media) { $media->getValue()->willReturn($value); $value->getEntity()->willReturn($product); $this->guessUpdates($em, $media, UpdateGuesserInterface::ACTION_UPDATE_ENTITY)->shouldReturn([$product]); }
/** * Predicate to know if file exists physically * * @param ProductMediaInterface $media * * @return bool */ protected function fileExists(ProductMediaInterface $media) { if (null === $media->getFilename()) { return false; } return $this->filesystem->has($media->getFilename()); }
function it_normalizes_media(ProductMediaInterface $media) { $media->getFilename()->willReturn('myfile.pdf'); $media->getOriginalFilename()->willReturn('myfile.pdf'); $this->normalize($media, 'mongodb_json', [])->shouldReturn(['filename' => 'myfile.pdf', 'originalFilename' => 'myfile.pdf']); }
function it_returns_null_if_media_does_not_exists_during_get_file_path(ProductMediaInterface $media) { $media->getFilename()->willReturn(null); $this->getFilePath($media, '/tmp/export/path/')->shouldReturn(null); }
function it_normalizes_media_by_keeping_the_media_filename(ProductMediaInterface $media) { $media->getFilename()->willReturn('foo.jpg'); $this->normalize($media, null, ['field_name' => 'front', 'versioning' => true])->shouldReturn(['front' => 'foo.jpg']); }