/** * Test for getViewData(). */ public function testGetViewData() { $filterStateMock = $this->getMockBuilder('ONGR\\FilterManagerBundle\\Filters\\FilterState')->getMock(); $filterStateMock->expects($this->any())->method('getValue')->willReturn(1); $filter = new Pager(); $filter->setMaxPages(1); $filter->setCountPerPage(2); $result = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\Result\\DocumentIterator')->disableOriginalConstructor()->getMock(); $result->expects($this->once())->method('getTotalCount')->willReturn(55); $viewData = $filter->createViewData(); $viewData->setState($filterStateMock); $viewData = $filter->getViewData($result, $viewData); $this->assertInstanceOf('ONGR\\FilterManagerBundle\\Filters\\ViewData\\PagerAwareViewData', $viewData); $this->assertInstanceOf('ONGR\\FilterManagerBundle\\Pager\\PagerService', $viewData->getPager()); $this->assertEquals(55, $viewData->getPager()->getAdapter()->getTotalResults()); }
/** * Returns filter manager. * * @param array $options * * @return FiltersManager */ protected function getFiltersManager(array $options) { $container = new FiltersContainer(); $choices = [['label' => 'Stock ASC', 'field' => 'stock', 'order' => 'asc', 'default' => false, 'mode' => null]]; $filter = new Pager(); $filter->setRequestField('page'); if (isset($options['count_per_page'])) { $filter->setCountPerPage($options['count_per_page']); } if (isset($options['max_pages'])) { $filter->setMaxPages($options['max_pages']); } $container->set('pager', $filter); $sort = new Sort(); $sort->setRequestField('sort'); $sort->setChoices($choices); $container->set('sorting', $sort); return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product')); }