Skip to content
Permalink
Browse files

Change findType to finder in PaginatorComponent.

Having everything be consistent is good and nice. I've left behind
compatibility with `findType` as unlike CounterCache and Associated
finders, PaginatorComponent is a bit more widely used and is harder to
change.
  • Loading branch information...
markstory committed Aug 23, 2014
1 parent 425faaa commit 6cb9d453bb303352797168179baa3c7d75072d89
@@ -107,20 +107,20 @@ public function implementedEvents() {
* {{{
* $settings = [
* 'Articles' => [
* 'findType' => 'custom',
* 'finder' => 'custom',
* 'sortWhitelist' => ['title', 'author_id', 'comment_count'],
* ]
* ];
* }}}
*
* ### Paginating with custom finders
*
* You can paginate with any find type defined on your table using the `findType` option.
* You can paginate with any find type defined on your table using the `finder` option.
*
* {{{
* $settings = array(
* 'Articles' => array(
* 'findType' => 'popular'
* 'finder' => 'popular'
* )
* );
* $results = $paginator->paginate($table, $settings);
@@ -156,8 +156,12 @@ public function paginate($object, array $settings = []) {
$options += ['page' => 1];
$options['page'] = intval($options['page']) < 1 ? 1 : (int)$options['page'];
$type = !empty($options['findType']) ? $options['findType'] : 'all';
unset($options['findType'], $options['maxLimit']);
if (!isset($options['finder']) && isset($options['findType'])) {
trigger_error('You should use finder instead of findType', E_USER_DEPRECATED);
$options['finder'] = $options['findType'];
}
$type = !empty($options['finder']) ? $options['finder'] : 'all';
unset($options['finder'], $options['maxLimit']);
if (empty($query)) {
$query = $object->find($type);
@@ -186,7 +190,7 @@ public function paginate($object, array $settings = []) {
}
$paging = array(
'findType' => $type,
'finder' => $type,
'page' => $page,
'current' => $numResults,
'count' => $count,
@@ -149,7 +149,7 @@ public function testPaginateExtraParams() {
public function testPaginateCustomFinder() {
$settings = array(
'PaginatorPosts' => array(
'findType' => 'popular',
'finder' => 'popular',
'fields' => array('id', 'title'),
'maxLimit' => 10,
)
@@ -163,7 +163,7 @@ public function testPaginateCustomFinder() {
->will($this->returnValue($query));
$this->Paginator->paginate($table, $settings);
$this->assertEquals('popular', $this->request->params['paging']['PaginatorPosts']['findType']);
$this->assertEquals('popular', $this->request->params['paging']['PaginatorPosts']['finder']);
}
/**
@@ -267,14 +267,14 @@ public function testMergeOptionsCustomFindKey() {
'page' => 1,
'limit' => 20,
'maxLimit' => 100,
'findType' => 'myCustomFind'
'finder' => 'myCustomFind'
];
$result = $this->Paginator->mergeOptions('Post', $settings);
$expected = array(
'page' => 10,
'limit' => 10,
'maxLimit' => 100,
'findType' => 'myCustomFind',
'finder' => 'myCustomFind',
'whitelist' => ['limit', 'sort', 'page', 'direction'],
);
$this->assertEquals($expected, $result);
@@ -683,7 +683,7 @@ public function testPaginateCustomFind() {
$this->assertEquals(4, $result['current']);
$this->assertEquals(4, $result['count']);
$settings = array('findType' => 'published');
$settings = array('finder' => 'published');
$result = $this->Paginator->paginate($table, $settings);
$this->assertCount(3, $result, '3 rows should come back');
$this->assertEquals(array(1, 2, 3), $idExtractor($result));
@@ -692,7 +692,7 @@ public function testPaginateCustomFind() {
$this->assertEquals(3, $result['current']);
$this->assertEquals(3, $result['count']);
$settings = array('findType' => 'published', 'limit' => 2);
$settings = array('finder' => 'published', 'limit' => 2);
$result = $this->Paginator->paginate($table, $settings);
$this->assertCount(2, $result, '2 rows should come back');
$this->assertEquals(array(1, 2), $idExtractor($result));
@@ -707,6 +707,18 @@ public function testPaginateCustomFind() {
$this->assertNull($result['limit']);
}
/**
* test paginate() and custom find with deprecated option.
*
* @expectedException PHPUnit_Framework_Error_Deprecated
* @return void
*/
public function testPaginateCustomFindOldOption() {
$this->loadFixtures('Post');
$table = TableRegistry::get('PaginatorPosts');
$this->Paginator->paginate($table, ['findType' => 'published']);
}
/**
* test paginate() and custom find with fields array, to make sure the correct count is returned.
*
@@ -719,7 +731,7 @@ public function testPaginateCustomFindFieldsArray() {
$table->save(new \Cake\ORM\Entity($data));
$settings = [
'findType' => 'list',
'finder' => 'list',
'conditions' => array('PaginatorPosts.published' => 'Y'),
'limit' => 2
];
@@ -748,7 +760,7 @@ public function testPaginateCustomFindFieldsArray() {
*/
public function testPaginateCustomFindCount() {
$settings = array(
'findType' => 'published',
'finder' => 'published',
'limit' => 2
);
$table = $this->_getMockPosts(['find']);

0 comments on commit 6cb9d45

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