Skip to content

Commit

Permalink
[Api][Products][Taxons] implement basic filtering by taxon
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Apr 15, 2021
1 parent 410863b commit 6816d57
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ Feature: Viewing products from a specific taxon
I want to be able to view products from a specific taxon

Background:
Given the store has currency "Euro"
And the store operates on a channel named "Poland"
Given the store operates on a channel named "Poland"
And the store classifies its products as "T-Shirts", "Funny" and "Sad"
And the store has a product "T-Shirt Banana" available in "Poland" channel
And this product belongs to "T-Shirts"
And the store has a product "Plastic Tomato" available in "Poland" channel
And this product belongs to "Funny"

@ui
@ui @api
Scenario: Viewing products from a specific taxon
When I browse products from taxon "T-Shirts"
Then I should see the product "T-Shirt Banana"
And I should not see the product "Plastic Tomato"

@ui
@ui @api
Scenario: Viewing information about empty list of products from a given taxon
When I browse products from taxon "Sad"
Then I should see empty list of products
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Feature: Viewing products from taxon children
I want to be able to view products from taxon and from taxon children

Background:
Given the store has currency "Euro"
And the store operates on a channel named "Poland"
And the store classifies its products as "T-Shirts"
And the "T-Shirts" taxon has children taxon "Men" and "Women"
Expand All @@ -24,7 +23,7 @@ Feature: Viewing products from taxon children
And this product belongs to "T-Shirts"
And this product belongs to "Men"

@ui
@ui @api
Scenario: Viewing products from taxon children
When I browse products from taxon "T-Shirts"
Then I should see the product "T-Shirt Coconut"
Expand Down
20 changes: 16 additions & 4 deletions src/Sylius/Behat/Context/Api/Shop/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@

namespace Sylius\Behat\Context\Api\Shop;

use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\Request;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Taxonomy\Model\TaxonInterface;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
use Symfony\Component\HttpFoundation\Response;
use Webmozart\Assert\Assert;

final class ProductContext implements Context
Expand All @@ -36,14 +35,19 @@ final class ProductContext implements Context
/** @var SharedStorageInterface */
private $sharedStorage;

/** @var IriConverterInterface */
private $iriConverter;

public function __construct(
ApiClientInterface $client,
ResponseCheckerInterface $responseChecker,
SharedStorageInterface $sharedStorage
SharedStorageInterface $sharedStorage,
IriConverterInterface $iriConverter
) {
$this->client = $client;
$this->responseChecker = $responseChecker;
$this->sharedStorage = $sharedStorage;
$this->iriConverter = $iriConverter;
}

/**
Expand All @@ -61,7 +65,7 @@ public function iOpenProductPage(ProductInterface $product): void
public function iBrowseProductsFromTaxon(TaxonInterface $taxon): void
{
$this->client->index();
$this->client->addFilter('productTaxons.taxon.code', $taxon->getCode());
$this->client->addFilter('productTaxons', $this->iriConverter->getIriFromItem($taxon));
$this->client->filter();
}

Expand Down Expand Up @@ -178,6 +182,14 @@ public function itsCurrentVariantShouldBeNamed(string $variantName): void
);
}

/**
* @Then I should see empty list of products
*/
public function iShouldSeeEmptyListOfProducts(): void
{
Assert::same(0, $this->responseChecker->countTotalCollectionItems($this->client->getLastResponse()));
}

private function hasProductWithPrice(array $products, int $price, ?string $productCode = null): bool
{
foreach ($products as $product) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<argument type="service" id="sylius.behat.api_platform_client.shop.product" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="api_platform.iri_converter" />
</service>

<service id="sylius.behat.context.api.shop.product_review" class="Sylius\Behat\Context\Api\Shop\ProductReviewContext">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ default:
- sylius.behat.context.setup.shop_security
- sylius.behat.context.setup.taxonomy

- sylius.behat.context.api.shop.channel
- sylius.behat.context.api.shop.product

filters:
Expand Down
19 changes: 19 additions & 0 deletions src/Sylius/Behat/Service/Context/ChannelContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Behat\Service\Context;

final class ChannelContext
{

}
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/Filter/TaxonFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class TaxonFilter extends AbstractContextAwareFilter
/** @var IriConverter */
private $iriConverter;

/** @var ManagerRegistry */
/** @var ManagerRegistry */
protected $managerRegistry;

public function __construct(IriConverter $iriConverter, ManagerRegistry $managerRegistry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<service id="sylius.api.product_taxon_code_filter" parent="api_platform.doctrine.orm.search_filter">
<argument type="collection">
<argument key="productTaxons.taxon">exact</argument>
<argument key="productTaxons.taxon.code">exact</argument>
</argument>
<tag name="api_platform.filter" />
</service>
Expand Down

0 comments on commit 6816d57

Please sign in to comment.