Example #1
0
 public function testWillProperlyCalculateLimitAndOffset()
 {
     $pagination = new Pagination();
     $pagination->setSize(25);
     $pagination->setCount(100);
     $this->assertSame(0, $pagination->getOffset(), 'That should start from 0');
     $this->assertSame(25, $pagination->getLimit(), 'That should limit to 25');
     // Set second page
     $pagination->setPage(2);
     $this->assertSame(25, $pagination->getOffset(), 'That should start from 25');
     $this->assertSame(25, $pagination->getLimit(), 'That should limit to 25');
 }
 public function testIfWillFindProperlyCountWithSearchProviderPagination()
 {
     $model = $this->prepare();
     $criteria = new SearchCriteria();
     $criteria->search('shanghai');
     $pagination = new Pagination();
     $pagination->setSize(2);
     $dp = new SearchProvider($model);
     $dp->setPagination($pagination);
     $dp->setCriteria($criteria);
     $this->assertSame(7, $dp->getTotalItemCount(), 'That total is 7 items');
     $this->assertSame(2, $dp->getItemCount(), 'That current result set has 2 items');
     $results = $dp->getData();
     $this->assertSame(2, count($results), 'That 2 result was returned');
     $this->assertTrue(array_key_exists(0, $results), 'That results starts with key 0');
     foreach ($results as $i => $result) {
         $this->assertInstanceOf(SimpleModel::class, $result, "That result {$i} has proper type");
         $this->assertSame('Shanghai', $result->title, "That title is properly populated");
     }
 }