assertPageEvent example


        $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());
    }

    protected function getPageLoader()
    {
        return $this->getContainer()->get(ErrorPageLoader::class);
    }

    private function createPage(): string
    {
        $page = [
            
$product = $this->getRandomProduct($context);

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

        $event = 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;
        
$request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

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

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

        static::assertInstanceOf(AccountOrderPage::class$page);
        static::assertSame(0, $page->getOrders()->count());
        self::assertPageEvent(AccountOrderPageLoadedEvent::class$event$context$request$page);
    }

    public function testSalesChannelRestriction(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
        $testContext = $this->createSalesChannelContext();

        $this->placeRandomOrder($context);
        $order = $this->placeRandomOrder($context);
        $this->getContainer()->get('order.repository')->update([
            [
$page = $this->getPageLoader()->load($request$context$this->createCustomer());

        static::assertInstanceOf(AccountOverviewPage::class$page);
        $order = $page->getNewestOrder();
        static::assertInstanceOf(OrderEntity::class$order);
        $transactions = $order->getTransactions();
        static::assertCount(2, $transactions);
        $transaction = $transactions->last();
        static::assertNotNull($transaction);
        static::assertSame(self::LAST_TRANSACTION_ID, $transaction->getId());
        self::assertPageEvent(AccountOverviewPageLoadedEvent::class$event$context$request$page);
    }

    public function testSalesChannelRestriction(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
        $testContext = $this->createSalesChannelContext();

        $order = $this->placeRandomOrder($context);
        $this->getContainer()->get('order.repository')->update([
            [
                
$request = new Request([][]['productId' => $product->getId()]);

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

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

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

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

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

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

        
$accountOrderDetailEvent = null;
        $this->catchEvent(AccountOrderDetailPageLoadedEvent::class$accountOrderDetailEvent);

        /** @var OrderRouteRequestEvent|null $orderRequestEvent */
        $orderRequestEvent = null;
        $this->catchEvent(OrderRouteRequestEvent::class$orderRequestEvent);

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

        static::assertInstanceOf(AccountOrderDetailPage::class$page);
        static::assertSame($orderId$page->getOrder()->getId());
        self::assertPageEvent(AccountOrderDetailPageLoadedEvent::class$accountOrderDetailEvent$context$request$page);

        static::assertNotNull($orderRequestEvent);
        static::assertSame($request$orderRequestEvent->getStorefrontRequest());
        static::assertSame($context$orderRequestEvent->getSalesChannelContext());
        static::assertSame($context->getContext()$orderRequestEvent->getContext());
    }

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

        
$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);
    }

    public function testAddsCurrentSelectedShippingMethod(): void
    {
        $response = new ShippingMethodRouteResponse(
            new EntitySearchResult(
                'shipping_method',
                0,
                new ShippingMethodCollection(),
                null,
                new Criteria(),
                
$context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

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

        $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());
    }

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

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

        static::assertInstanceOf(SearchPage::class$page);
        static::assertEmpty($page->getListing());
        static::assertSame(self::TEST_TERM, $page->getSearchTerm());
        self::assertPageEvent(SearchPageLoadedEvent::class$homePageLoadedEvent$context$request$page);
    }

    public function testItDoesApplyDefaultSorting(): void
    {
        $request = new Request(['search' => self::TEST_TERM]);

        $context = $this->createSalesChannelContextWithNavigation();

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

        

        );

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

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

        static::assertInstanceOf(CheckoutFinishPage::class$page);
        static::assertSame(13.04, $page->getOrder()->getPrice()->getNetPrice());
        self::assertPageEvent(CheckoutFinishPageLoadedEvent::class$event$context$request$page);
        static::assertTrue($eventWasThrown);

        $this->resetEventDispatcher();
    }

    /** * @return CheckoutFinishPageLoader */
    protected function getPageLoader()
    {
        return $this->getContainer()->get(CheckoutFinishPageLoader::class);
    }

        $request = new Request();
        $context = $this->createSalesChannelContext();

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

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

        static::assertInstanceOf(GuestWishlistPage::class$page);
        self::assertPageEvent(GuestWishlistPageLoadedEvent::class$event$context$request$page);
    }

    /** * @return GuestWishlistPageLoader */
    protected function getPageLoader()
    {
        return $this->getContainer()->get(GuestWishlistPageLoader::class);
    }
}
$this->createCustomerWishlist($customer->getId()$product->getId()$context->getSalesChannel()->getId());

        $event = null;
        $this->catchEvent(WishlistPageLoadedEvent::class$event);
        $page = $this->getPageLoader()->load($request$context$customer);

        static::assertInstanceOf(PageLoadedEvent::class$event);

        static::assertInstanceOf(WishlistPage::class$page);
        static::assertSame(1, $page->getWishlist()->getProductListing()->getTotal());
        static::assertSame($context->getContext()$page->getWishlist()->getProductListing()->getContext());
        self::assertPageEvent(WishlistPageLoadedEvent::class$event$context$request$page);
    }

    /** * @return WishlistPageLoader */
    protected function getPageLoader()
    {
        return $this->getContainer()->get(WishlistPageLoader::class);
    }

    private function createCustomerWishlist(string $customerId, string $productId, string $salesChannelId): string
    {

        $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);
    }

    public function testItDeniesAccessToInactiveCategoryPage(): void
    {
        $context = $this->createSalesChannelContextWithNavigation();
        $repository = $this->getContainer()->get('category.repository');

        $categoryId = $context->getSalesChannel()->getNavigationCategoryId();

        $repository->update([[
            'id' => $categoryId,
            
$event = null;
        $this->catchEvent(LandingPageLoadedEvent::class$event);

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

        static::assertInstanceOf(LandingPage::class$page);

        static::assertInstanceOf(LandingPageEntity::class$page->getLandingPage());
        static::assertInstanceOf(CmsPageEntity::class$page->getLandingPage()->getCmsPage());
        static::assertSame($this->ids->get('cms-page')$page->getLandingPage()->getCmsPage()->getId());

        self::assertPageEvent(LandingPageLoadedEvent::class$event$context$request$page);
    }

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

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

        

        $request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

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

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

        static::assertInstanceOf(AccountProfilePage::class$page);
        self::assertPageEvent(AccountProfilePageLoadedEvent::class$event$context$request$page);
    }

    /** * @return AccountProfilePageLoader */
    protected function getPageLoader()
    {
        return $this->getContainer()->get(AccountProfilePageLoader::class);
    }
}
Home | Imprint | This part of the site doesn't use cookies.