/trunk/api/pear/Pager/tests/pager_sliding_notExpanded_test.php |
---|
New file |
0,0 → 1,49 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPagerSlidingNotExpanded extends UnitTestCase { |
var $pager; |
function TestOfPagerSlidingNotExpanded($name='Test of Pager_Sliding - expanded=false') { |
$this->UnitTestCase($name); |
} |
function setUp() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), |
'perPage' => 2, |
'mode' => 'Sliding', |
'expanded' => false |
); |
$this->pager = new Pager($options); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testPageRangeByPageId1() { |
$this->assertEqual(array(1, 3), $this->pager->getPageRangeByPageId(1)); |
} |
function testPageRangeByPageId2() { |
$this->assertEqual(array(1, 4), $this->pager->getPageRangeByPageId(2)); |
} |
function testPageRangeByPageId3() { |
$this->assertEqual(array(1, 5), $this->pager->getPageRangeByPageId(3)); |
} |
function testPageRangeByPageId4() { |
$this->assertEqual(array(2, 6), $this->pager->getPageRangeByPageId(4)); |
} |
function testPageRangeByPageId9() { |
$this->assertEqual(array(7, 11), $this->pager->getPageRangeByPageId(9)); |
} |
function testPageRangeByPageId10() { |
$this->assertEqual(array(8, 11), $this->pager->getPageRangeByPageId(10)); |
} |
function testPageRangeByPageId11() { |
$this->assertEqual(array(9, 11), $this->pager->getPageRangeByPageId(11)); |
} |
function testPageRangeByPageId_outOfRange() { |
$this->assertEqual(array(0, 0), $this->pager->getPageRangeByPageId(20)); |
} |
} |
?> |
/trunk/api/pear/Pager/tests/pager_include.php |
---|
New file |
0,0 → 1,4 |
<?php |
// $Id$ |
require_once 'Pager/Pager.php'; |
?> |
/trunk/api/pear/Pager/tests/pager_wrapper_include.php |
---|
New file |
0,0 → 1,5 |
<?php |
// $Id$ |
require_once 'Pager/Pager.php'; |
require_once 'Pager/Wrapper.php'; |
?> |
/trunk/api/pear/Pager/tests/pager_post_test.php |
---|
New file |
0,0 → 1,67 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPagerPOST extends WebTestCase { |
var $pager; |
var $baseurl; |
var $options = array(); |
function TestOfPagerPOST($name='Test of Pager with httpMethod="POST"') { |
$this->WebTestCase($name); |
} |
function setUp() { |
$this->options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 1, |
'clearIfVoid' => false, |
'httpMethod' => 'POST', |
); |
//$this->pager = Pager::factory($this->options); |
$this->baseurl = 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testMultibyteEncoded() { |
$test_strings_encoded = array( |
'encoded1' => '测试', |
'encoded2' => '안녕', |
); |
$loaded = $this->get($this->baseurl.'/multibyte_post.php'); |
$this->assertTrue($loaded); |
$this->assertResponse(200); |
$this->assertTitle('Pager Test: page 1'); |
$this->assertNoLink('1'); |
$this->assertLink('2'); |
$this->assertLink('Next >>'); |
//$this->showSource(); |
foreach ($test_strings_encoded as $name => $value) { |
$this->assertWantedPattern('/'.$name.'.*'.preg_quote(str_replace('&', '&', $value)).'/Uims'); |
} |
} |
function testMultibytePlain() { |
$test_strings_plain = array( |
'plain1' => '안녕', |
'plain2' => '더보기', |
// 'plain3' => '이젠 전화도 |
//로 걸면 무료', |
); |
$loaded = $this->get($this->baseurl.'/multibyte_post.php'); |
$this->assertTrue($loaded); |
$this->assertResponse(200); |
$this->assertTitle('Pager Test: page 1'); |
$this->assertNoLink('1'); |
$this->assertLink('2'); |
$this->assertLink('Next >>'); |
//$this->showSource(); |
foreach ($test_strings_plain as $name => $value) { |
$this->assertWantedPattern('/'.$name.'.*'.preg_quote(urlencode($value)).'/Uims'); |
} |
} |
} |
?> |
/trunk/api/pear/Pager/tests/pager_sliding_test.php |
---|
New file |
0,0 → 1,56 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPagerSliding extends UnitTestCase { |
var $pager; |
function TestOfPagerSliding($name='Test of Pager_Sliding') { |
$this->UnitTestCase($name); |
} |
function setUp() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), |
'perPage' => 2, |
'mode' => 'Sliding', |
); |
$this->pager = Pager::factory($options); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testPageRangeByPageId1() { |
$this->assertEqual(array(1, 5), $this->pager->getPageRangeByPageId(1)); |
} |
function testPageRangeByPageId4() { |
$this->assertEqual(array(2, 6), $this->pager->getPageRangeByPageId(4)); |
} |
function testPageRangeByPageId_outOfRange() { |
$this->assertEqual(array(0, 0), $this->pager->getPageRangeByPageId(20)); |
} |
function testPageRangeByPageId2() { |
$this->assertEqual(array(2, 6), $this->pager->getPageRangeByPageId(4)); |
} |
function testGetPageData() { |
$this->assertEqual(array(0=>1, 1=>2), $this->pager->getPageData()); |
} |
function testGetPageData2() { |
$this->assertEqual(array(2=>3, 3=>4), $this->pager->getPageData(2)); |
} |
function testGetPageData_OutOfRange() { |
$this->assertEqual(false, $this->pager->getPageData(20)); |
} |
function testClearIfVoid() { |
$this->assertTrue(strlen($this->pager->links) > 0); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), |
'perPage' => 20, |
'mode' => 'Sliding', |
); |
$this->pager = Pager::factory($options); |
$this->assertEqual('', $this->pager->links); |
} |
} |
?> |
/trunk/api/pear/Pager/tests/README |
---|
New file |
0,0 → 1,5 |
These tests require Simple Test: http://www.lastcraft.com/simple_test.php |
- edit the simple_include.php script and set your SimpleTest install dir; |
- edit the pager_include.php and pager_wrapper_include.php scripts to set |
your Pager directory. |
/trunk/api/pear/Pager/tests/pager_jumping_tests.php |
---|
New file |
0,0 → 1,20 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class PagerJumpingTests extends GroupTest { |
function PagerJumpingTests() { |
$this->GroupTest('Pager_Jumping Tests'); |
$this->addTestFile('pager_jumping_test.php'); |
$this->addTestFile('pager_jumping_noData_test.php'); |
} |
} |
if (!defined('TEST_RUNNING')) { |
define('TEST_RUNNING', true); |
$test = &new PagerTests(); |
$test->run(new HtmlReporter()); |
} |
?> |
/trunk/api/pear/Pager/tests/pager_jumping_noData_test.php |
---|
New file |
0,0 → 1,36 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPagerJumpingNoData extends UnitTestCase { |
var $pager; |
function TestOfPagerJumpingNoData($name='Test of Pager_Jumping - no data') { |
$this->UnitTestCase($name); |
} |
function setUp() { |
$options = array( |
'totalItems' => 0, |
'perPage' => 2, |
'mode' => 'Jumping', |
); |
$this->pager = Pager::factory($options); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testOffsetByPageId() { |
$this->assertEqual(array(1, 0), $this->pager->getOffsetByPageId()); |
} |
function testPageIdByOffset() { |
$this->assertEqual(false, $this->pager->getPageIdByOffset(0)); |
} |
function testPageIdByOffset2() { |
$this->assertEqual(1, $this->pager->getPageIdByOffset(1)); |
} |
function testPageIdByOffset3() { |
$this->assertEqual(1, $this->pager->getPageIdByOffset(2)); |
} |
} |
?> |
/trunk/api/pear/Pager/tests/pager_tests.php |
---|
New file |
0,0 → 1,20 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class PagerTests extends GroupTest { |
function PagerTests() { |
$this->GroupTest('Pager Tests'); |
$this->addTestFile('pager_test.php'); |
$this->addTestFile('pager_noData_test.php'); |
} |
} |
if (!defined('TEST_RUNNING')) { |
define('TEST_RUNNING', true); |
$test = &new PagerTests(); |
$test->run(new HtmlReporter()); |
} |
?> |
/trunk/api/pear/Pager/tests/multibyte_post.php |
---|
New file |
0,0 → 1,48 |
<?php |
require_once 'Pager/Pager.php'; |
//create dummy array of data |
$myData = array(); |
for ($i=0; $i<200; $i++) { |
$myData[] = $i; |
} |
//set a string |
$test_strings_encoded = array( |
'encoded1' => '测试', |
'encoded2' => '안녕', |
); |
$test_strings_plain = array( |
'plain1' => '안녕', |
'plain2' => '더보기', |
// 'plain3' => '이젠 전화도 |
//로 걸면 무료', |
); |
$params = array( |
'itemData' => $myData, |
'perPage' => 10, |
'delta' => 2, |
'append' => true, |
'clearIfVoid' => false, |
'extraVars' => array_merge($test_strings_plain, $test_strings_encoded), |
'httpMethod' => 'POST', |
'path' => 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')), |
'fileName' => basename(__FILE__), |
); |
//var_dump($params['fileName']);exit; |
$pager = & Pager::factory($params); |
$page_data = $pager->getPageData(); |
?> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 |
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
<title>Pager Test: page <?php echo $pager->getCurrentPageID(); ?></title> |
</head> |
<body> |
<?php echo $pager->links; ?> |
<hr /> |
<pre><?php print_r($page_data); ?></pre> |
</body> |
</html> |
/trunk/api/pear/Pager/tests/pager_noData_test.php |
---|
New file |
0,0 → 1,48 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPagerNoData extends UnitTestCase { |
var $pager; |
function TestOfPagerNoData($name='Test of Pager - no data') { |
$this->UnitTestCase($name); |
} |
function setUp() { |
$options = array( |
'totalItems' => 0, |
'perPage' => 5, |
'mode' => 'Sliding', |
); |
$this->pager = Pager::factory($options); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testCurrentPageID () { |
$this->assertEqual(0, $this->pager->getCurrentPageID()); |
} |
function testNextPageID () { |
$this->assertEqual(false, $this->pager->getNextPageID()); |
} |
function testPrevPageID () { |
$this->assertEqual(false, $this->pager->getPreviousPageID()); |
} |
function testNumItems () { |
$this->assertEqual(0, $this->pager->numItems()); |
} |
function testNumPages () { |
$this->assertEqual(0, $this->pager->numPages()); |
} |
function testFirstPage () { |
$this->assertEqual(true, $this->pager->isFirstPage()); |
} |
function testLastPage () { |
$this->assertEqual(true, $this->pager->isLastPage()); |
} |
function testLastPageComplete () { |
$this->assertEqual(true, $this->pager->isLastPageComplete()); |
} |
} |
?> |
/trunk/api/pear/Pager/tests/pager_post_tests.php |
---|
New file |
0,0 → 1,11 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
$test = &new GroupTest('Pager POST tests'); |
$test->addTestFile('pager_post_test.php'); |
exit ($test->run(new HTMLReporter()) ? 0 : 1); |
?> |
/trunk/api/pear/Pager/tests/pager_jumping_test.php |
---|
New file |
0,0 → 1,83 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPagerJumping extends UnitTestCase { |
var $pager; |
function TestOfPagerJumping($name='Test of Pager_Jumping') { |
$this->UnitTestCase($name); |
} |
function setUp() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), |
'perPage' => 5, |
'mode' => 'Jumping', |
'delta' => 2 |
); |
$this->pager = Pager::factory($options); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testPageIdByOffset1() { |
$this->assertEqual(1, $this->pager->getPageIdByOffset(1)); |
} |
function testPageIdByOffset5() { |
$this->assertEqual(1, $this->pager->getPageIdByOffset(5)); |
} |
function testPageIdByOffset6() { |
$this->assertEqual(2, $this->pager->getPageIdByOffset(6)); |
} |
function testPageRangeByPageId1() { |
$this->assertEqual(array(1, 2), $this->pager->getPageRangeByPageId(1)); |
} |
function testPageRangeByPageId2() { |
$this->assertEqual(array(1, 2), $this->pager->getPageRangeByPageId(2)); |
} |
function testPageRangeByPageId3() { |
$this->assertEqual(array(3, 3), $this->pager->getPageRangeByPageId(3)); |
} |
function testPageRangeByPageId_outOfRange() { |
$this->assertEqual(array(0, 0), $this->pager->getPageRangeByPageId(20)); |
} |
function testGetPageData() { |
$this->assertEqual(array(0=>1, 1=>2, 2=>3, 3=>4, 4=>5), $this->pager->getPageData()); |
} |
function testGetPageData2() { |
$this->assertEqual(array(5=>6, 6=>7, 7=>8, 8=>9, 9=>10), $this->pager->getPageData(2)); |
} |
function testGetPageData_OutOfRange() { |
$this->assertEqual(false, $this->pager->getPageData(4)); |
} |
/** |
* Returns offsets for given pageID. Eg, if you pass pageID=5 and your |
* delta is 2, it will return 3 and 7. A pageID of 6 would give you 4 and 8 |
* If the method is called without parameter, pageID is set to currentPage#. |
* |
* Given a PageId, it returns the limits of the range of pages displayed. |
* While getOffsetByPageId() returns the offset of the data within the current |
* page, this method returns the offsets of the page numbers interval. |
* E.g., if you have perPage=10 and pageId=3, it will return you 1 and 10. |
* PageID of 8 would give you 1 and 10 as well, because 1 <= 8 <= 10. |
* PageID of 11 would give you 11 and 20. |
* |
* @param pageID PageID to get offsets for |
* @return array First and last offsets |
* @access public |
*/ |
/** |
* Given a PageId, it returns the limits of the range of pages displayed. |
* While getOffsetByPageId() returns the offset of the data within the |
* current page, this method returns the offsets of the page numbers interval. |
* E.g., if you have perPage=10 and pageId=3, it will return you 1 and 10. |
* PageID of 8 would give you 1 and 10 as well, because 1 <= 8 <= 10. |
* PageID of 11 would give you 11 and 20. |
* |
* @param pageID PageID to get offsets for |
* @return array First and last offsets |
* @access public |
*/ |
} |
?> |
/trunk/api/pear/Pager/tests/pager_sliding_tests.php |
---|
New file |
0,0 → 1,21 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class PagerSlidingTests extends GroupTest { |
function PagerSlidingTests() { |
$this->GroupTest('Pager_Sliding Tests'); |
$this->addTestFile('pager_sliding_test.php'); |
$this->addTestFile('pager_sliding_notExpanded_test.php'); |
$this->addTestFile('pager_sliding_noData_test.php'); |
} |
} |
if (!defined('TEST_RUNNING')) { |
define('TEST_RUNNING', true); |
$test = &new PagerTests(); |
$test->run(new HtmlReporter()); |
} |
?> |
/trunk/api/pear/Pager/tests/all_tests.php |
---|
New file |
0,0 → 1,25 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
define('TEST_RUNNING', true); |
require_once './pager_tests.php'; |
require_once './pager_jumping_tests.php'; |
require_once './pager_sliding_tests.php'; |
class AllTests extends GroupTest { |
function AllTests() { |
$this->GroupTest('All PEAR::Pager Tests'); |
$this->AddTestCase(new PagerTests()); |
$this->AddTestCase(new PagerJumpingTests()); |
$this->AddTestCase(new PagerSlidingTests()); |
} |
} |
$test = &new AllTests(); |
$test->run(new HtmlReporter()); |
?> |
/trunk/api/pear/Pager/tests/pager_test_xss.php |
---|
New file |
0,0 → 1,43 |
<?php |
// $Id$ |
//override url |
$_SERVER['PHP_SELF'] = '">test'; |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPagerXSS extends UnitTestCase { |
var $pager; |
var $baseurl; |
function TestOfPagerXSS($name='Test of Pager - XSS attacks') { |
$this->UnitTestCase($name); |
} |
function setUp() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
); |
$this->pager = Pager::factory($options); |
$this->baseurl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testXSS() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'nextImg' => '»' |
); |
$this->pager = Pager::factory($options); |
$expected = ' <a href="./">test?pageID=2" title="next page">»</a> '; |
$this->assertEqual($expected, $this->pager->_getNextLink()); |
} |
} |
if (!defined('TEST_RUNNING')) { |
define('TEST_RUNNING', true); |
$test = &new TestOfPagerXSS(); |
$test->run(new HtmlReporter()); |
} |
?> |
/trunk/api/pear/Pager/tests/simple_include.php |
---|
New file |
0,0 → 1,17 |
<?php |
// $Id$ |
// |
// This testsuite requires SimpleTest. |
// You can find it here: |
// http://www.lastcraft.com/simple_test.php |
// |
if (!defined('SIMPLE_TEST')) { |
define('SIMPLE_TEST', '../simpletest/'); |
} |
require_once(SIMPLE_TEST . 'unit_tester.php'); |
require_once(SIMPLE_TEST . 'reporter.php'); |
require_once(SIMPLE_TEST . 'mock_objects.php'); |
require_once(SIMPLE_TEST . 'web_tester.php'); |
require_once(SIMPLE_TEST . 'reporter.php'); |
?> |
/trunk/api/pear/Pager/tests/pager_sliding_noData_test.php |
---|
New file |
0,0 → 1,30 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPagerSlidingNoData extends UnitTestCase { |
var $pager; |
function TestOfPagerSlidingNoData($name='Test of Pager_Sliding - no data') { |
$this->UnitTestCase($name); |
} |
function setUp() { |
$options = array( |
'totalItems' => 0, |
'perPage' => 2, |
'mode' => 'Sliding', |
); |
$this->pager = Pager::factory($options); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testOffsetByPageId() { |
$this->assertEqual(array(1, 0), $this->pager->getOffsetByPageId()); |
} |
function testPageIdByOffset() { |
$this->assertNull($this->pager->getPageIdByOffset()); |
} |
} |
?> |
/trunk/api/pear/Pager/tests/pager_wrapper_test.php |
---|
New file |
0,0 → 1,205 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_wrapper_include.php'; |
class TestOfPagerWrapper extends UnitTestCase |
{ |
function TestOfPagerWrapper($name='Test of Pager_Wrapper') { |
$this->UnitTestCase($name); |
} |
function setUp() { } |
function tearDown() { } |
/** |
* Basic tests for rewriteCountQuery() |
*/ |
function testRewriteCountQuery() { |
//test LIMIT |
$query = 'SELECT a, b, c, d FROM mytable WHERE a=1 AND c="g" LIMIT 2'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
//test ORDER BY and quotes |
$query = 'SELECT a, b, c, d FROM mytable WHERE a=1 AND c="g" ORDER BY (a, b)'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
//test CR/LF |
$query = 'SELECT a, b, c, d FROM mytable |
WHERE a=1 |
AND c="g" |
ORDER BY (a, b)'; |
$expected = 'SELECT COUNT(*) FROM mytable |
WHERE a=1 |
AND c="g"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
//test GROUP BY |
$query = 'SELECT a, b, c, d FROM mytable WHERE a=1 GROUP BY c'; |
$this->assertFalse(rewriteCountQuery($query)); |
//test DISTINCT |
$query = 'SELECT DISTINCT a, b, c, d FROM mytable WHERE a=1 GROUP BY c'; |
$this->assertFalse(rewriteCountQuery($query)); |
//test MiXeD Keyword CaSe |
$query = 'SELECT a, b, c, d from mytable WHERE a=1 AND c="g"'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
//test function speed... this query used to be very slow to parse |
$query = "SELECT i.item_id, |
ia.addition, |
u.username, |
i.date_created, |
i.start_date, |
i.expiry_date |
FROM item i, item_addition ia, item_type it, item_type_mapping itm, usr u, category c |
WHERE ia.item_type_mapping_id = itm.item_type_mapping_id |
AND i.updated_by_id = u.usr_id |
AND it.item_type_id = itm.item_type_id |
AND i.item_id = ia.item_id |
AND i.item_type_id = it.item_type_id |
AND itm.field_name = 'title' AND it.item_type_id = 2 AND i.category_id = 1 AND i.status = 4 |
AND i.category_id = c.category_id |
AND 0 NOT IN (COALESCE(c.perms, '-1')) |
ORDER BY i.last_updated DESC"; |
$expected = "SELECT COUNT(*) FROM item i, item_addition ia, item_type it, item_type_mapping itm, usr u, category c |
WHERE ia.item_type_mapping_id = itm.item_type_mapping_id |
AND i.updated_by_id = u.usr_id |
AND it.item_type_id = itm.item_type_id |
AND i.item_id = ia.item_id |
AND i.item_type_id = it.item_type_id |
AND itm.field_name = 'title' AND it.item_type_id = 2 AND i.category_id = 1 AND i.status = 4 |
AND i.category_id = c.category_id |
AND 0 NOT IN (COALESCE(c.perms, '-1'))"; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
} |
/** |
* Test rewriteCountQuery() with queries having a subquery in the SELECT clause |
*/ |
function testRewriteCountQuery_SubqueriesInSelectClause() { |
$query = 'SELECT a, (SELECT a FROM b) AS b, c, d FROM mytable WHERE a=1 AND c="g" LIMIT 2'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; |
$this->assertFalse(rewriteCountQuery($query)); |
$query = 'SELECT a, (SELECT a FROM b) AS b, (SELECT c FROM c) AS c, d FROM mytable WHERE a=1 AND c="g" LIMIT 2'; |
//$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; |
$this->assertFalse(rewriteCountQuery($query)); |
$query = 'SELECT `id`, `ip`, ( |
SELECT TIMEDIFF(MAX(P.`time`), MIN(P.`time`)) |
FROM `przejscia` as P |
WHERE P.`id_wejscia`=W.`id` |
) as `czas` |
FROM `wejscia` as W |
WHERE W.id_domeny=? |
ORDER BY W.czas_wejscia DESC'; |
$expected = 'SELECT COUNT(*) |
FROM `wejscia` as W |
WHERE W.id_domeny=? |
ORDER BY W.czas_wejscia DESC'; |
$this->assertFalse(rewriteCountQuery($query)); |
} |
/** |
* Test rewriteCountQuery() with queries having a subquery in the FROM clause |
*/ |
function testRewriteCountQuery_SubqueriesInFromClause() { |
$query = 'SELECT a, b, c, d FROM (SELECT a, b, c, d FROM mytable WHERE a=1) AS tbl_alias WHERE a=1'; |
$expected = 'SELECT COUNT(*) FROM (SELECT a, b, c, d FROM mytable WHERE a=1) AS tbl_alias WHERE a=1'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
} |
/** |
* Test rewriteCountQuery() with queries having a subquery in the WHERE clause |
*/ |
function testRewriteCountQuery_SubqueriesInWhereClause() { |
//this one is not rewritten: subqueries with ORDER BY clauses might get truncated |
$query = 'SELECT Version.VersionId, Version.Identifier,News.* |
FROM VersionBroker |
JOIN ObjectType ON ObjectType.ObjectTypeId = VersionBroker.ObjectTypeId |
JOIN Version ON VersionBroker.Identifier = Version.Identifier |
JOIN News ON Version.ObjectId = News.NewsId |
WHERE Version.Status = \'Approved\' |
AND ObjectType.Name = \'News\' |
AND Version.ApprovedTS = ( |
SELECT SubV.ApprovedTS |
FROM Version SubV |
WHERE SubV.Identifier = VersionBroker.Identifier |
ORDER BY ApprovedTS DESC |
LIMIT 1) |
ORDER BY ApprovedTS DESC'; |
$expected = 'SELECT COUNT(*) |
FROM VersionBroker |
JOIN ObjectType ON ObjectType.ObjectTypeId = VersionBroker.ObjectTypeId |
JOIN Version ON VersionBroker.Identifier = Version.Identifier |
JOIN News ON Version.ObjectId = News.NewsId |
WHERE Version.Status = \'Approved\' |
AND ObjectType.Name = \'News\' |
AND Version.ApprovedTS = ( |
SELECT SubV.ApprovedTS |
FROM Version SubV |
WHERE SubV.Identifier = VersionBroker.Identifier |
ORDER BY ApprovedTS DESC |
LIMIT 1) |
ORDER BY ApprovedTS DESC'; |
//$this->assertEqual($expected, rewriteCountQuery($query)); |
$this->assertFalse(rewriteCountQuery($query)); |
//this one should pass... subquery without ORDER BY or LIMIT clause |
$query = 'SELECT Version.VersionId, Version.Identifier,News.* FROM VersionBroker JOIN |
ObjectType ON ObjectType.ObjectTypeId = VersionBroker.ObjectTypeId JOIN |
Version ON VersionBroker.Identifier = Version.Identifier JOIN News ON |
Version.ObjectId = News.NewsId WHERE Version.Status = \'Approved\' AND |
ObjectType.Name = \'News\' AND Version.ApprovedTS = ( SELECT SubV.ApprovedTS |
FROM Version SubV WHERE SubV.Identifier = VersionBroker.Identifier ) ORDER BY ApprovedTS DESC'; |
$expected = 'SELECT COUNT(*) FROM VersionBroker JOIN |
ObjectType ON ObjectType.ObjectTypeId = VersionBroker.ObjectTypeId JOIN |
Version ON VersionBroker.Identifier = Version.Identifier JOIN News ON |
Version.ObjectId = News.NewsId WHERE Version.Status = \'Approved\' AND |
ObjectType.Name = \'News\' AND Version.ApprovedTS = ( SELECT SubV.ApprovedTS |
FROM Version SubV WHERE SubV.Identifier = VersionBroker.Identifier )'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
} |
/** |
* Test rewriteCountQuery() with queries having keywords embedded in other words |
*/ |
function testRewriteCountQuery_EmbeddedKeywords() { |
$query = 'SELECT afieldFROM, b, c, d FROM mytable WHERE a=1 AND c="g"'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
$query = 'SELECT FROMafield, b, c, d FROM mytable WHERE a=1 AND c="g"'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
$query = 'SELECT afieldFROMaaa, b, c, d FROM mytable WHERE a=1 AND c="gLIMIT"'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="gLIMIT"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
$query = 'SELECT DISTINCTaaa, b, c, d FROM mytable WHERE a=1 AND c="g"'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
//this one fails... the regexp should NOT match keywords within quotes. |
//we need a full blown stack-based parser to catch this... |
$query = 'SELECT afieldFROMaaa, b, c, d FROM mytable WHERE a=1 AND c="g LIMIT a"'; |
$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g LIMIT a"'; |
$this->assertEqual($expected, rewriteCountQuery($query)); |
} |
} |
if (!defined('TEST_RUNNING')) { |
define('TEST_RUNNING', true); |
$test = &new TestOfPagerWrapper(); |
$test->run(new HtmlReporter()); |
} |
?> |
/trunk/api/pear/Pager/tests/pager_test.php |
---|
New file |
0,0 → 1,553 |
<?php |
// $Id$ |
require_once 'simple_include.php'; |
require_once 'pager_include.php'; |
class TestOfPager extends UnitTestCase { |
var $pager; |
var $baseurl; |
function TestOfPager($name='Test of Pager') { |
$this->UnitTestCase($name); |
} |
function setUp() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
); |
$this->pager = Pager::factory($options); |
$this->baseurl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
} |
function tearDown() { |
unset($this->pager); |
} |
function testCurrentPageID () { |
$this->assertEqual(1, $this->pager->getCurrentPageID()); |
} |
function testNextPageID () { |
$this->assertEqual(2, $this->pager->getNextPageID()); |
} |
function testPrevPageID () { |
$this->assertEqual(false, $this->pager->getPreviousPageID()); |
} |
function testNumItems () { |
$this->assertEqual(10, $this->pager->numItems()); |
} |
function testNumPages () { |
$this->assertEqual(2, $this->pager->numPages()); |
} |
function testFirstPage () { |
$this->assertEqual(true, $this->pager->isFirstPage()); |
} |
function testLastPage () { |
$this->assertEqual(false, $this->pager->isLastPage()); |
} |
function testLastPageComplete () { |
$this->assertEqual(true, $this->pager->isLastPageComplete()); |
} |
function testOffsetByPageId() { |
$this->assertEqual(array(1, 5), $this->pager->getOffsetByPageId(1)); |
$this->assertEqual(array(6, 10), $this->pager->getOffsetByPageId(2)); |
} |
function testOffsetByPageId_outOfRange() { |
$this->assertEqual(array(0, 0), $this->pager->getOffsetByPageId(20)); |
} |
function testGetPageData() { |
$this->assertEqual(array(0=>1, 1=>2, 2=>3, 3=>4, 4=>5), $this->pager->getPageData()); |
$this->assertEqual(array(5=>6, 6=>7, 7=>8, 8=>9, 9=>10), $this->pager->getPageData(2)); |
} |
function testGetPageData_OutOfRange() { |
$this->assertEqual(array(), $this->pager->getPageData(3)); |
} |
function testSelectBox() { |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">'; |
$selectBox .= '<option value="5" selected="selected">5</option>'; |
$selectBox .= '<option value="10">10</option>'; |
$selectBox .= '<option value="15">15</option>'; |
$selectBox .= '</select>'; |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5)); |
} |
function testSelectBoxWithString() { |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">'; |
$selectBox .= '<option value="5" selected="selected">5 bugs</option>'; |
$selectBox .= '<option value="10">10 bugs</option>'; |
$selectBox .= '<option value="15">15 bugs</option>'; |
$selectBox .= '</select>'; |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5, false, '%d bugs')); |
} |
function testSelectBoxWithShowAll() { |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">'; |
$selectBox .= '<option value="3">3</option>'; |
$selectBox .= '<option value="4">4</option>'; |
$selectBox .= '<option value="5" selected="selected">5</option>'; |
$selectBox .= '<option value="6">6</option>'; |
$selectBox .= '<option value="10">10</option>'; |
$selectBox .= '</select>'; |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true)); |
} |
function testSelectBoxWithShowAllAndText() { |
$this->pager->_showAllText = 'Show All'; |
$selectBox = '<select name="'.$this->pager->_sessionVar.'">'; |
$selectBox .= '<option value="3">3 bugs</option>'; |
$selectBox .= '<option value="4">4 bugs</option>'; |
$selectBox .= '<option value="5" selected="selected">5 bugs</option>'; |
$selectBox .= '<option value="6">6 bugs</option>'; |
$selectBox .= '<option value="10">Show All</option>'; |
$selectBox .= '</select>'; |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true, '%d bugs')); |
} |
function testSelectBoxWithShowAllWithExtraAttribs() { |
$this->pager->_showAllText = 'Show All'; |
$selectBox = '<select name="'.$this->pager->_sessionVar.'" onmouseover="doSth">'; |
$selectBox .= '<option value="3">3 bugs</option>'; |
$selectBox .= '<option value="4">4 bugs</option>'; |
$selectBox .= '<option value="5" selected="selected">5 bugs</option>'; |
$selectBox .= '<option value="6">6 bugs</option>'; |
$selectBox .= '<option value="10">Show All</option>'; |
$selectBox .= '</select>'; |
$params = array('optionText' => '%d bugs', 'attributes' => 'onmouseover="doSth"'); |
$this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true, $params)); |
} |
function testSelectBoxInvalid() { |
$err = $this->pager->getPerPageSelectBox(5, 15, 5, false, '%s bugs'); |
$this->assertEqual(ERROR_PAGER_INVALID_PLACEHOLDER, $err->getCode()); |
} |
function testAppendInvalid() { |
$options = array( |
'totalItems' => 10, |
'append' => false, |
'fileName' => 'invalidFileName' |
); |
$err =& Pager::factory($options); //ERROR_PAGER_INVALID_USAGE |
$this->assertError(); |
} |
function testAppendValid() { |
$options = array( |
'totalItems' => 10, |
'append' => false, |
'fileName' => 'valid_%d_FileName' |
); |
$err =& Pager::factory($options); |
$this->assertNoErrors(); |
} |
function testEscapeEntities() { |
//encode special chars |
$options = array( |
'extraVars' => array( |
'request' => array('aRequest'), |
'escape' => 'äö%<>+', |
), |
'perPage' => 5, |
); |
$this->pager =& Pager::factory($options); |
//$expected = '?request[]=aRequest&escape=äö%<>+&pageID='; |
//$this->assertEqual($expected, $this->pager->_getLinksUrl()); |
$expected = 'request%5B0%5D=aRequest&escape=%E4%F6%25%3C%3E%2B'; |
$rendered = $this->pager->_renderLink('', ''); |
preg_match('/href="(.*)"/U', $rendered, $matches); |
$actual = str_replace($_SERVER['PHP_SELF'].'?', '', $matches[1]); |
$this->assertEqual($expected, $actual); |
//don't encode slashes |
$options = array( |
'extraVars' => array( |
'request' => 'cat/subcat', |
), |
'perPage' => 5, |
); |
$this->pager =& Pager::factory($options); |
//$expected = '?request=cat/subcat&pageID='; |
//$this->assertEqual($expected, $this->pager->_getLinksUrl()); |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?request=cat/subcat" title=""></a>'; |
$actual = $this->pager->_renderLink('', ''); |
$this->assertEqual($expected, $actual); |
} |
function testMultibyteStrings() { |
$options = array( |
'extraVars' => array( |
'test' => '测试', |
), |
'perPage' => 5, |
); |
$this->pager =& Pager::factory($options); |
//$expected = '<a href="'.$_SERVER['PHP_SELF'].'?test=测试" title=""></a>'; |
$rendered = $this->pager->_renderLink('', ''); |
preg_match('/href="(.*)"/U', $rendered, $matches); |
$actual = str_replace($_SERVER['PHP_SELF'].'?test=', '', $matches[1]); |
$this->assertEqual(urlencode($options['extraVars']['test']), $actual); |
} |
function testCurrentPage() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 2, |
'currentPage' => 2, |
); |
$this->pager =& Pager::factory($options); |
$this->assertEqual(3, $this->pager->getNextPageID()); |
$this->assertEqual(1, $this->pager->getPreviousPageID()); |
$this->assertEqual(2, $this->pager->_currentPage); |
} |
function testArrayExtraVars() { |
$arr = array( |
'apple', |
'orange', |
); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'extraVars' => array('arr' => $arr, 'no' => 'test'), |
); |
$this->pager =& Pager::factory($options); |
/* |
//old |
$expected = '?arr[0]=apple&arr[1]=orange&pageID='; |
$this->assertEqual($expected, $this->pager->_getLinksUrl()); |
*/ |
$expected = $options['extraVars']; |
$this->assertEqual($expected, $this->pager->_getLinksData()); |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?arr%5B0%5D=apple&arr%5B1%5D=orange&no=test&pageID=2" title=""></a>'; |
$actual = $this->pager->_renderLink('', ''); |
$this->assertEqual($expected, $actual); |
} |
function testExcludeVars() { |
$arr = array( |
'apple', |
'orange', |
); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'extraVars' => array('arr' => $arr, 'no' => 'test'), |
'excludeVars' => array('no'), |
); |
$this->pager =& Pager::factory($options); |
$expected = array( |
'arr' => array( |
0 => 'apple', |
1 => 'orange' |
), |
); |
$actual = $this->pager->_getLinksData(); |
$this->assertEqual($expected, $this->pager->_getLinksData()); |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?arr%5B0%5D=apple&arr%5B1%5D=orange&pageID=2" title=""></a>'; |
$actual = $this->pager->_renderLink('', ''); |
$this->assertEqual($expected, $actual); |
} |
function testArgSeparator() { |
$bkp_arg_separator = ini_get('arg_separator.output'); |
ini_set('arg_separator.output', '&'); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'extraVars' => array('apple' => 1), |
); |
$this->pager =& Pager::factory($options); |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?apple=1&pageID=2" title=""></a>'; |
$actual = $this->pager->_renderLink('', ''); |
$this->assertEqual($expected, $actual); |
ini_set('arg_separator.output', $bkp_arg_separator); |
} |
function testAttributes() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'linkClass' => 'testclass', |
'attributes' => 'target="_blank"', |
); |
$this->pager =& Pager::factory($options); |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?pageID=2" class="testclass" target="_blank" title=""></a>'; |
$actual = $this->pager->_renderLink('', ''); |
$this->assertEqual($expected, $actual); |
} |
function testImportQuery() { |
//add some fake url vars |
$_GET['arr'] = array( |
'apple', |
'orange', |
); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'importQuery' => false, |
); |
$this->pager =& Pager::factory($options); |
$expected = array(); |
$actual = $this->pager->_getLinksData(); |
$this->assertEqual($expected, $this->pager->_getLinksData()); |
$expected = '<a href="'.$_SERVER['PHP_SELF'].'?pageID=2" title=""></a>'; |
$actual = $this->pager->_renderLink('', ''); |
$this->assertEqual($expected, $actual); |
//remove fake url vars |
unset($_GET['arr']); |
} |
function testGetNextLinkTag() { |
//append = true |
$expected = '<link rel="next" href="'.$_SERVER['PHP_SELF'].'?pageID=2" title="next page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getNextLinkTag()); |
//append = false |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 1, |
'append' => false, |
'fileName' => 'myfile.%d.php', |
); |
$this->pager = Pager::factory($options); |
$expected = '<link rel="next" href="'.$this->baseurl.'/myfile.2.php" title="next page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getNextLinkTag()); |
//test empty tag |
$options['currentPage'] = 2; |
$this->pager = Pager::factory($options); |
$this->assertEqual('', $this->pager->_getNextLinkTag()); |
} |
function testGetLastLinkTag() { |
//append = true |
$expected = '<link rel="last" href="'.$_SERVER['PHP_SELF'].'?pageID=2" title="last page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getLastLinkTag()); |
//append = false |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 1, |
'append' => false, |
'fileName' => 'myfile.%d.php', |
); |
$this->pager = Pager::factory($options); |
$expected = '<link rel="last" href="'.$this->baseurl.'/myfile.2.php" title="last page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getLastLinkTag()); |
//test empty tag |
$options['currentPage'] = 2; |
$this->pager = Pager::factory($options); |
$this->assertEqual('', $this->pager->_getLastLinkTag()); |
} |
function testGetFirstLinkTag() { |
//append = true |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 2, |
); |
$this->pager = Pager::factory($options); |
$expected = '<link rel="first" href="'.$_SERVER['PHP_SELF'].'?pageID=1" title="first page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getFirstLinkTag()); |
//append = false |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 2, |
'append' => false, |
'fileName' => 'myfile.%d.php', |
); |
$this->pager = Pager::factory($options); |
$expected = '<link rel="first" href="'.$this->baseurl.'/myfile.1.php" title="first page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getFirstLinkTag()); |
//test empty tag |
$options['currentPage'] = 1; |
$this->pager = Pager::factory($options); |
$this->assertEqual('', $this->pager->_getFirstLinkTag()); |
} |
function testGetPrevLinkTag() { |
//append = true |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 2, |
); |
$this->pager = Pager::factory($options); |
$expected = '<link rel="previous" href="'.$_SERVER['PHP_SELF'].'?pageID=1" title="previous page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getPrevLinkTag()); |
//append = false |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 2, |
'append' => false, |
'fileName' => 'myfile.%d.php', |
); |
$this->pager = Pager::factory($options); |
$expected = '<link rel="previous" href="'.$this->baseurl.'/myfile.1.php" title="previous page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getPrevLinkTag()); |
//test empty tag |
$options['currentPage'] = 1; |
$this->pager = Pager::factory($options); |
$this->assertEqual('', $this->pager->_getPrevLinkTag()); |
} |
function testPrintFirstPage() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 2, |
); |
$this->pager = Pager::factory($options); |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=1" title="first page">[1]</a> '; |
$this->assertEqual($expected, $this->pager->_printFirstPage()); |
$this->pager->_firstPageText = 'FIRST'; |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=1" title="first page">[FIRST]</a> '; |
$this->assertEqual($expected, $this->pager->_printFirstPage()); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 2, |
'altFirst' => 'page %d', |
); |
$this->pager = Pager::factory($options); |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=1" title="page 1">[1]</a> '; |
$this->assertEqual($expected, $this->pager->_printFirstPage()); |
} |
function testPrintLastPage() { |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="last page">[2]</a>'; |
$this->assertEqual($expected, $this->pager->_printLastPage()); |
$this->pager->_lastPageText = 'LAST'; |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="last page">[LAST]</a>'; |
$this->assertEqual($expected, $this->pager->_printLastPage()); |
$this->pager->_altLast = 'page %d'; |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="page 2">[LAST]</a>'; |
$this->assertEqual($expected, $this->pager->_printLastPage()); |
} |
function testGetBackLink() { |
$img = '«'; |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 2, |
'prevImg' => $img, |
); |
$this->pager = Pager::factory($options); |
$expected = '<a href="' . $_SERVER['PHP_SELF'] . '?pageID=1" title="previous page">'.$img.'</a> '; |
$this->assertEqual($expected, $this->pager->_getBackLink()); |
} |
function testGetNexLink() { |
$img = '»'; |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'currentPage' => 1, |
'nextImg' => $img, |
); |
$this->pager = Pager::factory($options); |
$expected = ' <a href="' . $_SERVER['PHP_SELF'] . '?pageID=2" title="next page">'.$img.'</a> '; |
$this->assertEqual($expected, $this->pager->_getNextLink()); |
} |
function testHttpMethodAutoDetect() { |
$_POST['pageID'] = 3; |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
); |
$this->pager = Pager::factory($options); |
$this->assertEqual('POST', $this->pager->_httpMethod); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'httpMethod' => 'GET', |
); |
$this->pager = Pager::factory($options); |
$this->assertEqual('GET', $this->pager->_httpMethod); |
unset($_POST['pageID']); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'httpMethod' => 'POST', |
); |
$this->pager = Pager::factory($options); |
$this->assertEqual('POST', $this->pager->_httpMethod); |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
); |
$this->pager = Pager::factory($options); |
$this->assertEqual('GET', $this->pager->_httpMethod); |
} |
function testAccesskey() { |
$options = array( |
'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
'perPage' => 5, |
'accesskey' => true, |
); |
$this->pager = Pager::factory($options); |
$this->assertWantedPattern('/accesskey="\d"/i', $this->pager->links); |
//var_dump($this->pager->links); |
} |
function testIsEncoded() { |
//var_dump(urlencode('안녕')); |
$test_strings_encoded = array( |
'encoded0' => '试', |
'encoded1' => '测试', |
'encoded2' => '안녕', |
'encoded3' => '안 녕', |
'encoded4' => '안 |
녕', |
); |
$test_strings_plain = array( |
'plain1' => '안녕', |
'plain2' => '더보기', |
// 'plain3' => '이젠 전화도 |
//로 걸면 무료', |
'plain4' => 'abcde', //not multibyte |
'plain5' => '&#abcfg;', //invalid hex-encoded char |
'plain5' => '안 nasty 녕', //mixed plain/encoded text |
); |
foreach ($test_strings_encoded as $string) { |
//echo '<hr />'.str_replace('&', '&', $string); |
$this->assertTrue($this->pager->_isEncoded($string)); |
} |
foreach ($test_strings_plain as $string) { |
$this->assertFalse($this->pager->_isEncoded($string)); |
} |
} |
function testGetOption() { |
$this->assertEqual(5, $this->pager->getOption('perPage')); |
$err = $this->pager->getOption('non_existent_option'); |
$this->assertEqual(ERROR_PAGER_INVALID, $err->getCode()); |
} |
function testGetOptions() { |
$options = $this->pager->getOptions(); |
$this->assertTrue(is_array($options)); |
$this->assertEqual(5, $options['perPage']); |
} |
function testSetOptionsAndBuild() { |
$options = array( |
'perPage' => 2, |
); |
$this->pager->setOptions($options); |
$this->pager->build(); |
$this->assertEqual(2, $this->pager->getOption('perPage')); |
$this->assertEqual(array(0=>1, 1=>2), $this->pager->getPageData()); |
$this->assertEqual(array(2=>3, 3=>4), $this->pager->getPageData(2)); |
$options = array( |
'currentPage' => 2, |
'append' => false, |
'fileName' => 'myfile.%d.php', |
); |
$this->pager->setOptions($options); |
$this->pager->build(); |
$expected = '<link rel="previous" href="'.$this->baseurl.'/myfile.1.php" title="previous page" />'."\n"; |
$this->assertEqual($expected, $this->pager->_getPrevLinkTag()); |
} |
} |
?> |