Commit 2be29106 authored by alexpott's avatar alexpott

Issue #2782221 by Grimreaper, dawehner, Lendude, alexpott: Result summary Area...

Issue #2782221 by Grimreaper, dawehner, Lendude, alexpott: Result summary Area plugin not displayed when there is no result
parent 347e3b1c
......@@ -83,9 +83,13 @@ public function render($empty = FALSE) {
// Not every view has total_rows set, use view->result instead.
$total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result);
$label = Html::escape($this->view->storage->label());
// If there is no result the "start" and "current_record_count" should be
// equal to 0. To have the same calculation logic, we use a "start offset"
// to handle all the cases.
$start_offset = empty($total) ? 0 : 1;
if ($per_page === 0) {
$page_count = 1;
$start = 1;
$start = $start_offset;
$end = $total;
}
else {
......@@ -94,10 +98,10 @@ public function render($empty = FALSE) {
if ($total_count > $total) {
$total_count = $total;
}
$start = ($current_page - 1) * $per_page + 1;
$start = ($current_page - 1) * $per_page + $start_offset;
$end = $total_count;
}
$current_record_count = ($end - $start) + 1;
$current_record_count = ($end - $start) + $start_offset;
// Get the search information.
$replacements = [];
$replacements['@start'] = $start;
......@@ -109,7 +113,7 @@ public function render($empty = FALSE) {
$replacements['@current_record_count'] = $current_record_count;
$replacements['@page_count'] = $page_count;
// Send the output.
if (!empty($total)) {
if (!empty($total) || !empty($this->options['empty'])) {
$output .= Xss::filterAdmin(str_replace(array_keys($replacements), array_values($replacements), $format));
}
// Return as render array.
......
langcode: en
status: true
dependencies: { }
id: test_area_result
label: ''
module: views
description: ''
tag: ''
base_table: views_test_data
base_field: nid
core: '8'
display:
default:
display_options:
defaults:
fields: false
pager: false
sorts: false
fields:
id:
field: id
id: id
relationship: none
table: views_test_data
plugin_id: numeric
pager:
options:
offset: 0
type: none
sorts:
id:
field: id
id: id
order: ASC
relationship: none
table: views_test_data
plugin_id: numeric
empty:
title:
field: title
id: title
table: views
plugin_id: title
title: test_title_empty
header:
result:
id: result
table: views
field: result
relationship: none
group_type: group
admin_label: ''
empty: true
content: "start: @start | end: @end | total: @total | label: @label | per page: @per_page | current page: @current_page | current record count: @current_record_count | page count: @page_count"
plugin_id: result
display_plugin: default
display_title: Master
id: default
position: 0
page_1:
display_options:
path: test-area-result
defaults:
header: false
header:
result:
id: result
table: views
field: result
relationship: none
group_type: group
admin_label: ''
empty: false
content: "start: @start | end: @end | total: @total | label: @label | per page: @per_page | current page: @current_page | current record count: @current_record_count | page count: @page_count"
plugin_id: result
display_plugin: page
display_title: 'Page 1'
id: page_1
position: 1
<?php
namespace Drupal\Tests\views\Kernel\Handler;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
/**
* Tests the result area handler.
*
* @group views
* @see \Drupal\views\Plugin\views\area\Result
*/
class AreaResultTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
public static $testViews = ['test_area_result'];
/**
* Tests the results area handler.
*/
public function testResult() {
$view = Views::getView('test_area_result');
$view->setDisplay('default');
$this->executeView($view);
$output = $view->render();
$output = \Drupal::service('renderer')->renderRoot($output);
$this->setRawContent($output);
$this->assertText('start: 1 | end: 5 | total: 5 | label: test_area_result | per page: 0 | current page: 1 | current record count: 5 | page count: 1');
}
/**
* Tests the results area handler.
*/
public function testResultEmpty() {
$view = Views::getView('test_area_result');
// Test that the area is displayed if we have checked the empty checkbox.
$view->setDisplay('default');
// Add a filter that will make the result set empty.
$view->displayHandlers->get('default')->overrideOption('filters', [
'name' => [
'id' => 'name',
'table' => 'views_test_data',
'field' => 'name',
'relationship' => 'none',
'operator' => '=',
'value' => 'non-existing-name',
],
]);
$this->executeView($view);
$output = $view->render();
$output = \Drupal::service('renderer')->renderRoot($output);
$this->setRawContent($output);
$this->assertText('start: 0 | end: 0 | total: 0 | label: test_area_result | per page: 0 | current page: 1 | current record count: 0 | page count: 1');
// Test that the area is not displayed if we have not checked the empty
// checkbox.
$view->setDisplay('page_1');
$this->executeView($view);
$output = $view->render();
$output = \Drupal::service('renderer')->renderRoot($output);
$this->setRawContent($output);
$this->assertNoText('start: 0 | end: 0 | total: 0 | label: test_area_result | per page: 0 | current page: 1 | current record count: 0 | page count: 1');
}
}
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