Skip to content

Commit

Permalink
TASK: Provide alternative for NodeDiscriminator::fromNode that does…
Browse files Browse the repository at this point in the history
…nt use Nodes content stream

Related #5034 and #5043
  • Loading branch information
mhsdesign committed Jun 16, 2024
1 parent 8cdcc5f commit 6e29ec5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.'
Expand Down

0 comments on commit 6e29ec5

Please sign in to comment.