4
4
5
5
use Bootstrap \View \Helper \PaginatorHelper ;
6
6
use Cake \Core \Configure ;
7
- use Cake \Network \ Request ;
7
+ use Cake \Http \ ServerRequest ;
8
8
use Cake \Routing \Router ;
9
9
use Cake \TestSuite \TestCase ;
10
10
use Cake \View \View ;
@@ -16,7 +16,14 @@ class PaginatorHelperTest extends TestCase {
16
16
*
17
17
* @var PaginatorHelper
18
18
*/
19
- public $ paginator ;
19
+ public $ Paginator ;
20
+
21
+ /**
22
+ * View associated with the PaginatorHelper.
23
+ *
24
+ * @var View
25
+ */
26
+ public $ View ;
20
27
21
28
/**
22
29
* setUp method
@@ -26,25 +33,29 @@ class PaginatorHelperTest extends TestCase {
26
33
public function setUp ()
27
34
{
28
35
parent ::setUp ();
29
- $ view = new View ();
30
- $ view ->loadHelper ('Html ' , [
36
+ $ request = new ServerRequest ([
37
+ 'url ' => '/ ' ,
38
+ 'params ' => [
39
+ 'paging ' => [
40
+ 'Article ' => [
41
+ 'page ' => 1 ,
42
+ 'current ' => 9 ,
43
+ 'count ' => 62 ,
44
+ 'prevPage ' => false ,
45
+ 'nextPage ' => true ,
46
+ 'pageCount ' => 7 ,
47
+ 'sort ' => null ,
48
+ 'direction ' => null ,
49
+ 'limit ' => null ,
50
+ ]
51
+ ]
52
+ ]
53
+ ]);
54
+ $ this ->View = new View ($ request );
55
+ $ this ->View ->loadHelper ('Html ' , [
31
56
'className ' => 'Bootstrap.Html '
32
57
]);
33
- $ this ->paginator = new PaginatorHelper ($ view );
34
- $ this ->paginator ->request = (new Request ())
35
- ->withParam ('paging ' , [
36
- 'Article ' => [
37
- 'page ' => 1 ,
38
- 'current ' => 9 ,
39
- 'count ' => 62 ,
40
- 'prevPage ' => false ,
41
- 'nextPage ' => true ,
42
- 'pageCount ' => 7 ,
43
- 'sort ' => null ,
44
- 'direction ' => null ,
45
- 'limit ' => null ,
46
- ]
47
- ]);
58
+ $ this ->Paginator = new PaginatorHelper ($ this ->View );
48
59
Configure::write ('Routing.prefixes ' , []);
49
60
Router::reload ();
50
61
Router::connect ('/:controller/:action/* ' );
@@ -53,7 +64,7 @@ public function setUp()
53
64
54
65
public function testNumbers ()
55
66
{
56
- $ this ->paginator -> request = $ this ->paginator -> request ->withParam ('paging ' , [
67
+ $ this ->View -> setRequest ( $ this ->View -> getRequest () ->withParam ('paging ' , [
57
68
'Client ' => [
58
69
'page ' => 8 ,
59
70
'current ' => 3 ,
@@ -62,8 +73,8 @@ public function testNumbers()
62
73
'nextPage ' => 2 ,
63
74
'pageCount ' => 15 ,
64
75
]
65
- ]);
66
- $ result = $ this ->paginator ->numbers ();
76
+ ])) ;
77
+ $ result = $ this ->Paginator ->numbers ();
67
78
$ expected = [
68
79
['ul ' => ['class ' => 'pagination ' ]],
69
80
['li ' => []], ['a ' => ['href ' => '/index?page=4 ' ]], '4 ' , '/a ' , '/li ' ,
@@ -78,7 +89,7 @@ public function testNumbers()
78
89
'/ul '
79
90
];
80
91
$ this ->assertHtml ($ expected , $ result );
81
- $ result = $ this ->paginator ->numbers (['first ' => 'first ' , 'last ' => 'last ' ]);
92
+ $ result = $ this ->Paginator ->numbers (['first ' => 'first ' , 'last ' => 'last ' ]);
82
93
$ expected = [
83
94
['ul ' => ['class ' => 'pagination ' ]],
84
95
['li ' => []], ['a ' => ['href ' => '/index ' ]], 'first ' , '/a ' , '/li ' ,
@@ -97,7 +108,7 @@ public function testNumbers()
97
108
'/ul '
98
109
];
99
110
$ this ->assertHtml ($ expected , $ result );
100
- $ result = $ this ->paginator ->numbers (['first ' => '2 ' , 'last ' => '8 ' ]);
111
+ $ result = $ this ->Paginator ->numbers (['first ' => '2 ' , 'last ' => '8 ' ]);
101
112
$ expected = [
102
113
['ul ' => ['class ' => 'pagination ' ]],
103
114
['li ' => []], ['a ' => ['href ' => '/index ' ]], '2 ' , '/a ' , '/li ' ,
@@ -116,7 +127,7 @@ public function testNumbers()
116
127
'/ul '
117
128
];
118
129
$ this ->assertHtml ($ expected , $ result );
119
- $ result = $ this ->paginator ->numbers (['first ' => '8 ' , 'last ' => '8 ' ]);
130
+ $ result = $ this ->Paginator ->numbers (['first ' => '8 ' , 'last ' => '8 ' ]);
120
131
$ expected = [
121
132
['ul ' => ['class ' => 'pagination ' ]],
122
133
['li ' => []], ['a ' => ['href ' => '/index ' ]], '8 ' , '/a ' , '/li ' ,
@@ -135,7 +146,7 @@ public function testNumbers()
135
146
'/ul '
136
147
];
137
148
$ this ->assertHtml ($ expected , $ result );
138
- $ this ->paginator -> request = $ this ->paginator -> request ->withParam ('paging ' , [
149
+ $ this ->View -> setRequest ( $ this ->View -> getRequest () ->withParam ('paging ' , [
139
150
'Client ' => [
140
151
'page ' => 1 ,
141
152
'current ' => 3 ,
@@ -144,8 +155,8 @@ public function testNumbers()
144
155
'nextPage ' => 2 ,
145
156
'pageCount ' => 15 ,
146
157
]
147
- ]);
148
- $ result = $ this ->paginator ->numbers ();
158
+ ])) ;
159
+ $ result = $ this ->Paginator ->numbers ();
149
160
$ expected = [
150
161
['ul ' => ['class ' => 'pagination ' ]],
151
162
['li ' => ['class ' => 'active ' ]], ['a ' => ['href ' => '/index ' ]], '1 ' , '/a ' , '/li ' ,
@@ -160,7 +171,7 @@ public function testNumbers()
160
171
'/ul '
161
172
];
162
173
$ this ->assertHtml ($ expected , $ result );
163
- $ this ->paginator -> request = $ this ->paginator -> request ->withParam ('paging ' , [
174
+ $ this ->View -> setRequest ( $ this ->View -> getRequest () ->withParam ('paging ' , [
164
175
'Client ' => [
165
176
'page ' => 14 ,
166
177
'current ' => 3 ,
@@ -169,8 +180,8 @@ public function testNumbers()
169
180
'nextPage ' => 2 ,
170
181
'pageCount ' => 15 ,
171
182
]
172
- ]);
173
- $ result = $ this ->paginator ->numbers ();
183
+ ])) ;
184
+ $ result = $ this ->Paginator ->numbers ();
174
185
$ expected = [
175
186
['ul ' => ['class ' => 'pagination ' ]],
176
187
['li ' => []], ['a ' => ['href ' => '/index?page=7 ' ]], '7 ' , '/a ' , '/li ' ,
@@ -185,7 +196,7 @@ public function testNumbers()
185
196
'/ul '
186
197
];
187
198
$ this ->assertHtml ($ expected , $ result );
188
- $ this ->paginator -> request = $ this ->paginator -> request ->withParam ('paging ' , [
199
+ $ this ->View -> setRequest ( $ this ->View -> getRequest () ->withParam ('paging ' , [
189
200
'Client ' => [
190
201
'page ' => 2 ,
191
202
'current ' => 3 ,
@@ -194,8 +205,8 @@ public function testNumbers()
194
205
'nextPage ' => 2 ,
195
206
'pageCount ' => 9 ,
196
207
]
197
- ]);
198
- $ result = $ this ->paginator ->numbers (['first ' => 1 ]);
208
+ ])) ;
209
+ $ result = $ this ->Paginator ->numbers (['first ' => 1 ]);
199
210
$ expected = [
200
211
['ul ' => ['class ' => 'pagination ' ]],
201
212
['li ' => []], ['a ' => ['href ' => '/index ' ]], '1 ' , '/a ' , '/li ' ,
@@ -210,7 +221,7 @@ public function testNumbers()
210
221
'/ul '
211
222
];
212
223
$ this ->assertHtml ($ expected , $ result );
213
- $ result = $ this ->paginator ->numbers (['last ' => 1 ]);
224
+ $ result = $ this ->Paginator ->numbers (['last ' => 1 ]);
214
225
$ expected = [
215
226
['ul ' => ['class ' => 'pagination ' ]],
216
227
['li ' => []], ['a ' => ['href ' => '/index ' ]], '1 ' , '/a ' , '/li ' ,
@@ -225,7 +236,7 @@ public function testNumbers()
225
236
'/ul '
226
237
];
227
238
$ this ->assertHtml ($ expected , $ result );
228
- $ this ->paginator -> request = $ this ->paginator -> request ->withParam ('paging ' , [
239
+ $ this ->View -> setRequest ( $ this ->View -> getRequest () ->withParam ('paging ' , [
229
240
'Client ' => [
230
241
'page ' => 15 ,
231
242
'current ' => 3 ,
@@ -234,8 +245,8 @@ public function testNumbers()
234
245
'nextPage ' => 2 ,
235
246
'pageCount ' => 15 ,
236
247
]
237
- ]);
238
- $ result = $ this ->paginator ->numbers (['first ' => 1 ]);
248
+ ])) ;
249
+ $ result = $ this ->Paginator ->numbers (['first ' => 1 ]);
239
250
$ expected = [
240
251
['ul ' => ['class ' => 'pagination ' ]],
241
252
['li ' => []], ['a ' => ['href ' => '/index ' ]], '1 ' , '/a ' , '/li ' ,
@@ -252,7 +263,7 @@ public function testNumbers()
252
263
'/ul '
253
264
];
254
265
$ this ->assertHtml ($ expected , $ result );
255
- $ this ->paginator -> request = $ this ->paginator -> request ->withParam ('paging ' , [
266
+ $ this ->View -> setRequest ( $ this ->View -> getRequest () ->withParam ('paging ' , [
256
267
'Client ' => [
257
268
'page ' => 10 ,
258
269
'current ' => 3 ,
@@ -261,8 +272,8 @@ public function testNumbers()
261
272
'nextPage ' => 2 ,
262
273
'pageCount ' => 15 ,
263
274
]
264
- ]);
265
- $ result = $ this ->paginator ->numbers (['first ' => 1 , 'last ' => 1 ]);
275
+ ])) ;
276
+ $ result = $ this ->Paginator ->numbers (['first ' => 1 , 'last ' => 1 ]);
266
277
$ expected = [
267
278
['ul ' => ['class ' => 'pagination ' ]],
268
279
['li ' => []], ['a ' => ['href ' => '/index ' ]], '1 ' , '/a ' , '/li ' ,
@@ -280,7 +291,7 @@ public function testNumbers()
280
291
'/ul '
281
292
];
282
293
$ this ->assertHtml ($ expected , $ result );
283
- $ this ->paginator -> request = $ this ->paginator -> request ->withParam ('paging ' , [
294
+ $ this ->View -> setRequest ( $ this ->View -> getRequest () ->withParam ('paging ' , [
284
295
'Client ' => [
285
296
'page ' => 6 ,
286
297
'current ' => 15 ,
@@ -289,8 +300,8 @@ public function testNumbers()
289
300
'nextPage ' => 1 ,
290
301
'pageCount ' => 42 ,
291
302
]
292
- ]);
293
- $ result = $ this ->paginator ->numbers (['first ' => 1 , 'last ' => 1 ]);
303
+ ])) ;
304
+ $ result = $ this ->Paginator ->numbers (['first ' => 1 , 'last ' => 1 ]);
294
305
$ expected = [
295
306
['ul ' => ['class ' => 'pagination ' ]],
296
307
['li ' => []], ['a ' => ['href ' => '/index ' ]], '1 ' , '/a ' , '/li ' ,
@@ -308,7 +319,7 @@ public function testNumbers()
308
319
'/ul '
309
320
];
310
321
$ this ->assertHtml ($ expected , $ result );
311
- $ this ->paginator -> request = $ this ->paginator -> request ->withParam ('paging ' , [
322
+ $ this ->View -> setRequest ( $ this ->View -> getRequest () ->withParam ('paging ' , [
312
323
'Client ' => [
313
324
'page ' => 37 ,
314
325
'current ' => 15 ,
@@ -317,8 +328,8 @@ public function testNumbers()
317
328
'nextPage ' => 1 ,
318
329
'pageCount ' => 42 ,
319
330
]
320
- ]);
321
- $ result = $ this ->paginator ->numbers (['first ' => 1 , 'last ' => 1 ]);
331
+ ])) ;
332
+ $ result = $ this ->Paginator ->numbers (['first ' => 1 , 'last ' => 1 ]);
322
333
$ expected = [
323
334
['ul ' => ['class ' => 'pagination ' ]],
324
335
['li ' => []], ['a ' => ['href ' => '/index ' ]], '1 ' , '/a ' , '/li ' ,
@@ -345,7 +356,7 @@ public function testPrev() {
345
356
]],
346
357
['a ' => true ], '< ' , '/a ' ,
347
358
'/li '
348
- ], $ this ->paginator ->prev ('< ' ));
359
+ ], $ this ->Paginator ->prev ('< ' ));
349
360
$ this ->assertHtml ([
350
361
['li ' => [
351
362
'class ' => 'disabled '
@@ -356,7 +367,7 @@ public function testPrev() {
356
367
'aria-hidden ' => 'true '
357
368
]],
358
369
'/i ' , '/a ' , '/li '
359
- ], $ this ->paginator ->prev ('i:chevron-left ' ));
370
+ ], $ this ->Paginator ->prev ('i:chevron-left ' ));
360
371
}
361
372
362
373
public function testNext () {
@@ -366,7 +377,7 @@ public function testNext() {
366
377
'href ' => '/index?page=2 '
367
378
]], '> ' , '/a ' ,
368
379
'/li '
369
- ], $ this ->paginator ->next ('> ' ));
380
+ ], $ this ->Paginator ->next ('> ' ));
370
381
$ this ->assertHtml ([
371
382
['li ' => true ],
372
383
['a ' => [
@@ -377,7 +388,7 @@ public function testNext() {
377
388
'aria-hidden ' => 'true '
378
389
]],
379
390
'/i ' , '/a ' , '/li '
380
- ], $ this ->paginator ->next ('i:chevron-right ' ));
391
+ ], $ this ->Paginator ->next ('i:chevron-right ' ));
381
392
}
382
393
383
394
};
0 commit comments