[BUGFIX] Unit tests call parent::tearDown()
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Routing / UriBuilderTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Routing;
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
17 use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
18 use TYPO3\CMS\Backend\Routing\Route;
19 use TYPO3\CMS\Backend\Routing\UriBuilder;
20 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 /**
24 * Test case
25 */
26 class UriBuilderTest extends UnitTestCase
27 {
28 /**
29 * @var UriBuilder|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
30 */
31 protected $uriBuilder;
32
33 protected function setUp()
34 {
35 parent::setUp();
36 $this->uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['loadBackendRoutes']);
37 }
38
39 /**
40 * @return array
41 */
42 public function validRoutesAreBuiltDataProvider()
43 {
44 return [
45 'plain route' => [
46 [ 'route' => new Route('/test/route', []) ],
47 'route',
48 [],
49 '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken',
50 ],
51 'AJAX route' => [
52 [ 'route' => new Route('/test/route', [ 'ajax' => true ]) ],
53 'route',
54 [],
55 '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken',
56 ],
57 'plain route with default parameters' => [
58 [ 'route' => new Route('/test/route', [ 'parameters' => [ 'key' => 'value' ] ]) ],
59 'route',
60 [],
61 '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=value',
62 ],
63 'AJAX route with default parameters' => [
64 [ 'route' => new Route('/test/route', [ 'ajax' => true, 'parameters' => [ 'key' => 'value' ] ]) ],
65 'route',
66 [],
67 '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=value',
68 ],
69 'plain route with overridden parameters' => [
70 [ 'route' => new Route('/test/route', [ 'parameters' => [ 'key' => 'value' ] ]) ],
71 'route',
72 ['key' => 'overridden'],
73 '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=overridden',
74 ],
75 'AJAX route with overridden parameters' => [
76 [ 'route' => new Route('/test/route', [ 'ajax' => true, 'parameters' => [ 'key' => 'value' ] ]) ],
77 'route',
78 ['key' => 'overridden'],
79 '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=overridden',
80 ],
81 ];
82 }
83
84 /**
85 * @param Route[] $routes
86 * @param string $routeName
87 * @param array $routeParameters
88 * @param string $expectation
89 *
90 * @test
91 * @dataProvider validRoutesAreBuiltDataProvider
92 */
93 public function validRoutesAreBuilt(
94 array $routes,
95 string $routeName,
96 array $routeParameters,
97 string $expectation
98 ) {
99 $this->uriBuilder->_set('routes', $routes);
100
101 $uri = $this->uriBuilder->buildUriFromRoute(
102 $routeName,
103 $routeParameters
104 );
105
106 $this->assertEquals($expectation, $uri->__toString());
107 }
108
109 /**
110 * @test
111 */
112 public function nonExistingRouteThrowsException()
113 {
114 $this->expectException(RouteNotFoundException::class);
115 $this->expectExceptionCode(1476050190);
116 $this->uriBuilder->buildUriFromRoute(uniqid('any'));
117 }
118 }