Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,16 @@ jobs:
user: 'root'
password: 'neos'
dbname: 'flow_functional_testing'

# see Neos\Flow\Tests\Functional\Mvc\RoutingTest
mvc:
routes:
'Neos.Flow': TRUE
"Neos.Flow:TestingAttributes":
providerFactory: Neos\Flow\Mvc\Routing\AttributeRoutesProviderFactory
providerOptions:
classNames:
- Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\*Controller
"Neos.Flow": true
EOF
echo "Running in context '$FLOW_CONTEXT'"
./flow configuration:show
Expand Down Expand Up @@ -196,9 +203,16 @@ jobs:
charset: 'utf8'
defaultTableOptions:
charset: 'utf8'

# see Neos\Flow\Tests\Functional\Mvc\RoutingTest
mvc:
routes:
'Neos.Flow': TRUE
"Neos.Flow:TestingAttributes":
providerFactory: Neos\Flow\Mvc\Routing\AttributeRoutesProviderFactory
providerOptions:
classNames:
- Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\*Controller
"Neos.Flow": true
EOF

- name: Run unit tests (PGSQL)
Expand Down
4 changes: 2 additions & 2 deletions Neos.Flow/Classes/Mvc/Routing/AttributeRoutesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ public static function compileRoutesConfiguration(ObjectManagerInterface $object
'uriPattern' => $annotation->uriPattern,
'httpMethods' => $annotation->httpMethods,
'defaults' => Arrays::arrayMergeRecursiveOverrule(
[
array_filter([
'@package' => $controllerPackageKey,
'@subpackage' => $subPackage,
'@controller' => $controller,
'@action' => $action,
'@format' => 'html'
],
], fn ($value) => $value !== null),
$annotation->defaults ?? []
)
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller;

/*
* This file is part of the Neos.Flow package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;

/**
* A controller fixture
*
* @Flow\Scope("singleton")
*/
class RoutingAnnotationTestBController extends ActionController
{
#[Flow\Route('neos/flow/test/annotation')]
public function annotatedAction()
{
return 'returned from "annotatedAction"';
}
}
54 changes: 51 additions & 3 deletions Neos.Flow/Tests/Functional/Mvc/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Neos\Flow\Mvc\Routing\Route;
use Neos\Flow\Mvc\Routing\TestingRoutesProvider;
use Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestAController;
use Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\RoutingAnnotationTestBController;
use Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\RoutingTestAController;
use Neos\Flow\Tests\FunctionalTestCase;
use Neos\Utility\Arrays;
Expand Down Expand Up @@ -48,11 +49,27 @@ protected function setUp(): void
parent::setUp();
$this->serverRequestFactory = $this->objectManager->get(ServerRequestFactoryInterface::class);

$routeSettings = $this->objectManager->get(ConfigurationManager::class)
->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow.mvc.routes');

if (
($this->objectManager->get(ConfigurationManager::class)
->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow.mvc.routes')['Neos.Flow'] ?? false) !== true
($routeSettings['Neos.Flow'] ?? false) !== true
|| !is_array($routeSettings['Neos.Flow:TestingAttributes'] ?? null)
) {
self::markTestSkipped(sprintf('In this distribution the Flow routes are not included into the global configuration and thus cannot be tested. Please set in Neos.Flow.mvc.routes "Neos.Flow": true.'));
self::markTestSkipped(<<<'EOF'
In this distribution the Neos.Flow or Flow\Annotation routes are not included into the global configuration and thus cannot be tested:

Neos:
Flow:
mvc:
routes:
"Neos.Flow:TestingAttributes":
providerFactory: Neos\Flow\Mvc\Routing\AttributeRoutesProviderFactory
providerOptions:
classNames:
- Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\*Controller
"Neos.Flow": true
EOF);
}
}

Expand Down Expand Up @@ -98,6 +115,19 @@ public function httpMethodsAreRespectedForPostRequests()
self::assertEquals('second', $actionRequest->getControllerActionName());
}

/**
* @test
*/
public function routeToControllerWithAnnotatedAction()
{
$requestUri = 'http://localhost/neos/flow/test/annotation';
$request = $this->serverRequestFactory->createServerRequest('GET', new Uri($requestUri));
$matchResults = $this->router->route(new RouteContext($request, RouteParameters::createEmpty()));
$actionRequest = $this->createActionRequest($request, $matchResults);
self::assertEquals(RoutingAnnotationTestBController::class, $actionRequest->getControllerObjectName());
self::assertEquals('annotated', $actionRequest->getControllerActionName());
}

/**
* Data provider for routeTests()
*
Expand Down Expand Up @@ -360,6 +390,24 @@ public function routerInitializesRoutesIfNotInjectedExplicitly()
self::assertSame('/neos/flow/test/http/foo', (string)$actualResult);
}

/**
* @test
*/
public function routerMatchesRouteFromAnnotation()
{
$routeValues = [
'@package' => 'Neos.Flow',
'@subpackage' => 'Tests\Functional\Mvc\Fixtures',
'@controller' => 'RoutingAnnotationTestB',
'@action' => 'annotated',
'@format' => 'html'
];
$baseUri = new Uri('http://localhost');
$actualResult = $this->router->resolve(new ResolveContext($baseUri, $routeValues, false, '', RouteParameters::createEmpty()));

self::assertSame('/neos/flow/test/annotation', (string)$actualResult);
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class ExampleController extends \Neos\Flow\Mvc\Controller\ActionController {
$expectedRoute1->setUriPattern('my/path');
$expectedRoute1->setDefaults([
'@package' => 'Vendor.Example',
'@subpackage' => null,
'@controller' => 'Example',
'@action' => 'special',
'@format' => 'html',
Expand All @@ -121,7 +120,6 @@ class ExampleController extends \Neos\Flow\Mvc\Controller\ActionController {
$expectedRoute2->setUriPattern('my/other/path');
$expectedRoute2->setDefaults([
'@package' => 'Vendor.Example',
'@subpackage' => null,
'@controller' => 'Example',
'@action' => 'special',
'@format' => 'html',
Expand Down