Skip to content

Commit 59d8f23

Browse files
committed
Change ServerController and BaseServerConfig unit test code to be cleaner.
1 parent 3ea77d6 commit 59d8f23

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

solid/tests/Unit/BaseServerConfigTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace OCA\Solid;
44

55
use OCA\Solid\AppInfo\Application;
6-
use OCA\Solid\BaseServerConfig;
76
use OCP\IConfig;
87
use PHPUnit\Framework\TestCase;
98
use TypeError;
@@ -20,13 +19,15 @@ function random_bytes()
2019
*/
2120
class BaseServerConfigTest extends TestCase
2221
{
23-
/////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
22+
////////////////////////////////// FIXTURES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
2423

2524
public const MOCK_RANDOM_BYTES = 'mock random bytes';
26-
const MOCK_REDIRECT_URI = 'mock redirect uri';
25+
private const MOCK_REDIRECT_URI = 'mock redirect uri';
2726
private const MOCK_CLIENT_ID = 'mock-client-id';
2827
private const MOCK_ORIGIN = 'mock origin';
2928

29+
/////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
30+
3031
/**
3132
* @testdox BaseServerConfig should complain when called before given a Configuration
3233
* @covers ::__construct

solid/tests/Unit/Controller/ServerControllerTest.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function testAuthorizeWithoutUser()
113113

114114
$controller = new ServerController(...$parameters);
115115

116-
$expected = new JSONResponse('Authorization required', 401);
116+
$expected = new JSONResponse('Authorization required', Http::STATUS_UNAUTHORIZED);
117117
$actual = $controller->authorize();
118118

119119
$this->assertEquals($expected, $actual);
@@ -135,7 +135,7 @@ public function testAuthorizeWithoutValidToken()
135135
$controller = new ServerController(...$parameters);
136136

137137
$actual = $controller->authorize();
138-
$expected = new JSONResponse('Bad request, does not contain valid token', 400);
138+
$expected = new JSONResponse('Bad request, does not contain valid token', Http::STATUS_BAD_REQUEST);
139139

140140
$this->assertEquals($expected, $actual);
141141
}
@@ -164,7 +164,7 @@ public function testAuthorizeWithoutApprovedClient()
164164
$controller = new ServerController(...$parameters);
165165

166166
$actual = $controller->authorize();
167-
$expected = new JSONResponse('Approval required', 302, ['Location' => '']);
167+
$expected = new JSONResponse('Approval required', Http::STATUS_FOUND, ['Location' => '']);
168168

169169
$this->assertEquals($expected, $actual);
170170
}
@@ -203,25 +203,24 @@ public function testAuthorizeWithApprovedClient()
203203
'headers' => [
204204
'Cache-Control' => 'no-cache, no-store, must-revalidate',
205205
'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'",
206+
'Content-Type' => 'application/json; charset=utf-8',
206207
'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
207208
'X-Robots-Tag' => 'noindex, nofollow',
208-
'Content-Type' => 'application/json; charset=utf-8',
209-
210209
],
211-
'status' => 302,
210+
'status' => Http::STATUS_FOUND,
212211
];
213212

214-
$headers = $response->getHeaders();
215-
$location = $headers['Location'];
216-
// Not comparing time-sensitive data
217-
unset($headers['X-Request-Id'], $headers['Location']);
218-
219213
$actual = [
220214
'data' => $response->getData(),
221-
'headers' => $headers,
215+
'headers' => $response->getHeaders(),
222216
'status' => $response->getStatus(),
223217
];
224218

219+
$location = $actual['headers']['Location'];
220+
221+
// Not comparing time-sensitive data
222+
unset($actual['headers']['X-Request-Id'], $actual['headers']['Location']);
223+
225224
$this->assertEquals($expected, $actual);
226225

227226
// @TODO: Move $location assert to a separate test
@@ -236,8 +235,8 @@ public function testAuthorizeWithApprovedClient()
236235
'host' => 'mock.client',
237236
'path' => '/redirect',
238237
'fragment' => [
239-
'token_type'=>'Bearer',
240-
'expires_in'=>'3600',
238+
'token_type' => 'Bearer',
239+
'expires_in' => '3600',
241240
],
242241
], $url);
243242
}

0 commit comments

Comments
 (0)