public function testUploadName() { $data = $this->getSimpleTestData(); $source = __DIR__ . '/fixtures/test-bild.jpg'; $dest = __DIR__ . '/fixtures/test-bild-used.jpg'; //copy image to execute test case multiple times. unlink($dest); copy($source, $dest); $data['file'] = $dest; $path = Shopware()->DocPath('media_image') . '/test-bild-used.jpg'; unlink($path); $media = $this->resource->create($data); $this->assertFileExists($path); //check if the thumbnails are generated $path = Shopware()->DocPath('media_image_thumbnail') . '/test-bild-used_140x140.jpg'; $this->assertFileExists($path); }
public function testUploadNameWithOver50Characters() { $data = $this->getSimpleTestData(); $source = __DIR__ . '/fixtures/test-bild.jpg'; $dest = __DIR__ . '/fixtures/test-bild-with-more-than-50-characaters-more-more-more-more-used.jpg'; //copy image to execute test case multiple times. unlink($dest); copy($source, $dest); $data['file'] = $dest; $media = $this->resource->create($data); $pathPicture = Shopware()->DocPath('media_image') . $media->getFileName(); $mediaService = Shopware()->Container()->get('shopware_media.media_service'); $this->assertTrue($mediaService->has($pathPicture)); //check if the thumbnails are generated $path = Shopware()->DocPath('media_image_thumbnail') . $media->getName() . '_140x140.jpg'; $this->assertTrue($mediaService->has($path)); $mediaService->delete(Shopware()->DocPath('media_image') . $media->getFileName()); $mediaService->delete($path); }
/** * @param PlentySoapResponse_ObjectItemImage $Image * @param Media $mediaResource * * @return MediaModel */ protected function createMedia(PlentySoapResponse_ObjectItemImage $Image, Media $mediaResource) { // cleanly add the new media from plenty $media = $mediaResource->internalCreateMediaByFileLink($Image->ImageURL); Shopware()->Models()->persist($media); Shopware()->Models()->flush(); $newHash = sha1_file($Image->ImageURL); $attributes = $media->getAttribute(); if (empty($attributes)) { $attributes = new MediaAttributes(); $media->setAttribute($attributes); Shopware()->Models()->persist($attributes); Shopware()->Models()->flush(); } $attributes->setPlentyHash($newHash); Shopware()->Models()->persist($attributes); Shopware()->Models()->flush(); PlentymarketsMappingController::addMedia($media->getId(), $Image->ImageID, true); // Generate the thumbnails if (version_compare('4.2', Shopware::VERSION) == 1) { PlentymarketsImportItemImageThumbnailController::getInstance()->addMediaResource($media); } return $media; }