‪TYPO3CMS  9.5
MiddlewareStackResolverTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Prophecy\Argument;
22 use TYPO3\CMS\Core\Package\PackageManager;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪MiddlewareStackResolverTest extends UnitTestCase
30 {
35  {
36  $package1 = $this->prophesize(Package::class);
37  $package1->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package1/');
38  $package2 = $this->prophesize(Package::class);
39  $package2->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package2/');
40  $packageManagerProphecy = $this->prophesize(PackageManager::class);
41  $packageManagerProphecy->getActivePackages()->willReturn([$package1->reveal(), $package2->reveal()]);
42  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
43  $dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
44  $phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class);
45  $phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false);
46  $phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false);
47 
48  $subject = new ‪MiddlewareStackResolver(
49  $packageManagerProphecy->reveal(),
50  $dependencyOrderingServiceProphecy->reveal(),
51  $phpFrontendCacheProphecy->reveal()
52  );
53  $expected = [
54  'secondMiddleware' => 'anotherClassName',
55  'firstMiddleware' => 'aClassName',
56  ];
57  $this->assertEquals($expected, $subject->resolve('testStack'));
58  }
59 
64  {
65  $packageManagerProphecy = $this->prophesize(PackageManager::class);
66  $packageManagerProphecy->getActivePackages()->willReturn([]);
67  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
68  $dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
69  $phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class);
70  $phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false);
71  $phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false);
72 
73  $subject = new ‪MiddlewareStackResolver(
74  $packageManagerProphecy->reveal(),
75  $dependencyOrderingServiceProphecy->reveal(),
76  $phpFrontendCacheProphecy->reveal()
77  );
78  // empty array expected
79  $expected = [];
80  $this->assertEquals($expected, $subject->resolve('testStack'));
81  }
82 
87  {
88  $package1 = $this->prophesize(Package::class);
89  $package1->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package1/');
90  $package2 = $this->prophesize(Package::class);
91  $package2->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package2Disables1/');
92  $packageManagerProphecy = $this->prophesize(PackageManager::class);
93  $packageManagerProphecy->getActivePackages()->willReturn([$package1->reveal(), $package2->reveal()]);
94  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
95  $dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
96  $phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class);
97  $phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false);
98  $phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false);
99 
100  $subject = new ‪MiddlewareStackResolver(
101  $packageManagerProphecy->reveal(),
102  $dependencyOrderingServiceProphecy->reveal(),
103  $phpFrontendCacheProphecy->reveal()
104  );
105  $expected = [
106  // firstMiddleware is missing, RequestMiddlewares.php of Package2 sets disables=true on firstMiddleware
107  'secondMiddleware' => 'anotherClassName',
108  ];
109  $this->assertEquals($expected, $subject->resolve('testStack'));
110  }
111 
116  {
117  $package1 = $this->prophesize(Package::class);
118  $package1->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package1/');
119  $package2 = $this->prophesize(Package::class);
120  $package2->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package2Replaces1/');
121  $packageManagerProphecy = $this->prophesize(PackageManager::class);
122  $packageManagerProphecy->getActivePackages()->willReturn([$package1->reveal(), $package2->reveal()]);
123  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
124  $dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
125  $phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class);
126  $phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false);
127  $phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false);
128 
129  $subject = new ‪MiddlewareStackResolver(
130  $packageManagerProphecy->reveal(),
131  $dependencyOrderingServiceProphecy->reveal(),
132  $phpFrontendCacheProphecy->reveal()
133  );
134  $expected = [
135  // firstMiddleware has been replaced, RequestMiddlewares.php of $package2 sets a new value for firstMiddleware
136  'firstMiddleware' => 'replacedClassName',
137  'secondMiddleware' => 'anotherClassName',
138  ];
139  $this->assertEquals($expected, $subject->resolve('testStack'));
140  }
141 }
‪TYPO3\CMS\Core\Tests\Unit\Http
‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend
Definition: PhpFrontend.php:24
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest\resolveReturnsMiddlewareStack
‪resolveReturnsMiddlewareStack()
Definition: MiddlewareStackResolverTest.php:34
‪TYPO3\CMS\Core\Http\MiddlewareStackResolver
Definition: MiddlewareStackResolver.php:29
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:21
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:31
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest
Definition: MiddlewareStackResolverTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest\resolveAllowsDisablingAMiddleware
‪resolveAllowsDisablingAMiddleware()
Definition: MiddlewareStackResolverTest.php:86
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest\resolveAllowsReplacingAMiddleware
‪resolveAllowsReplacingAMiddleware()
Definition: MiddlewareStackResolverTest.php:115
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest\resolveReturnsEmptyMiddlewareStackForZeroPackages
‪resolveReturnsEmptyMiddlewareStackForZeroPackages()
Definition: MiddlewareStackResolverTest.php:63