forked from ezsystems/repository-forms
/
PagelayoutContext.php
48 lines (42 loc) · 1.54 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
<?php
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Features\Context;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\MinkExtension\Context\RawMinkContext;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
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->configResolver->getParameter('pagelayout');
$searchedPattern = sprintf(self::TWIG_DEBUG_STOP_REGEX, preg_quote($pageLayout, null));
Assertion::assertRegExp($searchedPattern, $this->getSession()->getPage()->getOuterHtml());
}
}