Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
OffcanvasCartPage example
public
function
testOffCanvasRedirectOnShippingErrors
(
)
: void
{
$cart
=
new
Cart
(
Uuid::
randomHex
(
)
)
;
$cart
->
add
(
new
LineItem
(
Uuid::
randomHex
(
)
, LineItem::PRODUCT_LINE_ITEM_TYPE
)
)
;
$cart
->
addErrors
(
new
ShippingMethodChangedError
(
'old', 'new'
)
)
;
$context
=
$this
->
createMock
(
SalesChannelContext::
class
)
;
$context
->
method
(
'getCustomer'
)
->
willReturn
(
new
CustomerEntity
(
)
)
;
$cartPage
=
new
OffcanvasCartPage
(
)
;
$cartPage
->
setCart
(
$cart
)
;
$this
->offcanvasCartPageLoaderMock->
method
(
'load'
)
->
willReturn
(
$cartPage
)
;
$request
=
new
Request
(
)
;
$request
->query->
set
(
'redirected', false
)
;
$response
=
$this
->controller->
offcanvas
(
$request
,
$context
)
;
static
::
assertEquals
(
new
RedirectResponse
(
'url'
)
,
$response
)
;
}
/** * @return array<array<PageLoadedHook&CartAware>> */
public
static
function
dataProviderHooks
(
)
: array
{
$salesChannelContext
= Generator::
createSalesChannelContext
(
)
;
return
[
[
new
CheckoutCartPageLoadedHook
(
(
new
CheckoutCartPage
(
)
)
->
assign
(
[
'cart' =>
new
Cart
(
Uuid::
randomHex
(
)
)
]
)
,
$salesChannelContext
)
]
,
[
new
CheckoutConfirmPageLoadedHook
(
(
new
CheckoutConfirmPage
(
)
)
->
assign
(
[
'cart' =>
new
Cart
(
Uuid::
randomHex
(
)
)
]
)
,
$salesChannelContext
)
]
,
[
new
CheckoutInfoWidgetLoadedHook
(
(
new
OffcanvasCartPage
(
)
)
->
assign
(
[
'cart' =>
new
Cart
(
Uuid::
randomHex
(
)
)
]
)
,
$salesChannelContext
)
]
,
[
new
CheckoutOffcanvasWidgetLoadedHook
(
(
new
OffcanvasCartPage
(
)
)
->
assign
(
[
'cart' =>
new
Cart
(
Uuid::
randomHex
(
)
)
]
)
,
$salesChannelContext
)
]
,
[
new
CheckoutRegisterPageLoadedHook
(
(
new
CheckoutRegisterPage
(
)
)
->
assign
(
[
'cart' =>
new
Cart
(
Uuid::
randomHex
(
)
)
]
)
,
$salesChannelContext
)
]
,
]
;
}
/** * @dataProvider dataProviderHooks */
public
function
testNameRespectsCartSource
(
PageLoadedHook&CartAware
$hook
)
: void
{
$hook
->
getCart
(
)
->
setSource
(
'test'
)
;
$page
=
$offcanvasCartPageLoader
->
load
(
new
Request
(
)
,
$this
->
createMock
(
SalesChannelContext::
class
)
)
;
static
::
assertInstanceOf
(
OffcanvasCartPage::
class
,
$page
)
;
}
public
function
testRobotsMetaSetIfGiven
(
)
: void
{
$page
=
new
OffcanvasCartPage
(
)
;
$page
->
setMetaInformation
(
new
MetaInformation
(
)
)
;
$pageLoader
=
$this
->
createMock
(
GenericPageLoader::
class
)
;
$pageLoader
->
method
(
'load'
)
->
willReturn
(
$page
)
;
$offcanvasCartPageLoader
=
new
OffcanvasCartPageLoader
(
$this
->
createMock
(
EventDispatcher::
class
)
,
$this
->
createMock
(
StorefrontCartFacade::
class
)
,
$pageLoader
,