@@ -64,16 +64,19 @@ public function testIsLoggedInTrueWhenSessionDataSet() {
6464 self ::assertTrue ($ sut ->isLoggedIn ());
6565 }
6666
67- // TODO: Session shouldn't be cleared on call to logout - instead it should
68- // redirect to the provider, and a new test should asset the response data
69- // contains a logout confirmation.
70- public function TODO_UPDATE_testLogoutClearsSession () {
67+ public function testLogoutCallsLogoutUri () {
7168 $ sessionData = self ::createMock (SessionData::class);
7269 $ _SESSION = [
7370 Authenticator::SESSION_KEY => $ sessionData
7471 ];
7572
7673 $ redirectHandler = self ::createMock (RedirectHandler::class);
74+ $ redirectHandler ->expects (self ::once ())
75+ ->method ("redirect " )
76+ ->with (self ::callback (fn (UriInterface $ uri ) =>
77+ $ uri ->getHost () === "login.authwave.com "
78+ && $ uri ->getPath () === "/logout "
79+ ));
7780
7881 $ sut = new Authenticator (
7982 "test-key " ,
@@ -83,6 +86,44 @@ public function TODO_UPDATE_testLogoutClearsSession() {
8386 $ redirectHandler
8487 );
8588 $ sut ->logout ();
89+ self ::assertNotEmpty ($ _SESSION );
90+ }
91+
92+ public function testCompleteAuthFromLogoutClearsSession () {
93+ $ token = self ::createMock (Token::class);
94+
95+ $ sessionData = self ::createMock (SessionData::class);
96+ $ sessionData ->method ("getToken " )
97+ ->willReturn ($ token );
98+
99+ $ _SESSION = [
100+ Authenticator::SESSION_KEY => $ sessionData ,
101+ ];
102+
103+ $ responseCipher = "abcdef " ;
104+
105+ $ currentUri = "/example-page- " . uniqid ();
106+ $ currentUri .= "? " ;
107+ $ currentUri .= http_build_query ([
108+ Authenticator::RESPONSE_QUERY_PARAMETER => $ responseCipher ,
109+ ]);
110+
111+ $ redirectHandler = self ::createMock (RedirectHandler::class);
112+ $ redirectHandler ->expects (self ::once ())
113+ ->method ("redirect " )
114+ ->with (self ::callback (fn (UriInterface $ uri ) =>
115+ $ uri ->getHost () == ""
116+ && $ uri ->getPath () == $ currentUri
117+ ));
118+
119+ new Authenticator (
120+ "test-key " ,
121+ "/ " ,
122+ LoginUri::DEFAULT_BASE_REMOTE_URI ,
123+ null ,
124+ $ redirectHandler
125+ );
126+
86127 self ::assertEmpty ($ _SESSION );
87128 }
88129
0 commit comments