Skip to content

Commit

Permalink
bug #14155 [BUG] The hostname resolver does not check for the channel…
Browse files Browse the repository at this point in the history
… status (lruozzi9, jakubtobiasz)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.11 <!-- see the comment below -->          |
| Bug fix?        | yes                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | yes <!-- don't forget to update the UPGRADE-*.md file --> |
| Related tickets | continuation of #13697                      |
| License         | MIT                                                          |

<!--
 - Bug fixes must be submitted against the 1.10 or 1.11 branch(the lowest possible)
 - Features and deprecations must be submitted against the master 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
-->

What has been done:
- Updated behats (In my opinion now they're now a little bit more natural to read)
- I rebased the PR on top 1.11 and updated the `UPGRADE-1.11.md` and the `UPGRADE-1.10.md` files

We've had a discussion about parametrizing the `HostnameBasedRequestResolver` (what I've done btw 😂) but we decided to drop that idea and keep the original concept.

Thank you @lruozzi9 for your PR we could base on :). 


Commits
-------

28e39e2 [Channel] Do not consider disabled channel on hostname based request resolver
27406cd Adjust behat scenarios
066cf33 Update UPGRADE files
351425d Update deprecation message
55edb2d Remove redundant method
673eb91 Make filtering out scenario available in both ui and api contexts
  • Loading branch information
Zales0123 committed Jul 18, 2022
2 parents 116f2e4 + 673eb91 commit 9c8395d
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 3 deletions.
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()));
}

/**
* @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
19 changes: 19 additions & 0 deletions src/Sylius/Behat/Resources/config/suites/api/channel/channels.yml
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"
19 changes: 19 additions & 0 deletions src/Sylius/Behat/Resources/config/suites/ui/channel/channels.yml
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

0 comments on commit 9c8395d

Please sign in to comment.