Switch channel in API basing on hostname

This commit is contained in:
Mateusz Zalewski 2020-04-28 11:55:49 +02:00
parent e31de1fe6f
commit b3bd616bb3
No known key found for this signature in database
GPG key ID: 9BECA0BB71612E52
7 changed files with 53 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,11 @@ final class ApiPlatformClient implements ApiClientInterface
private function request(RequestInterface $request): Response
{
try {
$this->client->setServerParameter('HTTP_HOST', $this->sharedStorage->get('hostname'));
} catch (\InvalidArgumentException $exception) {
}
$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);