Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
removeUsedMedia example
public
function
testMediaIdsAreNotRemovedWhenMediaIsNotReferenced
(
)
: void
{
$mediaIds
=
array_values
(
$this
->
createMedia
(
10
)
->
all
(
)
)
;
$event
=
new
UnusedMediaSearchEvent
(
$mediaIds
)
;
$listener
=
new
CustomFieldsUnusedMediaSubscriber
(
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
,
$this
->
getContainer
(
)
->
get
(
DefinitionInstanceRegistry::
class
)
)
;
$listener
->
removeUsedMedia
(
$event
)
;
static
::
assertSame
(
$mediaIds
,
$event
->
getUnusedIds
(
)
)
;
}
public
function
testMediaIdsFromAllPossibleLocationsAreRemovedFromEvent
(
)
: void
{
$mediaIds
=
$this
->
createContent
(
)
;
$event
=
new
UnusedMediaSearchEvent
(
$mediaIds
)
;
$listener
=
new
CustomFieldsUnusedMediaSubscriber
(
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
,
$this
->
getContainer
(
)
->
get
(
DefinitionInstanceRegistry::
class
)
)
;
$themeService
=
$this
->
createMock
(
ThemeService::
class
)
;
$themeService
->
expects
(
static
::
exactly
(
2
)
)
->
method
(
'getThemeConfiguration'
)
->
willReturnCallback
(
function
Dstring
$themeId
, ...
$params
)
use
(
$themeConfigMap
)
{
return
$themeConfigMap
[
$themeId
]
;
}
)
;
$event
=
new
UnusedMediaSearchEvent
(
[
$mediaId1
,
$mediaId2
,
$mediaId3
,
$mediaId4
,
$mediaId5
]
)
;
$listener
=
new
UnusedMediaSubscriber
(
$themeRepository
,
$themeService
)
;
$listener
->
removeUsedMedia
(
$event
)
;
static
::
assertEquals
(
[
$mediaId4
,
$mediaId5
]
,
$event
->
getUnusedIds
(
)
)
;
}
}
'mimeType' => 'image/jpeg',
'fileSize' => 12345,
]
;
}
$this
->mediaRepository->
create
(
$media
, Context::
createDefaultContext
(
)
)
;
$mediaIds
=
array_values
(
$ids
->
all
(
)
)
;
$event
=
new
UnusedMediaSearchEvent
(
$mediaIds
)
;
$listener
=
new
UnusedMediaSubscriber
(
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
)
;
$listener
->
removeUsedMedia
(
$event
)
;
static
::
assertSame
(
$mediaIds
,
$event
->
getUnusedIds
(
)
)
;
}
public
function
testMediaIdsFromAllPossibleLocationsAreRemovedFromEvent
(
)
: void
{
$mediaIds
=
$this
->
createContent
(
)
;
$event
=
new
UnusedMediaSearchEvent
(
$mediaIds
)
;
$listener
=
new
UnusedMediaSubscriber
(
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
)
;
$listener
->
removeUsedMedia
(
$event
)
;