getPagelet example

$eventDidRun = null;
        $phpunit = $this;
        $listenerClosure = function DGuestWishlistPageletLoadedEvent $event) use (
            &$eventDidRun,
            $phpunit,
            $context,
            $request
        ): void {
            $eventDidRun = true;
            $phpunit->assertEquals($context$event->getSalesChannelContext());
            $phpunit->assertEquals($request$event->getRequest());
            $phpunit->assertEquals(3, $event->getPagelet()->getSearchResult()->getProducts()->count());
        };

        $this->addEventListener($this->eventDispatcher, GuestWishlistPageletLoadedEvent::class$listenerClosure);

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

        static::assertInstanceOf(GuestWishlistPagelet::class$page);
        $phpunit->assertEquals(3, $page->getSearchResult()->getProducts()->count());
        static::assertTrue($eventDidRun);
    }

    
public static function getSubscribedEvents(): array
    {
        return [
            CountryStateDataPageletLoadedEvent::class => 'onPageletLoaded',
            CountryStateDataPageletCriteriaEvent::class => 'onCriteria',
        ];
    }

    public function onPageletLoaded(CountryStateDataPageletLoadedEvent $event): void
    {
        $this->testPagelet = $event->getPagelet();
    }

    public function onCriteria(CountryStateDataPageletCriteriaEvent $event): void
    {
        $this->criteriaEvent = $event;
    }
}
public static function assertPageletEvent(
        string $expectedClass,
        PageletLoadedEvent $event,
        SalesChannelContext $salesChannelContext,
        Request $request,
        Struct $page
    ): void {
        TestCase::assertInstanceOf($expectedClass$event);
        TestCase::assertSame($salesChannelContext$event->getSalesChannelContext());
        TestCase::assertSame($salesChannelContext->getContext()$event->getContext());
        TestCase::assertSame($request$event->getRequest());
        TestCase::assertSame($page$event->getPagelet());
    }

    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
    {
Home | Imprint | This part of the site doesn't use cookies.