@@ -25,6 +25,7 @@ public function setUp()
25
25
{
26
26
$ this ->request = new Request ('/articles ' );
27
27
$ this ->response = $ this ->getMock ('Cake\Network\Response ' );
28
+ $ this ->controller = new ArticlesController ($ this ->request , $ this ->response );
28
29
$ this ->Articles = TableRegistry::get ('BryanCrowe/ApiPagination.Articles ' , ['table ' => 'bryancrowe_articles ' ]);
29
30
parent ::setUp ();
30
31
}
@@ -46,9 +47,8 @@ public function tearDown()
46
47
*/
47
48
public function testNonApiPaginatedRequest ()
48
49
{
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 );
52
52
53
53
$ this ->assertNull ($ apiPaginationComponent ->beforeRender ($ event ));
54
54
}
@@ -62,10 +62,9 @@ public function testNonApiPaginatedRequest()
62
62
public function testDefaultPaginationSettings ()
63
63
{
64
64
$ 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 );
69
68
$ apiPaginationComponent ->beforeRender ($ event );
70
69
71
70
$ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['pagination ' ];
@@ -96,9 +95,8 @@ public function testDefaultPaginationSettings()
96
95
public function testVisibilitySettings ()
97
96
{
98
97
$ 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 (), [
102
100
'visible ' => [
103
101
'page ' ,
104
102
'current ' ,
@@ -108,7 +106,7 @@ public function testVisibilitySettings()
108
106
'pageCount '
109
107
]
110
108
]);
111
- $ event = new Event ('Controller.beforeRender ' , $ controller );
109
+ $ event = new Event ('Controller.beforeRender ' , $ this -> controller );
112
110
$ apiPaginationComponent ->beforeRender ($ event );
113
111
114
112
$ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['pagination ' ];
@@ -132,16 +130,15 @@ public function testVisibilitySettings()
132
130
public function testAliasSettings ()
133
131
{
134
132
$ 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 (), [
138
135
'aliases ' => [
139
136
'page ' => 'curPage ' ,
140
137
'current ' => 'currentCount ' ,
141
138
'count ' => 'totalCount ' ,
142
139
]
143
140
]);
144
- $ event = new Event ('Controller.beforeRender ' , $ controller );
141
+ $ event = new Event ('Controller.beforeRender ' , $ this -> controller );
145
142
$ apiPaginationComponent ->beforeRender ($ event );
146
143
147
144
$ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['pagination ' ];
@@ -172,12 +169,11 @@ public function testAliasSettings()
172
169
public function testKeySetting ()
173
170
{
174
171
$ 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 (), [
178
174
'key ' => 'paging '
179
175
]);
180
- $ event = new Event ('Controller.beforeRender ' , $ controller );
176
+ $ event = new Event ('Controller.beforeRender ' , $ this -> controller );
181
177
$ apiPaginationComponent ->beforeRender ($ event );
182
178
183
179
$ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['paging ' ];
@@ -208,9 +204,8 @@ public function testKeySetting()
208
204
public function testAllSettings ()
209
205
{
210
206
$ 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 (), [
214
209
'key ' => 'fun ' ,
215
210
'aliases ' => [
216
211
'page ' => 'currentPage ' ,
@@ -225,7 +220,7 @@ public function testAllSettings()
225
220
'nextPage '
226
221
]
227
222
]);
228
- $ event = new Event ('Controller.beforeRender ' , $ controller );
223
+ $ event = new Event ('Controller.beforeRender ' , $ this -> controller );
229
224
$ apiPaginationComponent ->beforeRender ($ event );
230
225
231
226
$ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['fun ' ];
0 commit comments