@@ -153,6 +153,22 @@ protected function setUp(): void {
153153 $ login ->save ();
154154 $ this ->ids ['login ' ] = 'menu_link_content: ' . $ login ->uuid ();
155155
156+ $ query = MenuLinkContent::create ([
157+ 'title ' => 'With Query ' ,
158+ 'menu_name ' => 'main ' ,
159+ 'link ' => [
160+ 'uri ' => 'internal:/about-us ' ,
161+ 'options ' => [
162+ 'query ' => [
163+ 'utm ' => '1 ' ,
164+ ],
165+ 'fragment ' => 'frag ' ,
166+ ],
167+ ],
168+ ]);
169+ $ query ->save ();
170+ $ this ->ids ['query ' ] = 'menu_link_content: ' . $ query ->uuid ();
171+
156172 $ this ->config ('jsonapi_frontend.settings ' )
157173 ->set ('drupal_base_url ' , 'https://cms.example.com ' )
158174 ->save ();
@@ -272,6 +288,67 @@ public function testResolveCanBeDisabled(): void {
272288 $ this ->assertNull ($ about ['resolve ' ]);
273289 }
274290
291+ public function testMenuQueryDepthAndParentOptionsAreHandled (): void {
292+ $ this ->config ('jsonapi_frontend.settings ' )
293+ ->set ('resolver.cache_max_age ' , 60 )
294+ ->set ('resolver.langcode_fallback ' , 'current ' )
295+ ->save ();
296+
297+ $ this ->container ->get ('current_user ' )->setAccount (new AnonymousUserSession ());
298+
299+ $ controller = \Drupal \jsonapi_frontend_menu \Controller \MenuController::create ($ this ->container );
300+ $ request = Request::create ('/jsonapi/menu/main ' , 'GET ' , [
301+ '_format ' => 'json ' ,
302+ 'path ' => 'https://www.example.com/about-us/team?utm=1#frag ' ,
303+ 'min_depth ' => '2 ' ,
304+ 'max_depth ' => '3 ' ,
305+ 'parent ' => $ this ->ids ['about ' ],
306+ ]);
307+
308+ $ response = $ controller ->menu ($ request , 'main ' );
309+ $ this ->assertSame (200 , $ response ->getStatusCode ());
310+ $ this ->assertStringContainsString ('public ' , (string ) $ response ->headers ->get ('Cache-Control ' ));
311+
312+ $ payload = json_decode ((string ) $ response ->getContent (), TRUE );
313+ $ this ->assertIsArray ($ payload );
314+ $ this ->assertSame ([$ this ->ids ['about ' ], $ this ->ids ['team ' ]], $ payload ['meta ' ]['active_trail ' ]);
315+
316+ $ team = $ this ->findItemById ($ payload ['data ' ], $ this ->ids ['team ' ]);
317+ $ this ->assertNotNull ($ team );
318+ }
319+
320+ public function testAuthenticatedUserDisablesCaching (): void {
321+ $ this ->config ('jsonapi_frontend.settings ' )
322+ ->set ('resolver.cache_max_age ' , 60 )
323+ ->save ();
324+
325+ $ controller = \Drupal \jsonapi_frontend_menu \Controller \MenuController::create ($ this ->container );
326+ $ request = Request::create ('/jsonapi/menu/main ' , 'GET ' , [
327+ '_format ' => 'json ' ,
328+ ]);
329+
330+ $ response = $ controller ->menu ($ request , 'main ' );
331+ $ this ->assertSame (200 , $ response ->getStatusCode ());
332+ $ this ->assertStringContainsString ('no-store ' , (string ) $ response ->headers ->get ('Cache-Control ' ));
333+ }
334+
335+ public function testInternalUrlsAreNormalizedForResolve (): void {
336+ $ this ->container ->get ('current_user ' )->setAccount (new AnonymousUserSession ());
337+
338+ $ controller = \Drupal \jsonapi_frontend_menu \Controller \MenuController::create ($ this ->container );
339+ $ request = Request::create ('/jsonapi/menu/main ' , 'GET ' , [
340+ '_format ' => 'json ' ,
341+ ]);
342+
343+ $ response = $ controller ->menu ($ request , 'main ' );
344+ $ payload = json_decode ((string ) $ response ->getContent (), TRUE );
345+
346+ $ query = $ this ->findItemById ($ payload ['data ' ], $ this ->ids ['query ' ]);
347+ $ this ->assertNotNull ($ query );
348+ $ this ->assertSame ('/about-us?utm=1 ' , $ query ['url ' ]);
349+ $ this ->assertTrue ($ query ['resolve ' ]['resolved ' ]);
350+ }
351+
275352 /**
276353 * Find an item by id in a nested menu tree.
277354 *
0 commit comments