home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / pager_test.php < prev    next >
Encoding:
PHP Script  |  2004-10-01  |  4.8 KB  |  115 lines

  1. <?php
  2. // $Id: pager_test.php,v 1.5 2004/06/23 22:59: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.     function TestOfPager($name='Test of Pager') {
  10.         $this->UnitTestCase($name);
  11.     }
  12.     function setUp() {
  13.         $options = array(
  14.             'itemData'    => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
  15.             'perPage' => 5,
  16.  
  17.         );
  18.         $this->pager = Pager::factory($options);
  19.     }
  20.     function tearDown() {
  21.         unset($this->pager);
  22.     }
  23.     function testCurrentPageID () {
  24.         $this->assertEqual(1, $this->pager->getCurrentPageID());
  25.     }
  26.     function testNextPageID () {
  27.         $this->assertEqual(2, $this->pager->getNextPageID());
  28.     }
  29.     function testPrevPageID () {
  30.         $this->assertEqual(false, $this->pager->getPreviousPageID());
  31.     }
  32.     function testNumItems () {
  33.         $this->assertEqual(10, $this->pager->numItems());
  34.     }
  35.     function testNumPages () {
  36.         $this->assertEqual(2, $this->pager->numPages());
  37.     }
  38.     function testFirstPage () {
  39.         $this->assertEqual(true, $this->pager->isFirstPage());
  40.     }
  41.     function testLastPage () {
  42.         $this->assertEqual(false, $this->pager->isLastPage());
  43.     }
  44.     function testLastPageComplete () {
  45.         $this->assertEqual(true, $this->pager->isLastPageComplete());
  46.     }
  47.     function testOffsetByPageId1() {
  48.         $this->assertEqual(array(1, 5), $this->pager->getOffsetByPageId(1));
  49.     }
  50.     function testOffsetByPageId2() {
  51.         $this->assertEqual(array(6, 10), $this->pager->getOffsetByPageId(2));
  52.     }
  53.     function testOffsetByPageId_outOfRange() {
  54.         $this->assertEqual(array(0, 0), $this->pager->getOffsetByPageId(20));
  55.     }
  56.     function testGetPageData() {
  57.         $this->assertEqual(array(0=>1, 1=>2, 2=>3, 3=>4, 4=>5), $this->pager->getPageData());
  58.     }
  59.     function testGetPageData2() {
  60.         $this->assertEqual(array(5=>6, 6=>7, 7=>8, 8=>9, 9=>10), $this->pager->getPageData(2));
  61.     }
  62.     function testGetPageData_OutOfRange() {
  63.         $this->assertEqual(false, $this->pager->getPageData(3));
  64.     }
  65.     function testSelectBox() {
  66.         $selectBox  = '<select name="'.$this->pager->_sessionVar.'">';
  67.         $selectBox .= '<option value="5" selected="selected">5</option>';
  68.         $selectBox .= '<option value="10">10</option>';
  69.         $selectBox .= '<option value="15">15</option>';
  70.         $selectBox .= '</select>';
  71.         $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5));
  72.     }
  73.     function testSelectBoxWithString() {
  74.         $selectBox  = '<select name="'.$this->pager->_sessionVar.'">';
  75.         $selectBox .= '<option value="5" selected="selected">5 bugs</option>';
  76.         $selectBox .= '<option value="10">10 bugs</option>';
  77.         $selectBox .= '<option value="15">15 bugs</option>';
  78.         $selectBox .= '</select>';
  79.         $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5, false, '%d bugs'));
  80.     }
  81.     function testSelectBoxWithShowAll() {
  82.         $selectBox  = '<select name="'.$this->pager->_sessionVar.'">';
  83.         $selectBox .= '<option value="3">3</option>';
  84.         $selectBox .= '<option value="4">4</option>';
  85.         $selectBox .= '<option value="5" selected="selected">5</option>';
  86.         $selectBox .= '<option value="6">6</option>';
  87.         $selectBox .= '<option value="10">10</option>';
  88.         $selectBox .= '</select>';
  89.         $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true));
  90.     }
  91.     function testSelectBoxWithShowAllAndText() {
  92.         $this->pager->_showAllText = 'Show All';
  93.         $selectBox  = '<select name="'.$this->pager->_sessionVar.'">';
  94.         $selectBox .= '<option value="3">3 bugs</option>';
  95.         $selectBox .= '<option value="4">4 bugs</option>';
  96.         $selectBox .= '<option value="5" selected="selected">5 bugs</option>';
  97.         $selectBox .= '<option value="6">6 bugs</option>';
  98.         $selectBox .= '<option value="10">Show All</option>';
  99.         $selectBox .= '</select>';
  100.         $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true, '%d bugs'));
  101.     }
  102.     function testSelectBoxWithShowAllWithExtraAttribs() {
  103.         $this->pager->_showAllText = 'Show All';
  104.         $selectBox  = '<select name="'.$this->pager->_sessionVar.'" onmouseover="doSth">';
  105.         $selectBox .= '<option value="3">3 bugs</option>';
  106.         $selectBox .= '<option value="4">4 bugs</option>';
  107.         $selectBox .= '<option value="5" selected="selected">5 bugs</option>';
  108.         $selectBox .= '<option value="6">6 bugs</option>';
  109.         $selectBox .= '<option value="10">Show All</option>';
  110.         $selectBox .= '</select>';
  111.         $params = array('optionText' => '%d bugs', 'attributes' => 'onmouseover="doSth"');
  112.         $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true, $params));
  113.     }
  114. }
  115. ?>