Skip to content

Commit

Permalink
Fix controller tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 6, 2016
1 parent 2a4995e commit 055b574
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/Controller/Component/PaginatorComponent.php
Expand Up @@ -142,6 +142,22 @@ public function implementedEvents()
* $results = $paginator->paginate($query);
* ```
*
* ### Scoping Request parameters
*
* By using request parameter scopes you can paginate multiple queries in the same controller action:
*
* ```
* $articles = $paginator->paginate($articlesQuery, ['scope' => 'articles']);
* $tags = $paginator->paginate($tagsQuery, ['scope' => 'tags']);
* ```
*
* Each of the above queries will use different query string parameter sets
* for pagination data. An example URL paginating both results would be:
*
* ```
* /dashboard?articles[page]=1&tags[page]=2
* ```
*
* @param \Cake\Datasource\RepositoryInterface|\Cake\Datasource\QueryInterface $object The table or query to paginate.
* @param array $settings The settings/configuration used for pagination.
* @return \Cake\Datasource\ResultSetInterface Query results
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/Controller/ControllerTest.php
Expand Up @@ -728,7 +728,7 @@ public function testPaginate()
$Controller = new Controller($request, $response);
$Controller->request->query = [
'url' => [],
'prefix' => [
'posts' => [
'page' => 2,
'limit' => 2,
]
Expand All @@ -751,15 +751,17 @@ public function testPaginate()
$this->assertSame($Controller->request->params['paging']['Posts']['pageCount'], 1);
$this->assertSame($Controller->request->params['paging']['Posts']['prevPage'], false);
$this->assertSame($Controller->request->params['paging']['Posts']['nextPage'], false);
$this->assertNull($Controller->request->params['paging']['Posts']['scope']);

$results = $Controller->paginate(TableRegistry::get('Posts'), ['prefix' => 'prefix']);
$results = $Controller->paginate(TableRegistry::get('Posts'), ['scope' => 'posts']);
$this->assertInstanceOf('Cake\Datasource\ResultSetInterface', $results);
$this->assertCount(1, $results);

$this->assertSame($Controller->request->params['paging']['Posts']['page'], 2);
$this->assertSame($Controller->request->params['paging']['Posts']['pageCount'], 2);
$this->assertSame($Controller->request->params['paging']['Posts']['prevPage'], true);
$this->assertSame($Controller->request->params['paging']['Posts']['nextPage'], false);
$this->assertSame($Controller->request->params['paging']['Posts']['scope'], 'posts');
}

/**
Expand Down

0 comments on commit 055b574

Please sign in to comment.