Skip to content

Commit

Permalink
[Channel] Do not consider disabled channel on hostname based request …
Browse files Browse the repository at this point in the history
…resolver
  • Loading branch information
lruozzi9 committed Feb 28, 2022
1 parent 0c487a1 commit 3e14f90
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 3 deletions.
4 changes: 4 additions & 0 deletions UPGRADE-1.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ between guests and logged in customers.
2. Not passing `createdByGuestFlagResolver` through constructor in `Sylius\Component\Core\Cart\Context\ShopBasedCartContext`
is deprecated in Sylius 1.10.9 and it will be prohibited in Sylius 2.0.

# UPGRADE FROM `v1.10.9` TO `v1.10.10`

1. The ChannelRepository findOneByHostname has been deprecated, consider replace it with the new findOneEnabledByHostname method.

# UPGRADE FROM `v1.10.x` TO `v1.10.8`

1. Update `payum/payum` to `^1.7` and execute Doctrine Migrations
Expand Down
15 changes: 15 additions & 0 deletions features/channel/browsing_shop_on_right_channel.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@channels
Feature: Browsing shop on right channel
In order to shop
As a Customer
I want to be redirected to the right channel

Background:
Given the store operates on a channel named "Default" in "USD" currency and with hostname "127.0.0.1"
And the store also operates on a channel named "Alternative" in "USD" currency and with hostname "127.0.0.1"
And the channel "Default" is disabled

@ui
Scenario: Browsing shop in active channel
When I visit the homepage
Then I should be on channel "Alternative"
16 changes: 16 additions & 0 deletions src/Sylius/Behat/Context/Ui/ChannelContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,20 @@ public function shouldSeePluginMainPageWithContent(string $content): void
{
Assert::same($this->pluginMainPage->getContent(), $content);
}

/**
* @When I visit the homepage
*/
public function iVisitTheHomepage(): void
{
$this->homePage->open();
}

/**
* @Then I should be on channel :channel
*/
public function iShouldBeOnChannel(ChannelInterface $channel): void
{
Assert::eq($this->homePage->getMetaTitle(), $channel->getName());
}
}
6 changes: 6 additions & 0 deletions src/Sylius/Behat/Page/Shop/HomePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ function (NodeElement $element) {
);
}

public function getMetaTitle(): string
{
return $this->getElement('meta_title')->getText();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
Expand All @@ -111,6 +116,7 @@ protected function getDefinedElements(): array
'latest_products' => '[data-test-latest-products]',
'locale_selector' => '[data-test-locale-selector]',
'logout_button' => '[data-test-logout-button]',
'meta_title' => 'title',
]);
}
}
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Page/Shop/HomePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public function getAvailableLocales(): array;
public function switchLocale(string $localeCode): void;

public function getLatestProductsNames(): array;

public function getMetaTitle(): string;
}
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 @@ -69,6 +69,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
16 changes: 16 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,16 @@
# 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.ui.channel
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 @@ -28,6 +28,6 @@ public function __construct(ChannelRepositoryInterface $channelRepository)

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 No longer used by internal code and not recommended. */
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 3e14f90

Please sign in to comment.