ProductListingResult example



    public function testLoadSuccessfully(): void
    {
        $request = new Request();
        $request->query->set('search', 'test');

        $criteria = new Criteria();

        $this->listingLoader->expects(static::once())
            ->method('load')
            ->willReturn(new ProductListingResult(
                ProductDefinition::ENTITY_NAME,
                1,
                new ProductCollection([]),
                null,
                $criteria,
                Context::createDefaultContext()
            ));

        $this->searchBuilder->expects(static::once())->method('build');

        $suggestCriteriaEventFired = false;
        

class ProductListingTypeDataResolverTest extends TestCase
{
    private ProductListingCmsElementResolver $listingResolver;

    protected function setUp(): void
    {
        $mock = $this->createMock(ProductListingRoute::class);
        $mock->method('load')->willReturn(
            new ProductListingRouteResponse(
                new ProductListingResult('product', 0, new ProductCollection(), null, new Criteria(), Context::createDefaultContext())
            )
        );

        $this->listingResolver = new ProductListingCmsElementResolver($mock);
    }

    public function testGetType(): void
    {
        static::assertEquals('product-listing', $this->listingResolver->getType());
    }

    
->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
    }

    /** * @dataProvider criteriaProvider */
    public function testCriteria(Criteria $criteria): void
    {
        $ids = new IdsCollection();

        $context = $this->createMock(SalesChannelContext::class);
        $response = new ProductListingRouteResponse(new ProductListingResult('product', 0, new ProductCollection(), null, $criteria$context->getContext()));

        $core = $this->createMock(ProductListingRoute::class);
        $core->expects(static::exactly(2))
            ->method('load')
            ->willReturn($response);

        $route = new CachedProductListingRoute(
            $core,
            $this->getContainer()->get('cache.object'),
            $this->getContainer()->get(EntityCacheKeyGenerator::class),
            $this->getContainer()->get(CacheTracer::class),
            
$sortings = $this->buildSortings();

        $processor = new SortingListingProcessor(
            new StaticSystemConfigService([
                'core.listing.defaultSorting' => 'foo',
            ]),
            new StaticEntityRepository([
                $sortings,
            ])
        );

        $result = new ProductListingResult('foo', 1, new ProductCollection(), null, new Criteria(), Context::createDefaultContext());
        $result->getCriteria()->addExtension('sortings', $sortings);

        $processor->process(
            new Request(['order' => 'foo']),
            $result,
            $this->createMock(SalesChannelContext::class)
        );

        static::assertEquals('foo', $result->getSorting());
    }

    
new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );
        $this->response = new ProductListingRouteResponse(
            new ProductListingResult(
                'entity',
                1,
                new ProductCollection(),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
        );

        $this->cachedRoute = new CachedProductListingRoute(
            $this->decorated,
            


        yield 'Test negative page' => [
            new Request(['p' => -1]),
            (new Criteria())->setOffset(0)->setLimit(24),
        ];
    }

    public function testProcess(): void
    {
        $request = new Request(['p' => 2]);
        $result = new ProductListingResult('foo', 100, new ProductCollection(), null, new Criteria(), Context::createDefaultContext());
        $context = $this->createMock(SalesChannelContext::class);

        $config = new StaticSystemConfigService([
            'core.listing.productsPerPage' => 24,
        ]);

        $processor = new PagingListingProcessor($config);
        $processor->process($request$result$context);

        static::assertSame(2, $result->getPage());
        static::assertSame(24, $result->getLimit());
    }
'id' => 'size',
                            'position' => 1,
                        ]),
                    ]),
                ]);
            },
            new PropertyGroupOptionCollection(),
        ]$definition);

        $handler = new PropertyListingFilterHandler($repository$this->createMock(Connection::class));

        $result = new ProductListingResult(
            'test',
            1,
            new ProductCollection(),
            new AggregationResultCollection([
                new TermsResult('properties', [
                    new Bucket('red', 1, null),
                    new Bucket('green', 1, null),
                ]),
                new TermsResult('options', [
                    new Bucket('xl', 1, null),
                    new Bucket('l', 1, null),
                ]),


    public function testByPassProcess(): void
    {
        $processor = new AggregationListingProcessor(
            [$foo = new FooListingFilterHandler()],
            $this->createMock(EventDispatcherInterface::class)
        );

        $context = $this->createMock(SalesChannelContext::class);

        $result = new ProductListingResult('test', 0, new ProductCollection(), null, new Criteria(), Context::createDefaultContext());

        $processor->process(new Request()$result$context);

        static::assertTrue($foo->called);
    }

    public function testCurrentFiltersAttached(): void
    {
        $processor = new AggregationListingProcessor(
            [new FooListingFilterHandler()],
            $this->createMock(EventDispatcherInterface::class)
        );
Home | Imprint | This part of the site doesn't use cookies.