1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagerfanta\Tests\View; |
4
|
|
|
|
5
|
|
|
use Pagerfanta\View\DefaultView; |
6
|
|
|
|
7
|
|
|
class DefaultViewTest extends ViewTestCase |
8
|
|
|
{ |
9
|
|
|
protected function createView() |
10
|
|
|
{ |
11
|
|
|
return new DefaultView(); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
public function testRenderNormal() |
15
|
|
|
{ |
16
|
|
|
$this->setNbPages(100); |
17
|
|
|
$this->setCurrentPage(10); |
18
|
|
|
|
19
|
|
|
$options = array(); |
20
|
|
|
|
21
|
|
|
$this->assertRenderedView(<<<EOF |
22
|
|
|
<nav> |
23
|
|
|
<a href="|9|" rel="prev">Previous</a> |
24
|
|
|
<a href="|1|">1</a> |
25
|
|
|
<span class="dots">...</span> |
26
|
|
|
<a href="|8|">8</a> |
27
|
|
|
<a href="|9|">9</a> |
28
|
|
|
<span class="current">10</span> |
29
|
|
|
<a href="|11|">11</a> |
30
|
|
|
<a href="|12|">12</a> |
31
|
|
|
<span class="dots">...</span> |
32
|
|
|
<a href="|100|">100</a> |
33
|
|
|
<a href="|11|" rel="next">Next</a> |
34
|
|
|
</nav> |
35
|
|
|
EOF |
36
|
|
|
, $this->renderView($options)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testRenderFirstPage() |
40
|
|
|
{ |
41
|
|
|
$this->setNbPages(100); |
42
|
|
|
$this->setCurrentPage(1); |
43
|
|
|
|
44
|
|
|
$options = array(); |
45
|
|
|
|
46
|
|
|
$this->assertRenderedView(<<<EOF |
47
|
|
|
<nav> |
48
|
|
|
<span class="disabled">Previous</span> |
49
|
|
|
<span class="current">1</span> |
50
|
|
|
<a href="|2|">2</a> |
51
|
|
|
<a href="|3|">3</a> |
52
|
|
|
<a href="|4|">4</a> |
53
|
|
|
<a href="|5|">5</a> |
54
|
|
|
<span class="dots">...</span> |
55
|
|
|
<a href="|100|">100</a> |
56
|
|
|
<a href="|2|" rel="next">Next</a> |
57
|
|
|
</nav> |
58
|
|
|
EOF |
59
|
|
|
, $this->renderView($options)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testRenderLastPage() |
63
|
|
|
{ |
64
|
|
|
$this->setNbPages(100); |
65
|
|
|
$this->setCurrentPage(100); |
66
|
|
|
|
67
|
|
|
$options = array(); |
68
|
|
|
|
69
|
|
|
$this->assertRenderedView(<<<EOF |
70
|
|
|
<nav> |
71
|
|
|
<a href="|99|" rel="prev">Previous</a> |
72
|
|
|
<a href="|1|">1</a> |
73
|
|
|
<span class="dots">...</span> |
74
|
|
|
<a href="|96|">96</a> |
75
|
|
|
<a href="|97|">97</a> |
76
|
|
|
<a href="|98|">98</a> |
77
|
|
|
<a href="|99|">99</a> |
78
|
|
|
<span class="current">100</span> |
79
|
|
|
<span class="disabled">Next</span> |
80
|
|
|
</nav> |
81
|
|
|
EOF |
82
|
|
|
, $this->renderView($options)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testRenderWhenStartProximityIs2() |
86
|
|
|
{ |
87
|
|
|
$this->setNbPages(100); |
88
|
|
|
$this->setCurrentPage(4); |
89
|
|
|
|
90
|
|
|
$options = array(); |
91
|
|
|
|
92
|
|
|
$this->assertRenderedView(<<<EOF |
93
|
|
|
<nav> |
94
|
|
|
<a href="|3|" rel="prev">Previous</a> |
95
|
|
|
<a href="|1|">1</a> |
96
|
|
|
<a href="|2|">2</a> |
97
|
|
|
<a href="|3|">3</a> |
98
|
|
|
<span class="current">4</span> |
99
|
|
|
<a href="|5|">5</a> |
100
|
|
|
<a href="|6|">6</a> |
101
|
|
|
<span class="dots">...</span> |
102
|
|
|
<a href="|100|">100</a> |
103
|
|
|
<a href="|5|" rel="next">Next</a> |
104
|
|
|
</nav> |
105
|
|
|
EOF |
106
|
|
|
, $this->renderView($options)); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testRenderWhenStartProximityIs3() |
110
|
|
|
{ |
111
|
|
|
$this->setNbPages(100); |
112
|
|
|
$this->setCurrentPage(5); |
113
|
|
|
|
114
|
|
|
$options = array(); |
115
|
|
|
|
116
|
|
|
$this->assertRenderedView(<<<EOF |
117
|
|
|
<nav> |
118
|
|
|
<a href="|4|" rel="prev">Previous</a> |
119
|
|
|
<a href="|1|">1</a> |
120
|
|
|
<a href="|2|">2</a> |
121
|
|
|
<a href="|3|">3</a> |
122
|
|
|
<a href="|4|">4</a> |
123
|
|
|
<span class="current">5</span> |
124
|
|
|
<a href="|6|">6</a> |
125
|
|
|
<a href="|7|">7</a> |
126
|
|
|
<span class="dots">...</span> |
127
|
|
|
<a href="|100|">100</a> |
128
|
|
|
<a href="|6|" rel="next">Next</a> |
129
|
|
|
</nav> |
130
|
|
|
EOF |
131
|
|
|
, $this->renderView($options)); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function testRenderWhenEndProximityIs2FromLast() |
135
|
|
|
{ |
136
|
|
|
$this->setNbPages(100); |
137
|
|
|
$this->setCurrentPage(97); |
138
|
|
|
|
139
|
|
|
$options = array(); |
140
|
|
|
|
141
|
|
|
$this->assertRenderedView(<<<EOF |
142
|
|
|
<nav> |
143
|
|
|
<a href="|96|" rel="prev">Previous</a> |
144
|
|
|
<a href="|1|">1</a> |
145
|
|
|
<span class="dots">...</span> |
146
|
|
|
<a href="|95|">95</a> |
147
|
|
|
<a href="|96|">96</a> |
148
|
|
|
<span class="current">97</span> |
149
|
|
|
<a href="|98|">98</a> |
150
|
|
|
<a href="|99|">99</a> |
151
|
|
|
<a href="|100|">100</a> |
152
|
|
|
<a href="|98|" rel="next">Next</a> |
153
|
|
|
</nav> |
154
|
|
|
EOF |
155
|
|
|
, $this->renderView($options)); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testRenderWhenEndProximityIs3FromLast() |
159
|
|
|
{ |
160
|
|
|
$this->setNbPages(100); |
161
|
|
|
$this->setCurrentPage(96); |
162
|
|
|
|
163
|
|
|
$options = array(); |
164
|
|
|
|
165
|
|
|
$this->assertRenderedView(<<<EOF |
166
|
|
|
<nav> |
167
|
|
|
<a href="|95|" rel="prev">Previous</a> |
168
|
|
|
<a href="|1|">1</a> |
169
|
|
|
<span class="dots">...</span> |
170
|
|
|
<a href="|94|">94</a> |
171
|
|
|
<a href="|95|">95</a> |
172
|
|
|
<span class="current">96</span> |
173
|
|
|
<a href="|97|">97</a> |
174
|
|
|
<a href="|98|">98</a> |
175
|
|
|
<a href="|99|">99</a> |
176
|
|
|
<a href="|100|">100</a> |
177
|
|
|
<a href="|97|" rel="next">Next</a> |
178
|
|
|
</nav> |
179
|
|
|
EOF |
180
|
|
|
, $this->renderView($options)); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function testRenderModifyingProximity() |
184
|
|
|
{ |
185
|
|
|
$this->setNbPages(100); |
186
|
|
|
$this->setCurrentPage(10); |
187
|
|
|
|
188
|
|
|
$options = array('proximity' => 3); |
189
|
|
|
|
190
|
|
|
$this->assertRenderedView(<<<EOF |
191
|
|
|
<nav> |
192
|
|
|
<a href="|9|" rel="prev">Previous</a> |
193
|
|
|
<a href="|1|">1</a> |
194
|
|
|
<span class="dots">...</span> |
195
|
|
|
<a href="|7|">7</a> |
196
|
|
|
<a href="|8|">8</a> |
197
|
|
|
<a href="|9|">9</a> |
198
|
|
|
<span class="current">10</span> |
199
|
|
|
<a href="|11|">11</a> |
200
|
|
|
<a href="|12|">12</a> |
201
|
|
|
<a href="|13|">13</a> |
202
|
|
|
<span class="dots">...</span> |
203
|
|
|
<a href="|100|">100</a> |
204
|
|
|
<a href="|11|" rel="next">Next</a> |
205
|
|
|
</nav> |
206
|
|
|
EOF |
207
|
|
|
, $this->renderView($options)); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function testRenderModifyingPreviousAndNextMessages() |
211
|
|
|
{ |
212
|
|
|
$this->setNbPages(100); |
213
|
|
|
$this->setCurrentPage(10); |
214
|
|
|
|
215
|
|
|
$options = array( |
216
|
|
|
'prev_message' => 'Anterior', |
217
|
|
|
'next_message' => 'Siguiente', |
218
|
|
|
); |
219
|
|
|
|
220
|
|
|
$this->assertRenderedView(<<<EOF |
221
|
|
|
<nav> |
222
|
|
|
<a href="|9|" rel="prev">Anterior</a> |
223
|
|
|
<a href="|1|">1</a> |
224
|
|
|
<span class="dots">...</span> |
225
|
|
|
<a href="|8|">8</a> |
226
|
|
|
<a href="|9|">9</a> |
227
|
|
|
<span class="current">10</span> |
228
|
|
|
<a href="|11|">11</a> |
229
|
|
|
<a href="|12|">12</a> |
230
|
|
|
<span class="dots">...</span> |
231
|
|
|
<a href="|100|">100</a> |
232
|
|
|
<a href="|11|" rel="next">Siguiente</a> |
233
|
|
|
</nav> |
234
|
|
|
EOF |
235
|
|
|
, $this->renderView($options)); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
public function testRenderModifyingCssClasses() |
239
|
|
|
{ |
240
|
|
|
$this->setNbPages(100); |
241
|
|
|
$this->setCurrentPage(1); |
242
|
|
|
|
243
|
|
|
$options = array( |
244
|
|
|
'css_disabled_class' => 'deshabilitado', |
245
|
|
|
'css_dots_class' => 'puntos', |
246
|
|
|
'css_current_class' => 'actual', |
247
|
|
|
); |
248
|
|
|
|
249
|
|
|
$this->assertRenderedView(<<<EOF |
250
|
|
|
<nav> |
251
|
|
|
<span class="deshabilitado">Previous</span> |
252
|
|
|
<span class="actual">1</span> |
253
|
|
|
<a href="|2|">2</a> |
254
|
|
|
<a href="|3|">3</a> |
255
|
|
|
<a href="|4|">4</a> |
256
|
|
|
<a href="|5|">5</a> |
257
|
|
|
<span class="puntos">...</span> |
258
|
|
|
<a href="|100|">100</a> |
259
|
|
|
<a href="|2|" rel="next">Next</a> |
260
|
|
|
</nav> |
261
|
|
|
EOF |
262
|
|
|
, $this->renderView($options)); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function testRenderModifiyingStringTemplate() |
266
|
|
|
{ |
267
|
|
|
$this->setNbPages(100); |
268
|
|
|
$this->setCurrentPage(1); |
269
|
|
|
|
270
|
|
|
$options = array( |
271
|
|
|
'container_template' => '<nav><ul>%pages%</ul></nav>', |
272
|
|
|
'page_template' => '<li><a href="%href%">%text%</a></li>', |
273
|
|
|
'span_template' => '<li><span class="%class%">%text%</span></li>', |
274
|
|
|
); |
275
|
|
|
|
276
|
|
|
$this->assertRenderedView(<<<EOF |
277
|
|
|
<nav> |
278
|
|
|
<ul> |
279
|
|
|
<li><span class="disabled">Previous</span></li> |
280
|
|
|
<li><span class="current">1</span></li> |
281
|
|
|
<li><a href="|2|">2</a></li> |
282
|
|
|
<li><a href="|3|">3</a></li> |
283
|
|
|
<li><a href="|4|">4</a></li> |
284
|
|
|
<li><a href="|5|">5</a></li> |
285
|
|
|
<li><span class="dots">...</span></li> |
286
|
|
|
<li><a href="|100|">100</a></li> |
287
|
|
|
<li><a href="|2|">Next</a></li> |
288
|
|
|
</ul> |
289
|
|
|
</nav> |
290
|
|
|
EOF |
291
|
|
|
, $this->renderView($options)); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
protected function filterExpectedView($expected) |
295
|
|
|
{ |
296
|
|
|
return $this->removeWhitespacesBetweenTags($expected); |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|