PHP Classes

File: tests/unit/Pagination/CoreTest.php

Recommend this page to a friend!
  Classes of Haseeb Ahmad Basil   PHP Skeleton Framework   tests/unit/Pagination/CoreTest.php   Download  
File: tests/unit/Pagination/CoreTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Skeleton Framework
Extensive Web application development framework
Author: By
Last change:
Date: 8 years ago
Size: 2,438 bytes
 

Contents

Class file image Download
<?php

class Pagination_Core_DatasourceMock implements A_Pagination_Adapter {
    protected
$items = array(
                            array(
'id'=>1, 'name'=>'One', 'color'=>'blue'),
                            array(
'id'=>2, 'name'=>'Two', 'color'=>'red'),
                            array(
'id'=>3, 'name'=>'Three', 'color'=>'green'),
                            array(
'id'=>4, 'name'=>'Four', 'color'=>'blue'),
                            array(
'id'=>5, 'name'=>'Five', 'color'=>'blue'),
                            array(
'id'=>6, 'name'=>'Six', 'color'=>'black'),
                            array(
'id'=>7, 'name'=>'Seven', 'color'=>'green'),
                            array(
'id'=>8, 'name'=>'Eight', 'color'=>'blue'),
                            );

    public function
getItems($start, $size) {
        return
slice($this->items, $start-1, $size);
    }

    public function
getNumItems() {
        return
count($this->items);
    }

    public function
setOrderBy($field, $descending=false) {
    }

}

class
Pagination_CoreTest extends UnitTestCase {

    function
setUp() {
    }

    function
TearDown() {
    }

    function
testPaginationgetFirstPage() {
        
$datasource = new Pagination_Core_DatasourceMock();
       
$pager = new A_Pagination_Core($datasource, 5);

       
$result = true;
       
$this->assertEqual($pager->getCurrentPage(), 1);
       
$this->assertEqual($pager->getFirstPage(), 1);
       
$this->assertEqual($pager->getLastPage(), 2);
       
$this->assertEqual($pager->getFirstItem(), 1);
       
$this->assertEqual($pager->getLastItem(), 5);
       
$this->assertEqual($pager->getNumItems(), $datasource->getNumItems());
    }

    function
testPaginationSecondPage() {
        
$datasource = new Pagination_Core_DatasourceMock();
       
$pager = new A_Pagination_Core($datasource, 5);
       
$pager->setCurrentPage(2);

       
$result = true;
       
$this->assertEqual($pager->getCurrentPage(), 2);
       
$this->assertEqual($pager->getFirstPage(), 1);
       
$this->assertEqual($pager->getLastPage(), 2);
       
$this->assertEqual($pager->getFirstItem(), 6);
       
$this->assertEqual($pager->getLastItem(), 8);
       
$this->assertEqual($pager->getNumItems(), $datasource->getNumItems());
    }

    public function
testGetParamNameSetsKeyIfNotSet() {
       
$datasource = new Pagination_Core_DatasourceMock();
       
$pager = new A_Pagination_Core($datasource, 5);
       
$this->assertEqual ($pager->getParamName ('abc123'), 'abc123');
    }

    public function
testSetParamName() {
       
$datasource = new Pagination_Core_DatasourceMock();
       
$pager = new A_Pagination_Core($datasource, 5);
       
$pager->setParamName ('abc123', 'page');
       
$this->assertEqual ($pager->getParamName ('abc123'), 'page');
    }

}