Commit 64ad4081 authored by catch's avatar catch

Issue #2575245 by toniteof: Click-sorting broken in previews

parent 43ea3d9f
......@@ -397,6 +397,12 @@ function template_preprocess_views_view_table(&$variables) {
// A boolean variable which stores whether the table has a responsive class.
$responsive = FALSE;
// For the actual site we want to not render full URLs, because this would
// make pagers cacheable per URL, which is problematic in blocks, for example.
// For the actual live preview though the javascript relies on properly
// working URLs.
$route_name = !empty($view->live_preview) ? '<current>' : '<none>';
$query = tablesort_get_query_parameters();
if (isset($view->exposed_raw_input)) {
$query += $view->exposed_raw_input;
......@@ -438,9 +444,7 @@ function template_preprocess_views_view_table(&$variables) {
$link_options = array(
'query' => $query,
);
// It is ok to specify no URL path here as we will always reload the
// current page.
$url = new Url('<none>', [], $link_options);
$url = new Url($route_name, [], $link_options);
$variables['header'][$field]['url'] = $url->toString();
$variables['header'][$field]['content'] = $label;
$variables['header'][$field]['title'] = $title;
......
......@@ -21,7 +21,7 @@ class PreviewTest extends UITestBase {
*
* @var array
*/
public static $testViews = array('test_preview', 'test_preview_error', 'test_pager_full', 'test_mini_pager');
public static $testViews = array('test_preview', 'test_preview_error', 'test_pager_full', 'test_mini_pager', 'test_click_sort');
/**
* Tests contextual links in the preview form.
......@@ -270,6 +270,32 @@ public function testPreviewError() {
$this->assertText('Unable to preview due to validation errors.', 'Preview error text found.');
}
/**
* Tests the link to sort in the preview form.
*/
public function testPreviewSortLink() {
// Get the preview.
$this->getPreviewAJAX('test_click_sort', 'page_1', 0);
// Test that the header label is present.
$elements = $this->xpath('//th[contains(@class, :class)]/a', array(':class' => 'views-field views-field-name'));
$this->assertTrue(!empty($elements), 'The header label is present.');
// Verify link.
$this->assertLinkByHref('preview/page_1?_wrapper_format=drupal_ajax&order=name&sort=desc', 0, 'The output URL is as expected.');
// Click link to sort.
$this->clickPreviewLinkAJAX($elements[0]['href'], 0);
// Test that the header label is present.
$elements = $this->xpath('//th[contains(@class, :class)]/a', array(':class' => 'views-field views-field-name is-active'));
$this->assertTrue(!empty($elements), 'The header label is present.');
// Verify link.
$this->assertLinkByHref('preview/page_1?_wrapper_format=drupal_ajax&order=name&sort=asc', 0, 'The output URL is as expected.');
}
/**
* Get the preview form and force an AJAX preview update.
*
......
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