@@ -78,4 +78,107 @@ public function testDefaultPaginationSettings()
78
78
79
79
$ this ->assertSame ($ expected , $ result );
80
80
}
81
+
82
+ public function testVisibilitySettings ()
83
+ {
84
+ $ request = new Request ('/articles ' );
85
+ $ request ->env ('HTTP_ACCEPT ' , 'application/json ' );
86
+ $ response = $ this ->getMock ('Cake\Network\Response ' );
87
+ $ controller = new ArticlesController ($ request , $ response );
88
+ $ controller ->set ('data ' , $ controller ->paginate ($ this ->Articles ));
89
+ $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components (), [
90
+ 'visible ' => [
91
+ 'page ' ,
92
+ 'current ' ,
93
+ 'count ' ,
94
+ 'prevPage ' ,
95
+ 'nextPage ' ,
96
+ 'pageCount '
97
+ ]
98
+ ]);
99
+ $ event = new Event ('Controller.beforeRender ' , $ controller );
100
+ $ apiPaginationComponent ->beforeRender ($ event );
101
+
102
+ $ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['pagination ' ];
103
+ $ expected = [
104
+ 'page ' => 1 ,
105
+ 'current ' => 20 ,
106
+ 'count ' => 23 ,
107
+ 'prevPage ' => false ,
108
+ 'nextPage ' => true ,
109
+ 'pageCount ' => 2
110
+ ];
111
+
112
+ $ this ->assertSame ($ expected , $ result );
113
+ }
114
+
115
+ public function testAliasSettings ()
116
+ {
117
+ $ request = new Request ('/articles ' );
118
+ $ request ->env ('HTTP_ACCEPT ' , 'application/json ' );
119
+ $ response = $ this ->getMock ('Cake\Network\Response ' );
120
+ $ controller = new ArticlesController ($ request , $ response );
121
+ $ controller ->set ('data ' , $ controller ->paginate ($ this ->Articles ));
122
+ $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components (), [
123
+ 'aliases ' => [
124
+ 'page ' => 'curPage ' ,
125
+ 'current ' => 'currentCount ' ,
126
+ 'count ' => 'totalCount ' ,
127
+ ]
128
+ ]);
129
+ $ event = new Event ('Controller.beforeRender ' , $ controller );
130
+ $ apiPaginationComponent ->beforeRender ($ event );
131
+
132
+ $ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['pagination ' ];
133
+ $ expected = [
134
+ 'finder ' => 'all ' ,
135
+ 'perPage ' => 20 ,
136
+ 'prevPage ' => false ,
137
+ 'nextPage ' => true ,
138
+ 'pageCount ' => 2 ,
139
+ 'sort ' => null ,
140
+ 'direction ' => false ,
141
+ 'limit ' => null ,
142
+ 'sortDefault ' => false ,
143
+ 'directionDefault ' => false ,
144
+ 'curPage ' => 1 ,
145
+ 'currentCount ' => 20 ,
146
+ 'totalCount ' => 23 ,
147
+ ];
148
+
149
+ $ this ->assertSame ($ expected , $ result );
150
+ }
151
+
152
+ public function testKeySetting ()
153
+ {
154
+ $ request = new Request ('/articles ' );
155
+ $ request ->env ('HTTP_ACCEPT ' , 'application/json ' );
156
+ $ response = $ this ->getMock ('Cake\Network\Response ' );
157
+ $ controller = new ArticlesController ($ request , $ response );
158
+ $ controller ->set ('data ' , $ controller ->paginate ($ this ->Articles ));
159
+ $ apiPaginationComponent = new ApiPaginationComponent ($ controller ->components (), [
160
+ 'key ' => 'paging '
161
+ ]);
162
+ $ event = new Event ('Controller.beforeRender ' , $ controller );
163
+ $ apiPaginationComponent ->beforeRender ($ event );
164
+
165
+ $ result = $ apiPaginationComponent ->_registry ->getController ()->viewVars ['paging ' ];
166
+ $ expected = [
167
+ 'finder ' => 'all ' ,
168
+ 'page ' => 1 ,
169
+ 'current ' => 20 ,
170
+ 'count ' => 23 ,
171
+ 'perPage ' => 20 ,
172
+ 'prevPage ' => false ,
173
+ 'nextPage ' => true ,
174
+ 'pageCount ' => 2 ,
175
+ 'sort ' => null ,
176
+ 'direction ' => false ,
177
+ 'limit ' => null ,
178
+ 'sortDefault ' => false ,
179
+ 'directionDefault ' => false
180
+ ];
181
+
182
+ $ this ->assertSame ($ expected , $ result );
183
+ }
81
184
}
0 commit comments