Unverified Commit 48726e69 authored by alexpott's avatar alexpott

Issue #2798947 by Lendude, loopduplicate, rocketeerbkw, netdreamer, LoMo,...

Issue #2798947 by Lendude, loopduplicate, rocketeerbkw, netdreamer, LoMo, Kristen Pol, rwam, Berdir, dawehner: Views pagers include ajax metadata
parent e8179281
......@@ -132,7 +132,20 @@ public function ajaxView(Request $request) {
// Remove all of this stuff from the query of the request so it doesn't
// end up in pagers and tablesort URLs.
foreach (['view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER] as $key) {
// @todo Remove this parsing once these are removed from the request in
// https://www.drupal.org/node/2504709.
foreach ([
'view_name',
'view_display_id',
'view_args',
'view_path',
'view_dom_id',
'pager_element',
'view_base_path',
AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER,
FormBuilderInterface::AJAX_FORM_REQUEST,
MainContentViewSubscriber::WRAPPER_FORMAT,
] as $key) {
$request->query->remove($key);
$request->request->remove($key);
}
......@@ -152,6 +165,7 @@ public function ajaxView(Request $request) {
// Add all POST data, because AJAX is always a post and many things,
// such as tablesorts, exposed filters and paging assume GET.
$request_all = $request->request->all();
unset($request_all['ajax_page_state']);
$query_all = $request->query->all();
$request->query->replace($request_all + $query_all);
......@@ -159,13 +173,7 @@ public function ajaxView(Request $request) {
// @see the redirect.destination service.
$origin_destination = $path;
// Remove some special parameters you never want to have part of the
// destination query.
$used_query_parameters = $request->query->all();
// @todo Remove this parsing once these are removed from the request in
// https://www.drupal.org/node/2504709.
unset($used_query_parameters[FormBuilderInterface::AJAX_FORM_REQUEST], $used_query_parameters[MainContentViewSubscriber::WRAPPER_FORMAT], $used_query_parameters['ajax_page_state']);
$query = UrlHelper::buildQuery($used_query_parameters);
if ($query != '') {
$origin_destination .= '?' . $query;
......
......@@ -86,6 +86,10 @@ public function testBasicPagination() {
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertContains('Node 6 content', $rows[0]->getHtml());
$link = $page->findLink('Go to page 3');
// Test that no unwanted parameters are added to the URL.
$this->assertEquals('?status=All&type=All&langcode=All&items_per_page=5&order=changed&sort=asc&title=&page=2', $link->getAttribute('href'));
$this->assertNoDuplicateAssetsOnPage();
$this->clickLink('Go to page 3');
$session_assert->assertWaitOnAjaxRequest();
......@@ -115,4 +119,17 @@ public function testBasicPagination() {
$this->assertContains('Node 11 content', $rows[0]->getHtml());
}
/**
* Assert that assets are not loaded twice on a page.
*/
protected function assertNoDuplicateAssetsOnPage() {
/** @var \Behat\Mink\Element\NodeElement[] $scripts */
$scripts = $this->getSession()->getPage()->findAll('xpath', '//script');
$script_src = [];
foreach ($scripts as $script) {
$this->assertFalse(in_array($script->getAttribute('src'), $script_src));
$script_src[] = $script->getAttribute('src');
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment