1111use PHPUnit \Framework \TestCase ;
1212use SimpleSAML \Error \BadRequest ;
1313use SimpleSAML \Module \oidc \Bridges \PsrHttpBridge ;
14- use SimpleSAML \Module \oidc \Bridges \SspBridge ;
1514use SimpleSAML \Module \oidc \Controllers \EndSessionController ;
1615use SimpleSAML \Module \oidc \Factories \TemplateFactory ;
1716use SimpleSAML \Module \oidc \Server \AuthorizationServer ;
2524use SimpleSAML \OpenID \Codebooks \ClaimsEnum ;
2625use SimpleSAML \OpenID \Core \IdToken ;
2726use SimpleSAML \Session ;
27+ use SimpleSAML \XHTML \Template ;
2828use Symfony \Component \HttpFoundation \RedirectResponse ;
2929use Symfony \Component \HttpFoundation \Response ;
3030
@@ -51,9 +51,6 @@ class EndSessionControllerTest extends TestCase
5151 protected MockObject $ psrHttpBridgeMock ;
5252 protected MockObject $ errorResponderMock ;
5353 protected Stub $ uiLocalesResolverStub ;
54- protected MockObject $ sspBridgeMock ;
55- protected MockObject $ sspBridgeLocaleMock ;
56- protected MockObject $ sspBridgeLocaleLanguageMock ;
5754
5855 /**
5956 * @throws \PHPUnit\Framework\MockObject\Exception
@@ -76,25 +73,19 @@ public function setUp(): void
7673 $ this ->errorResponderMock = $ this ->createMock (ErrorResponder::class);
7774
7875 $ this ->uiLocalesResolverStub = $ this ->createStub (UiLocalesResolver::class);
79- $ this ->sspBridgeMock = $ this ->createMock (SspBridge::class);
80- $ this ->sspBridgeLocaleMock = $ this ->createMock (SspBridge \Locale::class);
81- $ this ->sspBridgeLocaleLanguageMock = $ this ->createMock (SspBridge \Locale \Language::class);
82- $ this ->sspBridgeMock ->method ('locale ' )->willReturn ($ this ->sspBridgeLocaleMock );
83- $ this ->sspBridgeLocaleMock ->method ('language ' )->willReturn ($ this ->sspBridgeLocaleLanguageMock );
8476 }
8577
86- protected function mock (): EndSessionController
78+ protected function mock (? TemplateFactory $ templateFactory = null ): EndSessionController
8779 {
8880 return new EndSessionController (
8981 $ this ->authorizationServerStub ,
9082 $ this ->sessionServiceStub ,
9183 $ this ->sessionLogoutTicketStoreBuilderStub ,
9284 $ this ->loggerServiceMock ,
93- $ this ->templateFactoryStub ,
85+ $ templateFactory ?? $ this ->templateFactoryStub ,
9486 $ this ->psrHttpBridgeMock ,
9587 $ this ->errorResponderMock ,
9688 $ this ->uiLocalesResolverStub ,
97- $ this ->sspBridgeMock ,
9889 );
9990 }
10091
@@ -232,37 +223,65 @@ public function testLogoutHandler(): never
232223 * @throws \SimpleSAML\Error\BadRequest
233224 * @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
234225 */
235- public function testSetsUiLanguageBasedOnUiLocales (): void
226+ public function testRendersLogoutPageInResolvedUiLanguage (): void
236227 {
237228 $ this ->currentSessionMock ->method ('getAuthorities ' )->willReturn ([]);
238229 $ this ->sessionServiceStub ->method ('getCurrentSession ' )->willReturn ($ this ->currentSessionMock );
239230 $ this ->logoutRequestStub ->method ('getUiLocales ' )->willReturn ('hr en ' );
240231 $ this ->authorizationServerStub ->method ('validateLogoutRequest ' )->willReturn ($ this ->logoutRequestStub );
241232 $ this ->uiLocalesResolverStub ->method ('resolve ' )->willReturn ('hr ' );
242233
243- $ this ->sspBridgeLocaleLanguageMock ->expects ($ this ->once ())
244- ->method ('setLanguageCookie ' )
245- ->with ('hr ' );
246-
247- $ this ->mock ()->__invoke ($ this ->serverRequestStub );
234+ $ this ->assertSame ('hr ' , $ this ->captureRenderedTemplateLanguage ());
248235 }
249236
250237 /**
251238 * @throws \Throwable
252239 * @throws \SimpleSAML\Error\BadRequest
253240 * @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
254241 */
255- public function testDoesNotSetUiLanguageWhenNoRequestedLanguageIsAvailable (): void
242+ public function testRendersLogoutPageWithoutLanguageWhenNoneResolved (): void
256243 {
257244 $ this ->currentSessionMock ->method ('getAuthorities ' )->willReturn ([]);
258245 $ this ->sessionServiceStub ->method ('getCurrentSession ' )->willReturn ($ this ->currentSessionMock );
259246 $ this ->logoutRequestStub ->method ('getUiLocales ' )->willReturn ('de ' );
260247 $ this ->authorizationServerStub ->method ('validateLogoutRequest ' )->willReturn ($ this ->logoutRequestStub );
261248 $ this ->uiLocalesResolverStub ->method ('resolve ' )->willReturn (null );
262249
263- $ this ->sspBridgeLocaleLanguageMock -> expects ($ this ->never ())
264- -> method ( ' setLanguageCookie ' );
250+ $ this ->assertNull ($ this ->captureRenderedTemplateLanguage ());
251+ }
265252
266- $ this ->mock ()->__invoke ($ this ->serverRequestStub );
253+ /**
254+ * Invoke the controller with a TemplateFactory mock and return the language passed to the rendered
255+ * logout template.
256+ *
257+ * @throws \Throwable
258+ * @throws \SimpleSAML\Error\BadRequest
259+ * @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
260+ */
261+ private function captureRenderedTemplateLanguage (): ?string
262+ {
263+ $ templateStub = $ this ->createStub (Template::class);
264+ $ capturedLanguage = null ;
265+
266+ $ templateFactoryMock = $ this ->createMock (TemplateFactory::class);
267+ $ templateFactoryMock ->method ('build ' )->willReturnCallback (
268+ function (
269+ string $ templateName ,
270+ array $ data = [],
271+ ?string $ activeHrefPath = null ,
272+ ?bool $ includeDefaultMenuItems = null ,
273+ ?bool $ showMenu = null ,
274+ ?bool $ showModuleName = null ,
275+ ?bool $ showSubPageTitle = null ,
276+ ?string $ language = null ,
277+ ) use (&$ capturedLanguage , $ templateStub ): Template {
278+ $ capturedLanguage = $ language ;
279+ return $ templateStub ;
280+ },
281+ );
282+
283+ $ this ->mock ($ templateFactoryMock )->__invoke ($ this ->serverRequestStub );
284+
285+ return $ capturedLanguage ;
267286 }
268287}
0 commit comments