summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-02-02 00:59:51 (GMT)
committerNathaniel Catchpole2016-02-02 00:59:51 (GMT)
commite3ad6a4d8b2b71821c725641e785382d7b3b0ce2 (patch)
treede099892ab990e388163874450196ebb3f038250
parent89d52d9a289df69b88672524c16a6fc5389d4b00 (diff)
Issue #2510076 by DuaelFr: The [view:page-count] token should never return 0
-rw-r--r--core/modules/views/src/Tests/TokenReplaceTest.php19
-rw-r--r--core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml20
-rw-r--r--core/modules/views/views.tokens.inc2
3 files changed, 40 insertions, 1 deletions
diff --git a/core/modules/views/src/Tests/TokenReplaceTest.php b/core/modules/views/src/Tests/TokenReplaceTest.php
index 0462756..149280f 100644
--- a/core/modules/views/src/Tests/TokenReplaceTest.php
+++ b/core/modules/views/src/Tests/TokenReplaceTest.php
@@ -77,4 +77,23 @@ class TokenReplaceTest extends ViewKernelTestBase {
}
}
+ /**
+ * 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)));
+ }
+ }
+
}
diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml
index bf9341b..2bb8216 100644
--- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml
+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml
@@ -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
diff --git a/core/modules/views/views.tokens.inc b/core/modules/views/views.tokens.inc
index 6d9de95..59faec3 100644
--- a/core/modules/views/views.tokens.inc
+++ b/core/modules/views/views.tokens.inc
@@ -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;
}
}