/** * {@inheritdoc} */ public function buildPager() { if ($this->bound) { return; } foreach ($this->getFilters() as $name => $filter) { list($type, $options) = $filter->getRenderSettings(); $this->formBuilder->add($filter->getFormName(), $type, $options); } $this->formBuilder->add('_sort_by', 'hidden'); $this->formBuilder->add('_sort_order', 'hidden'); $this->formBuilder->add('_page', 'hidden'); $this->formBuilder->add('_per_page', 'hidden'); $this->form = $this->formBuilder->getForm(); $this->form->submit($this->values); $data = $this->form->getData(); foreach ($this->getFilters() as $name => $filter) { $this->values[$name] = isset($this->values[$name]) ? $this->values[$name] : null; $filter->apply($this->query, $data[$filter->getFormName()]); } if (isset($this->values['_sort_by'])) { $this->query->setSortBy($this->values['_sort_by']); $this->query->setSortOrder(isset($this->values['_sort_order']) ? $this->values['_sort_order'] : null); } $this->pager->setMaxPerPage(isset($this->values['_per_page']) ? $this->values['_per_page'] : 25); $this->pager->setPage(isset($this->values['_page']) ? $this->values['_page'] : 1); $this->pager->setQuery($this->query); $this->pager->init(); $this->bound = true; }
public function testGetResults() { $this->assertEquals(null, $this->datagrid->getResults()); $this->pager->expects($this->once())->method('getResults')->will($this->returnValue(array('foo', 'bar'))); $this->assertEquals(array('foo', 'bar'), $this->datagrid->getResults()); }