forked from ezsystems/repository-forms
/
PagelayoutContext.php
66 lines (58 loc) · 2.29 KB
/
PagelayoutContext.php
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
<?php
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Behat\Context;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\MinkExtension\Context\RawMinkContext;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use EzSystems\EzPlatformAdminUi\Behat\Helper\EzEnvironmentConstants;
use EzSystems\EzPlatformAdminUi\Behat\Helper\InstallType;
use PHPUnit\Framework\Assert as Assertion;
class PagelayoutContext extends RawMinkContext implements Context, SnippetAcceptingContext
{
/** @var string Regex matching the way the Twig template name is inserted in debug mode */
const TWIG_DEBUG_STOP_REGEX = '<!-- STOP .*%s.* -->';
/**
* @var ConfigResolverInterface
*/
private $configResolver;
/**
* @injectService $configResolver @ezpublish.config.resolver
*/
public function __construct(ConfigResolverInterface $configResolver)
{
$this->configResolver = $configResolver;
}
/**
* @Given /^a pagelayout is configured$/
*/
public function aPagelayoutIsConfigured()
{
Assertion::assertTrue($this->configResolver->hasParameter('pagelayout'));
}
/**
* @Then /^it is rendered using the configured pagelayout$/
*/
public function itIsRenderedUsingTheConfiguredPagelayout()
{
$pageLayout = $this->getPageLayout();
$searchedPattern = sprintf(self::TWIG_DEBUG_STOP_REGEX, preg_quote($pageLayout, null));
Assertion::assertRegExp($searchedPattern, $this->getSession()->getPage()->getOuterHtml());
}
public function getPageLayout(): string
{
$installType = EzEnvironmentConstants::getInstallType();
switch ($installType) {
case InstallType::PLATFORM:
case InstallType::ENTERPRISE:
return $this->configResolver->getParameter('pagelayout', null, 'site');
case InstallType::PLATFORM_DEMO:
case InstallType::ENTERPRISE_DEMO:
return str_replace('@ezdesign', 'app/Resources/views/themes/tastefulplanet', $this->configResolver->getParameter('pagelayout', null, 'site'));
default:
throw new \Exception('Unrecognised install type');
}
}
}