Loading core/modules/views/src/Controller/ViewAjaxController.php +4 −2 Original line number Diff line number Diff line Loading @@ -142,7 +142,7 @@ public function ajaxView(Request $request) { $used_query_parameters = $request_clone->query->all(); $query = UrlHelper::buildQuery($used_query_parameters); if ($query != '') { if ($query != '' && $target_url) { $origin_destination .= '?' . $query; $target_url->setOption('query', $used_query_parameters); } Loading @@ -168,7 +168,9 @@ public function ajaxView(Request $request) { } $preview = $view->preview($display_id, $args); $request->attributes->remove('ajax_page_state'); if ($target_url) { $response->addCommand(new SetBrowserUrl($target_url->toString())); } $response->addCommand(new ReplaceCommand(".js-view-dom-id-$dom_id", $preview)); $response->addCommand(new PrependCommand(".js-view-dom-id-$dom_id", ['#type' => 'status_messages'])); $request->query->set('ajax_page_state', $existing_page_state); Loading core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php +44 −2 Original line number Diff line number Diff line Loading @@ -115,8 +115,13 @@ protected function setUp(): void { * Use a callback because container is not initialized yet * so we can't generate a URL object right now. */ ->willReturnCallback(function () { ->willReturnCallback(function ($path) { if ($path === '/invalid-test-page') { return FALSE; } else { return Url::fromUserInput('/foo'); } }); $unroutedUrlAssembler = $this->createMock(UnroutedUrlAssemblerInterface::class); $unroutedUrlAssembler->expects($this->any()) Loading Loading @@ -251,6 +256,43 @@ public function testAjaxView(): void { ], $response->getAttachments()); } /** * Tests a valid view without arguments pagers etc. */ public function testInvalidPath(): void { $request = new Request(); $request->query->set('view_name', 'test_view'); $request->query->set('view_display_id', 'page_1'); $request->query->set('view_path', '/invalid-test-page'); $request->query->set('_wrapper_format', 'ajax'); $request->query->set('ajax_page_state', 'drupal.settings[]'); $request->query->set('type', 'article'); $executable = $this->setupValidMocks(); $this->redirectDestination->expects($this->atLeastOnce()) ->method('set') ->with('/invalid-test-page'); $this->currentPath->expects($this->once()) ->method('setPath') ->with('/invalid-test-page', $request); $response = $this->viewAjaxController->ajaxView($request); $this->assertTrue($response instanceof ViewAjaxResponse); $this->assertSame($response->getView(), $executable); $this->assertViewResultCommand($response, 0); // Test that the ajax controller for Views contains the // Drupal Settings. $this->assertEquals([ 'drupalSettings' => [ 'testSetting' => ['Setting'], ], ], $response->getAttachments()); } /** * Tests a valid view with a view_path with no slash. */ Loading Loading
core/modules/views/src/Controller/ViewAjaxController.php +4 −2 Original line number Diff line number Diff line Loading @@ -142,7 +142,7 @@ public function ajaxView(Request $request) { $used_query_parameters = $request_clone->query->all(); $query = UrlHelper::buildQuery($used_query_parameters); if ($query != '') { if ($query != '' && $target_url) { $origin_destination .= '?' . $query; $target_url->setOption('query', $used_query_parameters); } Loading @@ -168,7 +168,9 @@ public function ajaxView(Request $request) { } $preview = $view->preview($display_id, $args); $request->attributes->remove('ajax_page_state'); if ($target_url) { $response->addCommand(new SetBrowserUrl($target_url->toString())); } $response->addCommand(new ReplaceCommand(".js-view-dom-id-$dom_id", $preview)); $response->addCommand(new PrependCommand(".js-view-dom-id-$dom_id", ['#type' => 'status_messages'])); $request->query->set('ajax_page_state', $existing_page_state); Loading
core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php +44 −2 Original line number Diff line number Diff line Loading @@ -115,8 +115,13 @@ protected function setUp(): void { * Use a callback because container is not initialized yet * so we can't generate a URL object right now. */ ->willReturnCallback(function () { ->willReturnCallback(function ($path) { if ($path === '/invalid-test-page') { return FALSE; } else { return Url::fromUserInput('/foo'); } }); $unroutedUrlAssembler = $this->createMock(UnroutedUrlAssemblerInterface::class); $unroutedUrlAssembler->expects($this->any()) Loading Loading @@ -251,6 +256,43 @@ public function testAjaxView(): void { ], $response->getAttachments()); } /** * Tests a valid view without arguments pagers etc. */ public function testInvalidPath(): void { $request = new Request(); $request->query->set('view_name', 'test_view'); $request->query->set('view_display_id', 'page_1'); $request->query->set('view_path', '/invalid-test-page'); $request->query->set('_wrapper_format', 'ajax'); $request->query->set('ajax_page_state', 'drupal.settings[]'); $request->query->set('type', 'article'); $executable = $this->setupValidMocks(); $this->redirectDestination->expects($this->atLeastOnce()) ->method('set') ->with('/invalid-test-page'); $this->currentPath->expects($this->once()) ->method('setPath') ->with('/invalid-test-page', $request); $response = $this->viewAjaxController->ajaxView($request); $this->assertTrue($response instanceof ViewAjaxResponse); $this->assertSame($response->getView(), $executable); $this->assertViewResultCommand($response, 0); // Test that the ajax controller for Views contains the // Drupal Settings. $this->assertEquals([ 'drupalSettings' => [ 'testSetting' => ['Setting'], ], ], $response->getAttachments()); } /** * Tests a valid view with a view_path with no slash. */ Loading