Skip to content

Commit

Permalink
bug #14405 [Symfony 6] JS Behat (Rafikooo)
Browse files Browse the repository at this point in the history
This PR was merged into the symfony-6 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | symfony-6 <!-- see the comment below -->                  |
| Bug fix?        | no                                                      |
| New feature?    | no                                                      |
| BC breaks?      | no                                                      |
| Deprecations?   | no<!-- don't forget to update the UPGRADE-*.md file --> |
| License         | MIT                                                          |

[This](41ac994) commit was created due to the changes to Symfony 5.4 and Symfony 6 `InputBag` class difference:
[Symfony 5.4](https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/HttpFoundation/InputBag.php#L39)
[Symfony 6](https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/HttpFoundation/InputBag.php#L37)
The array of `sylius_product_attribute_choice` query parameters has previously been processed internally in the `$form->handleRequest($request);` method call and since we cannot influence the way of processing the logic of fetching the attributes, it has been moved to the controller.

Reason for changing the `framework` configuration:
`framework.form` configuration reference:
https://symfony.com/doc/current/forms.html#form-validation-messages

Commits
-------

41ac994 [ProductAttribute] The way of processing query parameters changed
fb06971 [GithubActions] Redundand Run JS Behat command removed
0d9b3e7 [Forms] Legacy error messages disabled
0951b86 [Promotions][Behat] Form validation message changed according to the new messaging system
818e79e [Behat] Unused step implementation removed
c277914 [CatalogPromotions][API][Behat] Step with a different behavior in SF-5.4 and SF-6 changed
188b635 [Behat][API][Admin] Proper IRIs in the admin context
  • Loading branch information
Zales0123 committed Oct 5, 2022
2 parents eeb411f + 188b635 commit 4b50118
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/application.yml
Expand Up @@ -802,7 +802,7 @@ jobs:
name: Run JS Behat
run: |
bin/console cache:pool:clear cache.global_clearer
vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@javascript&&~@todo&&~@cli" || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@javascript&&~@todo&&~@cli" --rerun || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@javascript&&~@todo&&~@cli" --rerun
vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@javascript&&~@todo&&~@cli" || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@javascript&&~@todo&&~@cli" --rerun
-
name: Upload Behat logs
Expand Down
4 changes: 3 additions & 1 deletion config/packages/framework.yaml
@@ -1,6 +1,8 @@
framework:
secret: '%env(APP_SECRET)%'
form: true
form:
enabled: true
legacy_error_messages: false
csrf_protection: true
session:
handler_id: ~
Expand Up @@ -35,7 +35,7 @@ Feature: Creating a catalog promotion
And it should have "winter_sale" code and "Winter sale" name
And "Winter sale" catalog promotion should apply to "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
And it should have "50%" discount
And this catalog promotion should be usable
And it should be active
And "PHP T-Shirt" variant and "Kotlin T-Shirt" variant should be discounted

@api @ui @javascript
Expand Down
Expand Up @@ -30,16 +30,13 @@
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Promotion\Event\CatalogPromotionCreated;
use Symfony\Component\Messenger\MessageBusInterface;
use Webmozart\Assert\Assert;

final class ManagingCatalogPromotionsContext implements Context
{
public function __construct(
private ApiClientInterface $client,
private ResponseCheckerInterface $responseChecker,
private MessageBusInterface $messageBus,
private IriConverterInterface $iriConverter,
private SharedStorageInterface $sharedStorage,
) {
Expand Down Expand Up @@ -1175,14 +1172,6 @@ public function theCatalogPromotionShouldApplyToAllVariantsOfProduct(string $cat
);
}

/**
* @Then this catalog promotion should be usable
*/
public function thisCatalogPromotionShouldBeUsable(): void
{
Assert::isInstanceOf($this->messageBus->getDispatchedMessages()[0]['message'], CatalogPromotionCreated::class);
}

/**
* @Then the catalog promotion :catalogPromotion should be available in channel :channel
* @Then /^(this catalog promotion) should be available in (channel "[^"]+")$/
Expand Down
12 changes: 6 additions & 6 deletions src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php
Expand Up @@ -61,15 +61,15 @@ public function iSpecifyItsAs(string $field, string $value): void
*/
public function iChooseAsTheBaseCurrency(CurrencyInterface $currency): void
{
$this->client->addRequestData('baseCurrency', $this->iriConverter->getIriFromItem($currency));
$this->client->addRequestData('baseCurrency', $this->iriConverter->getIriFromItemInSection($currency, 'admin'));
}

/**
* @When I choose :locale as a default locale
*/
public function iChooseAsADefaultLocale(LocaleInterface $locale): void
{
$this->client->addRequestData('defaultLocale', $this->iriConverter->getIriFromItem($locale));
$this->client->addRequestData('defaultLocale', $this->iriConverter->getIriFromItemInSection($locale, 'admin'));
}

/**
Expand Down Expand Up @@ -102,8 +102,8 @@ public function iSetItsContactPhoneNumberAs(string $contactPhoneNumber): void
public function iChooseAndAsOperatingCountries(CountryInterface $country, CountryInterface $otherCountry): void
{
$this->client->addRequestData('countries', [
$this->iriConverter->getIriFromItem($country),
$this->iriConverter->getIriFromItem($otherCountry),
$this->iriConverter->getIriFromItemInSection($country, 'admin'),
$this->iriConverter->getIriFromItemInSection($otherCountry, 'admin'),
]);
}

Expand All @@ -128,7 +128,7 @@ public function iAllowToSkipPaymentStepIfOnlyOnePaymentMethodIsAvailable(): void
*/
public function iSpecifyMenuTaxonAs(TaxonInterface $taxon): void
{
$this->client->addRequestData('menuTaxon', $this->iriConverter->getIriFromItem($taxon));
$this->client->addRequestData('menuTaxon', $this->iriConverter->getIriFromItemInSection($taxon, 'admin'));
}

/**
Expand Down Expand Up @@ -242,7 +242,7 @@ public function theChannelShouldHaveAsAMenuTaxon(ChannelInterface $channel, Taxo
{
Assert::same(
$this->responseChecker->getValue($this->client->show(Resources::CHANNELS, $channel->getCode()), 'menuTaxon'),
$this->iriConverter->getIriFromItem($taxon),
$this->iriConverter->getIriFromItemInSection($taxon, 'admin'),
sprintf('Channel %s does not have %s menu taxon', $channel->getName(), $taxon->getName()),
);
}
Expand Down
Expand Up @@ -381,7 +381,7 @@ public function theShippingMethodShouldBeAvailableInChannel(ShippingMethodInterf
$this->responseChecker->hasValueInCollection(
$this->client->show(Resources::SHIPPING_METHODS, $shippingMethod->getCode()),
'channels',
$this->iriConverter->getIriFromItem($channel),
$this->iriConverter->getIriFromItemInSection($channel, 'admin'),
),
sprintf('Shipping method is not assigned to %s channel', $channel->getName()),
);
Expand Down
Expand Up @@ -701,14 +701,6 @@ public function iShouldBeNotifiedThatADiscountAmountShouldBeANumber(): void
Assert::same($this->formElement->getValidationMessage(), 'The percentage discount amount must be a number and can not be empty.');
}

/**
* @Then I should be notified that a discount amount is not valid
*/
public function iShouldBeNotifiedThatADiscountAmountIsNotValid(): void
{
Assert::same($this->formElement->getValidationMessage(), 'This value is not valid.');
}

/**
* @Then I should be notified that a discount amount should be configured for at least one channel
*/
Expand Down Expand Up @@ -921,14 +913,6 @@ public function thereShouldStillBeOnlyOneCatalogPromotionWithCode(string $code):
Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $code]));
}

/**
* @Then this catalog promotion should be usable
*/
public function thisCatalogPromotionShouldBeUsable(): void
{
// Intentionally left blank
}

/**
* @Then the catalog promotion :catalogPromotionName should be available in channel :channelName
*/
Expand Down
Expand Up @@ -277,7 +277,7 @@ public function iShouldBeNotifiedThatIsRequired($element)
*/
public function iShouldBeNotifiedThatAMinimalValueShouldBeNumeric($element)
{
$this->assertFieldValidationMessage($element, 'This value is not valid.');
$this->assertFieldValidationMessage($element, 'Please enter a valid money amount.');
}

/**
Expand Down Expand Up @@ -738,11 +738,7 @@ public function iShouldSeeThatTheActionForChannelHasCountValidationErrors(Channe
Assert::same($this->updatePage->getActionValidationErrorsCount($channel->getCode()), $count);
}

/**
* @param string $element
* @param string $expectedMessage
*/
private function assertFieldValidationMessage($element, $expectedMessage)
private function assertFieldValidationMessage(string $element, string $expectedMessage)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
Expand Down
Expand Up @@ -165,7 +165,6 @@
<service id="sylius.behat.context.api.admin.managing_catalog_promotions" class="Sylius\Behat\Context\Api\Admin\ManagingCatalogPromotionsContext">
<argument type="service" id="sylius.behat.api_platform_client.admin" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.event_bus" />
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>
Expand Down
Expand Up @@ -16,6 +16,7 @@
use Sylius\Bundle\ProductBundle\Form\Type\ProductAttributeChoiceType;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Attribute\Model\AttributeInterface;
use Sylius\Component\Product\Model\ProductAttribute;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -49,13 +50,12 @@ public function renderAttributeValueFormsAction(Request $request): Response
{
$template = $request->attributes->get('template', '@SyliusAttribute/attributeValueForms.html.twig');

$form = $this->get('form.factory')->create(ProductAttributeChoiceType::class, null, [
'multiple' => true,
/** @var ProductAttribute[] $attributes */
$attributes = $this->repository->findBy([
'code' => $request->query->all('sylius_product_attribute_choice')
]);
$form->handleRequest($request);

$attributes = $form->getData();
if (null === $attributes) {
if (empty($attributes)) {
throw new BadRequestHttpException();
}

Expand Down

0 comments on commit 4b50118

Please sign in to comment.