/**
  * @dataProvider getOffsets
  *
  * @param int $max_navigate
  * @param int $current_page
  * @param int $total_pages
  * @param int $left_offset
  * @param int $right_offset
  */
 public function testBuildOffset($max_navigate, $current_page, $total_pages, $left_offset, $right_offset)
 {
     $this->config->expects($this->exactly(2))->method('getMaxNavigate')->will($this->returnValue($max_navigate));
     $this->config->expects($this->atLeastOnce())->method('getCurrentPage')->will($this->returnValue($current_page));
     $this->config->expects($this->atLeastOnce())->method('getTotalPages')->will($this->returnValue($total_pages));
     $this->assertEquals($left_offset, $this->range->getLeftOffset());
     $this->assertEquals($right_offset, $this->range->getRightOffset());
 }
 public function testGetView()
 {
     $view = $this->config->getView();
     $this->assertInstanceOf(View::class, $view);
     // test lazy load
     $this->config->setPageLink('?p=%s');
     $this->assertEquals($view, $this->config->getView());
 }
Example #3
0
 public function testGetIteratorEmpty()
 {
     $this->config->expects($this->once())->method('getTotalPages')->will($this->returnValue(1));
     $this->config->expects($this->never())->method('getCurrentPage');
     $this->config->expects($this->never())->method('getPageLink');
     $this->config->expects($this->never())->method('getFirstPageLink');
     $this->range->expects($this->never())->method('getLeftOffset');
     $this->range->expects($this->never())->method('getRightOffset');
     $this->assertEquals(new ArrayCollection(), $this->view->getIterator());
 }
Example #4
0
 /**
  * @param int $page
  *
  * @return string
  */
 protected function buildLink($page)
 {
     if ($page == 1 && $this->config->getFirstPageLink()) {
         return $this->config->getFirstPageLink();
     }
     if (is_callable($this->config->getPageLink())) {
         return call_user_func($this->config->getPageLink(), $page);
     } else {
         return sprintf($this->config->getPageLink(), $page);
     }
 }
 /**
  * @param \Twig_Environment $env
  * @param Configuration $pagination
  * @param string $template
  * @param array $view_params
  *
  * @return string
  */
 public function renderPagination(\Twig_Environment $env, Configuration $pagination, $template = null, array $view_params = [])
 {
     return $env->render($template ?: $this->template, array_merge($view_params, ['pagination' => $pagination->getView()]));
 }