Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getPngWithFolder example
$this
->urlGenerator =
$this
->
getContainer
(
)
->
get
(
UrlGeneratorInterface::
class
)
;
$this
->mediaRepository =
$this
->
getContainer
(
)
->
get
(
'media.repository'
)
;
$this
->thumbnailRepository =
$this
->
getContainer
(
)
->
get
(
'media_thumbnail.repository'
)
;
$this
->context = Context::
createDefaultContext
(
)
;
$this
->handler =
$this
->
getContainer
(
)
->
get
(
GenerateThumbnailsHandler::
class
)
;
}
public
function
testGenerateThumbnails
(
)
: void
{
$this
->
setFixtureContext
(
$this
->context
)
;
$media
=
$this
->
getPngWithFolder
(
)
;
$this
->thumbnailRepository->
create
(
[
[
'mediaId' =>
$media
->
getId
(
)
,
'width' => 987,
'height' => 987,
]
,
[
'mediaId' =>
$media
->
getId
(
)
,
'width' => 150,
'height' => 150,
]
,
$this
->urlGenerator =
$this
->
getContainer
(
)
->
get
(
UrlGeneratorInterface::
class
)
;
$this
->mediaRepository =
$this
->
getContainer
(
)
->
get
(
'media.repository'
)
;
$this
->thumbnailRepository =
$this
->
getContainer
(
)
->
get
(
'media_thumbnail.repository'
)
;
$this
->context = Context::
createDefaultContext
(
)
;
$this
->thumbnailService =
$this
->
getContainer
(
)
->
get
(
ThumbnailService::
class
)
;
}
public
function
testThumbnailGeneration
(
)
: void
{
$this
->
setFixtureContext
(
$this
->context
)
;
$media
=
$this
->
getPngWithFolder
(
)
;
$filePath
=
$this
->urlGenerator->
getRelativeMediaUrl
(
$media
)
;
$resource
=
fopen
(
__DIR__ . '/../fixtures/shopware-logo.png', 'rb'
)
;
\
assert
(
$resource
!== false
)
;
$this
->
getPublicFilesystem
(
)
->
writeStream
(
$filePath
,
$resource
)
;
$this
->thumbnailService->
updateThumbnails
(
$media
,
$this
->context,
false
)
;
$thumbnailPath
=
$this
->urlGenerator->
getRelativeThumbnailUrl
(
$media
,
$thumbnail
)
;
static
::
assertTrue
(
$this
->
getPublicFilesystem
(
)
->
has
(
$thumbnailPath
)
)
;
}
protected
function
createValidMediaFiles
(
)
: void
{
$this
->
setFixtureContext
(
$this
->context
)
;
$mediaPng
=
$this
->
getPngWithFolder
(
)
;
$mediaJpg
=
$this
->
getJpgWithFolder
(
)
;
$filePath
=
$this
->urlGenerator->
getRelativeMediaUrl
(
$mediaPng
)
;
$this
->
getPublicFilesystem
(
)
->
writeStream
(
$filePath
,
fopen
(
__DIR__ . '/../fixtures/shopware-logo.png', 'rb'
)
)
;
$filePath
=
$this
->urlGenerator->
getRelativeMediaUrl
(
$mediaJpg
)
;
$this
->
getPublicFilesystem
(
)
->
writeStream
(
$filePath
,
$context
)
;
$this
->fileSaver->
renameMedia
(
$id
, 'new destination',
$context
)
;
}
public
function
testRenameMediaThrowsExceptionIfFileNameAlreadyExists
(
)
: void
{
$context
= Context::
createDefaultContext
(
)
;
$this
->
setFixtureContext
(
$context
)
;
$png
=
$this
->
getPng
(
)
;
$old
=
$this
->
getPngWithFolder
(
)
;
static
::
assertIsString
(
$png
->
getFileName
(
)
)
;
$this
->
expectException
(
MediaException::
class
)
;
$this
->
expectExceptionMessage
(
'A file with the name "pngFileWithExtension.png" already exists.'
)
;
$this
->fileSaver->
renameMedia
(
$old
->
getId
(
)
,
$png
->
getFileName
(
)
,
$context
)
;
}
public
function
testRenameMediaForNewExtensionWorksWithSameName
(
)
: void
{