@@ -23,9 +23,9 @@ class ApiPaginationComponentTest extends TestCase
2323 *
2424 * @return void
2525 */
26- public function setUp ()
26+ public function setUp (): void
2727 {
28- $ this ->request = new Request (' /articles ' );
28+ $ this ->request = new Request ([ ' url ' => ' /articles '] );
2929 $ this ->response = $ this ->createMock ('Cake\Http\Response ' );
3030 $ this ->controller = new ArticlesController ($ this ->request , $ this ->response );
3131 $ this ->Articles = TableRegistry::get ('BryanCrowe/ApiPagination.Articles ' , ['table ' => 'bryancrowe_articles ' ]);
@@ -37,7 +37,7 @@ public function setUp()
3737 *
3838 * @return void
3939 */
40- public function tearDown ()
40+ public function tearDown (): void
4141 {
4242 parent ::tearDown ();
4343 }
@@ -63,29 +63,34 @@ public function testNonApiPaginatedRequest()
6363 */
6464 public function testDefaultPaginationSettings ()
6565 {
66- $ this ->controller ->request = $ this ->controller ->request ->withEnv ('HTTP_ACCEPT ' , 'application/json ' );
66+ $ this ->controller ->setRequest (
67+ $ this ->controller ->getRequest ()->withEnv ('HTTP_ACCEPT ' , 'application/json ' )
68+ );
6769 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
6870 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components ());
6971 $ event = new Event ('Controller.beforeRender ' , $ this ->controller );
7072 $ apiPaginationComponent ->beforeRender ($ event );
7173
72- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'pagination ' ] ;
74+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'pagination ' ) ;
7375 $ expected = [
74- 'finder ' => 'all ' ,
75- 'page ' => 1 ,
76- 'current ' => 20 ,
7776 'count ' => 23 ,
77+ 'current ' => 20 ,
7878 'perPage ' => 20 ,
79+ 'page ' => 1 ,
80+ 'requestedPage ' => 1 ,
81+ 'pageCount ' => 2 ,
82+ 'start ' => 1 ,
83+ 'end ' => 20 ,
7984 'prevPage ' => false ,
8085 'nextPage ' => true ,
81- 'pageCount ' => 2 ,
8286 'sort ' => null ,
83- 'direction ' => false ,
84- 'limit ' => null ,
87+ 'direction ' => null ,
8588 'sortDefault ' => false ,
8689 'directionDefault ' => false ,
90+ 'completeSort ' => [],
91+ 'limit ' => null ,
8792 'scope ' => null ,
88- 'completeSort ' => []
93+ 'finder ' => ' all ' ,
8994 ];
9095
9196 $ this ->assertSame ($ expected , $ result );
@@ -98,7 +103,9 @@ public function testDefaultPaginationSettings()
98103 */
99104 public function testVisibilitySettings ()
100105 {
101- $ this ->controller ->request = $ this ->controller ->request ->withEnv ('HTTP_ACCEPT ' , 'application/json ' );
106+ $ this ->controller ->setRequest (
107+ $ this ->controller ->getRequest ()->withEnv ('HTTP_ACCEPT ' , 'application/json ' )
108+ );
102109 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
103110 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
104111 'visible ' => [
@@ -113,14 +120,14 @@ public function testVisibilitySettings()
113120 $ event = new Event ('Controller.beforeRender ' , $ this ->controller );
114121 $ apiPaginationComponent ->beforeRender ($ event );
115122
116- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'pagination ' ] ;
123+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'pagination ' ) ;
117124 $ expected = [
118- 'page ' => 1 ,
119- 'current ' => 20 ,
120125 'count ' => 23 ,
126+ 'current ' => 20 ,
127+ 'page ' => 1 ,
128+ 'pageCount ' => 2 ,
121129 'prevPage ' => false ,
122130 'nextPage ' => true ,
123- 'pageCount ' => 2
124131 ];
125132
126133 $ this ->assertSame ($ expected , $ result );
@@ -133,7 +140,9 @@ public function testVisibilitySettings()
133140 */
134141 public function testAliasSettings ()
135142 {
136- $ this ->controller ->request = $ this ->controller ->request ->withEnv ('HTTP_ACCEPT ' , 'application/json ' );
143+ $ this ->controller ->setRequest (
144+ $ this ->controller ->getRequest ()->withEnv ('HTTP_ACCEPT ' , 'application/json ' )
145+ );
137146 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
138147 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
139148 'aliases ' => [
@@ -145,20 +154,23 @@ public function testAliasSettings()
145154 $ event = new Event ('Controller.beforeRender ' , $ this ->controller );
146155 $ apiPaginationComponent ->beforeRender ($ event );
147156
148- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'pagination ' ] ;
157+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'pagination ' ) ;
149158 $ expected = [
150- 'finder ' => 'all ' ,
151159 'perPage ' => 20 ,
160+ 'requestedPage ' => 1 ,
161+ 'pageCount ' => 2 ,
162+ 'start ' => 1 ,
163+ 'end ' => 20 ,
152164 'prevPage ' => false ,
153165 'nextPage ' => true ,
154- 'pageCount ' => 2 ,
155166 'sort ' => null ,
156- 'direction ' => false ,
157- 'limit ' => null ,
167+ 'direction ' => null ,
158168 'sortDefault ' => false ,
159169 'directionDefault ' => false ,
160- 'scope ' => null ,
161170 'completeSort ' => [],
171+ 'limit ' => null ,
172+ 'scope ' => null ,
173+ 'finder ' => 'all ' ,
162174 'curPage ' => 1 ,
163175 'currentCount ' => 20 ,
164176 'totalCount ' => 23 ,
@@ -174,31 +186,36 @@ public function testAliasSettings()
174186 */
175187 public function testKeySetting ()
176188 {
177- $ this ->controller ->request = $ this ->controller ->request ->withEnv ('HTTP_ACCEPT ' , 'application/json ' );
189+ $ this ->controller ->setRequest (
190+ $ this ->controller ->getRequest ()->withEnv ('HTTP_ACCEPT ' , 'application/json ' )
191+ );
178192 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
179193 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
180194 'key ' => 'paging '
181195 ]);
182196 $ event = new Event ('Controller.beforeRender ' , $ this ->controller );
183197 $ apiPaginationComponent ->beforeRender ($ event );
184198
185- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'paging ' ] ;
199+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'paging ' ) ;
186200 $ expected = [
187- 'finder ' => 'all ' ,
188- 'page ' => 1 ,
189- 'current ' => 20 ,
190201 'count ' => 23 ,
202+ 'current ' => 20 ,
191203 'perPage ' => 20 ,
204+ 'page ' => 1 ,
205+ 'requestedPage ' => 1 ,
206+ 'pageCount ' => 2 ,
207+ 'start ' => 1 ,
208+ 'end ' => 20 ,
192209 'prevPage ' => false ,
193210 'nextPage ' => true ,
194- 'pageCount ' => 2 ,
195211 'sort ' => null ,
196- 'direction ' => false ,
197- 'limit ' => null ,
212+ 'direction ' => null ,
198213 'sortDefault ' => false ,
199214 'directionDefault ' => false ,
215+ 'completeSort ' => [],
216+ 'limit ' => null ,
200217 'scope ' => null ,
201- 'completeSort ' => []
218+ 'finder ' => ' all ' ,
202219 ];
203220
204221 $ this ->assertSame ($ expected , $ result );
@@ -211,7 +228,9 @@ public function testKeySetting()
211228 */
212229 public function testAllSettings ()
213230 {
214- $ this ->controller ->request = $ this ->controller ->request ->withEnv ('HTTP_ACCEPT ' , 'application/json ' );
231+ $ this ->controller ->setRequest (
232+ $ this ->controller ->getRequest ()->withEnv ('HTTP_ACCEPT ' , 'application/json ' )
233+ );
215234 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
216235 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
217236 'key ' => 'fun ' ,
@@ -231,7 +250,7 @@ public function testAllSettings()
231250 $ event = new Event ('Controller.beforeRender ' , $ this ->controller );
232251 $ apiPaginationComponent ->beforeRender ($ event );
233252
234- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'fun ' ] ;
253+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'fun ' ) ;
235254 $ expected = [
236255 'prevPage ' => false ,
237256 'nextPage ' => true ,
0 commit comments