getRandomProduct example

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

        $this->expectException(ProductNotFoundException::class);
        $this->getPageLoader()->load($request$context);
    }

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

        $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());
        
static::assertInstanceOf(WishlistPage::class$page);
        static::assertSame(0, $page->getWishlist()->getProductListing()->getTotal());
    }

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

        $this->systemConfigService->set('core.cart.wishlistEnabled', true);

        $product = $this->getRandomProduct($context);
        $customer = $context->getCustomer();
        static::assertInstanceOf(CustomerEntity::class$customer);
        $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);
        
$event = null;
        $this->catchEvent(MinimalQuickViewPageLoadedEvent::class$event);

        $this->expectException(ProductNotFoundException::class);
        $this->getPageLoader()->load($request$context);
    }

    public function testItDoesLoadATestProduct(): void
    {
        $context = $this->createSalesChannelContext();
        $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);
    }
abstract protected function getPageLoader();

    protected function expectParamMissingException(string $paramName): void
    {
        $this->expectException(RoutingException::class);
        $this->expectExceptionMessage('Parameter "' . $paramName . '" is missing');
    }

    protected function placeRandomOrder(SalesChannelContext $context): string
    {
        $product = $this->getRandomProduct($context);

        $lineItem = (new LineItem($product->getId(), LineItem::PRODUCT_LINE_ITEM_TYPE, $product->getId()))
            ->setRemovable(true)
            ->setStackable(true);

        $cartService = $this->getContainer()->get(CartService::class);
        $cart = $cartService->getCart($context->getToken()$context);
        $cart->add($lineItem);

        return $cartService->order($cart$contextnew RequestDataBag());
    }

    
Home | Imprint | This part of the site doesn't use cookies.