From f3f34f967d97da8f26f62097b6a3185d524755e5 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 21 Feb 2024 22:30:45 +0100 Subject: [PATCH] WIP: Fix basic test --- .../Features/Bootstrap/RoutingTrait.php | 71 +++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/Neos.Neos/Tests/Behavior/Features/Bootstrap/RoutingTrait.php b/Neos.Neos/Tests/Behavior/Features/Bootstrap/RoutingTrait.php index ed45891c0b7..7c797ac6e03 100644 --- a/Neos.Neos/Tests/Behavior/Features/Bootstrap/RoutingTrait.php +++ b/Neos.Neos/Tests/Behavior/Features/Bootstrap/RoutingTrait.php @@ -19,16 +19,15 @@ use GuzzleHttp\Psr7\Uri; use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\ContentRepository\Core\SharedModel\Node\NodeIdentity; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; -use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\CRTestSuiteRuntimeVariables; +use Neos\Flow\Configuration\ConfigurationManager; use Neos\Flow\Http\ServerRequestAttributes; -use Neos\Flow\Mvc\ActionRequest; use Neos\Flow\Mvc\Exception\NoMatchingRouteException; use Neos\Flow\Mvc\Routing\Dto\RouteContext; use Neos\Flow\Mvc\Routing\Dto\RouteParameters; use Neos\Flow\Mvc\Routing\RouterInterface; -use Neos\Flow\ObjectManagement\ObjectManagerInterface; use Neos\Flow\Persistence\PersistenceManagerInterface; use Neos\Flow\ResourceManagement\ResourceManager; use Neos\Flow\Tests\FunctionalTestRequestHandler; @@ -43,9 +42,8 @@ use Neos\Neos\Domain\Repository\SiteRepository; use Neos\Neos\FrontendRouting\DimensionResolution\DimensionResolverFactoryInterface; use Neos\Neos\FrontendRouting\DimensionResolution\RequestToDimensionSpacePointContext; -use Neos\Neos\FrontendRouting\NodeAddress; -use Neos\Neos\FrontendRouting\NodeAddressFactory; -use Neos\Neos\FrontendRouting\NodeUriBuilder; +use Neos\Neos\FrontendRouting\NodeUriBuilderFactory; +use Neos\Neos\FrontendRouting\NodeUriSpecification; use Neos\Neos\FrontendRouting\Projection\DocumentUriPathProjectionFactory; use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionMiddleware; use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult; @@ -195,17 +193,19 @@ public function iAmOnUrl(string $url): void */ public function theMatchedNodeShouldBeInContentStreamAndOriginDimension(string $nodeAggregateId, string $contentStreamId, string $dimensionSpacePoint): void { - $nodeAddress = $this->match($this->requestUrl); - Assert::assertNotNull($nodeAddress, 'Routing result does not have "node" key - this probably means that the FrontendNodeRoutePartHandler did not properly resolve the result.'); - Assert::assertTrue($nodeAddress->isInLiveWorkspace()); - Assert::assertSame($nodeAggregateId, $nodeAddress->nodeAggregateId->value); - Assert::assertSame($contentStreamId, $nodeAddress->contentStreamId->value); + $matchedNodeIdentity = $this->match($this->requestUrl); + Assert::assertNotNull($matchedNodeIdentity, 'Routing result does not have "node" key - this probably means that the FrontendNodeRoutePartHandler did not properly resolve the result.'); + Assert::assertTrue($matchedNodeIdentity->workspaceName->isLive()); + Assert::assertSame($nodeAggregateId, $matchedNodeIdentity->nodeAggregateId->value); + // todo useless check? + $workspace = $this->currentContentRepository->getWorkspaceFinder()->findOneByCurrentContentStreamId(ContentStreamId::fromString($contentStreamId)); + Assert::assertSame($contentStreamId, $workspace?->currentContentStreamId->value); Assert::assertSame( DimensionSpacePoint::fromJsonString($dimensionSpacePoint), - $nodeAddress->dimensionSpacePoint, + $matchedNodeIdentity->dimensionSpacePoint, sprintf( 'Dimension space point "%s" did not match the expected "%s"', - $nodeAddress->dimensionSpacePoint->toJson(), + $matchedNodeIdentity->dimensionSpacePoint->toJson(), $dimensionSpacePoint ) ); @@ -216,8 +216,8 @@ public function theMatchedNodeShouldBeInContentStreamAndOriginDimension(string $ */ public function noNodeShouldMatchUrl(string $url): void { - $matchedNodeAddress = $this->match(new Uri($url)); - Assert::assertNull($matchedNodeAddress, 'Expected no node to be found, but instead the following node address was matched: ' . $matchedNodeAddress ?? '- none -'); + $matchedNodeIdentity = $this->match(new Uri($url)); + Assert::assertNull($matchedNodeIdentity, 'Expected no node to be found, but instead the following node address was matched: ' . $matchedNodeIdentity ?? '- none -'); } /** @@ -225,17 +225,20 @@ public function noNodeShouldMatchUrl(string $url): void */ public function theUrlShouldMatchTheNodeInContentStreamAndDimension(string $url, $nodeAggregateId, $contentStreamId, $dimensionSpacePoint): void { - $matchedNodeAddress = $this->match(new Uri($url)); + $matchedNodeIdentity = $this->match(new Uri($url)); - Assert::assertNotNull($matchedNodeAddress, 'Expected node to be found, but instead nothing was found.'); - Assert::assertEquals(NodeAggregateId::fromString($nodeAggregateId), $matchedNodeAddress->nodeAggregateId, 'Expected nodeAggregateId doesn\'t match.'); - Assert::assertEquals(ContentStreamId::fromString($contentStreamId), $matchedNodeAddress->contentStreamId, 'Expected contentStreamId doesn\'t match.'); - Assert::assertTrue($matchedNodeAddress->dimensionSpacePoint->equals(DimensionSpacePoint::fromJsonString($dimensionSpacePoint)), 'Expected dimensionSpacePoint doesn\'t match.'); + Assert::assertNotNull($matchedNodeIdentity, 'Expected node to be found, but instead nothing was found.'); + Assert::assertEquals(NodeAggregateId::fromString($nodeAggregateId), $matchedNodeIdentity->nodeAggregateId, 'Expected nodeAggregateId doesn\'t match.'); + + // todo use workspace name instead here: + $workspace = $this->currentContentRepository->getWorkspaceFinder()->findOneByCurrentContentStreamId(ContentStreamId::fromString($contentStreamId)); + Assert::assertEquals($workspace->workspaceName, $matchedNodeIdentity->workspaceName, 'Expected workspace doesn\'t match.'); + Assert::assertTrue($matchedNodeIdentity->dimensionSpacePoint->equals(DimensionSpacePoint::fromJsonString($dimensionSpacePoint)), 'Expected dimensionSpacePoint doesn\'t match.'); } private $eventListenerRegistered = false; - private function match(UriInterface $uri): ?NodeAddress + private function match(UriInterface $uri): ?NodeIdentity { $router = $this->getObject(RouterInterface::class); $serverRequestFactory = $this->getObject(ServerRequestFactoryInterface::class); @@ -253,8 +256,7 @@ private function match(UriInterface $uri): ?NodeAddress return null; } - $nodeAddressFactory = NodeAddressFactory::create($this->currentContentRepository); - return $nodeAddressFactory->createFromUriString($routeValues['node']); + return NodeIdentity::fromJsonString($routeValues['node']); } @@ -273,6 +275,13 @@ public function theNodeShouldResolveToUrl(string $nodeAggregateId, string $conte */ public function theNodeShouldNotResolve(string $nodeAggregateId, string $contentStreamId, string $dimensionSpacePoint): void { + if ( + ($this->getObject(ConfigurationManager::class) + ->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow.mvc.routes')['Neos.Flow'] ?? null) === true + ) { + Assert::fail('In this distribution the Flow routes are included into the global configuration and thus any route arguments will always resolve. Please set in Neos.Flow.mvc.routes "Neos.Flow": false.'); + } + $resolvedUrl = null; $exception = false; try { @@ -308,18 +317,22 @@ private function resolveUrl(string $nodeAggregateId, string $contentStreamId, st if ($this->requestUrl === null) { $this->iAmOnUrl('/'); } - $nodeAddress = new NodeAddress( - ContentStreamId::fromString($contentStreamId), + $workspace = $this->currentContentRepository->getWorkspaceFinder()->findOneByCurrentContentStreamId(ContentStreamId::fromString($contentStreamId)); + + $nodeIdentity = NodeIdentity::create( + $this->currentContentRepository->id, + $workspace->workspaceName, // todo always live? DimensionSpacePoint::fromJsonString($dimensionSpacePoint), \str_starts_with($nodeAggregateId, '$') ? $this->rememberedNodeAggregateIds[\mb_substr($nodeAggregateId, 1)] - : NodeAggregateId::fromString($nodeAggregateId), - WorkspaceName::forLive() + : NodeAggregateId::fromString($nodeAggregateId) ); $httpRequest = $this->getObject(ServerRequestFactoryInterface::class)->createServerRequest('GET', $this->requestUrl); $httpRequest = $this->addRoutingParameters($httpRequest); - $actionRequest = ActionRequest::fromHttpRequest($httpRequest); - return NodeUriBuilder::fromRequest($actionRequest)->uriFor($nodeAddress); + + return $this->getObject(NodeUriBuilderFactory::class) + ->forRequest($httpRequest) + ->uriFor(NodeUriSpecification::create($nodeIdentity)); } private function addRoutingParameters(ServerRequestInterface $httpRequest): ServerRequestInterface