aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/AppFramework/DependencyInjection/DIContainerTest.php')
-rw-r--r--tests/lib/AppFramework/DependencyInjection/DIContainerTest.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
index 69367ad6ce2..bcf4e0a2771 100644
--- a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
+++ b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
@@ -25,9 +25,13 @@
namespace Test\AppFramework\DependencyInjection;
+use OC\AppFramework\Bootstrap\Coordinator;
+use OC\AppFramework\Bootstrap\RegistrationContext;
+use OC\AppFramework\Bootstrap\ServiceRegistration;
use OC\AppFramework\DependencyInjection\DIContainer;
use OC\AppFramework\Http\Request;
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
+use OCP\AppFramework\Middleware;
use OCP\AppFramework\QueryException;
use OCP\IConfig;
use OCP\IRequestId;
@@ -84,6 +88,38 @@ class DIContainerTest extends \Test\TestCase {
$this->assertTrue($found);
}
+ public function testMiddlewareDispatcherIncludesBootstrapMiddlewares(): void {
+ $coordinator = $this->createMock(Coordinator::class);
+ $this->container[Coordinator::class] = $coordinator;
+ $this->container['Request'] = $this->createMock(Request::class);
+ $registrationContext = $this->createMock(RegistrationContext::class);
+ $registrationContext->method('getMiddlewareRegistrations')
+ ->willReturn([
+ new ServiceRegistration($this->container['appName'], 'foo'),
+ new ServiceRegistration('otherapp', 'bar'),
+ ]);
+ $this->container['foo'] = new class extends Middleware {
+ };
+ $this->container['bar'] = new class extends Middleware {
+ };
+ $coordinator->method('getRegistrationContext')->willReturn($registrationContext);
+
+ $dispatcher = $this->container['MiddlewareDispatcher'];
+
+ $middlewares = $dispatcher->getMiddlewares();
+ self::assertNotEmpty($middlewares);
+ foreach ($middlewares as $middleware) {
+ if ($middleware === $this->container['bar']) {
+ $this->fail('Container must not register this middleware');
+ }
+ if ($middleware === $this->container['foo']) {
+ // It is done
+ return;
+ }
+ }
+ $this->fail('Bootstrap registered middleware not found');
+ }
+
public function testInvalidAppClass() {
$this->expectException(QueryException::class);
$this->container->query('\OCA\Name\Foo');