@@ -23,9 +23,9 @@ class ApiPaginationComponentTest extends TestCase
23
23
*
24
24
* @return void
25
25
*/
26
- public function setUp ()
26
+ public function setUp (): void
27
27
{
28
- $ this ->request = new Request (' /articles ' );
28
+ $ this ->request = new Request ([ ' url ' => ' /articles '] );
29
29
$ this ->response = $ this ->createMock ('Cake\Http\Response ' );
30
30
$ this ->controller = new ArticlesController ($ this ->request , $ this ->response );
31
31
$ this ->Articles = TableRegistry::get ('BryanCrowe/ApiPagination.Articles ' , ['table ' => 'bryancrowe_articles ' ]);
@@ -37,7 +37,7 @@ public function setUp()
37
37
*
38
38
* @return void
39
39
*/
40
- public function tearDown ()
40
+ public function tearDown (): void
41
41
{
42
42
parent ::tearDown ();
43
43
}
@@ -63,29 +63,34 @@ public function testNonApiPaginatedRequest()
63
63
*/
64
64
public function testDefaultPaginationSettings ()
65
65
{
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
+ );
67
69
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
68
70
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components ());
69
71
$ event = new Event ('Controller.beforeRender ' , $ this ->controller );
70
72
$ apiPaginationComponent ->beforeRender ($ event );
71
73
72
- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'pagination ' ] ;
74
+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'pagination ' ) ;
73
75
$ expected = [
74
- 'finder ' => 'all ' ,
75
- 'page ' => 1 ,
76
- 'current ' => 20 ,
77
76
'count ' => 23 ,
77
+ 'current ' => 20 ,
78
78
'perPage ' => 20 ,
79
+ 'page ' => 1 ,
80
+ 'requestedPage ' => 1 ,
81
+ 'pageCount ' => 2 ,
82
+ 'start ' => 1 ,
83
+ 'end ' => 20 ,
79
84
'prevPage ' => false ,
80
85
'nextPage ' => true ,
81
- 'pageCount ' => 2 ,
82
86
'sort ' => null ,
83
- 'direction ' => false ,
84
- 'limit ' => null ,
87
+ 'direction ' => null ,
85
88
'sortDefault ' => false ,
86
89
'directionDefault ' => false ,
90
+ 'completeSort ' => [],
91
+ 'limit ' => null ,
87
92
'scope ' => null ,
88
- 'completeSort ' => []
93
+ 'finder ' => ' all ' ,
89
94
];
90
95
91
96
$ this ->assertSame ($ expected , $ result );
@@ -98,7 +103,9 @@ public function testDefaultPaginationSettings()
98
103
*/
99
104
public function testVisibilitySettings ()
100
105
{
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
+ );
102
109
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
103
110
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
104
111
'visible ' => [
@@ -113,14 +120,14 @@ public function testVisibilitySettings()
113
120
$ event = new Event ('Controller.beforeRender ' , $ this ->controller );
114
121
$ apiPaginationComponent ->beforeRender ($ event );
115
122
116
- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'pagination ' ] ;
123
+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'pagination ' ) ;
117
124
$ expected = [
118
- 'page ' => 1 ,
119
- 'current ' => 20 ,
120
125
'count ' => 23 ,
126
+ 'current ' => 20 ,
127
+ 'page ' => 1 ,
128
+ 'pageCount ' => 2 ,
121
129
'prevPage ' => false ,
122
130
'nextPage ' => true ,
123
- 'pageCount ' => 2
124
131
];
125
132
126
133
$ this ->assertSame ($ expected , $ result );
@@ -133,7 +140,9 @@ public function testVisibilitySettings()
133
140
*/
134
141
public function testAliasSettings ()
135
142
{
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
+ );
137
146
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
138
147
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
139
148
'aliases ' => [
@@ -145,20 +154,23 @@ public function testAliasSettings()
145
154
$ event = new Event ('Controller.beforeRender ' , $ this ->controller );
146
155
$ apiPaginationComponent ->beforeRender ($ event );
147
156
148
- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'pagination ' ] ;
157
+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'pagination ' ) ;
149
158
$ expected = [
150
- 'finder ' => 'all ' ,
151
159
'perPage ' => 20 ,
160
+ 'requestedPage ' => 1 ,
161
+ 'pageCount ' => 2 ,
162
+ 'start ' => 1 ,
163
+ 'end ' => 20 ,
152
164
'prevPage ' => false ,
153
165
'nextPage ' => true ,
154
- 'pageCount ' => 2 ,
155
166
'sort ' => null ,
156
- 'direction ' => false ,
157
- 'limit ' => null ,
167
+ 'direction ' => null ,
158
168
'sortDefault ' => false ,
159
169
'directionDefault ' => false ,
160
- 'scope ' => null ,
161
170
'completeSort ' => [],
171
+ 'limit ' => null ,
172
+ 'scope ' => null ,
173
+ 'finder ' => 'all ' ,
162
174
'curPage ' => 1 ,
163
175
'currentCount ' => 20 ,
164
176
'totalCount ' => 23 ,
@@ -174,31 +186,36 @@ public function testAliasSettings()
174
186
*/
175
187
public function testKeySetting ()
176
188
{
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
+ );
178
192
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
179
193
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
180
194
'key ' => 'paging '
181
195
]);
182
196
$ event = new Event ('Controller.beforeRender ' , $ this ->controller );
183
197
$ apiPaginationComponent ->beforeRender ($ event );
184
198
185
- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'paging ' ] ;
199
+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'paging ' ) ;
186
200
$ expected = [
187
- 'finder ' => 'all ' ,
188
- 'page ' => 1 ,
189
- 'current ' => 20 ,
190
201
'count ' => 23 ,
202
+ 'current ' => 20 ,
191
203
'perPage ' => 20 ,
204
+ 'page ' => 1 ,
205
+ 'requestedPage ' => 1 ,
206
+ 'pageCount ' => 2 ,
207
+ 'start ' => 1 ,
208
+ 'end ' => 20 ,
192
209
'prevPage ' => false ,
193
210
'nextPage ' => true ,
194
- 'pageCount ' => 2 ,
195
211
'sort ' => null ,
196
- 'direction ' => false ,
197
- 'limit ' => null ,
212
+ 'direction ' => null ,
198
213
'sortDefault ' => false ,
199
214
'directionDefault ' => false ,
215
+ 'completeSort ' => [],
216
+ 'limit ' => null ,
200
217
'scope ' => null ,
201
- 'completeSort ' => []
218
+ 'finder ' => ' all ' ,
202
219
];
203
220
204
221
$ this ->assertSame ($ expected , $ result );
@@ -211,7 +228,9 @@ public function testKeySetting()
211
228
*/
212
229
public function testAllSettings ()
213
230
{
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
+ );
215
234
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
216
235
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
217
236
'key ' => 'fun ' ,
@@ -231,7 +250,7 @@ public function testAllSettings()
231
250
$ event = new Event ('Controller.beforeRender ' , $ this ->controller );
232
251
$ apiPaginationComponent ->beforeRender ($ event );
233
252
234
- $ result = $ apiPaginationComponent ->_registry -> getController ()->viewVars [ 'fun ' ] ;
253
+ $ result = $ apiPaginationComponent ->getController ()-> viewBuilder ()->getVar ( 'fun ' ) ;
235
254
$ expected = [
236
255
'prevPage ' => false ,
237
256
'nextPage ' => true ,
0 commit comments