|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace spec\Omikron\FactFinder\Shopware6\Subscriber; |
| 6 | + |
| 7 | +use Omikron\FactFinder\Shopware6\Config\Communication; |
| 8 | +use PhpSpec\ObjectBehavior; |
| 9 | +use Prophecy\Argument; |
| 10 | +use Prophecy\Argument\Token\LogicalAndToken; |
| 11 | +use Prophecy\Argument\Token\TypeToken; |
| 12 | +use Shopware\Core\Checkout\Customer\CustomerEntity; |
| 13 | +use Shopware\Core\Framework\Struct\ArrayEntity; |
| 14 | +use Shopware\Core\Framework\Struct\Struct; |
| 15 | +use Shopware\Core\System\Currency\CurrencyEntity; |
| 16 | +use Shopware\Core\System\SalesChannel\SalesChannelContext; |
| 17 | +use Shopware\Core\System\SalesChannel\SalesChannelEntity; |
| 18 | +use Shopware\Storefront\Page\GenericPageLoadedEvent; |
| 19 | +use Shopware\Storefront\Page\Page; |
| 20 | +use Symfony\Component\HttpFoundation\Request; |
| 21 | + |
| 22 | +class ConfigurationSubscriberSpec extends ObjectBehavior |
| 23 | +{ |
| 24 | + function let(Communication $communication) |
| 25 | + { |
| 26 | + $fieldRoles = []; |
| 27 | + $communicationParameters = []; |
| 28 | + $communication->getServerUrl()->willReturn('https://factfinder.server.com'); |
| 29 | + $this->beConstructedWith($communication, $fieldRoles, $communicationParameters); |
| 30 | + } |
| 31 | + |
| 32 | + function it_will_return_factfinderchannel_for_specific_sales_channel_id( |
| 33 | + Communication $communication, |
| 34 | + GenericPageLoadedEvent $event, |
| 35 | + SalesChannelContext $salesChannelContext, |
| 36 | + SalesChannelEntity $salesChannel, |
| 37 | + CustomerEntity $customer, |
| 38 | + CurrencyEntity $currency, |
| 39 | + Request $request, |
| 40 | + Struct $extension, |
| 41 | + Page $page |
| 42 | + ) { |
| 43 | + $event->getSalesChannelContext()->willReturn($salesChannelContext); |
| 44 | + $salesChannelContext->getCustomer()->willReturn($customer); |
| 45 | + $customer->getId()->willReturn(1); |
| 46 | + $salesChannelContext->getCurrency()->willReturn($currency); |
| 47 | + $currency->getIsoCode()->willReturn('EUR'); |
| 48 | + $salesChannelContext->getSalesChannel()->willReturn($salesChannel); |
| 49 | + $salesChannel->getId()->willReturn('main_sales_channel'); |
| 50 | + $communication->getChannel('main_sales_channel')->willReturn('some_ff_channel'); |
| 51 | + $event->getRequest()->willReturn($request); |
| 52 | + $request->get('_route')->willReturn('factfinder'); |
| 53 | + $request->getLocale()->willReturn('en'); |
| 54 | + $event->getPage()->willReturn($page); |
| 55 | + |
| 56 | + $page->addExtension( |
| 57 | + 'factfinder', |
| 58 | + new LogicalAndToken( |
| 59 | + [ |
| 60 | + new TypeToken(ArrayEntity::class), |
| 61 | + Argument::withEntry('communication', Argument::withEntry('channel', 'some_ff_channel')) |
| 62 | + ] |
| 63 | + ))->shouldBeCalled(); |
| 64 | + |
| 65 | + $this->onPageLoaded($event); |
| 66 | + } |
| 67 | +} |
0 commit comments