-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #15095 Viewing children taxons API scenario ceverage (TheMilek)
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
Showing
5 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters