Skip to content

Commit

Permalink
Formatting numbers produced by PaginatorHelper::counter()
Browse files Browse the repository at this point in the history
Fixes #1965
  • Loading branch information
lorenzo committed Sep 3, 2014
1 parent 001ec16 commit fb902eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/View/Helper/PaginatorHelper.php
Expand Up @@ -34,7 +34,7 @@ class PaginatorHelper extends Helper {
*
* @var array
*/
public $helpers = ['Url'];
public $helpers = ['Url', 'Number'];

/**
* Defualt config for this class
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions tests/TestCase/View/Helper/PaginatorHelperTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit fb902eb

Please sign in to comment.