feature #11404 [API] Channel switching (Zales0123)

This PR was merged into the 1.8-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | based on https://github.com/Sylius/Sylius/pull/11402
| License         | MIT

Commits
-------

b3bd616bb3 Switch channel in API basing on hostname
f00cdfb83b PR review fixes
This commit is contained in:
Łukasz Chruściel 2020-04-29 11:19:58 +02:00 committed by GitHub
commit 797955e487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 4 deletions

View file

@ -26,9 +26,9 @@ Feature: Viewing only taxons from the menu taxon
And I should not see "T-Shirts" and "Guns" in the menu
And I should not see "Rifles" and "Revolvers" in the menu
@ui
@ui @api
Scenario: Seeing correct taxons after switching the channel
Given the store operates on another channel named "Poland"
Given the store also operates on a channel named "Poland" with hostname "pl.store.com"
And channel "United States" has menu taxon "Guns"
And channel "Poland" has menu taxon "Clothes"
When I change my current channel to "Poland"

View file

@ -174,6 +174,10 @@ final class ApiPlatformClient implements ApiClientInterface
private function request(RequestInterface $request): Response
{
if ($this->sharedStorage->has('hostname')) {
$this->client->setServerParameter('HTTP_HOST', $this->sharedStorage->get('hostname'));
}
$this->client->request(
$request->method(),
$request->url(),

View file

@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Behat\Context\Api\Shop;
use Behat\Behat\Context\Context;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
final class ChannelContext implements Context
{
/** @var SharedStorageInterface */
private $sharedStorage;
public function __construct(SharedStorageInterface $sharedStorage)
{
$this->sharedStorage = $sharedStorage;
}
/**
* @When /^I change my current (channel to "([^"]+)")$/
*/
public function iChangeMyCurrentChannelTo(ChannelInterface $channel): void
{
$this->sharedStorage->set('hostname', $channel->getHostname());
}
}

View file

@ -18,8 +18,8 @@
<services>
<defaults public="true" />
<service id="sylius.behat.context.api.shop.login" class="Sylius\Behat\Context\Api\Shop\LoginContext">
<argument type="service" id="sylius.behat.client.shop_api_platform_security_client" />
<service id="sylius.behat.context.api.shop.channel" class="Sylius\Behat\Context\Api\Shop\ChannelContext">
<argument type="service" id="sylius.behat.shared_storage" />
</service>
<service id="sylius.behat.context.api.shop.homepage" class="Sylius\Behat\Context\Api\Shop\HomepageContext">
@ -29,6 +29,10 @@
<argument type="service" id="sylius.behat.shared_storage" />
</service>
<service id="sylius.behat.context.api.shop.login" class="Sylius\Behat\Context\Api\Shop\LoginContext">
<argument type="service" id="sylius.behat.client.shop_api_platform_security_client" />
</service>
<service id="sylius.behat.context.api.shop.registration" class="Sylius\Behat\Context\Api\Shop\RegistrationContext">
<argument type="service" id="test.client" />
</service>

View file

@ -16,6 +16,7 @@ default:
- sylius.behat.context.setup.product
- sylius.behat.context.setup.taxonomy
- sylius.behat.context.api.shop.channel
- sylius.behat.context.api.shop.homepage
filters:

View file

@ -110,6 +110,7 @@ final class DefaultUnitedStatesChannelFactory implements DefaultChannelFactoryIn
$channel->addLocale($locale);
$channel->setDefaultLocale($locale);
$channel->setTaxCalculationStrategy('order_items_based');
$channel->setHostname('us.store.com');
$defaultData = [
'channel' => $channel,

View file

@ -101,6 +101,7 @@ final class DefaultUnitedStatesChannelFactorySpec extends ObjectBehavior
$channel->addCurrency($currency)->shouldBeCalled();
$channel->setDefaultLocale($locale)->shouldBeCalled();
$channel->addLocale($locale)->shouldBeCalled();
$channel->setHostname('us.store.com')->shouldBeCalled();
$currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null);
$localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null);