‪TYPO3CMS  10.4
UriBuilderTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪UriBuilderTest extends UnitTestCase
29 {
34  {
35  return [
36  'plain route' => [
37  [ 'route' => new ‪Route('/test/route', []) ],
38  'route',
39  [],
40  '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken',
41  ],
42  'AJAX route' => [
43  [ 'route' => new ‪Route('/test/route', [ 'ajax' => true ]) ],
44  'route',
45  [],
46  '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken',
47  ],
48  'plain route with default parameters' => [
49  [ 'route' => new ‪Route('/test/route', [ 'parameters' => [ 'key' => 'value' ] ]) ],
50  'route',
51  [],
52  '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=value',
53  ],
54  'AJAX route with default parameters' => [
55  [ 'route' => new ‪Route('/test/route', [ 'ajax' => true, 'parameters' => [ 'key' => 'value' ] ]) ],
56  'route',
57  [],
58  '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=value',
59  ],
60  'plain route with overridden parameters' => [
61  [ 'route' => new ‪Route('/test/route', [ 'parameters' => [ 'key' => 'value' ] ]) ],
62  'route',
63  ['key' => 'overridden'],
64  '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=overridden',
65  ],
66  'AJAX route with overridden parameters' => [
67  [ 'route' => new ‪Route('/test/route', [ 'ajax' => true, 'parameters' => [ 'key' => 'value' ] ]) ],
68  'route',
69  ['key' => 'overridden'],
70  '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=overridden',
71  ],
72  ];
73  }
74 
84  public function ‪validRoutesAreBuilt(
85  array $routes,
86  string $routeName,
87  array $routeParameters,
88  string $expectation
89  ) {
90  $router = new ‪Router();
91  foreach ($routes as $routeName => $route) {
92  $router->addRoute($routeName, $route);
93  }
94  $subject = new ‪UriBuilder($router);
95  $uri = $subject->buildUriFromRoute(
96  $routeName,
97  $routeParameters
98  );
99 
100  self::assertEquals($expectation, $uri->__toString());
101  }
102 
107  {
108  $this->expectException(RouteNotFoundException::class);
109  $this->expectExceptionCode(1476050190);
110  $subject = new ‪UriBuilder(new ‪Router());
111  $subject->buildUriFromRoute(‪StringUtility::getUniqueId('any'));
112  }
113 }
‪TYPO3\CMS\Backend\Routing\Route
Definition: Route.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Routing\UriBuilderTest\nonExistingRouteThrowsException
‪nonExistingRouteThrowsException()
Definition: UriBuilderTest.php:106
‪TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
Definition: RouteNotFoundException.php:22
‪TYPO3\CMS\Backend\Tests\Unit\Routing\UriBuilderTest\validRoutesAreBuiltDataProvider
‪array validRoutesAreBuiltDataProvider()
Definition: UriBuilderTest.php:33
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Tests\Unit\Routing\UriBuilderTest\validRoutesAreBuilt
‪validRoutesAreBuilt(array $routes, string $routeName, array $routeParameters, string $expectation)
Definition: UriBuilderTest.php:84
‪TYPO3\CMS\Backend\Tests\Unit\Routing\UriBuilderTest
Definition: UriBuilderTest.php:29
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Backend\Tests\Unit\Routing
Definition: UriBuilderTest.php:16
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:34