[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/dbal/tests/cases/driver/ -> DriverRecordSetTestBase.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  abstract class DriverRecordSetTestBase extends UnitTestCase
  11  {
  12    var $record_class;
  13  
  14    function DriverRecordSetTestBase($record_class)
  15    {
  16      $this->record_class = $record_class;
  17    }
  18  
  19    function setUp()
  20    {
  21      $sql = "SELECT id, first FROM founding_fathers ORDER BY id";
  22      $this->stmt = $this->connection->newStatement($sql);
  23      $this->cursor = $this->stmt->getRecordSet();
  24    }
  25  
  26    function tearDown()
  27    {
  28      $this->connection->disconnect();
  29    }
  30  
  31    function testRewind()
  32    {
  33      $this->cursor->rewind();
  34      $this->assertTrue($this->cursor->valid());
  35      $record = $this->cursor->current();
  36      $this->assertIsA($record, $this->record_class);
  37      $this->assertEqual($record->get('id'), 1);
  38      $this->assertEqual($record->get('first'), 'George');
  39      $this->cursor->next();
  40      $this->cursor->next();
  41      $this->cursor->rewind();
  42      $record = $this->cursor->current();
  43      $this->assertIsA($record, $this->record_class);
  44      $this->assertEqual($record->get('id'), 1);
  45      $this->assertEqual($record->get('first'), 'George');
  46    }
  47  
  48    function testIteration()
  49    {
  50      for($this->cursor->rewind(), $i = 0; $this->cursor->valid(); $this->cursor->next(), $i++)
  51      {
  52        $record = $this->cursor->current();
  53        $this->assertIsA($record, $this->record_class);
  54      }
  55      $this->assertEqual($i, 3);
  56    }
  57  
  58    function testIteratorInterface()
  59    {
  60      $i = 0;
  61      foreach($this->cursor as $record)
  62      {
  63        $this->assertIsA($record, $this->record_class);
  64        $i++;
  65      }
  66      $this->assertEqual($i, 3);
  67    }
  68  
  69    function testPagerIteration()
  70    {
  71      $this->cursor->paginate($offset = 0, $limit = 2);
  72      for($this->cursor->rewind(), $i = 0; $this->cursor->valid(); $this->cursor->next(), $i++);
  73      $this->assertEqual($i, 2);
  74    }
  75  
  76    function testCount()
  77    {
  78      $sql = "SELECT * FROM founding_fathers";
  79      $rs = $this->connection->newStatement($sql)->getRecordSet();
  80      $rs->paginate(0, 2);
  81  
  82      $this->assertEqual($rs->count(), 3);
  83      $this->assertEqual($rs->countPaginated(), 2);
  84    }
  85  
  86    function testSort()
  87    {
  88      $sql = "SELECT id, first FROM founding_fathers";
  89      $rs = $this->connection->newStatement($sql)->getRecordSet();
  90      $rs->sort(array('id' => 'DESC'));
  91  
  92      $rs->rewind();
  93      $this->assertEqual($rs->current()->get('first'), 'Benjamin');
  94      $rs->next();
  95      $this->assertEqual($rs->current()->get('first'), 'Alexander');
  96      $rs->next();
  97      $this->assertEqual($rs->current()->get('first'), 'George');
  98    }
  99  
 100    function testSortPaginated()
 101    {
 102      $sql = "SELECT id, first FROM founding_fathers";
 103      $rs = $this->connection->newStatement($sql)->getRecordSet();
 104      $rs->sort(array('id' => 'DESC'));
 105      $rs->paginate(0, 1);
 106  
 107      $rs->rewind();
 108      $this->assertEqual($rs->current()->get('first'), 'Benjamin');
 109      $rs->next();
 110      $this->assertFalse($rs->valid());
 111    }
 112  
 113    function testSortPreservesExistingOrderBy()
 114    {
 115      $sql = "SELECT id, first FROM founding_fathers ORdeR By first";
 116      $rs = $this->connection->newStatement($sql)->getRecordSet();
 117      $rs->sort(array('id' => 'DESC'));
 118  
 119      $rs->rewind();
 120      $this->assertEqual($rs->current()->get('first'), 'Alexander');
 121      $rs->next();
 122      $this->assertEqual($rs->current()->get('first'), 'Benjamin');
 123      $rs->next();
 124      $this->assertEqual($rs->current()->get('first'), 'George');
 125    }
 126  
 127    function testAt()
 128    {
 129      $this->assertEqual($this->cursor->at(1)->get('first'), 'Alexander');
 130      $this->assertEqual($this->cursor->at(0)->get('first'), 'George');
 131      $this->assertNull($this->cursor->at(100));
 132    }
 133  
 134    function testsAtAfterPagination()
 135    {
 136      $sql = "SELECT id, first FROM founding_fathers";
 137      $rs = $this->connection->newStatement($sql)->getRecordSet();
 138      $rs->paginate(1, 1);
 139  
 140      $this->assertEqual($rs->at(0)->get('first'), 'George');
 141    }
 142  
 143    function testsAtAfterSort()
 144    {
 145      $sql = "SELECT id, first FROM founding_fathers";
 146      $rs = $this->connection->newStatement($sql)->getRecordSet();
 147      $rs->sort(array('id' => 'DESC'));
 148  
 149      $this->assertEqual($rs->at(0)->get('first'), 'Benjamin');
 150      $this->assertEqual($rs->at(1)->get('first'), 'Alexander');
 151      $this->assertEqual($rs->at(2)->get('first'), 'George');
 152    }
 153  }
 154  
 155  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7