diff --git a/src/View/Helper/PaginatorHelper.php b/src/View/Helper/PaginatorHelper.php index fc29801c364..8ae9869bf56 100644 --- a/src/View/Helper/PaginatorHelper.php +++ b/src/View/Helper/PaginatorHelper.php @@ -34,7 +34,7 @@ class PaginatorHelper extends Helper { * * @var array */ - public $helpers = ['Url']; + public $helpers = ['Url', 'Number']; /** * Defualt config for this class @@ -556,13 +556,16 @@ public function counter($options = []) { $template = 'counterCustom'; $this->templater()->add([$template => $options['format']]); } - $map = [ + $map = array_map([$this->Number, 'format'], [ 'page' => $paging['page'], 'pages' => $paging['pageCount'], 'current' => $paging['current'], 'count' => $paging['count'], 'start' => $start, - 'end' => $end, + 'end' => $end + ]); + + $map += [ 'model' => strtolower(Inflector::humanize(Inflector::tableize($options['model']))) ]; return $this->templater()->format($template, $map); diff --git a/tests/TestCase/View/Helper/PaginatorHelperTest.php b/tests/TestCase/View/Helper/PaginatorHelperTest.php index ad5a708ea84..f3afbc0a3e6 100644 --- a/tests/TestCase/View/Helper/PaginatorHelperTest.php +++ b/tests/TestCase/View/Helper/PaginatorHelperTest.php @@ -1869,6 +1869,36 @@ public function testCounter() { $this->assertEquals('Showing 1 of 5 clients', $result); } +/** + * Tests that numbers are formatted according to the locale when using counter() + * + * @return void + */ + public function testCounterBigNumbers() { + $this->Paginator->request->params['paging'] = [ + 'Client' => [ + 'page' => 1523, + 'current' => 1230, + 'count' => 234567, + 'perPage' => 3000, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 1000, + 'limit' => 5000, + 'sort' => 'Client.name', + 'order' => 'DESC', + ] + ]; + + $input = 'Page {{page}} of {{pages}}, showing {{current}} records out of {{count}} total, '; + $input .= 'starting on record {{start}}, ending on {{end}}'; + + $expected = 'Page 1,523 of 1,000, showing 1,230 records out of 234,567 total, '; + $expected .= 'starting on record 4,566,001, ending on 234,567'; + $result = $this->Paginator->counter($input); + $this->assertEquals($expected, $result); + } + /** * testHasPage method *