Commit e3ad6a4d authored by catch's avatar catch

Issue #2510076 by DuaelFr: The [view:page-count] token should never return 0

parent 89d52d9a
......@@ -77,4 +77,23 @@ function testTokenReplacement() {
}
}
/**
* Tests core token replacements generated from a view without results.
*/
function testTokenReplacementNoResults() {
$token_handler = \Drupal::token();
$view = Views::getView('test_tokens');
$view->setDisplay('page_2');
$this->executeView($view);
$expected = array(
'[view:page-count]' => '1',
);
foreach ($expected as $token => $expected_output) {
$output = $token_handler->replace($token, array('view' => $view));
$this->assertIdentical($output, $expected_output, format_string('Token %token replaced correctly.', array('%token' => $token)));
}
}
}
......@@ -57,3 +57,23 @@ display:
type: views_query
options: { }
path: test_tokens
page_2:
id: page_2
display_title: Page
display_plugin: page
position: 2
display_options:
defaults:
filters: false
query:
type: views_query
options: { }
filters:
name:
field: name
id: test_filter
table: views_test_data
plugin_id: string
operator: '='
value: 'not an existing name'
path: test_tokens_empty
......@@ -124,7 +124,7 @@ function views_tokens($type, $tokens, array $data, array $options, BubbleableMet
case 'page-count':
// If there are no items per page, set this to 1 for the division.
$per_page = $view->getItemsPerPage() ?: 1;
$replacements[$original] = (int) ceil(count($view->result) / $per_page);
$replacements[$original] = max(1, (int) ceil(count($view->result) / $per_page));
break;
}
}
......
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