Skip to content
Permalink
Browse files

Formatting numbers produced by PaginatorHelper::counter()

Fixes #1965
  • Loading branch information...
lorenzo committed Sep 3, 2014
1 parent 001ec16 commit fb902ebd24549775b039deaf47ade2fefe115afc
Showing with 36 additions and 3 deletions.
  1. +6 −3 src/View/Helper/PaginatorHelper.php
  2. +30 −0 tests/TestCase/View/Helper/PaginatorHelperTest.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);
@@ -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
*

0 comments on commit fb902eb

Please sign in to comment.
You can’t perform that action at this time.