‪TYPO3CMS  ‪main
UriBuilderTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪UriBuilderTest extends FunctionalTestCase
29 {
30  protected bool ‪$initializeDatabase = false;
31 
32  protected array ‪$coreExtensionsToLoad = ['workspaces'];
33 
34  #[Test]
36  {
37  $subject = GeneralUtility::makeInstance(UriBuilder::class);
38  $route = $subject->buildUriFromRoute('workspaces_admin');
39  $routeFromAlias = $subject->buildUriFromRoute('web_WorkspacesWorkspaces');
40  self::assertEquals($routeFromAlias->getPath(), $route->getPath());
41  }
42 
43  #[Test]
44  public function ‪buildUriFromRouteResolvesSubModule(): void
45  {
46  $subject = GeneralUtility::makeInstance(UriBuilder::class);
47  $uri = $subject->buildUriFromRoute('site_configuration.edit');
48  self::assertStringEndsWith('/module/site/configuration/edit', $uri->getPath());
49  }
50 
51  #[Test]
53  {
54  $subject = GeneralUtility::makeInstance(UriBuilder::class);
55  $route = GeneralUtility::makeInstance(Router::class)->getRoute('site_configuration.edit');
56  $route->setOption('_identifier', 'site_configuration.edit');
57  $request = new ‪ServerRequest('https://example.com/', 'GET');
58  $request = $request->withAttribute('route', $route);
59  $uri = $subject->buildUriFromRequest($request, ['foo' => 'bar']);
60  self::assertStringEndsWith('/module/site/configuration/edit', $uri->getPath());
61  }
62 
63  #[Test]
65  {
66  self::expectException(RouteNotFoundException::class);
67  self::expectExceptionCode(1476050190);
68  $subject = GeneralUtility::makeInstance(UriBuilder::class);
69  $route = GeneralUtility::makeInstance(Router::class)->getRoute('site_configuration.edit');
70  $request = new ‪ServerRequest('https://example.com/', 'GET');
71  // Route is not found in the registry of routes
72  $route->setOption('_identifier', 'foo.bar');
73  $request = $request->withAttribute('route', $route);
74  $subject->buildUriFromRequest($request, ['foo' => 'bar']);
75  }
76 
77  #[Test]
79  {
80  self::expectException(RouteNotFoundException::class);
81  self::expectExceptionCode(1691423325);
82  $subject = GeneralUtility::makeInstance(UriBuilder::class);
83  $request = new ‪ServerRequest('https://example.com/', 'GET');
84  $subject->buildUriFromRequest($request, ['foo' => 'bar']);
85  }
86 }
‪TYPO3\CMS\Backend\Tests\Functional\Routing\UriBuilderTest\buildUriFromRequestWithoutRouteThrowsException
‪buildUriFromRequestWithoutRouteThrowsException()
Definition: UriBuilderTest.php:78
‪TYPO3\CMS\Backend\Tests\Functional\Routing\UriBuilderTest\buildUriFromRequestCanLinkToValidRoute
‪buildUriFromRequestCanLinkToValidRoute()
Definition: UriBuilderTest.php:52
‪TYPO3\CMS\Backend\Tests\Functional\Routing\UriBuilderTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: UriBuilderTest.php:32
‪TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
Definition: RouteNotFoundException.php:21
‪TYPO3\CMS\Backend\Tests\Functional\Routing\UriBuilderTest\$initializeDatabase
‪bool $initializeDatabase
Definition: UriBuilderTest.php:30
‪TYPO3\CMS\Backend\Tests\Functional\Routing
Definition: RouterTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\Routing\UriBuilderTest\buildUriFromRouteResolvesAliasWhenLinking
‪buildUriFromRouteResolvesAliasWhenLinking()
Definition: UriBuilderTest.php:35
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Backend\Tests\Functional\Routing\UriBuilderTest\buildUriFromRequestWithInvalidRouteThrowsException
‪buildUriFromRequestWithInvalidRouteThrowsException()
Definition: UriBuilderTest.php:64
‪TYPO3\CMS\Backend\Tests\Functional\Routing\UriBuilderTest
Definition: UriBuilderTest.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:40
‪TYPO3\CMS\Backend\Tests\Functional\Routing\UriBuilderTest\buildUriFromRouteResolvesSubModule
‪buildUriFromRouteResolvesSubModule()
Definition: UriBuilderTest.php:44