| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Id: pager_test.php,v 1.35 2008/05/31 12:45:25 quipo Exp $
|
|
|
3 |
|
|
|
4 |
require_once 'simple_include.php';
|
|
|
5 |
require_once 'pager_include.php';
|
|
|
6 |
|
|
|
7 |
class TestOfPager extends UnitTestCase {
|
|
|
8 |
var $pager;
|
|
|
9 |
var $baseurl;
|
|
|
10 |
function TestOfPager($name='Test of Pager') {
|
|
|
11 |
$this->UnitTestCase($name);
|
|
|
12 |
}
|
|
|
13 |
function setUp() {
|
|
|
14 |
$options = array(
|
|
|
15 |
'itemData' => range(1, 10),
|
|
|
16 |
'perPage' => 5,
|
|
|
17 |
);
|
|
|
18 |
$this->pager = Pager::factory($options);
|
|
|
19 |
$this->baseurl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
|
|
|
20 |
}
|
|
|
21 |
function tearDown() {
|
|
|
22 |
unset($this->pager);
|
|
|
23 |
}
|
|
|
24 |
function testCurrentPageID() {
|
|
|
25 |
$this->assertEqual(1, $this->pager->getCurrentPageID());
|
|
|
26 |
}
|
|
|
27 |
function testNextPageID() {
|
|
|
28 |
$this->assertEqual(2, $this->pager->getNextPageID());
|
|
|
29 |
}
|
|
|
30 |
function testPrevPageID() {
|
|
|
31 |
$this->assertEqual(false, $this->pager->getPreviousPageID());
|
|
|
32 |
}
|
|
|
33 |
function testNumItems() {
|
|
|
34 |
$this->assertEqual(10, $this->pager->numItems());
|
|
|
35 |
}
|
|
|
36 |
function testNumPages() {
|
|
|
37 |
$this->assertEqual(2, $this->pager->numPages());
|
|
|
38 |
}
|
|
|
39 |
function testFirstPage() {
|
|
|
40 |
$this->assertEqual(true, $this->pager->isFirstPage());
|
|
|
41 |
}
|
|
|
42 |
function testLastPage() {
|
|
|
43 |
$this->assertEqual(false, $this->pager->isLastPage());
|
|
|
44 |
}
|
|
|
45 |
function testLastPageComplete() {
|
|
|
46 |
$this->assertEqual(true, $this->pager->isLastPageComplete());
|
|
|
47 |
}
|
|
|
48 |
function testOffsetByPageId() {
|
|
|
49 |
$this->assertEqual(array(1, 5), $this->pager->getOffsetByPageId(1));
|
|
|
50 |
$this->assertEqual(array(6, 10), $this->pager->getOffsetByPageId(2));
|
|
|
51 |
}
|
|
|
52 |
function testOffsetByPageId_outOfRange() {
|
|
|
53 |
$this->assertEqual(array(0, 0), $this->pager->getOffsetByPageId(20));
|
|
|
54 |
}
|
|
|
55 |
function testGetPageData() {
|
|
|
56 |
$this->assertEqual(array(0=>1, 1=>2, 2=>3, 3=>4, 4=>5), $this->pager->getPageData());
|
|
|
57 |
$this->assertEqual(array(5=>6, 6=>7, 7=>8, 8=>9, 9=>10), $this->pager->getPageData(2));
|
|
|
58 |
}
|
|
|
59 |
function testGetPageData_OutOfRange() {
|
|
|
60 |
$this->assertEqual(array(), $this->pager->getPageData(3));
|
|
|
61 |
}
|
|
|
62 |
function testSelectBox() {
|
|
|
63 |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">';
|
|
|
64 |
$selectBox .= '<option value="5" selected="selected">5</option>';
|
|
|
65 |
$selectBox .= '<option value="10">10</option>';
|
|
|
66 |
$selectBox .= '<option value="15">15</option>';
|
|
|
67 |
$selectBox .= '</select>';
|
|
|
68 |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5));
|
|
|
69 |
}
|
|
|
70 |
function testSelectBoxWithString() {
|
|
|
71 |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">';
|
|
|
72 |
$selectBox .= '<option value="5" selected="selected">5 bugs</option>';
|
|
|
73 |
$selectBox .= '<option value="10">10 bugs</option>';
|
|
|
74 |
$selectBox .= '<option value="15">15 bugs</option>';
|
|
|
75 |
$selectBox .= '</select>';
|
|
|
76 |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5, false, '%d bugs'));
|
|
|
77 |
}
|
|
|
78 |
function testSelectBoxWithShowAll() {
|
|
|
79 |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">';
|
|
|
80 |
$selectBox .= '<option value="3">3</option>';
|
|
|
81 |
$selectBox .= '<option value="4">4</option>';
|
|
|
82 |
$selectBox .= '<option value="5" selected="selected">5</option>';
|
|
|
83 |
$selectBox .= '<option value="6">6</option>';
|
|
|
84 |
$selectBox .= '<option value="10">10</option>';
|
|
|
85 |
$selectBox .= '</select>';
|
|
|
86 |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true));
|
|
|
87 |
}
|
|
|
88 |
function testSelectBoxWithShowAllAndText() {
|
|
|
89 |
$this->pager->_showAllText = 'Show All';
|
|
|
90 |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">';
|
|
|
91 |
$selectBox .= '<option value="3">3 bugs</option>';
|
|
|
92 |
$selectBox .= '<option value="4">4 bugs</option>';
|
|
|
93 |
$selectBox .= '<option value="5" selected="selected">5 bugs</option>';
|
|
|
94 |
$selectBox .= '<option value="6">6 bugs</option>';
|
|
|
95 |
$selectBox .= '<option value="'.max($this->pager->_itemData).'">Show All</option>';
|
|
|
96 |
$selectBox .= '</select>';
|
|
|
97 |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true, '%d bugs'));
|
|
|
98 |
}
|
|
|
99 |
function testSelectBoxWithShowAllWithExtraAttribs() {
|
|
|
100 |
$options = array(
|
|
|
101 |
'itemData' => range(1, 14),
|
|
|
102 |
'perPage' => 5,
|
|
|
103 |
);
|
|
|
104 |
$this->pager = Pager::factory($options);
|
|
|
105 |
$this->pager->_showAllText = 'Show All';
|
|
|
106 |
$selectBox = '<select name="'.$this->pager->_sessionVar.'" onmouseover="doSth">';
|
|
|
107 |
$selectBox .= '<option value="5" selected="selected">5 bugs</option>';
|
|
|
108 |
$selectBox .= '<option value="10">10 bugs</option>';
|
|
|
109 |
$selectBox .= '<option value="'.max($this->pager->_itemData).'">Show All</option>';
|
|
|
110 |
$selectBox .= '</select>';
|
|
|
111 |
$params = array(
|
|
|
112 |
'optionText' => '%d bugs',
|
|
|
113 |
'attributes' => 'onmouseover="doSth"',
|
|
|
114 |
'checkMaxLimit' => true,
|
|
|
115 |
);
|
|
|
116 |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5, true, $params));
|
|
|
117 |
}
|
|
|
118 |
function testSelectBoxWithShowAllAndFewValues() {
|
|
|
119 |
//test getPerPagerSelectBox() with $showAllData = true and $start > $totalItems
|
|
|
120 |
$options = array(
|
|
|
121 |
'itemData' => range(1, 5),
|
|
|
122 |
'perPage' => 5,
|
|
|
123 |
'showAllText' => 'Show All',
|
|
|
124 |
);
|
|
|
125 |
$this->pager = Pager::factory($options);
|
|
|
126 |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">';
|
|
|
127 |
$selectBox .= '<option value="'.max($this->pager->_itemData).'" selected="selected">Show All</option>';
|
|
|
128 |
$selectBox .= '</select>';
|
|
|
129 |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(25, 30, 1, true, array('checkMaxLimit' => true)));
|
|
|
130 |
}
|
|
|
131 |
function testSelectBoxInvalid() {
|
|
|
132 |
$err = $this->pager->getPerPageSelectBox(5, 15, 5, false, '%s bugs');
|
|
|
133 |
$this->assertEqual(ERROR_PAGER_INVALID_PLACEHOLDER, $err->getCode());
|
|
|
134 |
}
|
|
|
135 |
function testSelectBoxEmpty() {
|
|
|
136 |
$options = array(
|
|
|
137 |
'itemData' => array(),
|
|
|
138 |
'totalItems' => 0,
|
|
|
139 |
);
|
|
|
140 |
$this->pager = Pager::factory($options);
|
|
|
141 |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">';
|
|
|
142 |
$selectBox .= '<option />';
|
|
|
143 |
$selectBox .= '</select>';
|
|
|
144 |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5, false, array('checkMaxLimit' => true)));
|
|
|
145 |
}
|
|
|
146 |
function testAppendInvalid() {
|
|
|
147 |
$options = array(
|
|
|
148 |
'totalItems' => 10,
|
|
|
149 |
'append' => false,
|
|
|
150 |
'fileName' => 'invalidFileName'
|
|
|
151 |
);
|
|
|
152 |
$err =& Pager::factory($options); //ERROR_PAGER_INVALID_USAGE
|
|
|
153 |
$this->assertError();
|
|
|
154 |
}
|
|
|
155 |
function testAppendValid() {
|
|
|
156 |
$options = array(
|
|
|
157 |
'totalItems' => 10,
|
|
|
158 |
'append' => false,
|
|
|
159 |
'fileName' => 'valid_%d_FileName'
|
|
|
160 |
);
|
|
|
161 |
$err =& Pager::factory($options);
|
|
|
162 |
$this->assertNoErrors();
|
|
|
163 |
}
|
|
|
164 |
function testEscapeEntities() {
|
|
|
165 |
//encode special chars
|
|
|
166 |
$options = array(
|
|
|
167 |
'extraVars' => array(
|
|
|
168 |
'request' => array('aRequest'),
|
|
|
169 |
'escape' => 'äö%<>+',
|
|
|
170 |
),
|
|
|
171 |
'perPage' => 5,
|
|
|
172 |
);
|
|
|
173 |
$this->pager =& Pager::factory($options);
|
|
|
174 |
//$expected = '?request[]=aRequest&escape=äö%<>+&pageID=';
|
|
|
175 |
//$this->assertEqual($expected, $this->pager->_getLinksUrl());
|
|
|
176 |
|
|
|
177 |
$expected = 'request%5B0%5D=aRequest&escape=%E4%F6%25%3C%3E%2B';
|
|
|
178 |
if (1 == version_compare(PHP_VERSION, '5.2.99')) {
|
|
|
179 |
$expected = 'request%5B0%5D=aRequest&escape=%C3%A4%C3%B6%25%3C%3E%2B';
|
|
|
180 |
}
|
|
|
181 |
$rendered = $this->pager->_renderLink('', '');
|
|
|
182 |
preg_match('/href="(.*)"/U', $rendered, $matches);
|
|
|
183 |
$actual = str_replace($_SERVER['PHP_SELF'].'?', '', $matches[1]);
|
|
|
184 |
$this->assertEqual($expected, $actual);
|
|
|
185 |
|
|
|
186 |
//don't encode slashes
|
|
|
187 |
$options = array(
|
|
|
188 |
'extraVars' => array(
|
|
|
189 |
'request' => 'cat/subcat',
|
|
|
190 |
),
|
|
|
191 |
'perPage' => 5,
|
|
|
192 |
);
|
|
|
193 |
$this->pager =& Pager::factory($options);
|
|
|
194 |
//$expected = '?request=cat/subcat&pageID=';
|
|
|
195 |
//$this->assertEqual($expected, $this->pager->_getLinksUrl());
|
|
|
196 |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?request=cat/subcat" title=""></a>';
|
|
|
197 |
$actual = $this->pager->_renderLink('', '');
|
|
|
198 |
$this->assertEqual($expected, $actual);
|
|
|
199 |
}
|
|
|
200 |
function testMultibyteStrings() {
|
|
|
201 |
$options = array(
|
|
|
202 |
'extraVars' => array(
|
|
|
203 |
'test' => '测试',
|
|
|
204 |
),
|
|
|
205 |
'perPage' => 5,
|
|
|
206 |
);
|
|
|
207 |
$this->pager =& Pager::factory($options);
|
|
|
208 |
//$expected = '<a href="'.$_SERVER['PHP_SELF'].'?test=测试" title=""></a>';
|
|
|
209 |
$rendered = $this->pager->_renderLink('', '');
|
|
|
210 |
preg_match('/href="(.*)"/U', $rendered, $matches);
|
|
|
211 |
$actual = str_replace($_SERVER['PHP_SELF'].'?test=', '', $matches[1]);
|
|
|
212 |
$this->assertEqual(urlencode($options['extraVars']['test']), $actual);
|
|
|
213 |
}
|
|
|
214 |
function testMultibyteJapaneseStrings() {
|
|
|
215 |
$options = array(
|
|
|
216 |
'extraVars' => array(
|
|
|
217 |
'test' => '漢字',
|
|
|
218 |
),
|
|
|
219 |
'perPage' => 5,
|
|
|
220 |
);
|
|
|
221 |
$this->pager =& Pager::factory($options);
|
|
|
222 |
//$expected = '<a href="'.$_SERVER['PHP_SELF'].'?test=测试" title=""></a>';
|
|
|
223 |
$rendered = $this->pager->_renderLink('', '');
|
|
|
224 |
preg_match('/href="(.*)"/U', $rendered, $matches);
|
|
|
225 |
$actual = str_replace($_SERVER['PHP_SELF'].'?test=', '', $matches[1]);
|
|
|
226 |
$this->assertEqual(urlencode($options['extraVars']['test']), $actual);
|
|
|
227 |
}
|
|
|
228 |
function testCurrentPage() {
|
|
|
229 |
$options = array(
|
|
|
230 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
231 |
'perPage' => 2,
|
|
|
232 |
'currentPage' => 2,
|
|
|
233 |
);
|
|
|
234 |
$this->pager =& Pager::factory($options);
|
|
|
235 |
$this->assertEqual(3, $this->pager->getNextPageID());
|
|
|
236 |
$this->assertEqual(1, $this->pager->getPreviousPageID());
|
|
|
237 |
$this->assertEqual(2, $this->pager->_currentPage);
|
|
|
238 |
}
|
|
|
239 |
function testArrayExtraVars() {
|
|
|
240 |
$arr = array(
|
|
|
241 |
'apple',
|
|
|
242 |
'orange',
|
|
|
243 |
);
|
|
|
244 |
$options = array(
|
|
|
245 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
246 |
'perPage' => 5,
|
|
|
247 |
'extraVars' => array('arr' => $arr, 'no' => 'test'),
|
|
|
248 |
);
|
|
|
249 |
$this->pager =& Pager::factory($options);
|
|
|
250 |
/*
|
|
|
251 |
//old
|
|
|
252 |
$expected = '?arr[0]=apple&arr[1]=orange&pageID=';
|
|
|
253 |
$this->assertEqual($expected, $this->pager->_getLinksUrl());
|
|
|
254 |
*/
|
|
|
255 |
$expected = $options['extraVars'];
|
|
|
256 |
$this->assertEqual($expected, $this->pager->_getLinksData());
|
|
|
257 |
$separator = ini_get('arg_separator.output');
|
|
|
258 |
if ($separator == '&') {
|
|
|
259 |
$separator = '&';
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?arr%5B0%5D=apple'.$separator.'arr%5B1%5D=orange'.$separator.'no=test'.$separator.'pageID=2" title=""></a>';
|
|
|
263 |
$actual = $this->pager->_renderLink('', '');
|
|
|
264 |
$this->assertEqual($expected, $actual);
|
|
|
265 |
}
|
|
|
266 |
function testExcludeVars() {
|
|
|
267 |
$_GET['excludeMe'] = 'foo';
|
|
|
268 |
$extraVars = array(
|
|
|
269 |
'arr' => array(
|
|
|
270 |
'apple',
|
|
|
271 |
'orange',
|
|
|
272 |
),
|
|
|
273 |
'no' => 'test', // do not remove this one, because it has been explicitely added
|
|
|
274 |
);
|
|
|
275 |
$excludeVars = array(
|
|
|
276 |
'no', // do not remove, @see above
|
|
|
277 |
'excludeMe', //remove
|
|
|
278 |
);
|
|
|
279 |
$options = array(
|
|
|
280 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
281 |
'perPage' => 5,
|
|
|
282 |
'extraVars' => $extraVars,
|
|
|
283 |
'excludeVars' => $excludeVars,
|
|
|
284 |
);
|
|
|
285 |
$this->pager =& Pager::factory($options);
|
|
|
286 |
$expected = array(
|
|
|
287 |
'arr' => array(
|
|
|
288 |
|
|
|
289 |
1 => 'orange'
|
|
|
290 |
),
|
|
|
291 |
'no' => 'test',
|
|
|
292 |
);
|
|
|
293 |
$actual = $this->pager->_getLinksData();
|
|
|
294 |
$this->assertEqual($expected, $actual);
|
|
|
295 |
$separator = ini_get('arg_separator.output');
|
|
|
296 |
if ($separator == '&') {
|
|
|
297 |
$separator = '&';
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?arr%5B0%5D=apple'.$separator.'arr%5B1%5D=orange'.$separator.'no=test'.$separator.'pageID=2" title=""></a>';
|
|
|
301 |
$actual = $this->pager->_renderLink('', '');
|
|
|
302 |
$this->assertEqual($expected, $actual);
|
|
|
303 |
unset($_GET['excludeMe']); //cleanup
|
|
|
304 |
|
|
|
305 |
//exclude with regexp
|
|
|
306 |
|
|
|
307 |
$_GET['reMoveAAA'] = 'aaa';
|
|
|
308 |
$_GET['RemoveBBB'] = 'bbb';
|
|
|
309 |
$_GET['leaveCCC'] = 'ccc';
|
|
|
310 |
$excludeVars = array(
|
|
|
311 |
'/remove.*/i', //regexp
|
|
|
312 |
);
|
|
|
313 |
$options = array(
|
|
|
314 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
315 |
'perPage' => 5,
|
|
|
316 |
'extraVars' => $extraVars,
|
|
|
317 |
'excludeVars' => $excludeVars,
|
|
|
318 |
);
|
|
|
319 |
$this->pager =& Pager::factory($options);
|
|
|
320 |
$expected = array(
|
|
|
321 |
'arr' => array(
|
|
|
322 |
|
|
|
323 |
1 => 'orange'
|
|
|
324 |
),
|
|
|
325 |
'no' => 'test',
|
|
|
326 |
'leaveCCC' => 'ccc',
|
|
|
327 |
);
|
|
|
328 |
$this->assertEqual($expected, $this->pager->_getLinksData());
|
|
|
329 |
//cleanup
|
|
|
330 |
foreach (array_keys($_GET) as $k) {
|
|
|
331 |
unset($_GET[$k]);
|
|
|
332 |
}
|
|
|
333 |
}
|
|
|
334 |
function testArgSeparator() {
|
|
|
335 |
$bkp_arg_separator = ini_get('arg_separator.output');
|
|
|
336 |
ini_set('arg_separator.output', '&');
|
|
|
337 |
|
|
|
338 |
$options = array(
|
|
|
339 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
340 |
'perPage' => 5,
|
|
|
341 |
'extraVars' => array('apple' => 1),
|
|
|
342 |
);
|
|
|
343 |
$this->pager =& Pager::factory($options);
|
|
|
344 |
|
|
|
345 |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?apple=1&pageID=2" title=""></a>';
|
|
|
346 |
$actual = $this->pager->_renderLink('', '');
|
|
|
347 |
$this->assertEqual($expected, $actual);
|
|
|
348 |
|
|
|
349 |
ini_set('arg_separator.output', $bkp_arg_separator);
|
|
|
350 |
}
|
|
|
351 |
function testAttributes() {
|
|
|
352 |
$options = array(
|
|
|
353 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
354 |
'perPage' => 5,
|
|
|
355 |
'linkClass' => 'testclass',
|
|
|
356 |
'attributes' => 'target="_blank"',
|
|
|
357 |
);
|
|
|
358 |
$this->pager =& Pager::factory($options);
|
|
|
359 |
|
|
|
360 |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?pageID=2" class="testclass" target="_blank" title=""></a>';
|
|
|
361 |
$actual = $this->pager->_renderLink('', '');
|
|
|
362 |
$this->assertEqual($expected, $actual);
|
|
|
363 |
}
|
|
|
364 |
function testOnClick() {
|
|
|
365 |
$options = array(
|
|
|
366 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
367 |
'perPage' => 5,
|
|
|
368 |
'linkClass' => 'testclass',
|
|
|
369 |
'onclick' => 'doSomething(%d)',
|
|
|
370 |
);
|
|
|
371 |
$this->pager =& Pager::factory($options);
|
|
|
372 |
|
|
|
373 |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?pageID=2" class="testclass" onclick="doSomething(2)" title=""></a>';
|
|
|
374 |
$actual = $this->pager->_renderLink('', '');
|
|
|
375 |
$this->assertEqual($expected, $actual);
|
|
|
376 |
}
|
|
|
377 |
function testImportQuery() {
|
|
|
378 |
//add some fake url vars
|
|
|
379 |
$_GET['arr'] = array(
|
|
|
380 |
'apple',
|
|
|
381 |
'orange',
|
|
|
382 |
);
|
|
|
383 |
$options = array(
|
|
|
384 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
385 |
'perPage' => 5,
|
|
|
386 |
'importQuery' => false,
|
|
|
387 |
);
|
|
|
388 |
$this->pager =& Pager::factory($options);
|
|
|
389 |
$expected = array();
|
|
|
390 |
$actual = $this->pager->_getLinksData();
|
|
|
391 |
$this->assertEqual($expected, $this->pager->_getLinksData());
|
|
|
392 |
|
|
|
393 |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?pageID=2" title=""></a>';
|
|
|
394 |
$actual = $this->pager->_renderLink('', '');
|
|
|
395 |
$this->assertEqual($expected, $actual);
|
|
|
396 |
//remove fake url vars
|
|
|
397 |
unset($_GET['arr']);
|
|
|
398 |
}
|
|
|
399 |
function testGetNextLinkTag() {
|
|
|
400 |
//append = true
|
|
|
401 |
$expected = '<link rel="next" href="'.$_SERVER['PHP_SELF'].'?pageID=2" title="next page" />'."\n";
|
|
|
402 |
$this->assertEqual($expected, $this->pager->_getNextLinkTag());
|
|
|
403 |
|
|
|
404 |
//append = false
|
|
|
405 |
$options = array(
|
|
|
406 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
407 |
'perPage' => 5,
|
|
|
408 |
'currentPage' => 1,
|
|
|
409 |
'append' => false,
|
|
|
410 |
'fileName' => 'myfile.%d.php',
|
|
|
411 |
);
|
|
|
412 |
$this->pager = Pager::factory($options);
|
|
|
413 |
$expected = '<link rel="next" href="'.$this->baseurl.'/myfile.2.php" title="next page" />'."\n";
|
|
|
414 |
$this->assertEqual($expected, $this->pager->_getNextLinkTag());
|
|
|
415 |
|
|
|
416 |
//test empty tag
|
|
|
417 |
$options['currentPage'] = 2;
|
|
|
418 |
$this->pager = Pager::factory($options);
|
|
|
419 |
$this->assertEqual('', $this->pager->_getNextLinkTag());
|
|
|
420 |
}
|
|
|
421 |
function testGetLastLinkTag() {
|
|
|
422 |
//append = true
|
|
|
423 |
$expected = '<link rel="last" href="'.$_SERVER['PHP_SELF'].'?pageID=2" title="last page" />'."\n";
|
|
|
424 |
$this->assertEqual($expected, $this->pager->_getLastLinkTag());
|
|
|
425 |
|
|
|
426 |
//append = false
|
|
|
427 |
$options = array(
|
|
|
428 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
429 |
'perPage' => 5,
|
|
|
430 |
'currentPage' => 1,
|
|
|
431 |
'append' => false,
|
|
|
432 |
'fileName' => 'myfile.%d.php',
|
|
|
433 |
);
|
|
|
434 |
$this->pager = Pager::factory($options);
|
|
|
435 |
$expected = '<link rel="last" href="'.$this->baseurl.'/myfile.2.php" title="last page" />'."\n";
|
|
|
436 |
$this->assertEqual($expected, $this->pager->_getLastLinkTag());
|
|
|
437 |
|
|
|
438 |
//test empty tag
|
|
|
439 |
$options['currentPage'] = 2;
|
|
|
440 |
$this->pager = Pager::factory($options);
|
|
|
441 |
$this->assertEqual('', $this->pager->_getLastLinkTag());
|
|
|
442 |
}
|
|
|
443 |
function testGetFirstLinkTag() {
|
|
|
444 |
//append = true
|
|
|
445 |
$options = array(
|
|
|
446 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
447 |
'perPage' => 5,
|
|
|
448 |
'currentPage' => 2,
|
|
|
449 |
);
|
|
|
450 |
$this->pager = Pager::factory($options);
|
|
|
451 |
$expected = '<link rel="first" href="'.$_SERVER['PHP_SELF'].'?pageID=1" title="first page" />'."\n";
|
|
|
452 |
$this->assertEqual($expected, $this->pager->_getFirstLinkTag());
|
|
|
453 |
|
|
|
454 |
//append = false
|
|
|
455 |
$options = array(
|
|
|
456 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
457 |
'perPage' => 5,
|
|
|
458 |
'currentPage' => 2,
|
|
|
459 |
'append' => false,
|
|
|
460 |
'fileName' => 'myfile.%d.php',
|
|
|
461 |
);
|
|
|
462 |
$this->pager = Pager::factory($options);
|
|
|
463 |
$expected = '<link rel="first" href="'.$this->baseurl.'/myfile.1.php" title="first page" />'."\n";
|
|
|
464 |
$this->assertEqual($expected, $this->pager->_getFirstLinkTag());
|
|
|
465 |
|
|
|
466 |
//test empty tag
|
|
|
467 |
$options['currentPage'] = 1;
|
|
|
468 |
$this->pager = Pager::factory($options);
|
|
|
469 |
$this->assertEqual('', $this->pager->_getFirstLinkTag());
|
|
|
470 |
}
|
|
|
471 |
function testGetPrevLinkTag() {
|
|
|
472 |
//append = true
|
|
|
473 |
$options = array(
|
|
|
474 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
475 |
'perPage' => 5,
|
|
|
476 |
'currentPage' => 2,
|
|
|
477 |
);
|
|
|
478 |
$this->pager = Pager::factory($options);
|
|
|
479 |
$expected = '<link rel="previous" href="'.$_SERVER['PHP_SELF'].'?pageID=1" title="previous page" />'."\n";
|
|
|
480 |
$this->assertEqual($expected, $this->pager->_getPrevLinkTag());
|
|
|
481 |
|
|
|
482 |
//append = false
|
|
|
483 |
$options = array(
|
|
|
484 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
485 |
'perPage' => 5,
|
|
|
486 |
'currentPage' => 2,
|
|
|
487 |
'append' => false,
|
|
|
488 |
'fileName' => 'myfile.%d.php',
|
|
|
489 |
);
|
|
|
490 |
$this->pager = Pager::factory($options);
|
|
|
491 |
$expected = '<link rel="previous" href="'.$this->baseurl.'/myfile.1.php" title="previous page" />'."\n";
|
|
|
492 |
$this->assertEqual($expected, $this->pager->_getPrevLinkTag());
|
|
|
493 |
|
|
|
494 |
//test empty tag
|
|
|
495 |
$options['currentPage'] = 1;
|
|
|
496 |
$this->pager = Pager::factory($options);
|
|
|
497 |
$this->assertEqual('', $this->pager->_getPrevLinkTag());
|
|
|
498 |
}
|
|
|
499 |
function testPrintFirstPage() {
|
|
|
500 |
$options = array(
|
|
|
501 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
502 |
'perPage' => 5,
|
|
|
503 |
'currentPage' => 2,
|
|
|
504 |
);
|
|
|
505 |
$this->pager = Pager::factory($options);
|
|
|
506 |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=1" title="first page">[1]</a> ';
|
|
|
507 |
$this->assertEqual($expected, $this->pager->_printFirstPage());
|
|
|
508 |
|
|
|
509 |
$this->pager->_firstPageText = 'FIRST';
|
|
|
510 |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=1" title="first page">[FIRST]</a> ';
|
|
|
511 |
$this->assertEqual($expected, $this->pager->_printFirstPage());
|
|
|
512 |
|
|
|
513 |
$options = array(
|
|
|
514 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
515 |
'perPage' => 5,
|
|
|
516 |
'currentPage' => 2,
|
|
|
517 |
'altFirst' => 'page %d',
|
|
|
518 |
);
|
|
|
519 |
$this->pager = Pager::factory($options);
|
|
|
520 |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=1" title="page 1">[1]</a> ';
|
|
|
521 |
$this->assertEqual($expected, $this->pager->_printFirstPage());
|
|
|
522 |
}
|
|
|
523 |
function testPrintLastPage() {
|
|
|
524 |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="last page">[2]</a>';
|
|
|
525 |
$this->assertEqual($expected, $this->pager->_printLastPage());
|
|
|
526 |
|
|
|
527 |
$this->pager->_lastPageText = 'LAST';
|
|
|
528 |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="last page">[LAST]</a>';
|
|
|
529 |
$this->assertEqual($expected, $this->pager->_printLastPage());
|
|
|
530 |
|
|
|
531 |
$this->pager->_altLast = 'page %d';
|
|
|
532 |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="page 2">[LAST]</a>';
|
|
|
533 |
$this->assertEqual($expected, $this->pager->_printLastPage());
|
|
|
534 |
}
|
|
|
535 |
function testGetPageLinks() {
|
|
|
536 |
$links = $this->pager->_getPageLinks();
|
|
|
537 |
$this->assertTrue(false !== strpos($links, 'title="page 2"'));
|
|
|
538 |
$this->pager->setOptions(array('altPage' => '%d page'));
|
|
|
539 |
$this->pager->build();
|
|
|
540 |
$links = $this->pager->_getPageLinks();
|
|
|
541 |
$this->assertTrue(false !== strpos($links, 'title="2 page"'));
|
|
|
542 |
}
|
|
|
543 |
function testGetBackLink() {
|
|
|
544 |
$img = '«';
|
|
|
545 |
$options = array(
|
|
|
546 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
547 |
'perPage' => 5,
|
|
|
548 |
'currentPage' => 2,
|
|
|
549 |
'prevImg' => $img,
|
|
|
550 |
);
|
|
|
551 |
$this->pager = Pager::factory($options);
|
|
|
552 |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=1" title="previous page">'.$img.'</a> ';
|
|
|
553 |
$this->assertEqual($expected, $this->pager->_getBackLink());
|
|
|
554 |
}
|
|
|
555 |
function testGetBackLinkEmpty() {
|
|
|
556 |
$img = '[FIRST]';
|
|
|
557 |
$options = array(
|
|
|
558 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
559 |
'perPage' => 5,
|
|
|
560 |
);
|
|
|
561 |
$this->pager = Pager::factory($options);
|
|
|
562 |
$expected = '';
|
|
|
563 |
$this->assertEqual($expected, $this->pager->_getBackLink());
|
|
|
564 |
|
|
|
565 |
$options['prevImgEmpty'] = $img;
|
|
|
566 |
$this->pager = Pager::factory($options);
|
|
|
567 |
$expected = $img.' ';
|
|
|
568 |
$this->assertEqual($expected, $this->pager->_getBackLink());
|
|
|
569 |
}
|
|
|
570 |
function testGetNexLink() {
|
|
|
571 |
$img = '»';
|
|
|
572 |
$options = array(
|
|
|
573 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
574 |
'perPage' => 5,
|
|
|
575 |
'currentPage' => 1,
|
|
|
576 |
'nextImg' => $img,
|
|
|
577 |
);
|
|
|
578 |
$this->pager = Pager::factory($options);
|
|
|
579 |
$expected = ' <a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="next page">'.$img.'</a> ';
|
|
|
580 |
$this->assertEqual($expected, $this->pager->_getNextLink());
|
|
|
581 |
}
|
|
|
582 |
function testGetNexLinkEmpty() {
|
|
|
583 |
$img = '[LAST]';
|
|
|
584 |
$options = array(
|
|
|
585 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
586 |
'perPage' => 5,
|
|
|
587 |
'currentPage' => 2,
|
|
|
588 |
);
|
|
|
589 |
$this->pager = Pager::factory($options);
|
|
|
590 |
$expected = '';
|
|
|
591 |
$this->assertEqual($expected, $this->pager->_getNextLink());
|
|
|
592 |
|
|
|
593 |
$options['nextImgEmpty'] = $img;
|
|
|
594 |
$this->pager = Pager::factory($options);
|
|
|
595 |
$expected = ' '.$img.' ';
|
|
|
596 |
$this->assertEqual($expected, $this->pager->_getNextLink());
|
|
|
597 |
}
|
|
|
598 |
function testHttpMethodAutoDetect() {
|
|
|
599 |
$_POST['pageID'] = 3;
|
|
|
600 |
$options = array(
|
|
|
601 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
602 |
'perPage' => 5,
|
|
|
603 |
);
|
|
|
604 |
$this->pager = Pager::factory($options);
|
|
|
605 |
$this->assertEqual('POST', $this->pager->_httpMethod);
|
|
|
606 |
|
|
|
607 |
$options = array(
|
|
|
608 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
609 |
'perPage' => 5,
|
|
|
610 |
'httpMethod' => 'GET',
|
|
|
611 |
);
|
|
|
612 |
$this->pager = Pager::factory($options);
|
|
|
613 |
$this->assertEqual('GET', $this->pager->_httpMethod);
|
|
|
614 |
|
|
|
615 |
unset($_POST['pageID']);
|
|
|
616 |
|
|
|
617 |
$options = array(
|
|
|
618 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
619 |
'perPage' => 5,
|
|
|
620 |
'httpMethod' => 'POST',
|
|
|
621 |
);
|
|
|
622 |
$this->pager = Pager::factory($options);
|
|
|
623 |
$this->assertEqual('POST', $this->pager->_httpMethod);
|
|
|
624 |
|
|
|
625 |
$options = array(
|
|
|
626 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
627 |
'perPage' => 5,
|
|
|
628 |
);
|
|
|
629 |
$this->pager = Pager::factory($options);
|
|
|
630 |
$this->assertEqual('GET', $this->pager->_httpMethod);
|
|
|
631 |
}
|
|
|
632 |
function testAccesskey() {
|
|
|
633 |
$options = array(
|
|
|
634 |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
635 |
'perPage' => 5,
|
|
|
636 |
'accesskey' => true,
|
|
|
637 |
);
|
|
|
638 |
$this->pager = Pager::factory($options);
|
|
|
639 |
$this->assertPattern('/accesskey="\d"/i', $this->pager->links);
|
|
|
640 |
//var_dump($this->pager->links);
|
|
|
641 |
}
|
|
|
642 |
function testIsEncoded() {
|
|
|
643 |
//var_dump(urlencode('안녕'));
|
|
|
644 |
$test_strings_encoded = array(
|
|
|
645 |
'encoded0' => '试',
|
|
|
646 |
'encoded1' => '测试',
|
|
|
647 |
'encoded2' => '안녕',
|
|
|
648 |
'encoded3' => '안 녕',
|
|
|
649 |
'encoded4' => '안
|
|
|
650 |
녕',
|
|
|
651 |
);
|
|
|
652 |
$test_strings_plain = array(
|
|
|
653 |
'plain1' => '안녕',
|
|
|
654 |
'plain2' => '더보기',
|
|
|
655 |
// 'plain3' => '이젠 전화도
|
|
|
656 |
//로 걸면 무료',
|
|
|
657 |
'plain4' => 'abcde', //not multibyte
|
|
|
658 |
'plain5' => '&#abcfg;', //invalid hex-encoded char
|
|
|
659 |
'plain5' => '안 nasty 녕', //mixed plain/encoded text
|
|
|
660 |
);
|
|
|
661 |
foreach ($test_strings_encoded as $string) {
|
|
|
662 |
//echo '<hr />'.str_replace('&', '&', $string);
|
|
|
663 |
$this->assertTrue($this->pager->_isEncoded($string));
|
|
|
664 |
}
|
|
|
665 |
foreach ($test_strings_plain as $string) {
|
|
|
666 |
$this->assertFalse($this->pager->_isEncoded($string));
|
|
|
667 |
}
|
|
|
668 |
}
|
|
|
669 |
function testGetOption() {
|
|
|
670 |
$this->assertEqual(5, $this->pager->getOption('perPage'));
|
|
|
671 |
$err = $this->pager->getOption('non_existent_option');
|
|
|
672 |
$this->assertEqual(ERROR_PAGER_INVALID, $err->getCode());
|
|
|
673 |
}
|
|
|
674 |
function testGetOptions() {
|
|
|
675 |
$options = $this->pager->getOptions();
|
|
|
676 |
$this->assertTrue(is_array($options));
|
|
|
677 |
$this->assertEqual(5, $options['perPage']);
|
|
|
678 |
}
|
|
|
679 |
function testSetOptionsAndBuild() {
|
|
|
680 |
$options = array(
|
|
|
681 |
'perPage' => 2,
|
|
|
682 |
);
|
|
|
683 |
$this->pager->setOptions($options);
|
|
|
684 |
$this->pager->build();
|
|
|
685 |
$this->assertEqual(2, $this->pager->getOption('perPage'));
|
|
|
686 |
$this->assertEqual(array(0=>1, 1=>2), $this->pager->getPageData());
|
|
|
687 |
$this->assertEqual(array(2=>3, 3=>4), $this->pager->getPageData(2));
|
|
|
688 |
|
|
|
689 |
$options = array(
|
|
|
690 |
'currentPage' => 2,
|
|
|
691 |
'append' => false,
|
|
|
692 |
'fileName' => 'myfile.%d.php',
|
|
|
693 |
);
|
|
|
694 |
$this->pager->setOptions($options);
|
|
|
695 |
$this->pager->build();
|
|
|
696 |
$expected = '<link rel="previous" href="'.$this->baseurl.'/myfile.1.php" title="previous page" />'."\n";
|
|
|
697 |
$this->assertEqual($expected, $this->pager->_getPrevLinkTag());
|
|
|
698 |
}
|
|
|
699 |
function testRelativeLinks() {
|
|
|
700 |
$fileName = array_pop(explode('/', $_SERVER['PHP_SELF']));
|
|
|
701 |
$options = array(
|
|
|
702 |
'mode' => 'Sliding',
|
|
|
703 |
'path' => '',
|
|
|
704 |
'fileName' => $fileName,
|
|
|
705 |
'itemData' => range('a', 'z'),
|
|
|
706 |
'spacesBeforeSeparator' => 0,
|
|
|
707 |
'spacesAfterSeparator' => 0,
|
|
|
708 |
);
|
|
|
709 |
$this->pager = Pager::factory($options);
|
|
|
710 |
$expected = '<a href="' . $fileName . '?pageID=2" title="next page">»</a>';
|
|
|
711 |
$this->assertEqual($expected, $this->pager->_getNextLink());
|
|
|
712 |
|
|
|
713 |
$options = array(
|
|
|
714 |
'mode' => 'Sliding',
|
|
|
715 |
'itemData' => range('a', 'z'),
|
|
|
716 |
'spacesBeforeSeparator' => 0,
|
|
|
717 |
'spacesAfterSeparator' => 0,
|
|
|
718 |
);
|
|
|
719 |
$this->pager = Pager::factory($options);
|
|
|
720 |
$this->pager->build();
|
|
|
721 |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="next page">»</a>';
|
|
|
722 |
$this->assertEqual($expected, $this->pager->_getNextLink());
|
|
|
723 |
}
|
|
|
724 |
//http://pear.php.net/bugs/bug.php?id=12306
|
|
|
725 |
function testAbsoluteLinks() {
|
|
|
726 |
// Reproduces bug #13881
|
|
|
727 |
$options = array (
|
|
|
728 |
'mode' => 'Sliding',
|
|
|
729 |
'delta' => 5,
|
|
|
730 |
'totalItems' => 50,
|
|
|
731 |
'perPage' => 10,
|
|
|
732 |
'urlVar' => 'page',
|
|
|
733 |
'currentPage' => 1,
|
|
|
734 |
'append' => false,
|
|
|
735 |
'path' => '',
|
|
|
736 |
'fileName' => '/report/alpha/page/%d/orderBy/foo/direction/asc',
|
|
|
737 |
'spacesBeforeSeparator' => 0,
|
|
|
738 |
'spacesAfterSeparator' => 0,
|
|
|
739 |
);
|
|
|
740 |
$this->pager = Pager::factory($options);
|
|
|
741 |
$this->pager->build();
|
|
|
742 |
$expected = '<a href="/report/alpha/page/2/orderBy/foo/direction/asc" title="next page">»</a>';
|
|
|
743 |
$this->assertEqual($expected, $this->pager->_getNextLink());
|
|
|
744 |
|
|
|
745 |
$options['path'] = '/';
|
|
|
746 |
$options['fileName'] = '/report/alpha/page/%d/orderBy/foo/direction/asc';
|
|
|
747 |
$this->pager = Pager::factory($options);
|
|
|
748 |
$this->pager->build();
|
|
|
749 |
$expected = '<a href="/report/alpha/page/2/orderBy/foo/direction/asc" title="next page">»</a>';
|
|
|
750 |
$this->assertEqual($expected, $this->pager->_getNextLink());
|
|
|
751 |
}
|
|
|
752 |
//http://pear.php.net/bugs/bug.php?id=13913
|
|
|
753 |
function testEmptyPagerWithImgEmpty() {
|
|
|
754 |
$options = array(
|
|
|
755 |
'itemData' => range(1, 2),
|
|
|
756 |
'perPage' => 5,
|
|
|
757 |
'prevImgEmpty' => 'YYY',
|
|
|
758 |
'nextImgEmpty' => 'XXX',
|
|
|
759 |
);
|
|
|
760 |
$this->pager = Pager::factory($options);
|
|
|
761 |
$expected = '';
|
|
|
762 |
$this->assertEqual($expected, $this->pager->links);
|
|
|
763 |
}
|
|
|
764 |
}
|
|
|
765 |
if (!defined('TEST_RUNNING')) {
|
|
|
766 |
define('TEST_RUNNING', true);
|
|
|
767 |
$test = new TestOfPager();
|
|
|
768 |
$test->run(new HtmlReporter());
|
|
|
769 |
}
|
|
|
770 |
?>
|