/**
  * Rebuilds an index.
  *
  * @param array $arguments
  * @param array $options
  */
 public function execute($arguments = array(), $options = array())
 {
     $index = $arguments['index'];
     $this->checkIndexExists($index);
     $prefix = $this->formatter->format($arguments['index'], array('fg' => 'green', 'bold' => true)) . ' >> ';
     $index = new $index();
     $index->setLogger(new xfLoggerTask($this->dispatcher, $this->formatter));
     $parser = new xfParserLucene();
     $criteria = $parser->parse($arguments['query']);
     $this->log($prefix . 'Query ' . $this->formatter->format($criteria->toString(), array('fg' => 'blue', 'bold' => true)));
     $results = $index->find($criteria);
     $pager = new xfPager($results);
     $pager->setPerPage($options['limit']);
     $pager->setPage($options['page']);
     if ($pager->getNbResults() == 0) {
         $this->log($prefix . $this->formatter->format('No', array('fg' => 'red', 'bold' => true)) . ' results found.');
         return;
     } elseif ($pager->getNbResults() == 1) {
         $this->log($prefix . $this->formatter->format('1', array('fg' => 'blue', 'bold' => true)) . ' result found:');
     } else {
         $this->log($prefix . $this->formatter->format($pager->getNbResults(), array('fg' => 'blue', 'bold' => true)) . ' results found:');
     }
     if ($pager->getStartPosition() > 1) {
         $msg = $pager->getStartPosition() - 1 . ' skipped';
         $this->log('');
         $this->log($this->formatter->format($msg, array('fg' => 'yellow')));
     }
     $count = $pager->getStartPosition();
     foreach ($pager->getResults() as $result) {
         $this->processHit($result, $count, $options['verbose']);
         $count++;
     }
     if (0 < ($diff = $pager->getNbResults() - $pager->getEndPosition())) {
         $msg = $diff . ' remaining';
         $this->log('');
         $this->log($this->formatter->format($msg, array('fg' => 'yellow')));
     }
 }
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
require 'result/xfPager.class.php';
$t = new lime_test(37, new lime_output_color());
$pager = new xfPager(new ArrayIterator(range(1, 1000)));
$t->diag('->getPage(), ->setPage()');
$t->is($pager->getPage(), 1, '->getPage() returns the current page');
$pager->setPage(3);
$t->is($pager->getPage(), 3, '->setPage() changes the page');
$pager->setPage(31415926);
$t->is($pager->getPage(), 1000 / 10, '->setPage() does not go higher than the last page');
$pager->setPage(0);
$t->is($pager->getPage(), 1, ' ->setPage() does not go lower than the first page');
$t->diag('->getPerPage(), ->setPerPage()');
$t->is($pager->getPerPage(), 10, '->getPerPage() returns the per page count');
$pager->setPerPage(11);
$t->is($pager->getPerPage(), 11, '->setPerPage() changes the per page count');
$pager->setPerPage(-1);
$t->is($pager->getPerpage(), 0, '->setPerPage() does not allow the per page count to go below 0');
$pager->setPerPage(10);
$pager->setPage(100);
$pager->setPerPage(100);
$t->is($pager->getPage(), 10, '->setPerPage() keeps the page count in bounds');
$t->diag('->getResults(), ->getNbResults()');
$pager->setPage(2);
$t->isa_ok($pager->getResults(), 'LimitIterator', '->getResults() returns a LimitIterator');
$t->is($pager->getResults()->getPosition(), 0, '->getResults() returns a LimitIterator with correct position');
$t->isa_ok($pager->getResults()->getInnerIterator(), 'ArrayIterator', '->getResults() returns LimitIterator with the correct iterator');
$t->is($pager->getNbResults(), 1000, '->getNbResults() returns the number of results');
$t->diag('->getFirstPage(), ->getLastPage()');
$pager->setPerPage(11);