[Behat][API] Add step implementation for not seeing disabled variants

This commit is contained in:
Rafikooo 2023-06-07 14:56:03 +02:00
parent 41274eb8d7
commit debb53d38f
No known key found for this signature in database
GPG key ID: 4A26D8327BC2442B
4 changed files with 34 additions and 5 deletions

View file

@ -114,6 +114,13 @@ final class Request implements RequestInterface
private function mergeArraysUniquely(array $firstArray, array $secondArray): array
{
foreach ($secondArray as $key => $value) {
if (is_string($key) && str_ends_with($key, '[]')) {
$key = substr($key, 0, -2);
$firstArray[$key][] = $value;
continue;
}
if (is_array($value) && is_array(@$firstArray[$key])) {
$value = $this->mergeArraysUniquely($firstArray[$key], $value);
}

View file

@ -579,6 +579,18 @@ final class ProductContext implements Context
Assert::false($this->hasProductOptionWithNameAndValue($optionName, $optionValueValue));
}
/**
* @Then /^I should be able to select the "([^"]+)" and "([^"]+)" ([^\s]+) option values$/
*/
public function iShouldBeAbleToSelectTheAndColorOptionValues(
string $optionValueValue1,
string $optionValueValue2,
string $optionName,
): void {
Assert::true($this->hasProductOptionWithNameAndValue($optionName, $optionValueValue1));
Assert::true($this->hasProductOptionWithNameAndValue($optionName, $optionValueValue2));
}
/**
* @Then I should be able to select between :count variants
*/
@ -741,12 +753,10 @@ final class ProductContext implements Context
private function hasProductOptionWithNameAndValue(string $expectedOptionName, string $expectedOptionValueValue): bool
{
$response = $this->client->getLastResponse();
$productVariants = $this->responseChecker->getCollection(
$this->client->index(
Resources::PRODUCT_VARIANTS,
['product' => $this->responseChecker->getValue($response, '@id')],
['product' => $this->iriConverter->getIriFromItem($this->sharedStorage->get('product'))],
),
);

View file

@ -75,11 +75,11 @@ final class ProductVariantContext implements Context
}
/**
* @When /^I filter variants by ("[^"]+" option value)$/
* @When /^I filter (?:them|variants) by ("[^"]+" option value)$/
*/
public function iFilterVariantsByOption(ProductOptionValueInterface $optionValue): void
{
$this->client->addFilter('optionValues', $this->iriConverter->getIriFromItem($optionValue));
$this->client->addFilter('optionValues[]', $this->iriConverter->getIriFromItem($optionValue));
$response = $this->client->filter();
$this->sharedStorage->set('product_variant_collection', $this->responseChecker->getCollection($response));
@ -350,6 +350,17 @@ final class ProductVariantContext implements Context
}
}
/**
* @Then I should not see any variants
*/
public function iShouldNotSeeAnyVariants(): void
{
Assert::same(
count($this->sharedStorage->get('product_variant_collection')),
0,
);
}
private function findVariant(?ProductVariantInterface $variant): array
{
$response = $this->sharedStorage->has('response') ? $this->sharedStorage->get('response') : $this->client->getLastResponse();

View file

@ -12,6 +12,7 @@ default:
- sylius.behat.context.transform.locale
- sylius.behat.context.transform.product
- sylius.behat.context.transform.product_association_type
- sylius.behat.context.transform.product_option_value
- sylius.behat.context.transform.product_variant
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.taxon