Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
FieldConfigCollection example
static
::
assertSame
(
'product-box',
$this
->productBoxResolver->
getType
(
)
)
;
}
public
function
testCollectWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'product-box'
)
;
$slot
->
setConfig
(
[
]
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
)
)
;
$criteriaCollection
=
$this
->productBoxResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$criteriaCollection
)
;
}
public
function
testCollectWithStaticConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
protected
function
setUp
(
)
: void
{
$resolverMock
=
$this
->
getMockBuilder
(
AbstractProductDetailCmsElementResolver::
class
)
->
onlyMethods
(
[
'getType'
]
)
->
getMockForAbstractClass
(
)
;
$resolverMock
->
method
(
'getType'
)
->
willReturn
(
'dummy-type'
)
;
$this
->dummyResolver =
$resolverMock
;
}
public
function
testCollectWithStaticConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
$fieldConfig
->
add
(
new
FieldConfig
(
'product', FieldConfig::SOURCE_STATIC, 'product123'
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'dummy-type'
)
;
$slot
->
setFieldConfig
(
$fieldConfig
)
;
$criteriaCollection
=
$this
->dummyResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNotNull
(
$criteriaCollection
)
;
static
::
assertCount
(
1,
$criteriaCollection
->
all
(
)
)
;
static
::
assertSame
(
'text',
$this
->textResolver->
getType
(
)
)
;
}
public
function
testCollectWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'text'
)
;
$slot
->
setConfig
(
[
]
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
)
)
;
$criteriaCollection
=
$this
->textResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$criteriaCollection
)
;
}
public
function
testEnrichWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$result
=
new
ElementDataCollection
(
)
;
static
::
assertSame
(
'product-slider',
$this
->sliderResolver->
getType
(
)
)
;
}
public
function
testCollectWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'product-slider'
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
)
)
;
$collection
=
$this
->sliderResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$collection
)
;
}
public
function
testCollectWithEmptyStaticConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
$product
=
new
SalesChannelProductEntity
(
)
;
$product
->
setId
(
'product_01'
)
;
$product
->
setName
(
'Product 01'
)
;
$resolverContext
=
new
EntityResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
,
$this
->
getContainer
(
)
->
get
(
SalesChannelProductDefinition::
class
)
,
$product
)
;
$result
=
new
ElementDataCollection
(
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'product-name'
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
[
new
FieldConfig
(
'content', FieldConfig::SOURCE_MAPPED, 'product.name'
)
]
)
)
;
$this
->productNameCmsElementResolver->
enrich
(
$slot
,
$resolverContext
,
$result
)
;
/** @var TextStruct|null $textStruct */
$textStruct
=
$slot
->
getData
(
)
;
static
::
assertInstanceOf
(
TextStruct::
class
,
$textStruct
)
;
static
::
assertNotEmpty
(
$textStruct
->
getContent
(
)
)
;
static
::
assertEquals
(
'Product 01',
$textStruct
->
getContent
(
)
)
;
}
public
function
testWithStaticContentAndMappedVariable
(
)
: void
{
static
::
assertSame
(
'cross-selling',
$this
->crossSellingResolver->
getType
(
)
)
;
}
public
function
testCollectWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'cross-selling'
)
;
$slot
->
setConfig
(
[
]
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
)
)
;
$criteriaCollection
=
$this
->crossSellingResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$criteriaCollection
)
;
}
public
function
testCollectWithConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
$media
->
setId
(
'media_01'
)
;
$result
->
add
(
'media_id',
new
EntitySearchResult
(
'media',
1,
new
MediaCollection
(
[
$media
]
)
,
null,
new
Criteria
(
)
,
$resolverContext
->
getSalesChannelContext
(
)
->
getContext
(
)
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
$fieldConfig
->
add
(
new
FieldConfig
(
'media', FieldConfig::SOURCE_STATIC, 'media_01'
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'manufacturer-logo'
)
;
$slot
->
setFieldConfig
(
$fieldConfig
)
;
$this
->manufacturerLogoCmsElementResolver->
enrich
(
$slot
,
$resolverContext
,
$result
)
;
/** @var ManufacturerLogoStruct|null $manufacturerLogoStruct */
$manufacturerLogoStruct
=
$slot
->
getData
(
)
;
static
::
assertSame
(
'image',
$this
->imageResolver->
getType
(
)
)
;
}
public
function
testCollectWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'image'
)
;
$slot
->
setConfig
(
[
]
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
)
)
;
$criteriaCollection
=
$this
->imageResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$criteriaCollection
)
;
}
public
function
testCollectWithMediaId
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
public
function
setLocked
(
bool
$locked
)
: void
{
$this
->locked =
$locked
;
}
public
function
getFieldConfig
(
)
: FieldConfigCollection
{
if
(
$this
->fieldConfig
)
{
return
$this
->fieldConfig;
}
$collection
=
new
FieldConfigCollection
(
)
;
$config
=
$this
->
getTranslation
(
'config'
)
??
[
]
;
foreach
(
$config
as
$key
=>
$value
)
{
$collection
->
add
(
new
FieldConfig
(
$key
,
$value
[
'source'
]
,
$value
[
'value'
]
)
)
;
}
return
$this
->fieldConfig =
$collection
;
}
$product
=
$this
->
getRandomProduct
(
$context
, 10, false,
$productCmsPageData
)
;
$request
=
new
Request
(
[
]
,
[
]
,
[
'productId' =>
$product
->
getId
(
)
]
)
;
/** @var ProductPageLoadedEvent $event */
$event
= null;
$this
->
catchEvent
(
ProductPageLoadedEvent::
class
,
$event
)
;
$page
=
$this
->
getPageLoader
(
)
->
load
(
$request
,
$context
)
;
$cmsPage
=
$page
->
getCmsPage
(
)
;
$fieldConfigCollection
=
new
FieldConfigCollection
(
[
new
FieldConfig
(
'content', 'static', 'overwrittenByProduct'
)
]
)
;
static
::
assertNotNull
(
$cmsPage
)
;
static
::
assertIsIterable
(
$cmsPage
->
getSections
(
)
)
;
static
::
assertNotNull
(
$cmsPage
->
getSections
(
)
->
first
(
)
)
;
static
::
assertIsIterable
(
$cmsPage
->
getSections
(
)
->
first
(
)
->
getBlocks
(
)
)
;
$blocks
=
$cmsPage
->
getSections
(
)
->
first
(
)
->
getBlocks
(
)
;
static
::
assertInstanceOf
(
CmsBlockCollection::
class
,
$blocks
)
;
static
::
assertIsIterable
(
$blocks
->
getSlots
(
)
)
;
static
::
assertNotNull
(
$blocks
->
getSlots
(
)
->
get
(
$firstSlotId
)
)
;
static
::
assertNotNull
(
$blocks
->
getSlots
(
)
->
get
(
$secondSlotId
)
)
;
$blocks
=
$firstSection
->
getBlocks
(
)
;
static
::
assertNotNull
(
$blocks
)
;
$firstSlot
=
$blocks
->
getSlots
(
)
->
get
(
self::
$firstSlotId
)
;
static
::
assertNotNull
(
$firstSlot
)
;
static
::
assertEquals
(
self::
$category
[
'cmsPage'
]
[
'sections'
]
[
0
]
[
'blocks'
]
[
0
]
[
'slots'
]
[
0
]
[
'config'
]
,
$firstSlot
->
getConfig
(
)
)
;
static
::
assertEquals
(
new
FieldConfigCollection
(
[
new
FieldConfig
(
'content', 'static', 'initial'
)
]
)
,
$firstSlot
->
getFieldConfig
(
)
)
;
$secondSlot
=
$blocks
->
getSlots
(
)
->
get
(
self::
$secondSlotId
)
;
static
::
assertNotNull
(
$secondSlot
)
;
static
::
assertNull
(
$secondSlot
->
getConfig
(
)
)
;
// overwrite in category
$customSlotConfig
=
[
(string)
self::
$category
[
'cmsPage'
]
[
'sections'
]
[
0
]
[
'blocks'
]
[
0
]
[
'slots'
]
[
0
]
[
'id'
]
=>
[
'content' =>
[
static
::
assertSame
(
'product-box',
$this
->boxCmsElementResolver->
getType
(
)
)
;
}
public
function
testCollectWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'product-box'
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
)
)
;
$collection
=
$this
->boxCmsElementResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$collection
)
;
}
public
function
testCollectWithEmptyStaticConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
static
::
assertSame
(
'buy-box',
$this
->buyBoxResolver->
getType
(
)
)
;
}
public
function
testCollectWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'buy-box'
)
;
$slot
->
setConfig
(
[
]
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
)
)
;
$criteriaCollection
=
$this
->buyBoxResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$criteriaCollection
)
;
}
public
function
testCollectWithStaticConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
static
::
assertSame
(
'image-slider',
$this
->imageSliderResolver->
getType
(
)
)
;
}
public
function
testCollectWithEmptyConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'image-slider'
)
;
$slot
->
setConfig
(
[
]
)
;
$slot
->
setFieldConfig
(
new
FieldConfigCollection
(
)
)
;
$criteriaCollection
=
$this
->imageSliderResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$criteriaCollection
)
;
}
public
function
testCollectWithStaticConfig
(
)
: void
{
$resolverContext
=
new
ResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;