‪TYPO3CMS  10.4
StaticRouteResolverTest.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 Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Psr\Http\Server\RequestHandlerInterface;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
32 class ‪StaticRouteResolverTest extends UnitTestCase
33 {
34  protected ‪$requestHandler;
35 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
42  // A request handler which expects a site to be found.
43  $this->requestHandler = new class() implements RequestHandlerInterface {
44  public function handle(ServerRequestInterface $request): ResponseInterface
45  {
46  return new ‪NullResponse();
47  }
48  };
49  }
50 
55  {
56  $requestFactoryProphecy = $this->prophesize(RequestFactory::class);
57  $linkServiceProphecy = $this->prophesize(LinkService::class);
58  $subject = new ‪StaticRouteResolver(
59  $requestFactoryProphecy->reveal(),
60  $linkServiceProphecy->reveal()
61  );
62  $site = new ‪Site('lotus-flower', 13, [
63  'base' => 'https://example.com/',
64  'languages' => [
65  0 => [
66  'languageId' => 0,
67  'locale' => 'en_US.UTF-8',
68  'base' => '/en/'
69  ],
70  ],
71  'routes' => [
72  [
73  'route' => '/lotus/',
74  'type' => 'staticText',
75  'content' => 'nice'
76  ],
77  [
78  'route' => null,
79  'type' => 'staticText',
80  'content' => 'no-route'
81  ],
82  [
83  'route' => '',
84  'type' => 'staticText',
85  'content' => 'empty-route'
86  ],
87  [
88  'route' => '/empty-type',
89  'type' => ''
90  ],
91  [
92  'route' => '/no-type'
93  ],
94  [
95  'route' => '',
96  'type' => ''
97  ]
98  ]
99  ]);
100 
101  $request = new ‪ServerRequest('https://example.com/lotus/');
102  $request = $request->withAttribute('site', $site);
103  $response = $subject->process($request, $this->requestHandler);
104  self::assertInstanceOf(HtmlResponse::class, $response);
105  self::assertEquals('nice', $response->getBody()->getContents());
106 
107  $request = new ‪ServerRequest('https://example.com/nothing');
108  $request = $request->withAttribute('site', $site);
109  $response = $subject->process($request, $this->requestHandler);
110  self::assertInstanceOf(NullResponse::class, $response);
111 
112  $request = new ‪ServerRequest('https://example.com/no-type');
113  $request = $request->withAttribute('site', $site);
114  $response = $subject->process($request, $this->requestHandler);
115  self::assertInstanceOf(NullResponse::class, $response);
116  }
117 }
‪TYPO3\CMS\Frontend\Middleware\StaticRouteResolver
Definition: StaticRouteResolver.php:37
‪TYPO3\CMS\Core\Http\NullResponse
Definition: NullResponse.php:26
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware\StaticRouteResolverTest\$requestHandler
‪$requestHandler
Definition: StaticRouteResolverTest.php:34
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:40
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware\StaticRouteResolverTest\invalidStaticRouteDoesNotWork
‪invalidStaticRouteDoesNotWork()
Definition: StaticRouteResolverTest.php:54
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware
Definition: PageArgumentValidatorTest.php:18
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware\StaticRouteResolverTest
Definition: StaticRouteResolverTest.php:33
‪TYPO3\CMS\Core\Http\RequestFactory
Definition: RequestFactory.php:31
‪TYPO3\CMS\Frontend\Tests\Unit\Middleware\StaticRouteResolverTest\setUp
‪setUp()
Definition: StaticRouteResolverTest.php:39
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26