@@ -25,6 +25,7 @@ public function setUp()
2525 {
2626 $ this ->request = new Request ('/articles ' );
2727 $ this ->response = $ this ->getMock ('Cake\Network\Response ' );
28+ $ this ->controller = new ArticlesController ($ this ->request , $ this ->response );
2829 $ this ->Articles = TableRegistry::get ('BryanCrowe/ApiPagination.Articles ' , ['table ' => 'bryancrowe_articles ' ]);
2930 parent ::setUp ();
3031 }
@@ -46,9 +47,8 @@ public function tearDown()
4647 */
4748 public function testNonApiPaginatedRequest ()
4849 {
49- $ controller = new ArticlesController ($ this ->request , $ this ->response );
50- $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components ());
51- $ event = new Event ('Controller.beforeRender ' , $ controller );
50+ $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components ());
51+ $ event = new Event ('Controller.beforeRender ' , $ this ->controller );
5252
5353 $ this ->assertNull ($ apiPaginationComponent ->beforeRender ($ event ));
5454 }
@@ -62,10 +62,9 @@ public function testNonApiPaginatedRequest()
6262 public function testDefaultPaginationSettings ()
6363 {
6464 $ this ->request ->env ('HTTP_ACCEPT ' , 'application/json ' );
65- $ controller = new ArticlesController ($ this ->request , $ this ->response );
66- $ controller ->set ('data ' , $ controller ->paginate ($ this ->Articles ));
67- $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components ());
68- $ event = new Event ('Controller.beforeRender ' , $ controller );
65+ $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
66+ $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components ());
67+ $ event = new Event ('Controller.beforeRender ' , $ this ->controller );
6968 $ apiPaginationComponent ->beforeRender ($ event );
7069
7170 $ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['pagination ' ];
@@ -96,9 +95,8 @@ public function testDefaultPaginationSettings()
9695 public function testVisibilitySettings ()
9796 {
9897 $ this ->request ->env ('HTTP_ACCEPT ' , 'application/json ' );
99- $ controller = new ArticlesController ($ this ->request , $ this ->response );
100- $ controller ->set ('data ' , $ controller ->paginate ($ this ->Articles ));
101- $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components (), [
98+ $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
99+ $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
102100 'visible ' => [
103101 'page ' ,
104102 'current ' ,
@@ -108,7 +106,7 @@ public function testVisibilitySettings()
108106 'pageCount '
109107 ]
110108 ]);
111- $ event = new Event ('Controller.beforeRender ' , $ controller );
109+ $ event = new Event ('Controller.beforeRender ' , $ this -> controller );
112110 $ apiPaginationComponent ->beforeRender ($ event );
113111
114112 $ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['pagination ' ];
@@ -132,16 +130,15 @@ public function testVisibilitySettings()
132130 public function testAliasSettings ()
133131 {
134132 $ this ->request ->env ('HTTP_ACCEPT ' , 'application/json ' );
135- $ controller = new ArticlesController ($ this ->request , $ this ->response );
136- $ controller ->set ('data ' , $ controller ->paginate ($ this ->Articles ));
137- $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components (), [
133+ $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
134+ $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
138135 'aliases ' => [
139136 'page ' => 'curPage ' ,
140137 'current ' => 'currentCount ' ,
141138 'count ' => 'totalCount ' ,
142139 ]
143140 ]);
144- $ event = new Event ('Controller.beforeRender ' , $ controller );
141+ $ event = new Event ('Controller.beforeRender ' , $ this -> controller );
145142 $ apiPaginationComponent ->beforeRender ($ event );
146143
147144 $ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['pagination ' ];
@@ -172,12 +169,11 @@ public function testAliasSettings()
172169 public function testKeySetting ()
173170 {
174171 $ this ->request ->env ('HTTP_ACCEPT ' , 'application/json ' );
175- $ controller = new ArticlesController ($ this ->request , $ this ->response );
176- $ controller ->set ('data ' , $ controller ->paginate ($ this ->Articles ));
177- $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components (), [
172+ $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
173+ $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
178174 'key ' => 'paging '
179175 ]);
180- $ event = new Event ('Controller.beforeRender ' , $ controller );
176+ $ event = new Event ('Controller.beforeRender ' , $ this -> controller );
181177 $ apiPaginationComponent ->beforeRender ($ event );
182178
183179 $ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['paging ' ];
@@ -208,9 +204,8 @@ public function testKeySetting()
208204 public function testAllSettings ()
209205 {
210206 $ this ->request ->env ('HTTP_ACCEPT ' , 'application/json ' );
211- $ controller = new ArticlesController ($ this ->request , $ this ->response );
212- $ controller ->set ('data ' , $ controller ->paginate ($ this ->Articles ));
213- $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components (), [
207+ $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
208+ $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
214209 'key ' => 'fun ' ,
215210 'aliases ' => [
216211 'page ' => 'currentPage ' ,
@@ -225,7 +220,7 @@ public function testAllSettings()
225220 'nextPage '
226221 ]
227222 ]);
228- $ event = new Event ('Controller.beforeRender ' , $ controller );
223+ $ event = new Event ('Controller.beforeRender ' , $ this -> controller );
229224 $ apiPaginationComponent ->beforeRender ($ event );
230225
231226 $ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['fun ' ];
0 commit comments