File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 33
44use OCA \Solid \DpopFactoryTrait ;
55use OCA \Solid \ServerConfig ;
6+ use OCA \Solid \Service \UserService ;
67
78use OCP \AppFramework \Controller ;
89use OCP \AppFramework \Http ;
@@ -47,6 +48,8 @@ class ServerController extends Controller
4748 /* @var \Pdsinterop\Solid\Auth\TokenGenerator */
4849 private $ tokenGenerator ;
4950
51+ private UserService $ userService ;
52+
5053 public function __construct (
5154 $ AppName ,
5255 IRequest $ request ,
@@ -55,7 +58,7 @@ public function __construct(
5558 IURLGenerator $ urlGenerator ,
5659 $ userId ,
5760 IConfig $ config ,
58- \OCA \Solid \Service \UserService $ UserService ,
61+ \OCA \Solid \Service \UserService $ userService ,
5962 IDBConnection $ connection ,
6063 ) {
6164 parent ::__construct ($ AppName , $ request );
@@ -66,6 +69,7 @@ public function __construct(
6669 $ this ->request = $ request ;
6770 $ this ->urlGenerator = $ urlGenerator ;
6871 $ this ->session = $ session ;
72+ $ this ->userService = $ userService ;
6973
7074 $ this ->setJtiStorage ($ connection );
7175
Original file line number Diff line number Diff line change @@ -421,6 +421,45 @@ public function testToken()
421421 $ this ->assertEquals ($ expected , $ actual );
422422 }
423423
424+ /**
425+ * @testdox ServerController should return an OK when asked to logout
426+ *
427+ * @covers ::logout
428+ */
429+ public function testLogout () {
430+ $ parameters = $ this ->createMockConstructorParameters ();
431+
432+ $ controller = new ServerController (...array_values ($ parameters ));
433+
434+ $ actual = $ controller ->logout ();
435+ $ expected = new JSONResponse ('ok ' , Http::STATUS_OK );
436+
437+ $ this ->assertEquals ($ expected , $ actual );
438+ }
439+
440+ /**
441+ * @testdox ServerController should complain when asked to logout and the logout fails
442+ *
443+ * @covers ::logout
444+ */
445+ public function testLogoutError () {
446+ $ parameters = $ this ->createMockConstructorParameters ();
447+
448+ $ mockError = 'Mock logout error ' ;
449+ $ expectedException = new \Exception ($ mockError );
450+ $ parameters ['MockUserService ' ]
451+ ->method ('logout ' )
452+ ->willThrowException ($ expectedException )
453+ ;
454+
455+ $ controller = new ServerController (...array_values ($ parameters ));
456+
457+ $ this ->expectException ($ expectedException ::class);
458+ $ this ->expectExceptionMessage ($ mockError );
459+
460+ $ controller ->logout ();
461+ }
462+
424463 ////////////////////////////// MOCKS AND STUBS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
425464
426465 public function createMockConfig ($ clientData ): IConfig |MockObject
You can’t perform that action at this time.
0 commit comments