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