‪TYPO3CMS  9.5
StaticRouteResolverTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
21 use Psr\Http\Server\RequestHandlerInterface;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
31 class ‪StaticRouteResolverTest extends UnitTestCase
32 {
33  protected ‪$requestHandler;
34 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41  // A request handler which expects a site to be found.
42  $this->requestHandler = new class implements RequestHandlerInterface {
43  public function handle(ServerRequestInterface $request): ResponseInterface
44  {
45  return new ‪NullResponse();
46  }
47  };
48  }
49 
54  {
55  $requestFactoryProphecy = $this->prophesize(RequestFactory::class);
56  $linkServiceProphecy = $this->prophesize(LinkService::class);
57  $subject = new ‪StaticRouteResolver(
58  $requestFactoryProphecy->reveal(),
59  $linkServiceProphecy->reveal()
60  );
61  $site = new ‪Site('lotus-flower', 13, [
62  'base' => 'https://example.com/',
63  'languages' => [
64  0 => [
65  'languageId' => 0,
66  'locale' => 'en_US.UTF-8',
67  'base' => '/en/'
68  ],
69  ],
70  'routes' => [
71  [
72  'route' => '/lotus/',
73  'type' => 'staticText',
74  'content' => 'nice'
75  ],
76  [
77  'route' => null,
78  'type' => 'staticText',
79  'content' => 'no-route'
80  ],
81  [
82  'route' => '',
83  'type' => 'staticText',
84  'content' => 'empty-route'
85  ],
86  [
87  'route' => '/empty-type',
88  'type' => ''
89  ],
90  [
91  'route' => '/no-type'
92  ],
93  [
94  'route' => '',
95  'type' => ''
96  ]
97  ]
98  ]);
99 
100  $request = new ‪ServerRequest('https://example.com/lotus/');
101  $request = $request->withAttribute('site', $site);
102  $response = $subject->process($request, $this->requestHandler);
103  self::assertInstanceOf(HtmlResponse::class, $response);
104  self::assertEquals('nice', $response->getBody()->getContents());
105 
106  $request = new ‪ServerRequest('https://example.com/nothing');
107  $request = $request->withAttribute('site', $site);
108  $response = $subject->process($request, $this->requestHandler);
109  self::assertInstanceOf(NullResponse::class, $response);
110 
111  $request = new ‪ServerRequest('https://example.com/no-type');
112  $request = $request->withAttribute('site', $site);
113  $response = $subject->process($request, $this->requestHandler);
114  self::assertInstanceOf(NullResponse::class, $response);
115  }
116 }
‪TYPO3\CMS\Frontend\Middleware\StaticRouteResolver
Definition: StaticRouteResolver.php:37
‪TYPO3\CMS\Core\Http\NullResponse
Definition: NullResponse.php:24
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware\StaticRouteResolverTest\$requestHandler
‪$requestHandler
Definition: StaticRouteResolverTest.php:33
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:39
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware\StaticRouteResolverTest\invalidStaticRouteDoesNotWork
‪invalidStaticRouteDoesNotWork()
Definition: StaticRouteResolverTest.php:53
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware
Definition: PageArgumentValidatorTest.php:4
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:35
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware\StaticRouteResolverTest
Definition: StaticRouteResolverTest.php:32
‪TYPO3\CMS\Core\Http\RequestFactory
Definition: RequestFactory.php:27
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware\StaticRouteResolverTest\setUp
‪setUp()
Definition: StaticRouteResolverTest.php:38
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25