From 6e29ec58952e774d63611150086983a720afae6d Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 16 Jun 2024 18:53:08 +0200 Subject: [PATCH] TASK: Provide alternative for `NodeDiscriminator::fromNode` that doesnt use Nodes content stream Related #5034 and #5043 --- .../Bootstrap/CRTestSuiteRuntimeVariables.php | 15 +++++++++++---- .../Bootstrap/Helpers/NodeDiscriminator.php | 15 +++++++++++++++ .../Bootstrap/Helpers/NodeDiscriminators.php | 8 -------- .../Features/Bootstrap/ProjectedNodeTrait.php | 11 ++++++----- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php index 656e45666cc..6642d015bf7 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteRuntimeVariables.php @@ -17,6 +17,7 @@ use Neos\ContentRepository\Core\ContentGraphFinder; use Neos\ContentRepository\Core\ContentRepository; use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate; @@ -147,16 +148,22 @@ public function visibilityConstraintsAreSetTo(string $restrictionType): void }; } - public function getCurrentSubgraph(): ContentSubgraphInterface + public function getCurrentContentGraph(): ContentGraphInterface { + // todo cache content graph per test run??? Otherwise it will be flushed too often? $contentGraphFinder = $this->currentContentRepository->projectionState(ContentGraphFinder::class); $contentGraphFinder->forgetInstances(); - if (isset($this->currentContentStreamId)) { + if ($this->currentContentStreamId !== null) { // This must still be supported for low level tests, e.g. for content stream forking - return $contentGraphFinder->getByWorkspaceNameAndContentStreamId($this->currentWorkspaceName, $this->currentContentStreamId)->getSubgraph($this->currentDimensionSpacePoint, $this->currentVisibilityConstraints); + return $contentGraphFinder->getByWorkspaceNameAndContentStreamId($this->currentWorkspaceName, $this->currentContentStreamId); } - return $contentGraphFinder->getByWorkspaceName($this->currentWorkspaceName)->getSubgraph( + return $contentGraphFinder->getByWorkspaceName($this->currentWorkspaceName); + } + + public function getCurrentSubgraph(?ContentGraphInterface $contentGraphToUse = null): ContentSubgraphInterface + { + return ($contentGraphToUse ?? $this->getCurrentContentGraph())->getSubgraph( $this->currentDimensionSpacePoint, $this->currentVisibilityConstraints ); diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php index 005e5464e4d..8539c8c4cf5 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminator.php @@ -15,6 +15,7 @@ namespace Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers; use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint; +use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; @@ -47,6 +48,7 @@ public static function fromShorthand(string $shorthand): self ); } + /** @deprecated will be removed */ public static function fromNode(Node $node): self { return new self( @@ -56,6 +58,19 @@ public static function fromNode(Node $node): self ); } + public static function fromNodeAndContentGraph(Node $node, ContentGraphInterface $contentGraph): self + { + if (!$node->workspaceName->equals($contentGraph->getWorkspaceName())) { + throw new \InvalidArgumentException(sprintf('Expected nodes workspace %s to match given subgraph workspace %s.', $node->workspaceName->value, $contentGraph->getWorkspaceName()->value), 1718554466); + } + + return new self( + $contentGraph->getContentStreamId(), + $node->aggregateId, + $node->originDimensionSpacePoint + ); + } + public function equals(self $other): bool { return $this->contentStreamId->equals($other->contentStreamId) diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminators.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminators.php index 2bedcbce70e..07924d1de4a 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminators.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Helpers/NodeDiscriminators.php @@ -53,14 +53,6 @@ public static function fromArray(array $array): self )); } - public static function fromNodes(Nodes $nodes): self - { - return new self(...array_map( - fn (Node $node): NodeDiscriminator => NodeDiscriminator::fromNode($node), - iterator_to_array($nodes) - )); - } - public function equal(self $other): bool { return $this->discriminators == $other->discriminators; diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php index ad96bdacce4..3eeb6cbc538 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/ProjectedNodeTrait.php @@ -456,15 +456,16 @@ public function iExpectThisNodeToHaveNoReferences(): void */ public function iExpectThisNodeToBeReferencedBy(TableNode $expectedReferences): void { - $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedReferences) { - $actualReferences = $this->getCurrentSubgraph() + $contentGraph = $this->getCurrentContentGraph(); + $this->assertOnCurrentNode(function (Node $currentNode) use ($expectedReferences, $contentGraph) { + $actualReferences = $this->getCurrentSubgraph($contentGraph) ->findBackReferences($currentNode->aggregateId, FindBackReferencesFilter::create()); - $this->assertReferencesMatch($expectedReferences, $actualReferences); + $this->assertReferencesMatch($expectedReferences, $actualReferences, $contentGraph); }); } - private function assertReferencesMatch(TableNode $expectedReferencesTable, References $actualReferences): void + private function assertReferencesMatch(TableNode $expectedReferencesTable, References $actualReferences, ContentGraphInterface $contentGraph): void { $expectedReferences = $expectedReferencesTable->getHash(); Assert::assertSame( @@ -480,7 +481,7 @@ private function assertReferencesMatch(TableNode $expectedReferencesTable, Refer $actualReferences[$index]->name->value ); $expectedReferenceDiscriminator = NodeDiscriminator::fromShorthand($row['Node']); - $actualReferenceDiscriminator = NodeDiscriminator::fromNode($actualReferences[$index]->node); + $actualReferenceDiscriminator = NodeDiscriminator::fromNodeAndContentGraph($actualReferences[$index]->node, $contentGraph); Assert::assertTrue( $expectedReferenceDiscriminator->equals($actualReferenceDiscriminator), 'Reference discriminator does not match.'