Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] The hostname resolver does not check for the channel status #14155

Merged
merged 6 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADE-1.11.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# UPGRADE FROM `v1.11.6` TO `v1.11.7`

1. Method `Sylius\Component\Channel\Repository\ChannelRepository::findOneByHostname` has become deprecated, use
`Sylius\Component\Channel\Repository\ChannelRepository::findOneEnabledByHostname` instead. Simultaneously with this change
`Sylius\Component\Channel\Context\RequestBased\HostnameBasedRequestResolver::findChannel` will start selecting only a channel from a range
of enabled channels.

# UPGRADE FROM `v1.11.2` TO `v1.11.3`

1. Order Processors' priorities have changed and `sylius.order_processing.order_prices_recalculator` has now a higher priority than `sylius.order_processing.order_shipment_processor`.
Expand Down
18 changes: 18 additions & 0 deletions features/channel/filtering_out_disabled_channels.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@channels
Feature: Filtering out disabled channels
In order to avoid mistakes
As a Customer
I want to be able to browse only available shops

Background:
Given the store operates on a channel named "Fashion" in "USD" currency and with hostname "127.0.0.1"
And the store operates on a channel named "Furniture" in "EUR" currency and with hostname "127.0.0.1"
And there is product "Black T-Shirt" available in "Fashion" channel
And there is product "Old Wardrobe" available in "Furniture" channel
And the channel "Fashion" is disabled

@ui @api
Scenario: Seeing Furniture shop products
When I check latest products
Then I should see "Old Wardrobe" product
And I should not see "Black T-Shirt" product
28 changes: 28 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/HomepageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ public function iCheckLatestProducts(): void
);
}

/**
* @Then I should see :productName product
*/
public function iShouldSeeProduct(string $productName): void
{
Assert::true(
$this->responseChecker->hasItemWithValue(
$this->productsClient->getLastResponse(),
'name',
$productName
)
);
}

/**
* @Then I should not see :productName product
*/
public function iShouldNotSeeProduct(string $productName): void
{
Assert::false(
$this->responseChecker->hasItemWithValue(
$this->productsClient->getLastResponse(),
'name',
$productName
)
);
}

/**
* @When I check available taxons
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Sylius/Behat/Context/Ui/Shop/HomepageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ public function iShouldSeeProductsInTheList(int $numberOfProducts): void
Assert::same(count($this->homePage->getLatestProductsNames()), $numberOfProducts);
}

/**
* @Then I should see :productName product
*/
public function iShouldSeeProduct(string $productName): void
{
Assert::inArray($productName, $this->homePage->getLatestProductsNames());
}

/**
* @Then I should not see :productName product
*/
public function iShouldNotSeeProduct(string $productName): void
{
Assert::true(!in_array($productName, $this->homePage->getLatestProductsNames()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm genuinely surprised there is no Assert::notInArray 😱

}

/**
* @Then I should see :firstMenuItem in the menu
* @Then I should see :firstMenuItem and :secondMenuItem in the menu
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Resources/config/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ imports:
- suites/ui/admin/locale.yml
- suites/ui/admin/login.yml
- suites/ui/cart/shopping_cart.yml
- suites/ui/channel/channels.yml
- suites/ui/channel/managing_channels.yml
- suites/ui/channel/products_accessibility_in_multiple_channels.yml
- suites/ui/channel/theming.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
ui_channels:
contexts:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.channel

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.product

- sylius.behat.context.api.channel
- sylius.behat.context.api.shop.homepage

filters:
tags: "@channels&&@api"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
ui_channels:
contexts:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.channel

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.product

- sylius.behat.context.ui.channel
- sylius.behat.context.ui.shop.homepage

filters:
tags: "@channels&&@ui"
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public function findOneByHostname(string $hostname): ?ChannelInterface
return $this->findOneBy(['hostname' => $hostname]);
}

public function findOneEnabledByHostname(string $hostname): ?ChannelInterface
{
return $this->findOneBy(['hostname' => $hostname, 'enabled' => true]);
}

public function findOneByCode(string $code): ?ChannelInterface
{
return $this->findOneBy(['code' => $code]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function __construct(private ChannelRepositoryInterface $channelRepositor

public function findChannel(Request $request): ?ChannelInterface
{
return $this->channelRepository->findOneByHostname($request->getHost());
return $this->channelRepository->findOneEnabledByHostname($request->getHost());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

interface ChannelRepositoryInterface extends RepositoryInterface
{
/** @deprecated since Sylius 1.11, use the `findOneEnabledByHostname` method instead */
public function findOneByHostname(string $hostname): ?ChannelInterface;

public function findOneEnabledByHostname(string $hostname): ?ChannelInterface;

public function findOneByCode(string $code): ?ChannelInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function it_finds_the_channel_by_request_hostname(
): void {
$request->getHost()->willReturn('example.org');

$channelRepository->findOneByHostname('example.org')->willReturn($channel);
$channelRepository->findOneEnabledByHostname('example.org')->willReturn($channel);

$this->findChannel($request)->shouldReturn($channel);
}
Expand All @@ -49,7 +49,7 @@ function it_returns_null_if_channel_was_not_found(
): void {
$request->getHost()->willReturn('example.org');

$channelRepository->findOneByHostname('example.org')->willReturn(null);
$channelRepository->findOneEnabledByHostname('example.org')->willReturn(null);

$this->findChannel($request)->shouldReturn(null);
}
Expand Down