From 06a2b54f453961c32eb25f241b07880ff84271b4 Mon Sep 17 00:00:00 2001 From: Bryan Crowe Date: Mon, 28 Sep 2015 15:17:34 -0400 Subject: [PATCH] Make controller property rather than local vars --- .../Component/ApiPaginationComponentTest.php | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/tests/TestCase/Controller/Component/ApiPaginationComponentTest.php b/tests/TestCase/Controller/Component/ApiPaginationComponentTest.php index 6a0ae46..65c07db 100644 --- a/tests/TestCase/Controller/Component/ApiPaginationComponentTest.php +++ b/tests/TestCase/Controller/Component/ApiPaginationComponentTest.php @@ -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(); } @@ -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)); } @@ -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']; @@ -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', @@ -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']; @@ -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']; @@ -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']; @@ -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', @@ -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'];