Skip to content
Permalink
Browse files

Fix controller tests.

  • Loading branch information...
markstory committed Jul 6, 2016
1 parent 2a4995e commit 055b574d8678316f5c3aa1155810777cd4cb7bf1
Showing with 20 additions and 2 deletions.
  1. +16 −0 src/Controller/Component/PaginatorComponent.php
  2. +4 −2 tests/TestCase/Controller/ControllerTest.php
@@ -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
@@ -728,7 +728,7 @@ public function testPaginate()
$Controller = new Controller($request, $response);
$Controller->request->query = [
'url' => [],
'prefix' => [
'posts' => [
'page' => 2,
'limit' => 2,
]
@@ -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');
}
/**

0 comments on commit 055b574

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