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