Skip to content

Commit

Permalink
Merge pull request #66 from neos/task/fixBehatTests
Browse files Browse the repository at this point in the history
BUGFIX: Repair behat tests and Neos9-Beta-10 compatibility
  • Loading branch information
kitsunet authored Jun 25, 2024
2 parents ee3533b + 325a10c commit 44da854
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 218 deletions.
21 changes: 8 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
cd ${NEOS_BASE_FOLDER}
composer require --no-update --no-interaction neos/redirecthandler:"^6.0"
composer require --no-update --no-interaction neos/redirecthandler-databasestorage:"^6.0"
git -C ../${{ env.PACKAGE_FOLDER }} checkout -b build
composer config repositories.package '{ "type": "path", "url": "../${{ env.PACKAGE_FOLDER }}", "options": { "symlink": false } }'
composer require --no-update --no-interaction neos/redirecthandler-neosadapter:"dev-build as dev-${PACKAGE_TARGET_VERSION}"
Expand All @@ -94,7 +94,7 @@ jobs:
- name: Setup Flow configuration
run: |
cd ${NEOS_BASE_FOLDER}
cd ${NEOS_BASE_FOLDER}
mkdir -p Configuration/Testing
rm -f Configuration/Testing/Settings.yaml
cat <<EOF >> Configuration/Testing/Settings.yaml
Expand All @@ -109,20 +109,15 @@ jobs:
dbname: 'neos_functional_testing'
EOF
- name: Setup database schema
- name: Run Behavioral tests
run: |
cd ${NEOS_BASE_FOLDER}
./flow doctrine:migrate --quite
# we have to doctrine migrate and setup the cr here as otherwise a transaction error will occur:
# see also https://github.com/neos/neos-development-collection/pull/5005
FLOW_CONTEXT=Testing ./flow doctrine:migrate --quiet; FLOW_CONTEXT=Testing ./flow cr:setup
- name: Setup CR
run: |
cd ${NEOS_BASE_FOLDER}
./flow cr:setup
- name: Run Functional tests
run: |
cd ${NEOS_BASE_FOLDER}
CATCHUPTRIGGER_ENABLE_SYNCHRONOUS_OPTION=1 bin/behat -c Packages/Application/Neos.RedirectHandler.NeosAdapter/Tests/Behavior/behat.yml.dist
cd Packages/Application/Neos.RedirectHandler.NeosAdapter
composer run test:behavioral:stop-on-failure
- name: Show log on failure
if: ${{ failure() }}
Expand Down
34 changes: 14 additions & 20 deletions Classes/CatchUpHook/DocumentUriPathProjectionHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
use Neos\RedirectHandler\NeosAdapter\Service\NodeRedirectService;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\Neos\FrontendRouting\Projection\DocumentUriPathFinder;
use Neos\ContentRepository\Core\Feature\NodeMove\Dto\CoverageNodeMoveMapping;
use Neos\Neos\FrontendRouting\Projection\DocumentNodeInfo;
use Neos\Neos\FrontendRouting\Exception\NodeNotFoundException;
use Neos\Neos\FrontendRouting\NodeAddress;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Neos\FrontendRouting\NodeAddressFactory;

final class DocumentUriPathProjectionHook implements CatchUpHookInterface
Expand Down Expand Up @@ -197,25 +195,21 @@ private function handleNodeWasMoved(NodeAggregateWasMoved $event, \Closure $clos
return;
}

foreach ($event->nodeMoveMappings as $moveMapping) {
/* @var \Neos\ContentRepository\Core\Feature\NodeMove\Dto\OriginNodeMoveMapping $moveMapping */
foreach ($moveMapping->newLocations as $newLocation) {
/* @var $newLocation CoverageNodeMoveMapping */
$node = $this->findNodeByIdAndDimensionSpacePointHash($event->nodeAggregateId, $newLocation->coveredDimensionSpacePoint->hash);
if ($node === null) {
// node probably no document node, skip
continue;
}

$closure($node, $this->getNodeAddress($event->contentStreamId, $newLocation->coveredDimensionSpacePoint, $node->getNodeAggregateId()), $this->contentRepository->id);

$descendantsOfNode = $this->getState()->getDescendantsOfNode($node);
array_map(fn (DocumentNodeInfo $descendantOfNode) => $closure(
$descendantOfNode,
$this->getNodeAddress($event->contentStreamId, $newLocation->coveredDimensionSpacePoint, $descendantOfNode->getNodeAggregateId()),
$this->contentRepository->id
), iterator_to_array($descendantsOfNode));
foreach ($event->succeedingSiblingsForCoverage as $interdimensionalSibling) {
$node = $this->findNodeByIdAndDimensionSpacePointHash($event->nodeAggregateId, $interdimensionalSibling->dimensionSpacePoint->hash);
if ($node === null) {
// node probably no document node, skip
continue;
}

$closure($node, $this->getNodeAddress($event->contentStreamId, $interdimensionalSibling->dimensionSpacePoint, $node->getNodeAggregateId()), $this->contentRepository->id);

$descendantsOfNode = $this->getState()->getDescendantsOfNode($node);
array_map(fn (DocumentNodeInfo $descendantOfNode) => $closure(
$descendantOfNode,
$this->getNodeAddress($event->contentStreamId, $interdimensionalSibling->dimensionSpacePoint, $descendantOfNode->getNodeAggregateId()),
$this->contentRepository->id
), iterator_to_array($descendantsOfNode));
}
}

Expand Down
47 changes: 12 additions & 35 deletions Tests/Behavior/Features/Bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,36 @@
<?php

use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Behat\Tests\Behat\FlowContextTrait;
use Neos\Flow\Utility\Environment;
use Neos\Neos\Tests\Functional\Command\BehatTestHelper;
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\CRTestSuiteTrait;
use Behat\Behat\Context\Context;
use Neos\Behat\FlowBootstrapTrait;
use Neos\Behat\FlowEntitiesTrait;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\CRBehavioralTestsSubjectProvider;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinPyStringNodeBasedNodeTypeManagerFactory;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinTableNodeBasedContentDimensionSourceFactory;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinTableNodeBasedContentDimensionSourceFactory;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinPyStringNodeBasedNodeTypeManagerFactory;
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\CRTestSuiteTrait;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;

require_once(__DIR__ . '/../../../../../../Application/Neos.Behat/Tests/Behat/FlowContextTrait.php');
require_once(__DIR__ . '/../../../../../../Neos/Neos.Neos/Tests/Behavior/Features/Bootstrap/RoutingTrait.php');

/**
* Features context
*/
class FeatureContext implements Context
{
use FlowContextTrait;
use FlowBootstrapTrait;
use FlowEntitiesTrait;
use CRTestSuiteTrait;
use CRBehavioralTestsSubjectProvider;

use RoutingTrait;
use RedirectOperationTrait;

/**
* @var string
*/
protected $behatTestHelperObjectName = BehatTestHelper::class;

/**
* @var ObjectManagerInterface
*/
protected $objectManager;

/**
* @var Environment
*/
protected $environment;
private ContentRepositoryRegistry $contentRepositoryRegistry;

public function __construct()
{
if (self::$bootstrap === null) {
self::$bootstrap = $this->initializeFlow();
}
$this->objectManager = self::$bootstrap->getObjectManager();
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);

$this->setupCRTestSuiteTrait();
self::bootstrapFlow();
$this->contentRepositoryRegistry = $this->getObject(ContentRepositoryRegistry::class);
}

protected function getContentRepositoryService(
Expand Down
20 changes: 14 additions & 6 deletions Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@

trait RedirectOperationTrait
{
/**
* @template T of object
* @param class-string<T> $className
*
* @return T
*/
abstract private function getObject(string $className): object;

/**
* @Given /^I have the following redirects:$/
* @When /^I create the following redirects:$/
*/
public function iHaveTheFollowingRedirects($table): void
{
$rows = $table->getHash();
$nodeRedirectStorage = $this->objectManager->get(RedirectStorage::class);
$redirectRepository = $this->objectManager->get(RedirectRepository::class);
$nodeRedirectStorage = $this->getObject(RedirectStorage::class);
$redirectRepository = $this->getObject(RedirectRepository::class);

foreach ($rows as $row) {
$nodeRedirectStorage->addRedirect(
Expand All @@ -42,7 +50,7 @@ public function iHaveTheFollowingRedirects($table): void
*/
public function iShouldHaveARedirectWithSourceUriAndTargetUri($sourceUri, $targetUri): void
{
$nodeRedirectStorage = $this->objectManager->get(RedirectStorage::class);
$nodeRedirectStorage = $this->getObject(RedirectStorage::class);

$redirect = $nodeRedirectStorage->getOneBySourceUriPathAndHost($sourceUri);

Expand All @@ -62,7 +70,7 @@ public function iShouldHaveARedirectWithSourceUriAndTargetUri($sourceUri, $targe
*/
public function iShouldHaveARedirectWithSourceUriAndStatus($sourceUri, $statusCode): void
{
$nodeRedirectStorage = $this->objectManager->get(RedirectStorage::class);
$nodeRedirectStorage = $this->getObject(RedirectStorage::class);

$redirect = $nodeRedirectStorage->getOneBySourceUriPathAndHost($sourceUri);

Expand All @@ -82,7 +90,7 @@ public function iShouldHaveARedirectWithSourceUriAndStatus($sourceUri, $statusCo
*/
public function iShouldHaveNoRedirectWithSourceUriAndTargetUri($sourceUri, $targetUri): void
{
$nodeRedirectStorage = $this->objectManager->get(RedirectStorage::class);
$nodeRedirectStorage = $this->getObject(RedirectStorage::class);
$redirect = $nodeRedirectStorage->getOneBySourceUriPathAndHost($sourceUri);

if ($redirect !== null) {
Expand All @@ -101,7 +109,7 @@ public function iShouldHaveNoRedirectWithSourceUriAndTargetUri($sourceUri, $targ
*/
public function iShouldHaveNoRedirectWithSourceUri($sourceUri): void
{
$nodeRedirectStorage = $this->objectManager->get(RedirectStorage::class);
$nodeRedirectStorage = $this->getObject(RedirectStorage::class);

$redirect = $nodeRedirectStorage->getOneBySourceUriPathAndHost($sourceUri);

Expand Down
Loading

0 comments on commit 44da854

Please sign in to comment.