Skip to content

Commit

Permalink
Merge branch '4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon committed Apr 1, 2022
2 parents 88c7d42 + c985f53 commit e667191
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 502 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/browser-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
with:
project-edition: 'oss'
project-version: '4.1.x-dev'
test-suite: '--mode=standard --profile=core --tags=~@broken'
test-setup-phase-1: '--mode=standard --profile=core --suite=setup'
test-suite: "--mode=standard --profile=core --tags='~@broken&&~@setup'"
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ parameters:
count: 1
path: src/bundle/Core/Features/Context/ContentTypeContext.php

-
message: "#^Access to an undefined property Ibexa\\\\Bundle\\\\Core\\\\Features\\\\Context\\\\QueryControllerContext\\:\\:\\$repository\\.$#"
count: 7
path: src/bundle/Core/Features/Context/QueryControllerContext.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Core\\\\Features\\\\Context\\\\UserContext\\:\\:ensureUserExists\\(\\) invoked with 2 parameters, 3\\-4 required\\.$#"
count: 1
Expand Down
305 changes: 1 addition & 304 deletions src/bundle/Core/Features/Context/QueryControllerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,233 +6,11 @@
*/
namespace Ibexa\Bundle\Core\Features\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\MinkExtension\Context\RawMinkContext;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use PHPUnit\Framework\Assert;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;

class QueryControllerContext extends RawMinkContext implements Context
class QueryControllerContext extends RawMinkContext
{
/** @var YamlConfigurationContext */
private $configurationContext;

/**
* Content item matched by the view configuration.
*
* @var \Ibexa\Contracts\Core\Repository\Values\Content\Content
*/
private $matchedContent;

public function __construct(Repository $repository)
{
$this->repository = $repository;
}

/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();

$this->configurationContext = $environment->getContext(
YamlConfigurationContext::class
);
}

/**
* @Given /^the following content view configuration block:$/
*/
public function addContentViewConfigurationBlock(PyStringNode $string)
{
$configurationBlock = array_merge(
Yaml::parse($string),
[
'template' => '@eZBehat/tests/dump.html.twig',
'match' => [
'Id\Content' => $this->matchedContent->id,
],
]
);

$configurationBlockName = 'behat_query_controller_' . $this->matchedContent->id;

$configuration = [
'ibexa' => [
'system' => [
'default' => [
'content_view' => [
'full' => [
$configurationBlockName => $configurationBlock,
],
],
],
],
],
];

$this->configurationContext->addConfiguration($configuration);
}

/**
* @Given /^the following content view configuration block with paging action:$/
*/
public function addContentViewConfigurationBlockWithPagingAction(PyStringNode $string)
{
$configurationBlock = array_merge(
Yaml::parse($string),
[
'template' => '@eZBehat/tests/dump.html.twig',
'match' => [
'Id\Content' => $this->matchedContent->id,
],
]
);

$configurationBlockName = 'behat_paging_query_controller_' . $this->matchedContent->id;

$configuration = [
'ibexa' => [
'system' => [
'default' => [
'content_view' => [
'full' => [
$configurationBlockName => $configurationBlock,
],
],
],
],
],
];

$this->configurationContext->addConfiguration($configuration);
}

/**
* @Given /^a content item that matches the view configuration block below$/
*/
public function aContentItemThatMatchesTheViewConfigurationBlockBelow()
{
$this->matchedContent = $this->repository->sudo(function (Repository $repository) {
return $this->createFolder($repository);
});
}

/**
* @Given :arg1 contents are created to test paging
*/
public function contentsAreCreatedToTestPaging2($numberOfContents)
{
for ($i = 0; $i < $numberOfContents; ++$i) {
$this->repository->sudo(function (Repository $repository) {
return $this->createFolder($repository);
});
}
}

/**
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Content
*/
private function createFolder(Repository $repository)
{
$contentService = $repository->getContentService();
$contentTypeService = $repository->getContentTypeService();
$locationService = $repository->getLocationService();

$struct = $contentService->newContentCreateStruct(
$contentTypeService->loadContentTypeByIdentifier('folder'),
'eng-GB'
);

$struct->setField('name', uniqid('Query Controller BDD ', true));

$contentDraft = $contentService->createContent(
$struct,
[$locationService->newLocationCreateStruct(2)]
);
$contentService->publishVersion($contentDraft->versionInfo);

return $contentService->loadContent($contentDraft->id);
}

/**
* @Given /^a LocationChildren QueryType defined in "([^"]*)":$/
*/
public function createPhpFile($phpFilePath, PyStringNode $phpFileContents)
{
$fs = new Filesystem();
$fs->mkdir(\dirname($phpFilePath));
$fs->dumpFile($phpFilePath, $phpFileContents);
if ($this->configurationContext->isSymfonyCacheClearRequired()) {
$this->configurationContext->clearSymfonyCache();
}
}

/**
* @When /^I view a content matched by the view configuration above$/
*/
public function visitMatchedContent()
{
$urlAliasService = $this->repository->getURLAliasService();
$urlAlias = $urlAliasService->reverseLookup(
$this->repository->getLocationService()->loadLocation(
$this->matchedContent->contentInfo->mainLocationId
)
);

$this->visitPath($urlAlias->path);

if ($this->getSession()->getStatusCode() !== 200) {
$page = $this->getSession()->getPage();
$exceptionElements = $page->findAll('xpath', "//div[@class='text-exception']/h1");
$exceptionStackTraceItems = $page->findAll('xpath', "//ol[@id='traces-0']/li");
if (\count($exceptionElements) > 0) {
$exceptionElement = $exceptionElements[0];
$exceptionLines = [$exceptionElement->getText(), ''];

foreach ($exceptionStackTraceItems as $stackTraceItem) {
$html = $stackTraceItem->getHtml();
$html = substr($html, 0, strpos($html, '<a href', 1));
$html = htmlspecialchars_decode(strip_tags($html));
$html = preg_replace('/\s+/', ' ', $html);
$html = str_replace(' (', '(', $html);
$html = str_replace(' ->', '->', $html);
$exceptionLines[] = trim($html);
}
$message = 'An exception occurred during rendering:' . implode("\n", $exceptionLines);
Assert::assertTrue(false, $message);
}
}
$this->assertSession()->statusCodeEquals(200);
}

/**
* @Then /^the viewed content's main location id is mapped to the parentLocationId QueryType parameter$/
*/
public function theViewedContentSMainLocationIdIsMappedToTheParentLocationIdQueryTypeParameter()
{
// not sure how to assert that
}

/**
* @Then /^a LocationChildren Query is built from the LocationChildren QueryType$/
*/
public function aLocationChildrenQueryIsBuiltFromTheLocationChildrenQueryType()
{
// not sure how to assert that either
}

/**
* @Given /^a Location Search is executed with the LocationChildren Query$/
*/
public function aLocationSearchIsExecutedWithTheLocationChildrenQuery()
{
// still not sure...
}

/**
* @Given /^the Query results are assigned to the "([^"]*)" twig variable$/
*/
Expand All @@ -254,87 +32,6 @@ public function theQueryResultsAssignedToTheTwigVariableIsAObject($twigVariableN
Assert::assertEquals($className, $variableTypes[$twigVariableName], "The $twigVariableName twig variable does not have $className type");
}

/**
* @Given /^the following template defined in "([^"]*)":$/
*/
public function createTemplateFile($tplFilePath, PyStringNode $tplFileContents)
{
$fs = new Filesystem();
$fs->mkdir(\dirname($tplFilePath));
$fs->dumpFile($tplFilePath, $tplFileContents);
}

/**
* @Given the following content view configuration block with paging action and the template set above:
*/
public function theFollowingContentViewConfigurationBlockWithPagingActionAndTheTemplateSetAbove(PyStringNode $string)
{
$configurationBlock = array_merge(
Yaml::parse($string),
[
'match' => [
'Id\Content' => $this->matchedContent->id,
],
]
);

$configurationBlockName = 'behat_paging_query_controller_' . $this->matchedContent->id;

$configuration = [
'ibexa' => [
'system' => [
'default' => [
'content_view' => [
'full' => [
$configurationBlockName => $configurationBlock,
],
],
],
],
],
];

$this->configurationContext->addConfiguration($configuration);
}

/**
* @When I view a content matched by the view configuration above on page :arg1 with the :arg2 parameter
*/
public function iViewAContentMatchedByTheViewConfigurationAboveOnPageWithTheParameter($pageNumber, $pageParam)
{
$urlAliasService = $this->repository->getURLAliasService();
$urlAlias = $urlAliasService->reverseLookup(
$this->repository->getLocationService()->loadLocation(
$this->matchedContent->contentInfo->mainLocationId
)
);

$this->visitPath($urlAlias->path . "?$pageParam=$pageNumber");

if ($this->getSession()->getStatusCode() !== 200) {
$page = $this->getSession()->getPage();
$exceptionElements = $page->findAll('xpath', "//div[@class='text-exception']/h1");
$exceptionStackTraceItems = $page->findAll('xpath', "//ol[@id='traces-0']/li");
if (\count($exceptionElements) > 0) {
$exceptionElement = $exceptionElements[0];
$exceptionLines = [$exceptionElement->getText(), ''];

foreach ($exceptionStackTraceItems as $stackTraceItem) {
$html = $stackTraceItem->getHtml();
$html = substr($html, 0, strpos($html, '<a href', 1));
$html = htmlspecialchars_decode(strip_tags($html));
$html = preg_replace('/\s+/', ' ', $html);
$html = str_replace(' (', '(', $html);
$html = str_replace(' ->', '->', $html);
$exceptionLines[] = trim($html);
}
$message = 'An exception occurred during rendering:' . implode("\n", $exceptionLines);
Assert::assertTrue(false, $message);
}
}
$this->assertSession()->statusCodeEquals(200);
}

/**
* @Then the Query results assigned to the twig variable is a Pagerfanta object and has limit :arg1 and selected page :arg2
*/
Expand Down
Loading

0 comments on commit e667191

Please sign in to comment.