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']]);
 }
예제 #4
0
 /**
  * Upload a file
  *
  * @param ProductMediaInterface $media     ProductMediaInterface entity
  * @param string                $filename  Filename
  * @param bool                  $overwrite Overwrite file or not
  */
 protected function upload(ProductMediaInterface $media, $filename, $overwrite = false)
 {
     if ($file = $media->getFile()) {
         if ($file instanceof UploadedFile && UPLOAD_ERR_OK !== $file->getError()) {
             return;
         }
         $pathname = $file->getPathname();
         $this->write($filename, file_get_contents($pathname), $overwrite);
         if ($file instanceof UploadedFile) {
             $originalFilename = $file->getClientOriginalName();
             $media->resetFile();
         } elseif (false !== strpos($file->getFilename(), $media->getOriginalFilename())) {
             $originalFilename = $media->getOriginalFilename();
         } elseif (null !== $media->getOriginalFilename() && '' !== $media->getOriginalFilename()) {
             $originalFilename = $media->getOriginalFilename();
             $media->resetFile();
         } else {
             $originalFilename = $file->getFilename();
             $media->resetFile();
         }
         $media->setOriginalFilename($originalFilename);
         $media->setFilename($filename);
         $media->setMimeType($file->getMimeType());
     }
 }
 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_provides_export_path($filesystem, ProductMediaInterface $media, ProductValueInterface $value, AttributeInterface $attribute, ProductInterface $product)
 {
     $filesystem->has('akeneo.jpg')->willReturn(true);
     $media->getValue()->willReturn($value);
     $media->getFilename()->willReturn('akeneo.jpg');
     $value->getAttribute()->willReturn($attribute);
     $value->getEntity()->willReturn($product);
     $product->getIdentifier()->willReturn('my-sku');
     $attribute->getCode()->willReturn('thumbnail');
     $attribute->isLocalizable()->willReturn(true);
     $value->getLocale()->willReturn('en_US');
     $attribute->isScopable()->willReturn(true);
     $value->getScope()->willReturn('mobile');
     $media->getOriginalFilename()->willReturn('akeneo.jpg');
     $this->getExportPath($media)->shouldReturn('files/my-sku/thumbnail/en_US/mobile/akeneo.jpg');
     $this->getExportPath($media, 'custom-sku')->shouldReturn('files/custom-sku/thumbnail/en_US/mobile/akeneo.jpg');
 }