Viewing children taxons API scenario ceverage

This commit is contained in:
TheMilek 2023-06-13 12:44:20 +02:00
parent 6a12565419
commit 7d2b1c07ad
No known key found for this signature in database
GPG key ID: 2E44205E7374692F
5 changed files with 89 additions and 2 deletions

View file

@ -11,14 +11,14 @@ Feature: Viewing children taxons of current taxon
And the "Clothes" taxon has children taxons "T-Shirts", "Coats" and "Trousers"
And channel "United States" has menu taxon "Category"
@ui
@ui @api
Scenario: Viewing only enabled taxons in the vertical menu
Given the "Coats" taxon is disabled
When I try to browse products from taxon "Clothes"
Then I should not see "Coats" in the vertical menu
And I should see "T-Shirts" and "Trousers" in the vertical menu
@ui
@ui @no-api
Scenario: Cannot navigate to disabled parent taxon
Given the "Clothes" taxon is disabled
When I try to browse products from taxon "T-Shirts"

View file

@ -0,0 +1,77 @@
<?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\Context\Api\Shop;
use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Doctrine\Persistence\ObjectManager;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Context\Api\Resources;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;
final class TaxonContext implements Context
{
public function __construct(
private ApiClientInterface $client,
private ResponseCheckerInterface $responseChecker,
private IriConverterInterface $iriConverter,
private ObjectManager $objectManager,
private string $apiUrlPrefix,
) {
}
/**
* @When /^I try to browse products from (taxon "([^"]+)")$/
*/
public function iTryToBrowseProductsFrom(TaxonInterface $taxon): void
{
$this->objectManager->clear(); // avoiding doctrine cache
$this->client->show(Resources::TAXONS, $taxon->getCode());
}
/**
* @Then I should not see :taxon in the vertical menu
*/
public function iShouldNotSeeInTheVerticalMenu(TaxonInterface $taxon): void
{
Assert::false(
$this->isTaxonChildVisible($taxon),
sprintf('Taxon %s is in the vertical menu, but it should not.', $taxon->getName())
);
}
/**
* @Then /^I should see ("([^"]+)" and "([^"]+)" in the vertical menu)$/
*/
public function iShouldSeeInTheVerticalMenu(iterable $taxons): void
{
foreach ($taxons as $taxon) {
Assert::true(
$this->isTaxonChildVisible($taxon),
sprintf('Taxon %s is not in the vertical menu, but it should be.', $taxon->getName())
);
}
}
private function isTaxonChildVisible(TaxonInterface $taxon): bool
{
$taxonIri = $this->iriConverter->getIriFromItem($taxon);
$response = $this->client->getLastResponse();
$children = $this->responseChecker->getValue($response, 'children');
return in_array($taxonIri, $children, true);
}
}

View file

@ -67,6 +67,7 @@ final class TaxonContext implements Context
* @Transform /^configured with "([^"]+)" and "([^"]+)"$/
* @Transform /^"([^"]+)" and "([^"]+)" taxons$/
* @Transform /^belongs to "([^"]+)" and "([^"]+)"/
* @Transform /^"([^"]+)" and "([^"]+)" in the vertical menu$/
*/
public function getTaxonsByNames(string ...$taxonNames): iterable
{

View file

@ -189,5 +189,13 @@
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="sylius.behat.api_platform_client.shop" />
</service>
<service id="Sylius\Behat\Context\Api\Shop\TaxonContext">
<argument type="service" id="sylius.behat.api_platform_client.shop" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="doctrine.orm.entity_manager" />
<argument>%sylius.security.new_api_route%</argument>
</service>
</services>
</container>

View file

@ -36,6 +36,7 @@ default:
- sylius.behat.context.api.shop.product
- sylius.behat.context.api.shop.product_attribute
- sylius.behat.context.api.shop.product_variant
- Sylius\Behat\Context\Api\Shop\TaxonContext
filters:
tags: "@viewing_products&&@api"