Skip to content

Commit d160bed

Browse files
committed
Add test using all config keys
1 parent c9b641f commit d160bed

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/TestCase/Controller/Component/ApiPaginationComponentTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,40 @@ public function testKeySetting()
181181

182182
$this->assertSame($expected, $result);
183183
}
184+
185+
public function testAllSettings()
186+
{
187+
$request = new Request('/articles');
188+
$request->env('HTTP_ACCEPT', 'application/json');
189+
$response = $this->getMock('Cake\Network\Response');
190+
$controller = new ArticlesController($request, $response);
191+
$controller->set('data', $controller->paginate($this->Articles));
192+
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
193+
'key' => 'fun',
194+
'aliases' => [
195+
'page' => 'currentPage',
196+
'count' => 'totalCount',
197+
'limit' => 'unusedAlias'
198+
],
199+
'visible' => [
200+
'currentPage',
201+
'totalCount',
202+
'limit',
203+
'prevPage',
204+
'nextPage'
205+
]
206+
]);
207+
$event = new Event('Controller.beforeRender', $controller);
208+
$apiPaginationComponent->beforeRender($event);
209+
210+
$result = $apiPaginationComponent->_registry->getController()->viewVars['fun'];
211+
$expected = [
212+
'prevPage' => false,
213+
'nextPage' => true,
214+
'currentPage' => 1,
215+
'totalCount' => 23,
216+
];
217+
218+
$this->assertSame($expected, $result);
219+
}
184220
}

0 commit comments

Comments
 (0)