-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathResultControllerSpec.php
More file actions
109 lines (102 loc) · 5.17 KB
/
Copy pathResultControllerSpec.php
File metadata and controls
109 lines (102 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);
namespace spec\Omikron\FactFinder\Shopware6\Storefront\Controller;
use Omikron\FactFinder\Shopware6\Config\Communication;
use Omikron\FactFinder\Shopware6\Utilites\Ssr\SearchAdapter;
use Omikron\FactFinder\Shopware6\Utilites\Ssr\Template\Engine;
use PhpSpec\ObjectBehavior;
use PhpSpec\Wrapper\Collaborator;
use Prophecy\Argument;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Shopware\Core\Content\Media\MediaUrlPlaceholderHandlerInterface;
use Shopware\Core\Content\Seo\SeoUrlPlaceholderHandlerInterface;
use Shopware\Core\Framework\Adapter\Twig\TemplateFinder;
use Shopware\Core\Framework\Event\NestedEventDispatcher;
use Shopware\Core\PlatformRequest;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Framework\Routing\RequestTransformer;
use Shopware\Storefront\Page\GenericPageLoader;
use Shopware\Storefront\Page\Page;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
class ResultControllerSpec extends ObjectBehavior
{
private Collaborator $request;
private Collaborator $config;
private Collaborator $pageLoader;
private Collaborator $container;
private Collaborator $salesChannelContext;
private Collaborator $twig;
private Collaborator $seoUrlPlaceholderHandler;
private Collaborator $mediaUrlPlaceholderHandler;
private Collaborator $factfinderLogger;
public function let(
Request $request,
Communication $config,
GenericPageLoader $pageLoader,
ContainerInterface $container,
RequestStack $requestStack,
SalesChannelContext $salesChannelContext,
ParameterBag $attributes,
TemplateFinder $templateFinder,
NestedEventDispatcher $nestedEventDispatcher,
SystemConfigService $systemConfigService,
Environment $twig,
SeoUrlPlaceholderHandlerInterface $seoUrlPlaceholderHandler,
MediaUrlPlaceholderHandlerInterface $mediaUrlPlaceholderHandler,
LoggerInterface $factfinderLogger,
): void {
$this->request = $request;
$this->config = $config;
$this->pageLoader = $pageLoader;
$this->container = $container;
$this->salesChannelContext = $salesChannelContext;
$this->twig = $twig;
$this->seoUrlPlaceholderHandler = $seoUrlPlaceholderHandler;
$this->mediaUrlPlaceholderHandler = $mediaUrlPlaceholderHandler;
$this->factfinderLogger = $factfinderLogger;
$this->beConstructedWith($config, $pageLoader, $factfinderLogger);
$requestStack->getCurrentRequest()->willReturn($request);
$container->get('request_stack')->willReturn($requestStack);
$this->request->attributes = $attributes;
$attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT)->willReturn($salesChannelContext);
$attributes->get(RequestTransformer::STOREFRONT_URL)->willReturn('https://shop.com');
$templateFinder->find('@Parent/storefront/page/factfinder/result.html.twig')->willReturn('@OmikronFactFinder/storefront/page/factfinder/result.html.twig');
$this->container->get(TemplateFinder::class)->willReturn($templateFinder);
$this->container->get('event_dispatcher')->willReturn($nestedEventDispatcher);
$this->container->get(SystemConfigService::class)->willReturn($systemConfigService);
$this->container->get(SeoUrlPlaceholderHandlerInterface::class)->willReturn($seoUrlPlaceholderHandler);
$this->container->get(MediaUrlPlaceholderHandlerInterface::class)->willReturn($mediaUrlPlaceholderHandler);
$this->container->get('twig')->willReturn($twig);
$nestedEventDispatcher->dispatch(Argument::any())->willReturn(Argument::any());
$this->setContainer($container);
}
public function it_should_return_original_response_content_when_ssr_is_not_active(
SearchAdapter $searchAdapter,
Page $page,
Engine $handlebars,
EventDispatcherInterface $eventDispatcher
): void {
$content = 'original content';
$this->pageLoader->load($this->request, $this->salesChannelContext)->willReturn($page);
$this->config->isSsrActive()->willReturn(false);
$this->twig->render('@OmikronFactFinder/storefront/page/factfinder/result.html.twig', Argument::any())->willReturn($content);
$this->seoUrlPlaceholderHandler->replace($content, 'https://shop.com', $this->salesChannelContext)->willReturn($content);
$this->mediaUrlPlaceholderHandler->replace($content)->willReturn($content);
$response = $this->result(
$this->request,
$this->salesChannelContext,
$searchAdapter,
$handlebars,
$eventDispatcher
);
$response->shouldBeAnInstanceOf(Response::class);
$response->getContent()->shouldReturn($content);
}
}