Skip to content

Commit

Permalink
feature #15095 Viewing children taxons API scenario ceverage (TheMilek)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13 <!-- see the comment below -->                  |
| Bug fix?        | no                                                     |
| New feature?    | no                                                       |
| BC breaks?      | no                                                      |
| License         | MIT                                                          |

<!--
 - Bug fixes must be submitted against the 1.12 branch
 - Features and deprecations must be submitted against the 1.13 branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------

7d2b1c0 Viewing children taxons API scenario ceverage
  • Loading branch information
GSadee committed Jun 15, 2023
2 parents 5ccd65c + 7d2b1c0 commit aba91d8
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
77 changes: 77 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/TaxonContext.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Transform/TaxonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function getTaxonByCode(string $code): TaxonInterface
* @Transform /^configured with "([^"]+)" and "([^"]+)"$/
* @Transform /^"([^"]+)" and "([^"]+)" taxons$/
* @Transform /^belongs to "([^"]+)" and "([^"]+)"/
* @Transform /^"([^"]+)" and "([^"]+)" in the vertical menu$/
*/
public function getTaxonsByNames(string ...$taxonNames): iterable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit aba91d8

Please sign in to comment.