Skip to content

Commit

Permalink
Implement the UI part of removing the locales
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Jun 3, 2023
1 parent 8817a9e commit 49fa194
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
4 changes: 2 additions & 2 deletions features/locale/managing_locales/removing_locale.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Removing locales
And it uses the "English (United States)" locale by default
And I am logged in as an administrator

@api
@ui @api
Scenario: The developer tries to delete a not used locale
Given the store has a product "T-Shirt banana"
And this product is named "Banana T-Shirt with Minions" in the "English (United States)" locale
Expand All @@ -19,7 +19,7 @@ Feature: Removing locales
Then I should be informed that locale "Polish (Poland)" has been deleted
And only the "English (United States)" locale should be present in the system

@api
@ui @api
Scenario: The developer tries to deleted a locale in usage
Given the store has a product "T-Shirt banana"
And this product is named "Banana T-Shirt with Minions" in the "English (United States)" locale
Expand Down
53 changes: 53 additions & 0 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingLocalesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@
namespace Sylius\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Page\Admin\Locale\CreatePageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Component\Locale\Converter\LocaleConverterInterface;
use Webmozart\Assert\Assert;

final class ManagingLocalesContext implements Context
{
public function __construct(
private CreatePageInterface $createPage,
private IndexPageInterface $indexPage,
private NotificationCheckerInterface $notificationChecker,
private LocaleConverterInterface $localeConverter,
) {
}

Expand Down Expand Up @@ -51,6 +56,15 @@ public function iAdd()
$this->createPage->create();
}

/**
* @When I remove :localeCode locale
*/
public function iRemoveLocale(string $localeCode): void
{
$this->indexPage->open();
$this->indexPage->deleteResourceOnPage(['code' => $localeCode]);
}

/**
* @Then the store should be available in the :name language
*/
Expand All @@ -68,4 +82,43 @@ public function iShouldNotBeAbleToChoose($name)
{
Assert::false($this->createPage->isOptionAvailable($name));
}

/**
* @Then I should be informed that locale :localeCode has been deleted
*/
public function iShouldBeInformedThatLocaleHasBeenDeleted(string $localeCode): void
{
$this->notificationChecker->checkNotification(
'Locale has been successfully deleted.',
NotificationType::success(),
);
}

/**
* @Then only the :localeCode locale should be present in the system
*/
public function onlyTheLocaleShouldBePresentInTheSystem(string $localeCode): void
{
Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $localeCode]));
Assert::true($this->indexPage->countItems() === 1);
}

/**
* @Then I should be informed that locale :localeCode is in use and cannot be deleted
*/
public function iShouldBeInformedThatLocaleIsInUseAndCannotBeDeleted(string $localeCode): void
{
$this->notificationChecker->checkNotification(
'Cannot delete the locale, as it is used by at least one translation.',
NotificationType::failure(),
);
}

/**
* @Then the :localeCode locale should be still present in the system
*/
public function theLocaleShouldBeStillPresentInTheSystem(string $localeCode): void
{
Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $localeCode]));
}
}
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Resources/config/services/contexts/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
<service id="sylius.behat.context.ui.admin.managing_locales" class="Sylius\Behat\Context\Ui\Admin\ManagingLocalesContext">
<argument type="service" id="sylius.behat.page.admin.locale.create" />
<argument type="service" id="sylius.behat.page.admin.locale.index" />
<argument type="service" id="sylius.behat.notification_checker" />
<argument type="service" id="sylius.locale_converter" />
</service>

<service id="sylius.behat.context.ui.admin.managing_orders" class="Sylius\Behat\Context\Ui\Admin\ManagingOrdersContext">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __invoke(Request $request): Response
$session = $request->getSession();

try {
$this->localeRemover->removeById($request->attributes->get('id'));
$this->localeRemover->removeById((int) $request->attributes->get('id'));

$session->getFlashBag()->add('success', 'sylius.locale.delete.success');
} catch (LocaleNotFoundException $exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ sylius:
cannot_generate_variants: 'Cannot generate variants for a product without options values.'
locale:
delete:
is_used: 'Cannot delete the "%locale%" locale, as it is used by at least one translation.'
success: 'Locale "%locale%" has been successfully deleted.'
is_used: 'Cannot delete the locale, as it is used by at least one translation.'
success: 'Locale has been successfully deleted.'
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function it_throws_not_found_exception_when_a_locale_is_not_found(
$request->headers = $headerBag;
$request->getSession()->willReturn($session);

$attributes->get('id')->willReturn(1);
$attributes->get('id')->willReturn("1");

$localeRemover->removeById(1)->willThrow(LocaleNotFoundException::class);

Expand Down

0 comments on commit 49fa194

Please sign in to comment.