createSalesChannelContextWithNavigation example

$this->systemConfigRepository = $this->getContainer()->get('system_config.repository');
        $this->cmsPageRepository = $this->getContainer()->get('cms_page.repository');
        $this->salesChannelContext = $contextFactory->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        $this->errorLayoutId = $this->createPage();
        $this->systemConfigService->set('core.basicInformation.http404Page', $this->errorLayoutId);
    }

    public function testItDoesLoad404CmsLayoutPageIn404Case(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();

        /** @var ErrorPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(ErrorPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($this->errorLayoutId, $request$context);

        static::assertInstanceOf(ErrorPage::class$page);
        self::assertPageEvent(ErrorPageLoadedEvent::class$event$context$request$page);
        static::assertSame('404 layout', $page->getCmsPage()->getName());
    }

    
class LandingPageLoaderTest extends TestCase
{
    use IntegrationTestBehaviour;
    use StorefrontPageTestBehaviour;

    private TestDataCollection $ids;

    public function testLoadWithoutId(): void
    {
        $this->expectExceptionObject(RoutingException::missingRequestParameter('landingPageId', '/landingPageId'));

        $context = $this->createSalesChannelContextWithNavigation();
        $this->getPageLoader()->load(new Request()$context);
    }

    public function testLoad(): void
    {
        $this->ids = new TestDataCollection();

        $request = new Request([][][
            'landingPageId' => $this->ids->get('landing-page'),
        ]);

        
$page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(AccountLoginPage::class$page);
        static::assertSame(StorefrontPageTestConstants::COUNTRY_COUNT, $page->getCountries()->count());
        static::assertInstanceOf(CountryStateCollection::class$page->getCountries()->first()->getStates());
        self::assertPageEvent(AccountLoginPageLoadedEvent::class$event$context$request$page);
    }

    public function testItLoadsWithoutACustomer(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();
        $page = $this->getPageLoader()->load($request$context);

        static::assertSame(StorefrontPageTestConstants::COUNTRY_COUNT, $page->getCountries()->count());
        static::assertInstanceOf(CountryStateCollection::class$page->getCountries()->first()->getStates());
    }

    /** * @return AccountLoginPageLoader */
    protected function getPageLoader()
    {
        
#[Package('buyers-experience')] class SearchPageTest extends TestCase
{
    use IntegrationTestBehaviour;
    use StorefrontPageTestBehaviour;

    private const TEST_TERM = 'foo';

    public function testItRequiresSearchParam(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();

        $this->expectParamMissingException('search');
        $this->getPageLoader()->load($request$context);
    }

    public function testItDoesSearch(): void
    {
        $request = new Request(['search' => self::TEST_TERM]);
        $context = $this->createSalesChannelContextWithNavigation();
        /** @var SearchPageLoadedEvent $homePageLoadedEvent */
        $homePageLoadedEvent = null;
        
$this->catchEvent(MinimalQuickViewPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(MinimalQuickViewPage::class$page);
        static::assertSame(StorefrontPageTestConstants::PRODUCT_NAME, $page->getProduct()->getName());
        self::assertPageEvent(MinimalQuickViewPageLoadedEvent::class$event$context$request$page);
    }

    public function testItDispatchPageCriteriaEvent(): void
    {
        $context = $this->createSalesChannelContextWithNavigation();
        $product = $this->getRandomProduct($context);

        $request = new Request([][]['productId' => $product->getId()]);

        /** @var ProductPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(MinimalQuickViewPageCriteriaEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(MinimalQuickViewPage::class$page);
    }
/** * @internal */
class CartPageTest extends TestCase
{
    use IntegrationTestBehaviour;
    use StorefrontPageTestBehaviour;

    public function testItLoadsTheCart(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();

        /** @var CheckoutCartPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(CheckoutCartPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(CheckoutCartPage::class$page);
        static::assertSame(0.0, $page->getCart()->getPrice()->getNetPrice());
        static::assertSame($context->getToken()$page->getCart()->getToken());
        self::assertPageEvent(CheckoutCartPageLoadedEvent::class$event$context$request$page);
    }
/** * @internal */
class NavigationPageTest extends TestCase
{
    use IntegrationTestBehaviour;
    use StorefrontPageTestBehaviour;

    public function testItDoesLoadAPage(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();

        /** @var NavigationPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(NavigationPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(NavigationPage::class$page);
        self::assertPageEvent(NavigationPageLoadedEvent::class$event$context$request$page);
    }

    
/** * @internal */
class ProductPageTest extends TestCase
{
    use IntegrationTestBehaviour;
    use StorefrontPageTestBehaviour;

    public function testItRequiresProductParam(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();

        $this->expectParamMissingException('productId');
        $this->getPageLoader()->load($request$context);
    }

    public function testItRequiresAValidProductParam(): void
    {
        $request = new Request([][]['productId' => '99999911ffff4fffafffffff19830531']);
        $context = $this->createSalesChannelContextWithNavigation();

        $this->expectException(ProductNotFoundException::class);
        
Home | Imprint | This part of the site doesn't use cookies.