Skip to content

Commit

Permalink
Make controller property rather than local vars
Browse files Browse the repository at this point in the history
  • Loading branch information
bcrowe committed Sep 28, 2015
1 parent 019e314 commit 06a2b54
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions tests/TestCase/Controller/Component/ApiPaginationComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function setUp()
{
$this->request = new Request('/articles');
$this->response = $this->getMock('Cake\Network\Response');
$this->controller = new ArticlesController($this->request, $this->response);
$this->Articles = TableRegistry::get('BryanCrowe/ApiPagination.Articles', ['table' => 'bryancrowe_articles']);
parent::setUp();
}
Expand All @@ -46,9 +47,8 @@ public function tearDown()
*/
public function testNonApiPaginatedRequest()
{
$controller = new ArticlesController($this->request, $this->response);
$apiPaginationComponent = new ApiPaginationComponent($controller->components());
$event = new Event('Controller.beforeRender', $controller);
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components());
$event = new Event('Controller.beforeRender', $this->controller);

$this->assertNull($apiPaginationComponent->beforeRender($event));
}
Expand All @@ -62,10 +62,9 @@ public function testNonApiPaginatedRequest()
public function testDefaultPaginationSettings()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$controller = new ArticlesController($this->request, $this->response);
$controller->set('data', $controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($controller->components());
$event = new Event('Controller.beforeRender', $controller);
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components());
$event = new Event('Controller.beforeRender', $this->controller);
$apiPaginationComponent->beforeRender($event);

$result = $apiPaginationComponent->_registry->getController()->viewVars['pagination'];
Expand Down Expand Up @@ -96,9 +95,8 @@ public function testDefaultPaginationSettings()
public function testVisibilitySettings()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$controller = new ArticlesController($this->request, $this->response);
$controller->set('data', $controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
'visible' => [
'page',
'current',
Expand All @@ -108,7 +106,7 @@ public function testVisibilitySettings()
'pageCount'
]
]);
$event = new Event('Controller.beforeRender', $controller);
$event = new Event('Controller.beforeRender', $this->controller);
$apiPaginationComponent->beforeRender($event);

$result = $apiPaginationComponent->_registry->getController()->viewVars['pagination'];
Expand All @@ -132,16 +130,15 @@ public function testVisibilitySettings()
public function testAliasSettings()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$controller = new ArticlesController($this->request, $this->response);
$controller->set('data', $controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
'aliases' => [
'page' => 'curPage',
'current' => 'currentCount',
'count' => 'totalCount',
]
]);
$event = new Event('Controller.beforeRender', $controller);
$event = new Event('Controller.beforeRender', $this->controller);
$apiPaginationComponent->beforeRender($event);

$result = $apiPaginationComponent->_registry->getController()->viewVars['pagination'];
Expand Down Expand Up @@ -172,12 +169,11 @@ public function testAliasSettings()
public function testKeySetting()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$controller = new ArticlesController($this->request, $this->response);
$controller->set('data', $controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
'key' => 'paging'
]);
$event = new Event('Controller.beforeRender', $controller);
$event = new Event('Controller.beforeRender', $this->controller);
$apiPaginationComponent->beforeRender($event);

$result = $apiPaginationComponent->_registry->getController()->viewVars['paging'];
Expand Down Expand Up @@ -208,9 +204,8 @@ public function testKeySetting()
public function testAllSettings()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$controller = new ArticlesController($this->request, $this->response);
$controller->set('data', $controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
'key' => 'fun',
'aliases' => [
'page' => 'currentPage',
Expand All @@ -225,7 +220,7 @@ public function testAllSettings()
'nextPage'
]
]);
$event = new Event('Controller.beforeRender', $controller);
$event = new Event('Controller.beforeRender', $this->controller);
$apiPaginationComponent->beforeRender($event);

$result = $apiPaginationComponent->_registry->getController()->viewVars['fun'];
Expand Down

0 comments on commit 06a2b54

Please sign in to comment.