44use BryanCrowe \ApiPagination \Controller \Component \ApiPaginationComponent ;
55use BryanCrowe \ApiPagination \TestApp \Controller \ArticlesController ;
66use 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 ;
99use Cake \ORM \TableRegistry ;
1010use Cake \TestSuite \TestCase ;
1111
1212/**
1313 * ApiPaginationComponentTest class
14+ *
15+ * @property ArticlesController $controller
1416 */
1517class ApiPaginationComponentTest extends TestCase
1618{
@@ -24,7 +26,7 @@ class ApiPaginationComponentTest extends TestCase
2426 public function setUp ()
2527 {
2628 $ this ->request = new Request ('/articles ' );
27- $ this ->response = $ this ->getMock ('Cake\Network \Response ' );
29+ $ this ->response = $ this ->createMock ('Cake\Http \Response ' );
2830 $ this ->controller = new ArticlesController ($ this ->request , $ this ->response );
2931 $ this ->Articles = TableRegistry::get ('BryanCrowe/ApiPagination.Articles ' , ['table ' => 'bryancrowe_articles ' ]);
3032 parent ::setUp ();
@@ -61,7 +63,7 @@ public function testNonApiPaginatedRequest()
6163 */
6264 public function testDefaultPaginationSettings ()
6365 {
64- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
66+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
6567 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
6668 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components ());
6769 $ event = new Event ('Controller.beforeRender ' , $ this ->controller );
@@ -81,7 +83,9 @@ public function testDefaultPaginationSettings()
8183 'direction ' => false ,
8284 'limit ' => null ,
8385 'sortDefault ' => false ,
84- 'directionDefault ' => false
86+ 'directionDefault ' => false ,
87+ 'scope ' => null ,
88+ 'completeSort ' => []
8589 ];
8690
8791 $ this ->assertSame ($ expected , $ result );
@@ -94,7 +98,7 @@ public function testDefaultPaginationSettings()
9498 */
9599 public function testVisibilitySettings ()
96100 {
97- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
101+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
98102 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
99103 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
100104 'visible ' => [
@@ -129,7 +133,7 @@ public function testVisibilitySettings()
129133 */
130134 public function testAliasSettings ()
131135 {
132- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
136+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
133137 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
134138 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
135139 'aliases ' => [
@@ -153,6 +157,8 @@ public function testAliasSettings()
153157 'limit ' => null ,
154158 'sortDefault ' => false ,
155159 'directionDefault ' => false ,
160+ 'scope ' => null ,
161+ 'completeSort ' => [],
156162 'curPage ' => 1 ,
157163 'currentCount ' => 20 ,
158164 'totalCount ' => 23 ,
@@ -168,7 +174,7 @@ public function testAliasSettings()
168174 */
169175 public function testKeySetting ()
170176 {
171- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
177+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
172178 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
173179 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
174180 'key ' => 'paging '
@@ -190,7 +196,9 @@ public function testKeySetting()
190196 'direction ' => false ,
191197 'limit ' => null ,
192198 'sortDefault ' => false ,
193- 'directionDefault ' => false
199+ 'directionDefault ' => false ,
200+ 'scope ' => null ,
201+ 'completeSort ' => []
194202 ];
195203
196204 $ this ->assertSame ($ expected , $ result );
@@ -203,7 +211,7 @@ public function testKeySetting()
203211 */
204212 public function testAllSettings ()
205213 {
206- $ this ->request -> env ('HTTP_ACCEPT ' , 'application/json ' );
214+ $ this ->controller -> request = $ this -> controller -> request -> withEnv ('HTTP_ACCEPT ' , 'application/json ' );
207215 $ this ->controller ->set ('data ' , $ this ->controller ->paginate ($ this ->Articles ));
208216 $ apiPaginationComponent = new ApiPaginationComponent ($ this ->controller ->components (), [
209217 'key ' => 'fun ' ,
0 commit comments