Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
CategoryEntity example
$collection
->
add
(
'c'
)
;
$collection
->
add
(
'a'
)
;
$collection
->
sort
(
fn
(
$a
,
$b
)
=>
strcmp
(
(string)
$a
,
(string)
$b
)
)
;
static
::
assertEquals
(
[
2 => 'a', 0 => 'b', 1 => 'c'
]
,
$collection
->
getElements
(
)
)
;
}
public
function
testFilterInstance
(
)
: void
{
$productStruct
=
new
ProductEntity
(
)
;
$categoryStruct
=
new
CategoryEntity
(
)
;
$collection
=
new
TestCollection
(
)
;
static
::
assertEquals
(
0,
$collection
->
filterInstance
(
ProductEntity::
class
)
->
count
(
)
)
;
$collection
->
add
(
'a'
)
;
$collection
->
add
(
$productStruct
)
;
$collection
->
add
(
$categoryStruct
)
;
$filtered
=
$collection
->
filterInstance
(
Struct::
class
)
;
static
::
assertEquals
(
[
$productStruct
,
$categoryStruct
]
,
array_values
(
$filtered
->
getElements
(
)
)
)
;
}
protected
function
setUp
(
)
: void
{
$this
->replacer =
$this
->
getMockBuilder
(
SeoUrlPlaceholderHandlerInterface::
class
)
->
getMock
(
)
;
$this
->urlGenerator =
new
CategoryUrlGenerator
(
$this
->replacer
)
;
$this
->replacer->
method
(
'generate'
)
->
willReturnArgument
(
0
)
;
$this
->salesChannel =
new
SalesChannelEntity
(
)
;
$this
->salesChannel->
setNavigationCategoryId
(
Uuid::
randomHex
(
)
)
;
}
public
function
testPage
(
)
: void
{
$category
=
new
CategoryEntity
(
)
;
$category
->
setId
(
Uuid::
randomHex
(
)
)
;
$category
->
setType
(
CategoryDefinition::TYPE_PAGE
)
;
static
::
assertSame
(
'frontend.navigation.page',
$this
->urlGenerator->
generate
(
$category
,
$this
->salesChannel
)
)
;
}
public
function
testFolder
(
)
: void
{
$category
=
new
CategoryEntity
(
)
;
$category
->
setType
(
CategoryDefinition::TYPE_FOLDER
)
;
protected
function
setUp
(
)
: void
{
parent::
setUp
(
)
;
$this
->context =
$this
->
getSalesChannelContext
(
)
;
}
public
function
testGetProductSeoCategoryShouldReturnMainCategory
(
)
: void
{
$categoryIds
=
[
Uuid::
randomHex
(
)
]
;
$streamIds
=
[
Uuid::
randomHex
(
)
]
;
$categoryEntity
=
new
CategoryEntity
(
)
;
$categoryEntity
->
setId
(
$categoryIds
[
0
]
)
;
$categoryEntity
->
setName
(
'category-name-1'
)
;
$categoryBreadcrumbBuilder
=
new
CategoryBreadcrumbBuilder
(
$this
->
getCategoryRepositoryMock
(
[
$categoryEntity
]
,
[
$categoryEntity
]
)
)
;
$product
=
$this
->
getProductEntity
(
$streamIds
,
$categoryIds
)
;
$categoryEntity
=
$categoryBreadcrumbBuilder
->
getProductSeoCategory
(
$product
,
$this
->context
)
;
static
::
assertNotNull
(
$categoryEntity
)
;
}
public
function
testGetProductSeoCategoryMissingCategoryIdsAndStreamIds
(
)
: void
{
public
function
testGetDecoratedShouldThrowException
(
)
: void
{
static
::
expectException
(
DecorationPatternException::
class
)
;
$this
->searchIndexer->
getDecorated
(
)
;
}
public
function
testGlobalData
(
)
: void
{
$context
= Context::
createDefaultContext
(
)
;
$repository
=
$this
->
createMock
(
EntityRepository::
class
)
;
$category
=
new
CategoryEntity
(
)
;
$category
->
setUniqueIdentifier
(
Uuid::
randomHex
(
)
)
;
$repository
->
method
(
'search'
)
->
willReturn
(
new
EntitySearchResult
(
'category',
1,
new
EntityCollection
(
[
$category
]
)
,
null,
new
Criteria
(
)
,
$context
)
)
;
$searchResult
=
new
EntitySearchResult
(
'product', 1,
$col
, null,
$criteria
,
$context
)
;
$definition
=
$this
->
getContainer
(
)
->
get
(
CategoryDefinition::
class
)
;
$request
= Request::
create
(
$path
, 'GET',
[
]
,
[
]
,
[
]
,
[
'HTTP_ACCEPT' =>
$accept
]
)
;
$this
->
setOrigin
(
$request
,
$context
)
;
return
$this
->
getFactory
(
$request
)
->
createListingResponse
(
$criteria
,
$searchResult
,
$definition
,
$request
,
$context
)
;
}
private
function
getTestCategory
(
string
$id
)
: CategoryEntity
{
$category
=
new
CategoryEntity
(
)
;
$category
->
setId
(
$id
)
;
$category
->
setName
(
$id
)
;
$category
->
internalSetEntityData
(
'category',
new
FieldVisibility
(
[
]
)
)
;
return
$category
;
}
private
function
setOrigin
(
Request
$request
, Context
$context
)
: void
{
$this
->
setRequestAttributeHack
(
$request
, PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT,
$context
)
;
}
return
new
StaticSystemConfigService
(
[
$salesChannelId
=>
[
CategoryDefinition::CONFIG_KEY_DEFAULT_CMS_PAGE_CATEGORY =>
$cmsPageId
,
]
,
]
)
;
}
private
static
function
getCategory
(
?string
$cmsPageId
, bool
$cmsPageIdSwitched
)
: CategoryEntity
{
$category
=
new
CategoryEntity
(
)
;
if
(
$cmsPageId
)
{
$category
->
setCmsPageId
(
$cmsPageId
)
;
}
$category
->
setCmsPageIdSwitched
(
$cmsPageIdSwitched
)
;
return
$category
;
}
private
function
getSalesChannelContext
(
string
$salesChanelId
)
: SalesChannelContext
{
new
CurrencyEntity
(
)
,
new
CustomerGroupEntity
(
)
,
new
TaxCollection
(
)
,
new
PaymentMethodEntity
(
)
,
new
ShippingMethodEntity
(
)
,
new
ShippingLocation
(
new
CountryEntity
(
)
, null, null
)
,
new
CustomerEntity
(
)
,
new
CashRoundingConfig
(
1, 1.1, true
)
,
new
CashRoundingConfig
(
1, 1.1, true
)
)
;
$this
->response =
new
CategoryRouteResponse
(
new
CategoryEntity
(
)
)
;
$this
->cachedRoute =
new
CachedCategoryRoute
(
$this
->decorated,
$this
->cache,
$this
->
createMock
(
EntityCacheKeyGenerator::
class
)
,
$this
->
createMock
(
AbstractCacheTracer::
class
)
,
$this
->eventDispatcher,
[
]
)
;
}
$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
{
$category
=
new
CategoryEntity
(
)
;
$category
->
setName
(
'TextCategory'
)
;
$resolverContext
=
new
EntityResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
,
$this
->
createMock
(
CategoryDefinition::
class
)
,
$category
)
;
$result
=
new
ElementDataCollection
(
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
$fieldConfig
->
add
(
new
FieldConfig
(
'content', FieldConfig::SOURCE_STATIC, '<h1>Title {{ category.name }}</h1>'
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'text'
)
;
$this
->
expectException
(
RoutingException::
class
)
;
}
else
{
$this
->
expectException
(
MissingRequestParameterException::
class
)
;
}
$this
->
expectExceptionMessage
(
'Parameter "navigationId" is missing.'
)
;
$this
->controller->
category
(
null,
new
Request
(
)
,
$this
->
createMock
(
SalesChannelContext::
class
)
)
;
}
public
function
testCategoryReturn
(
)
: void
{
$categoryEntity
=
new
CategoryEntity
(
)
;
$categoryEntity
->
setCmsPage
(
new
CmsPageEntity
(
)
)
;
$categoryRouteResponse
=
new
CategoryRouteResponse
(
$categoryEntity
)
;
$this
->categoryRouteMock->
method
(
'load'
)
->
willReturn
(
$categoryRouteResponse
)
;
$ids
=
new
IdsCollection
(
)
;
$this
->controller->
category
(
$ids
->
get
(
'category'
)
,
new
Request
(
)
,
$this
->
createMock
(
SalesChannelContext::
class
)
)
;
static
::
assertEquals
(
$categoryRouteResponse
->
getCategory
(
)
->
getCmsPage
(
)
,
$this
->controller->renderStorefrontParameters
[
'cmsPage'
]
)
;
}
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'product-slider'
)
;
$slot
->
setFieldConfig
(
$fieldConfig
)
;
$collection
=
$this
->sliderResolver->
collect
(
$slot
,
$resolverContext
)
;
static
::
assertNull
(
$collection
)
;
}
public
function
testCollectWithMappedConfigButWithInvalidProperty
(
)
: void
{
$category
=
new
CategoryEntity
(
)
;
$category
->
setUniqueIdentifier
(
'category1'
)
;
$resolverContext
=
new
EntityResolverContext
(
$this
->
createMock
(
SalesChannelContext::
class
)
,
new
Request
(
)
,
$this
->
createMock
(
CategoryDefinition::
class
)
,
$category
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
$fieldConfig
->
add
(
new
FieldConfig
(
'products', FieldConfig::SOURCE_MAPPED, 'category.foo'
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setType
(
'product-slider'
)
;
$slot
->
setFieldConfig
(
$fieldConfig
)
;