4
4
use BryanCrowe \ApiPagination \Controller \Component \ApiPaginationComponent ;
5
5
use BryanCrowe \ApiPagination \TestApp \Controller \ArticlesController ;
6
6
use Cake \Event \Event ;
7
- use Cake \Network \ Request ;
8
- use Cake \Network \Response ;
7
+ use Cake \Http \ ServerRequest as Request ;
8
+ use Cake \Http \Response ;
9
9
use Cake \ORM \TableRegistry ;
10
10
use Cake \TestSuite \TestCase ;
11
11
12
12
/**
13
13
* ApiPaginationComponentTest class
14
+ *
15
+ * @property ArticlesController $controller
14
16
*/
15
17
class ApiPaginationComponentTest extends TestCase
16
18
{
@@ -24,7 +26,7 @@ class ApiPaginationComponentTest extends TestCase
24
26
public function setUp ()
25
27
{
26
28
$ this ->request = new Request ('/articles ' );
27
- $ this ->response = $ this ->getMock ('Cake\Network \Response ' );
29
+ $ this ->response = $ this ->createMock ('Cake\Http \Response ' );
28
30
$ this ->controller = new ArticlesController ($ this ->request , $ this ->response );
29
31
$ this ->Articles = TableRegistry::get ('BryanCrowe/ApiPagination.Articles ' , ['table ' => 'bryancrowe_articles ' ]);
30
32
parent ::setUp ();
@@ -61,7 +63,7 @@ public function testNonApiPaginatedRequest()
61
63
*/
62
64
public function testDefaultPaginationSettings ()
63
65
{
64
- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
66
+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
65
67
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
66
68
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components ());
67
69
$ event = new Event ('Controller.beforeRender ' , $ this ->controller );
@@ -81,7 +83,9 @@ public function testDefaultPaginationSettings()
81
83
'direction ' => false ,
82
84
'limit ' => null ,
83
85
'sortDefault ' => false ,
84
- 'directionDefault ' => false
86
+ 'directionDefault ' => false ,
87
+ 'scope ' => null ,
88
+ 'completeSort ' => []
85
89
];
86
90
87
91
$ this ->assertSame ($ expected , $ result );
@@ -94,7 +98,7 @@ public function testDefaultPaginationSettings()
94
98
*/
95
99
public function testVisibilitySettings ()
96
100
{
97
- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
101
+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
98
102
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
99
103
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
100
104
'visible ' => [
@@ -129,7 +133,7 @@ public function testVisibilitySettings()
129
133
*/
130
134
public function testAliasSettings ()
131
135
{
132
- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
136
+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
133
137
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
134
138
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
135
139
'aliases ' => [
@@ -153,6 +157,8 @@ public function testAliasSettings()
153
157
'limit ' => null ,
154
158
'sortDefault ' => false ,
155
159
'directionDefault ' => false ,
160
+ 'scope ' => null ,
161
+ 'completeSort ' => [],
156
162
'curPage ' => 1 ,
157
163
'currentCount ' => 20 ,
158
164
'totalCount ' => 23 ,
@@ -168,7 +174,7 @@ public function testAliasSettings()
168
174
*/
169
175
public function testKeySetting ()
170
176
{
171
- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
177
+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
172
178
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
173
179
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
174
180
'key ' => 'paging '
@@ -190,7 +196,9 @@ public function testKeySetting()
190
196
'direction ' => false ,
191
197
'limit ' => null ,
192
198
'sortDefault ' => false ,
193
- 'directionDefault ' => false
199
+ 'directionDefault ' => false ,
200
+ 'scope ' => null ,
201
+ 'completeSort ' => []
194
202
];
195
203
196
204
$ this ->assertSame ($ expected , $ result );
@@ -203,7 +211,7 @@ public function testKeySetting()
203
211
*/
204
212
public function testAllSettings ()
205
213
{
206
- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
214
+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
207
215
$ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
208
216
$ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
209
217
'key ' => 'fun ' ,
0 commit comments