Completed
Push — master ( c214ec...1447f1 )
by Joas
21:41
created
tests/lib/AppFramework/Bootstrap/CoordinatorTest.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -27,78 +27,78 @@
 block discarded – undo
27 27
 use Test\TestCase;
28 28
 
29 29
 class CoordinatorTest extends TestCase {
30
-	private IAppManager&MockObject $appManager;
31
-	private IServerContainer&MockObject $serverContainer;
32
-	private Registry&MockObject $crashReporterRegistry;
33
-	private IManager&MockObject $dashboardManager;
34
-	private IEventDispatcher&MockObject $eventDispatcher;
35
-	private IEventLogger&MockObject $eventLogger;
36
-	private LoggerInterface&MockObject $logger;
37
-	private Coordinator $coordinator;
38
-
39
-	protected function setUp(): void {
40
-		parent::setUp();
41
-
42
-		$this->appManager = $this->createMock(IAppManager::class);
43
-		$this->serverContainer = $this->createMock(IServerContainer::class);
44
-		$this->crashReporterRegistry = $this->createMock(Registry::class);
45
-		$this->dashboardManager = $this->createMock(IManager::class);
46
-		$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
47
-		$this->eventLogger = $this->createMock(IEventLogger::class);
48
-		$this->logger = $this->createMock(LoggerInterface::class);
49
-
50
-		$this->coordinator = new Coordinator(
51
-			$this->serverContainer,
52
-			$this->crashReporterRegistry,
53
-			$this->dashboardManager,
54
-			$this->eventDispatcher,
55
-			$this->eventLogger,
56
-			$this->appManager,
57
-			$this->logger,
58
-		);
59
-	}
60
-
61
-	public function testBootAppNotLoadable(): void {
62
-		$appId = 'settings';
63
-		$this->serverContainer->expects($this->once())
64
-			->method('query')
65
-			->with(Application::class)
66
-			->willThrowException(new QueryException(''));
67
-		$this->logger->expects($this->once())
68
-			->method('error');
69
-
70
-		$this->coordinator->bootApp($appId);
71
-	}
72
-
73
-	public function testBootAppNotBootable(): void {
74
-		$appId = 'settings';
75
-		$mockApp = $this->createMock(Application::class);
76
-		$this->serverContainer->expects($this->once())
77
-			->method('query')
78
-			->with(Application::class)
79
-			->willReturn($mockApp);
80
-
81
-		$this->coordinator->bootApp($appId);
82
-	}
83
-
84
-	public function testBootApp(): void {
85
-		$appId = 'settings';
86
-		$mockApp = new class extends App implements IBootstrap {
87
-			public function __construct() {
88
-				parent::__construct('test', []);
89
-			}
90
-
91
-			public function register(IRegistrationContext $context): void {
92
-			}
93
-
94
-			public function boot(IBootContext $context): void {
95
-			}
96
-		};
97
-		$this->serverContainer->expects($this->once())
98
-			->method('query')
99
-			->with(Application::class)
100
-			->willReturn($mockApp);
101
-
102
-		$this->coordinator->bootApp($appId);
103
-	}
30
+    private IAppManager&MockObject $appManager;
31
+    private IServerContainer&MockObject $serverContainer;
32
+    private Registry&MockObject $crashReporterRegistry;
33
+    private IManager&MockObject $dashboardManager;
34
+    private IEventDispatcher&MockObject $eventDispatcher;
35
+    private IEventLogger&MockObject $eventLogger;
36
+    private LoggerInterface&MockObject $logger;
37
+    private Coordinator $coordinator;
38
+
39
+    protected function setUp(): void {
40
+        parent::setUp();
41
+
42
+        $this->appManager = $this->createMock(IAppManager::class);
43
+        $this->serverContainer = $this->createMock(IServerContainer::class);
44
+        $this->crashReporterRegistry = $this->createMock(Registry::class);
45
+        $this->dashboardManager = $this->createMock(IManager::class);
46
+        $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
47
+        $this->eventLogger = $this->createMock(IEventLogger::class);
48
+        $this->logger = $this->createMock(LoggerInterface::class);
49
+
50
+        $this->coordinator = new Coordinator(
51
+            $this->serverContainer,
52
+            $this->crashReporterRegistry,
53
+            $this->dashboardManager,
54
+            $this->eventDispatcher,
55
+            $this->eventLogger,
56
+            $this->appManager,
57
+            $this->logger,
58
+        );
59
+    }
60
+
61
+    public function testBootAppNotLoadable(): void {
62
+        $appId = 'settings';
63
+        $this->serverContainer->expects($this->once())
64
+            ->method('query')
65
+            ->with(Application::class)
66
+            ->willThrowException(new QueryException(''));
67
+        $this->logger->expects($this->once())
68
+            ->method('error');
69
+
70
+        $this->coordinator->bootApp($appId);
71
+    }
72
+
73
+    public function testBootAppNotBootable(): void {
74
+        $appId = 'settings';
75
+        $mockApp = $this->createMock(Application::class);
76
+        $this->serverContainer->expects($this->once())
77
+            ->method('query')
78
+            ->with(Application::class)
79
+            ->willReturn($mockApp);
80
+
81
+        $this->coordinator->bootApp($appId);
82
+    }
83
+
84
+    public function testBootApp(): void {
85
+        $appId = 'settings';
86
+        $mockApp = new class extends App implements IBootstrap {
87
+            public function __construct() {
88
+                parent::__construct('test', []);
89
+            }
90
+
91
+            public function register(IRegistrationContext $context): void {
92
+            }
93
+
94
+            public function boot(IBootContext $context): void {
95
+            }
96
+        };
97
+        $this->serverContainer->expects($this->once())
98
+            ->method('query')
99
+            ->with(Application::class)
100
+            ->willReturn($mockApp);
101
+
102
+        $this->coordinator->bootApp($appId);
103
+    }
104 104
 }
Please login to merge, or discard this patch.
tests/lib/AppFramework/Bootstrap/BootContextTest.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,34 +16,34 @@
 block discarded – undo
16 16
 use Test\TestCase;
17 17
 
18 18
 class BootContextTest extends TestCase {
19
-	private IAppContainer&MockObject $appContainer;
19
+    private IAppContainer&MockObject $appContainer;
20 20
 
21
-	private BootContext $context;
21
+    private BootContext $context;
22 22
 
23
-	protected function setUp(): void {
24
-		parent::setUp();
23
+    protected function setUp(): void {
24
+        parent::setUp();
25 25
 
26
-		$this->appContainer = $this->createMock(IAppContainer::class);
26
+        $this->appContainer = $this->createMock(IAppContainer::class);
27 27
 
28
-		$this->context = new BootContext(
29
-			$this->appContainer
30
-		);
31
-	}
28
+        $this->context = new BootContext(
29
+            $this->appContainer
30
+        );
31
+    }
32 32
 
33
-	public function testGetAppContainer(): void {
34
-		$container = $this->context->getAppContainer();
33
+    public function testGetAppContainer(): void {
34
+        $container = $this->context->getAppContainer();
35 35
 
36
-		$this->assertSame($this->appContainer, $container);
37
-	}
36
+        $this->assertSame($this->appContainer, $container);
37
+    }
38 38
 
39
-	public function testGetServerContainer(): void {
40
-		$serverContainer = $this->createMock(IServerContainer::class);
41
-		$this->appContainer->method('get')
42
-			->with(IServerContainer::class)
43
-			->willReturn($serverContainer);
39
+    public function testGetServerContainer(): void {
40
+        $serverContainer = $this->createMock(IServerContainer::class);
41
+        $this->appContainer->method('get')
42
+            ->with(IServerContainer::class)
43
+            ->willReturn($serverContainer);
44 44
 
45
-		$container = $this->context->getServerContainer();
45
+        $container = $this->context->getServerContainer();
46 46
 
47
-		$this->assertSame($serverContainer, $container);
48
-	}
47
+        $this->assertSame($serverContainer, $container);
48
+    }
49 49
 }
Please login to merge, or discard this patch.
tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -20,151 +20,151 @@
 block discarded – undo
20 20
 use Test\TestCase;
21 21
 
22 22
 class RegistrationContextTest extends TestCase {
23
-	private LoggerInterface&MockObject $logger;
24
-	private RegistrationContext $context;
25
-
26
-	protected function setUp(): void {
27
-		parent::setUp();
28
-
29
-		$this->logger = $this->createMock(LoggerInterface::class);
30
-
31
-		$this->context = new RegistrationContext(
32
-			$this->logger
33
-		);
34
-	}
35
-
36
-	public function testRegisterCapability(): void {
37
-		$app = $this->createMock(App::class);
38
-		$name = 'abc';
39
-		$container = $this->createMock(IAppContainer::class);
40
-		$app->method('getContainer')
41
-			->willReturn($container);
42
-		$container->expects($this->once())
43
-			->method('registerCapability')
44
-			->with($name);
45
-		$this->logger->expects($this->never())
46
-			->method('error');
47
-
48
-		$this->context->for('myapp')->registerCapability($name);
49
-		$this->context->delegateCapabilityRegistrations([
50
-			'myapp' => $app,
51
-		]);
52
-	}
53
-
54
-	public function testRegisterEventListener(): void {
55
-		$event = 'abc';
56
-		$service = 'def';
57
-		$dispatcher = $this->createMock(IEventDispatcher::class);
58
-		$dispatcher->expects($this->once())
59
-			->method('addServiceListener')
60
-			->with($event, $service, 0);
61
-		$this->logger->expects($this->never())
62
-			->method('error');
63
-
64
-		$this->context->for('myapp')->registerEventListener($event, $service);
65
-		$this->context->delegateEventListenerRegistrations($dispatcher);
66
-	}
67
-
68
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataProvider_TrueFalse')]
69
-	public function testRegisterService(bool $shared): void {
70
-		$app = $this->createMock(App::class);
71
-		$service = 'abc';
72
-		$factory = function () {
73
-			return 'def';
74
-		};
75
-		$container = $this->createMock(IAppContainer::class);
76
-		$app->method('getContainer')
77
-			->willReturn($container);
78
-		$container->expects($this->once())
79
-			->method('registerService')
80
-			->with($service, $factory, $shared);
81
-		$this->logger->expects($this->never())
82
-			->method('error');
83
-
84
-		$this->context->for('myapp')->registerService($service, $factory, $shared);
85
-		$this->context->delegateContainerRegistrations([
86
-			'myapp' => $app,
87
-		]);
88
-	}
89
-
90
-	public function testRegisterServiceAlias(): void {
91
-		$app = $this->createMock(App::class);
92
-		$alias = 'abc';
93
-		$target = 'def';
94
-		$container = $this->createMock(IAppContainer::class);
95
-		$app->method('getContainer')
96
-			->willReturn($container);
97
-		$container->expects($this->once())
98
-			->method('registerAlias')
99
-			->with($alias, $target);
100
-		$this->logger->expects($this->never())
101
-			->method('error');
102
-
103
-		$this->context->for('myapp')->registerServiceAlias($alias, $target);
104
-		$this->context->delegateContainerRegistrations([
105
-			'myapp' => $app,
106
-		]);
107
-	}
108
-
109
-	public function testRegisterParameter(): void {
110
-		$app = $this->createMock(App::class);
111
-		$name = 'abc';
112
-		$value = 'def';
113
-		$container = $this->createMock(IAppContainer::class);
114
-		$app->method('getContainer')
115
-			->willReturn($container);
116
-		$container->expects($this->once())
117
-			->method('registerParameter')
118
-			->with($name, $value);
119
-		$this->logger->expects($this->never())
120
-			->method('error');
121
-
122
-		$this->context->for('myapp')->registerParameter($name, $value);
123
-		$this->context->delegateContainerRegistrations([
124
-			'myapp' => $app,
125
-		]);
126
-	}
127
-
128
-	public function testRegisterUserMigrator(): void {
129
-		$appIdA = 'myapp';
130
-		$migratorClassA = 'OCA\App\UserMigration\AppMigrator';
131
-
132
-		$appIdB = 'otherapp';
133
-		$migratorClassB = 'OCA\OtherApp\UserMigration\OtherAppMigrator';
134
-
135
-		$serviceRegistrationA = new ServiceRegistration($appIdA, $migratorClassA);
136
-		$serviceRegistrationB = new ServiceRegistration($appIdB, $migratorClassB);
137
-
138
-		$this->context
139
-			->for($appIdA)
140
-			->registerUserMigrator($migratorClassA);
141
-		$this->context
142
-			->for($appIdB)
143
-			->registerUserMigrator($migratorClassB);
144
-
145
-		$this->assertEquals(
146
-			[
147
-				$serviceRegistrationA,
148
-				$serviceRegistrationB,
149
-			],
150
-			$this->context->getUserMigrators(),
151
-		);
152
-	}
153
-
154
-	public static function dataProvider_TrueFalse(): array {
155
-		return[
156
-			[true],
157
-			[false]
158
-		];
159
-	}
160
-
161
-	public function testGetMiddlewareRegistrations(): void {
162
-		$this->context->registerMiddleware('core', TwoFactorMiddleware::class, false);
163
-
164
-		$registrations = $this->context->getMiddlewareRegistrations();
165
-
166
-		self::assertNotEmpty($registrations);
167
-		self::assertSame('core', $registrations[0]->getAppId());
168
-		self::assertSame(TwoFactorMiddleware::class, $registrations[0]->getService());
169
-	}
23
+    private LoggerInterface&MockObject $logger;
24
+    private RegistrationContext $context;
25
+
26
+    protected function setUp(): void {
27
+        parent::setUp();
28
+
29
+        $this->logger = $this->createMock(LoggerInterface::class);
30
+
31
+        $this->context = new RegistrationContext(
32
+            $this->logger
33
+        );
34
+    }
35
+
36
+    public function testRegisterCapability(): void {
37
+        $app = $this->createMock(App::class);
38
+        $name = 'abc';
39
+        $container = $this->createMock(IAppContainer::class);
40
+        $app->method('getContainer')
41
+            ->willReturn($container);
42
+        $container->expects($this->once())
43
+            ->method('registerCapability')
44
+            ->with($name);
45
+        $this->logger->expects($this->never())
46
+            ->method('error');
47
+
48
+        $this->context->for('myapp')->registerCapability($name);
49
+        $this->context->delegateCapabilityRegistrations([
50
+            'myapp' => $app,
51
+        ]);
52
+    }
53
+
54
+    public function testRegisterEventListener(): void {
55
+        $event = 'abc';
56
+        $service = 'def';
57
+        $dispatcher = $this->createMock(IEventDispatcher::class);
58
+        $dispatcher->expects($this->once())
59
+            ->method('addServiceListener')
60
+            ->with($event, $service, 0);
61
+        $this->logger->expects($this->never())
62
+            ->method('error');
63
+
64
+        $this->context->for('myapp')->registerEventListener($event, $service);
65
+        $this->context->delegateEventListenerRegistrations($dispatcher);
66
+    }
67
+
68
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider_TrueFalse')]
69
+    public function testRegisterService(bool $shared): void {
70
+        $app = $this->createMock(App::class);
71
+        $service = 'abc';
72
+        $factory = function () {
73
+            return 'def';
74
+        };
75
+        $container = $this->createMock(IAppContainer::class);
76
+        $app->method('getContainer')
77
+            ->willReturn($container);
78
+        $container->expects($this->once())
79
+            ->method('registerService')
80
+            ->with($service, $factory, $shared);
81
+        $this->logger->expects($this->never())
82
+            ->method('error');
83
+
84
+        $this->context->for('myapp')->registerService($service, $factory, $shared);
85
+        $this->context->delegateContainerRegistrations([
86
+            'myapp' => $app,
87
+        ]);
88
+    }
89
+
90
+    public function testRegisterServiceAlias(): void {
91
+        $app = $this->createMock(App::class);
92
+        $alias = 'abc';
93
+        $target = 'def';
94
+        $container = $this->createMock(IAppContainer::class);
95
+        $app->method('getContainer')
96
+            ->willReturn($container);
97
+        $container->expects($this->once())
98
+            ->method('registerAlias')
99
+            ->with($alias, $target);
100
+        $this->logger->expects($this->never())
101
+            ->method('error');
102
+
103
+        $this->context->for('myapp')->registerServiceAlias($alias, $target);
104
+        $this->context->delegateContainerRegistrations([
105
+            'myapp' => $app,
106
+        ]);
107
+    }
108
+
109
+    public function testRegisterParameter(): void {
110
+        $app = $this->createMock(App::class);
111
+        $name = 'abc';
112
+        $value = 'def';
113
+        $container = $this->createMock(IAppContainer::class);
114
+        $app->method('getContainer')
115
+            ->willReturn($container);
116
+        $container->expects($this->once())
117
+            ->method('registerParameter')
118
+            ->with($name, $value);
119
+        $this->logger->expects($this->never())
120
+            ->method('error');
121
+
122
+        $this->context->for('myapp')->registerParameter($name, $value);
123
+        $this->context->delegateContainerRegistrations([
124
+            'myapp' => $app,
125
+        ]);
126
+    }
127
+
128
+    public function testRegisterUserMigrator(): void {
129
+        $appIdA = 'myapp';
130
+        $migratorClassA = 'OCA\App\UserMigration\AppMigrator';
131
+
132
+        $appIdB = 'otherapp';
133
+        $migratorClassB = 'OCA\OtherApp\UserMigration\OtherAppMigrator';
134
+
135
+        $serviceRegistrationA = new ServiceRegistration($appIdA, $migratorClassA);
136
+        $serviceRegistrationB = new ServiceRegistration($appIdB, $migratorClassB);
137
+
138
+        $this->context
139
+            ->for($appIdA)
140
+            ->registerUserMigrator($migratorClassA);
141
+        $this->context
142
+            ->for($appIdB)
143
+            ->registerUserMigrator($migratorClassB);
144
+
145
+        $this->assertEquals(
146
+            [
147
+                $serviceRegistrationA,
148
+                $serviceRegistrationB,
149
+            ],
150
+            $this->context->getUserMigrators(),
151
+        );
152
+    }
153
+
154
+    public static function dataProvider_TrueFalse(): array {
155
+        return[
156
+            [true],
157
+            [false]
158
+        ];
159
+    }
160
+
161
+    public function testGetMiddlewareRegistrations(): void {
162
+        $this->context->registerMiddleware('core', TwoFactorMiddleware::class, false);
163
+
164
+        $registrations = $this->context->getMiddlewareRegistrations();
165
+
166
+        self::assertNotEmpty($registrations);
167
+        self::assertSame('core', $registrations[0]->getAppId());
168
+        self::assertSame(TwoFactorMiddleware::class, $registrations[0]->getService());
169
+    }
170 170
 }
Please login to merge, or discard this patch.
tests/lib/AppFramework/Controller/PublicShareControllerTest.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -15,72 +15,72 @@
 block discarded – undo
15 15
 use PHPUnit\Framework\MockObject\MockObject;
16 16
 
17 17
 class TestController extends PublicShareController {
18
-	public function __construct(
19
-		string $appName,
20
-		IRequest $request,
21
-		ISession $session,
22
-		private string $hash,
23
-		private bool $isProtected,
24
-	) {
25
-		parent::__construct($appName, $request, $session);
26
-	}
27
-
28
-	protected function getPasswordHash(): string {
29
-		return $this->hash;
30
-	}
31
-
32
-	public function isValidToken(): bool {
33
-		return false;
34
-	}
35
-
36
-	protected function isPasswordProtected(): bool {
37
-		return $this->isProtected;
38
-	}
18
+    public function __construct(
19
+        string $appName,
20
+        IRequest $request,
21
+        ISession $session,
22
+        private string $hash,
23
+        private bool $isProtected,
24
+    ) {
25
+        parent::__construct($appName, $request, $session);
26
+    }
27
+
28
+    protected function getPasswordHash(): string {
29
+        return $this->hash;
30
+    }
31
+
32
+    public function isValidToken(): bool {
33
+        return false;
34
+    }
35
+
36
+    protected function isPasswordProtected(): bool {
37
+        return $this->isProtected;
38
+    }
39 39
 }
40 40
 
41 41
 class PublicShareControllerTest extends \Test\TestCase {
42
-	private IRequest&MockObject $request;
43
-	private ISession&MockObject $session;
44
-
45
-	protected function setUp(): void {
46
-		parent::setUp();
47
-
48
-		$this->request = $this->createMock(IRequest::class);
49
-		$this->session = $this->createMock(ISession::class);
50
-	}
51
-
52
-	public function testGetToken(): void {
53
-		$controller = new TestController('app', $this->request, $this->session, 'hash', false);
54
-
55
-		$controller->setToken('test');
56
-		$this->assertEquals('test', $controller->getToken());
57
-	}
58
-
59
-	public static function dataIsAuthenticated(): array {
60
-		return [
61
-			[false, 'token1', 'token1', 'hash1', 'hash1',  true],
62
-			[false, 'token1', 'token1', 'hash1', 'hash2',  true],
63
-			[false, 'token1', 'token2', 'hash1', 'hash1',  true],
64
-			[false, 'token1', 'token2', 'hash1', 'hash2',  true],
65
-			[ true, 'token1', 'token1', 'hash1', 'hash1',  true],
66
-			[ true, 'token1', 'token1', 'hash1', 'hash2', false],
67
-			[ true, 'token1', 'token2', 'hash1', 'hash1', false],
68
-			[ true, 'token1', 'token2', 'hash1', 'hash2', false],
69
-		];
70
-	}
71
-
72
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataIsAuthenticated')]
73
-	public function testIsAuthenticatedNotPasswordProtected(bool $protected, string $token1, string $token2, string $hash1, string $hash2, bool $expected): void {
74
-		$controller = new TestController('app', $this->request, $this->session, $hash2, $protected);
75
-
76
-		$this->session->method('get')
77
-			->willReturnMap([
78
-				['public_link_authenticated_token', $token1],
79
-				['public_link_authenticated_password_hash', $hash1],
80
-			]);
81
-
82
-		$controller->setToken($token2);
83
-
84
-		$this->assertEquals($expected, $controller->isAuthenticated());
85
-	}
42
+    private IRequest&MockObject $request;
43
+    private ISession&MockObject $session;
44
+
45
+    protected function setUp(): void {
46
+        parent::setUp();
47
+
48
+        $this->request = $this->createMock(IRequest::class);
49
+        $this->session = $this->createMock(ISession::class);
50
+    }
51
+
52
+    public function testGetToken(): void {
53
+        $controller = new TestController('app', $this->request, $this->session, 'hash', false);
54
+
55
+        $controller->setToken('test');
56
+        $this->assertEquals('test', $controller->getToken());
57
+    }
58
+
59
+    public static function dataIsAuthenticated(): array {
60
+        return [
61
+            [false, 'token1', 'token1', 'hash1', 'hash1',  true],
62
+            [false, 'token1', 'token1', 'hash1', 'hash2',  true],
63
+            [false, 'token1', 'token2', 'hash1', 'hash1',  true],
64
+            [false, 'token1', 'token2', 'hash1', 'hash2',  true],
65
+            [ true, 'token1', 'token1', 'hash1', 'hash1',  true],
66
+            [ true, 'token1', 'token1', 'hash1', 'hash2', false],
67
+            [ true, 'token1', 'token2', 'hash1', 'hash1', false],
68
+            [ true, 'token1', 'token2', 'hash1', 'hash2', false],
69
+        ];
70
+    }
71
+
72
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataIsAuthenticated')]
73
+    public function testIsAuthenticatedNotPasswordProtected(bool $protected, string $token1, string $token2, string $hash1, string $hash2, bool $expected): void {
74
+        $controller = new TestController('app', $this->request, $this->session, $hash2, $protected);
75
+
76
+        $this->session->method('get')
77
+            ->willReturnMap([
78
+                ['public_link_authenticated_token', $token1],
79
+                ['public_link_authenticated_password_hash', $hash1],
80
+            ]);
81
+
82
+        $controller->setToken($token2);
83
+
84
+        $this->assertEquals($expected, $controller->isAuthenticated());
85
+    }
86 86
 }
Please login to merge, or discard this patch.
tests/lib/AppFramework/Controller/ApiControllerTest.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,25 +20,25 @@
 block discarded – undo
20 20
 
21 21
 
22 22
 class ApiControllerTest extends \Test\TestCase {
23
-	protected ChildApiController $controller;
24
-
25
-	public function testCors(): void {
26
-		$request = new Request(
27
-			['server' => ['HTTP_ORIGIN' => 'test']],
28
-			$this->createMock(IRequestId::class),
29
-			$this->createMock(IConfig::class)
30
-		);
31
-		$this->controller = new ChildApiController('app', $request, 'verbs',
32
-			'headers', 100);
33
-
34
-		$response = $this->controller->preflightedCors();
35
-
36
-		$headers = $response->getHeaders();
37
-
38
-		$this->assertEquals('test', $headers['Access-Control-Allow-Origin']);
39
-		$this->assertEquals('verbs', $headers['Access-Control-Allow-Methods']);
40
-		$this->assertEquals('headers', $headers['Access-Control-Allow-Headers']);
41
-		$this->assertEquals('false', $headers['Access-Control-Allow-Credentials']);
42
-		$this->assertEquals(100, $headers['Access-Control-Max-Age']);
43
-	}
23
+    protected ChildApiController $controller;
24
+
25
+    public function testCors(): void {
26
+        $request = new Request(
27
+            ['server' => ['HTTP_ORIGIN' => 'test']],
28
+            $this->createMock(IRequestId::class),
29
+            $this->createMock(IConfig::class)
30
+        );
31
+        $this->controller = new ChildApiController('app', $request, 'verbs',
32
+            'headers', 100);
33
+
34
+        $response = $this->controller->preflightedCors();
35
+
36
+        $headers = $response->getHeaders();
37
+
38
+        $this->assertEquals('test', $headers['Access-Control-Allow-Origin']);
39
+        $this->assertEquals('verbs', $headers['Access-Control-Allow-Methods']);
40
+        $this->assertEquals('headers', $headers['Access-Control-Allow-Headers']);
41
+        $this->assertEquals('false', $headers['Access-Control-Allow-Credentials']);
42
+        $this->assertEquals(100, $headers['Access-Control-Max-Age']);
43
+    }
44 44
 }
Please login to merge, or discard this patch.
tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -18,123 +18,123 @@
 block discarded – undo
18 18
 use PHPUnit\Framework\MockObject\MockObject;
19 19
 
20 20
 class AuthPublicShareControllerTest extends \Test\TestCase {
21
-	private IRequest&MockObject $request;
22
-	private ISession&MockObject $session;
23
-	private IURLGenerator&MockObject $urlGenerator;
24
-	private AuthPublicShareController&MockObject $controller;
25
-
26
-
27
-	protected function setUp(): void {
28
-		parent::setUp();
29
-
30
-		$this->request = $this->createMock(IRequest::class);
31
-		$this->session = $this->createMock(ISession::class);
32
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
33
-
34
-		$this->controller = $this->getMockBuilder(AuthPublicShareController::class)
35
-			->setConstructorArgs([
36
-				'app',
37
-				$this->request,
38
-				$this->session,
39
-				$this->urlGenerator
40
-			])->onlyMethods([
41
-				'authFailed',
42
-				'getPasswordHash',
43
-				'isAuthenticated',
44
-				'isPasswordProtected',
45
-				'isValidToken',
46
-				'showShare',
47
-				'verifyPassword',
48
-				'validateIdentity',
49
-				'generatePassword'
50
-			])->getMock();
51
-	}
52
-
53
-	public function testShowAuthenticate(): void {
54
-		$expects = new TemplateResponse('core', 'publicshareauth', [], 'guest');
55
-
56
-		$this->assertEquals($expects, $this->controller->showAuthenticate());
57
-	}
58
-
59
-	public function testAuthenticateAuthenticated(): void {
60
-		$this->controller->method('isAuthenticated')
61
-			->willReturn(true);
62
-
63
-		$this->controller->setToken('myToken');
64
-
65
-		$this->session->method('get')
66
-			->willReturnMap([
67
-				['public_link_authenticate_redirect', json_encode(['foo' => 'bar'])],
68
-			]);
69
-
70
-		$this->urlGenerator->method('linkToRoute')
71
-			->willReturn('myLink!');
72
-
73
-		$result = $this->controller->authenticate('password');
74
-		$this->assertInstanceOf(RedirectResponse::class, $result);
75
-		$this->assertSame('myLink!', $result->getRedirectURL());
76
-	}
77
-
78
-	public function testAuthenticateInvalidPassword(): void {
79
-		$this->controller->setToken('token');
80
-		$this->controller->method('isPasswordProtected')
81
-			->willReturn(true);
82
-
83
-		$this->controller->method('verifyPassword')
84
-			->with('password')
85
-			->willReturn(false);
86
-
87
-		$this->controller->expects($this->once())
88
-			->method('authFailed');
89
-
90
-		$expects = new TemplateResponse('core', 'publicshareauth', ['wrongpw' => true], 'guest');
91
-		$expects->throttle();
92
-
93
-		$result = $this->controller->authenticate('password');
94
-
95
-		$this->assertEquals($expects, $result);
96
-	}
97
-
98
-	public function testAuthenticateValidPassword(): void {
99
-		$this->controller->setToken('token');
100
-		$this->controller->method('isPasswordProtected')
101
-			->willReturn(true);
102
-		$this->controller->method('verifyPassword')
103
-			->with('password')
104
-			->willReturn(true);
105
-		$this->controller->method('getPasswordHash')
106
-			->willReturn('hash');
107
-
108
-		$this->session->expects($this->once())
109
-			->method('regenerateId');
110
-		$this->session->method('get')
111
-			->willReturnMap([
112
-				['public_link_authenticate_redirect', json_encode(['foo' => 'bar'])],
113
-			]);
114
-
115
-		$tokenSet = false;
116
-		$hashSet = false;
117
-		$this->session
118
-			->method('set')
119
-			->willReturnCallback(function ($key, $value) use (&$tokenSet, &$hashSet) {
120
-				if ($key === 'public_link_authenticated_token' && $value === 'token') {
121
-					$tokenSet = true;
122
-					return true;
123
-				}
124
-				if ($key === 'public_link_authenticated_password_hash' && $value === 'hash') {
125
-					$hashSet = true;
126
-					return true;
127
-				}
128
-				return false;
129
-			});
130
-
131
-		$this->urlGenerator->method('linkToRoute')
132
-			->willReturn('myLink!');
133
-
134
-		$result = $this->controller->authenticate('password');
135
-		$this->assertInstanceOf(RedirectResponse::class, $result);
136
-		$this->assertSame('myLink!', $result->getRedirectURL());
137
-		$this->assertTrue($tokenSet);
138
-		$this->assertTrue($hashSet);
139
-	}
21
+    private IRequest&MockObject $request;
22
+    private ISession&MockObject $session;
23
+    private IURLGenerator&MockObject $urlGenerator;
24
+    private AuthPublicShareController&MockObject $controller;
25
+
26
+
27
+    protected function setUp(): void {
28
+        parent::setUp();
29
+
30
+        $this->request = $this->createMock(IRequest::class);
31
+        $this->session = $this->createMock(ISession::class);
32
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
33
+
34
+        $this->controller = $this->getMockBuilder(AuthPublicShareController::class)
35
+            ->setConstructorArgs([
36
+                'app',
37
+                $this->request,
38
+                $this->session,
39
+                $this->urlGenerator
40
+            ])->onlyMethods([
41
+                'authFailed',
42
+                'getPasswordHash',
43
+                'isAuthenticated',
44
+                'isPasswordProtected',
45
+                'isValidToken',
46
+                'showShare',
47
+                'verifyPassword',
48
+                'validateIdentity',
49
+                'generatePassword'
50
+            ])->getMock();
51
+    }
52
+
53
+    public function testShowAuthenticate(): void {
54
+        $expects = new TemplateResponse('core', 'publicshareauth', [], 'guest');
55
+
56
+        $this->assertEquals($expects, $this->controller->showAuthenticate());
57
+    }
58
+
59
+    public function testAuthenticateAuthenticated(): void {
60
+        $this->controller->method('isAuthenticated')
61
+            ->willReturn(true);
62
+
63
+        $this->controller->setToken('myToken');
64
+
65
+        $this->session->method('get')
66
+            ->willReturnMap([
67
+                ['public_link_authenticate_redirect', json_encode(['foo' => 'bar'])],
68
+            ]);
69
+
70
+        $this->urlGenerator->method('linkToRoute')
71
+            ->willReturn('myLink!');
72
+
73
+        $result = $this->controller->authenticate('password');
74
+        $this->assertInstanceOf(RedirectResponse::class, $result);
75
+        $this->assertSame('myLink!', $result->getRedirectURL());
76
+    }
77
+
78
+    public function testAuthenticateInvalidPassword(): void {
79
+        $this->controller->setToken('token');
80
+        $this->controller->method('isPasswordProtected')
81
+            ->willReturn(true);
82
+
83
+        $this->controller->method('verifyPassword')
84
+            ->with('password')
85
+            ->willReturn(false);
86
+
87
+        $this->controller->expects($this->once())
88
+            ->method('authFailed');
89
+
90
+        $expects = new TemplateResponse('core', 'publicshareauth', ['wrongpw' => true], 'guest');
91
+        $expects->throttle();
92
+
93
+        $result = $this->controller->authenticate('password');
94
+
95
+        $this->assertEquals($expects, $result);
96
+    }
97
+
98
+    public function testAuthenticateValidPassword(): void {
99
+        $this->controller->setToken('token');
100
+        $this->controller->method('isPasswordProtected')
101
+            ->willReturn(true);
102
+        $this->controller->method('verifyPassword')
103
+            ->with('password')
104
+            ->willReturn(true);
105
+        $this->controller->method('getPasswordHash')
106
+            ->willReturn('hash');
107
+
108
+        $this->session->expects($this->once())
109
+            ->method('regenerateId');
110
+        $this->session->method('get')
111
+            ->willReturnMap([
112
+                ['public_link_authenticate_redirect', json_encode(['foo' => 'bar'])],
113
+            ]);
114
+
115
+        $tokenSet = false;
116
+        $hashSet = false;
117
+        $this->session
118
+            ->method('set')
119
+            ->willReturnCallback(function ($key, $value) use (&$tokenSet, &$hashSet) {
120
+                if ($key === 'public_link_authenticated_token' && $value === 'token') {
121
+                    $tokenSet = true;
122
+                    return true;
123
+                }
124
+                if ($key === 'public_link_authenticated_password_hash' && $value === 'hash') {
125
+                    $hashSet = true;
126
+                    return true;
127
+                }
128
+                return false;
129
+            });
130
+
131
+        $this->urlGenerator->method('linkToRoute')
132
+            ->willReturn('myLink!');
133
+
134
+        $result = $this->controller->authenticate('password');
135
+        $this->assertInstanceOf(RedirectResponse::class, $result);
136
+        $this->assertSame('myLink!', $result->getRedirectURL());
137
+        $this->assertTrue($tokenSet);
138
+        $this->assertTrue($hashSet);
139
+    }
140 140
 }
Please login to merge, or discard this patch.
tests/lib/AppFramework/Controller/ControllerTest.php 2 patches
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -17,118 +17,118 @@
 block discarded – undo
17 17
 use OCP\IRequestId;
18 18
 
19 19
 class ChildController extends Controller {
20
-	public function __construct(string $appName, IRequest $request) {
21
-		parent::__construct($appName, $request);
22
-		$this->registerResponder('tom', function ($respone) {
23
-			return 'hi';
24
-		});
25
-	}
26
-
27
-	public function custom($in) {
28
-		$this->registerResponder('json', function ($response) {
29
-			return new JSONResponse([strlen($response)]);
30
-		});
31
-
32
-		return $in;
33
-	}
34
-
35
-	public function customDataResponse(mixed $in): DataResponse {
36
-		$response = new DataResponse($in, 300);
37
-		$response->addHeader('test', 'something');
38
-		return $response;
39
-	}
20
+    public function __construct(string $appName, IRequest $request) {
21
+        parent::__construct($appName, $request);
22
+        $this->registerResponder('tom', function ($respone) {
23
+            return 'hi';
24
+        });
25
+    }
26
+
27
+    public function custom($in) {
28
+        $this->registerResponder('json', function ($response) {
29
+            return new JSONResponse([strlen($response)]);
30
+        });
31
+
32
+        return $in;
33
+    }
34
+
35
+    public function customDataResponse(mixed $in): DataResponse {
36
+        $response = new DataResponse($in, 300);
37
+        $response->addHeader('test', 'something');
38
+        return $response;
39
+    }
40 40
 };
41 41
 
42 42
 class ControllerTest extends \Test\TestCase {
43
-	private Controller $controller;
44
-	private Request $request;
43
+    private Controller $controller;
44
+    private Request $request;
45 45
 
46
-	protected function setUp(): void {
47
-		parent::setUp();
46
+    protected function setUp(): void {
47
+        parent::setUp();
48 48
 
49
-		$request = new Request(
50
-			[
51
-				'get' => ['name' => 'John Q. Public', 'nickname' => 'Joey'],
52
-				'post' => ['name' => 'Jane Doe', 'nickname' => 'Janey'],
53
-				'urlParams' => ['name' => 'Johnny Weissmüller'],
54
-				'files' => ['file' => 'filevalue'],
55
-				'env' => ['PATH' => 'daheim'],
56
-				'session' => ['sezession' => 'kein'],
57
-				'method' => 'hi',
58
-			],
59
-			$this->createMock(IRequestId::class),
60
-			$this->createMock(IConfig::class)
61
-		);
49
+        $request = new Request(
50
+            [
51
+                'get' => ['name' => 'John Q. Public', 'nickname' => 'Joey'],
52
+                'post' => ['name' => 'Jane Doe', 'nickname' => 'Janey'],
53
+                'urlParams' => ['name' => 'Johnny Weissmüller'],
54
+                'files' => ['file' => 'filevalue'],
55
+                'env' => ['PATH' => 'daheim'],
56
+                'session' => ['sezession' => 'kein'],
57
+                'method' => 'hi',
58
+            ],
59
+            $this->createMock(IRequestId::class),
60
+            $this->createMock(IConfig::class)
61
+        );
62 62
 
63
-		$this->controller = new ChildController('apptemplate_advanced', $request);
64
-		$this->overwriteService(IRequest::class, $request);
65
-		$this->request = $request;
66
-	}
63
+        $this->controller = new ChildController('apptemplate_advanced', $request);
64
+        $this->overwriteService(IRequest::class, $request);
65
+        $this->request = $request;
66
+    }
67 67
 
68 68
 
69
-	public function testFormatResonseInvalidFormat(): void {
70
-		$this->expectException(\DomainException::class);
69
+    public function testFormatResonseInvalidFormat(): void {
70
+        $this->expectException(\DomainException::class);
71 71
 
72
-		$this->controller->buildResponse(null, 'test');
73
-	}
72
+        $this->controller->buildResponse(null, 'test');
73
+    }
74 74
 
75 75
 
76
-	public function testFormat(): void {
77
-		$response = $this->controller->buildResponse(['hi'], 'json');
76
+    public function testFormat(): void {
77
+        $response = $this->controller->buildResponse(['hi'], 'json');
78 78
 
79
-		$this->assertEquals(['hi'], $response->getData());
80
-	}
79
+        $this->assertEquals(['hi'], $response->getData());
80
+    }
81 81
 
82 82
 
83
-	public function testFormatDataResponseJSON(): void {
84
-		$expectedHeaders = [
85
-			'test' => 'something',
86
-			'Cache-Control' => 'no-cache, no-store, must-revalidate',
87
-			'Content-Type' => 'application/json; charset=utf-8',
88
-			'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'",
89
-			'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
90
-			'X-Request-Id' => $this->request->getId(),
91
-			'X-Robots-Tag' => 'noindex, nofollow',
92
-		];
83
+    public function testFormatDataResponseJSON(): void {
84
+        $expectedHeaders = [
85
+            'test' => 'something',
86
+            'Cache-Control' => 'no-cache, no-store, must-revalidate',
87
+            'Content-Type' => 'application/json; charset=utf-8',
88
+            'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'",
89
+            'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
90
+            'X-Request-Id' => $this->request->getId(),
91
+            'X-Robots-Tag' => 'noindex, nofollow',
92
+        ];
93 93
 
94
-		$response = $this->controller->customDataResponse(['hi']);
95
-		$response = $this->controller->buildResponse($response, 'json');
94
+        $response = $this->controller->customDataResponse(['hi']);
95
+        $response = $this->controller->buildResponse($response, 'json');
96 96
 
97
-		$this->assertEquals(['hi'], $response->getData());
98
-		$this->assertEquals(300, $response->getStatus());
99
-		$this->assertEquals($expectedHeaders, $response->getHeaders());
100
-	}
97
+        $this->assertEquals(['hi'], $response->getData());
98
+        $this->assertEquals(300, $response->getStatus());
99
+        $this->assertEquals($expectedHeaders, $response->getHeaders());
100
+    }
101 101
 
102 102
 
103
-	public function testCustomFormatter(): void {
104
-		$response = $this->controller->custom('hi');
105
-		$response = $this->controller->buildResponse($response, 'json');
103
+    public function testCustomFormatter(): void {
104
+        $response = $this->controller->custom('hi');
105
+        $response = $this->controller->buildResponse($response, 'json');
106 106
 
107
-		$this->assertEquals([2], $response->getData());
108
-	}
107
+        $this->assertEquals([2], $response->getData());
108
+    }
109 109
 
110 110
 
111
-	public function testDefaultResponderToJSON(): void {
112
-		$responder = $this->controller->getResponderByHTTPHeader('*/*');
111
+    public function testDefaultResponderToJSON(): void {
112
+        $responder = $this->controller->getResponderByHTTPHeader('*/*');
113 113
 
114
-		$this->assertEquals('json', $responder);
115
-	}
114
+        $this->assertEquals('json', $responder);
115
+    }
116 116
 
117 117
 
118
-	public function testResponderAcceptHeaderParsed(): void {
119
-		$responder = $this->controller->getResponderByHTTPHeader(
120
-			'*/*, application/tom, application/json'
121
-		);
118
+    public function testResponderAcceptHeaderParsed(): void {
119
+        $responder = $this->controller->getResponderByHTTPHeader(
120
+            '*/*, application/tom, application/json'
121
+        );
122 122
 
123
-		$this->assertEquals('tom', $responder);
124
-	}
123
+        $this->assertEquals('tom', $responder);
124
+    }
125 125
 
126 126
 
127
-	public function testResponderAcceptHeaderParsedUpperCase(): void {
128
-		$responder = $this->controller->getResponderByHTTPHeader(
129
-			'*/*, apPlication/ToM, application/json'
130
-		);
127
+    public function testResponderAcceptHeaderParsedUpperCase(): void {
128
+        $responder = $this->controller->getResponderByHTTPHeader(
129
+            '*/*, apPlication/ToM, application/json'
130
+        );
131 131
 
132
-		$this->assertEquals('tom', $responder);
133
-	}
132
+        $this->assertEquals('tom', $responder);
133
+    }
134 134
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@
 block discarded – undo
19 19
 class ChildController extends Controller {
20 20
 	public function __construct(string $appName, IRequest $request) {
21 21
 		parent::__construct($appName, $request);
22
-		$this->registerResponder('tom', function ($respone) {
22
+		$this->registerResponder('tom', function($respone) {
23 23
 			return 'hi';
24 24
 		});
25 25
 	}
26 26
 
27 27
 	public function custom($in) {
28
-		$this->registerResponder('json', function ($response) {
28
+		$this->registerResponder('json', function($response) {
29 29
 			return new JSONResponse([strlen($response)]);
30 30
 		});
31 31
 
Please login to merge, or discard this patch.