public function testBuildPagerWithGlobalSearchField()
 {
     $filter = $this->getMock('Sonata\\AdminBundle\\Filter\\FilterInterface');
     $filter->expects($this->once())->method('getOption')->will($this->returnValue(true));
     $pager = $this->getMock('Sonata\\AdminBundle\\Datagrid\\PagerInterface');
     $pager->expects($this->once())->method('setPage');
     $pager->expects($this->once())->method('setMaxPerPage');
     $datagrid = $this->getMock('Sonata\\AdminBundle\\Datagrid\\DatagridInterface');
     $datagrid->expects($this->once())->method('getFilters')->will($this->returnValue(array($filter)));
     $datagrid->expects($this->once())->method('setValue');
     $datagrid->expects($this->once())->method('getPager')->will($this->returnValue($pager));
     $admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
     $admin->expects($this->once())->method('getDatagrid')->will($this->returnValue($datagrid));
     $handler = new SearchHandler($this->getPool($admin));
     $this->assertInstanceOf('Sonata\\AdminBundle\\Datagrid\\PagerInterface', $handler->search($admin, 'myservice'));
 }
 /**
  * {@inheritdoc}
  */
 public function execute(BlockContextInterface $blockContext, Response $response = null)
 {
     try {
         $admin = $this->pool->getAdminByAdminCode($blockContext->getSetting('admin_code'));
     } catch (ServiceNotFoundException $e) {
         throw new \RuntimeException('Unable to find the Admin instance', $e->getCode(), $e);
     }
     if (!$admin instanceof AdminInterface) {
         throw new \RuntimeException('The requested service is not an Admin instance');
     }
     if (!$admin->isGranted('LIST')) {
         throw new AccessDeniedException();
     }
     $pager = $this->searchHandler->search($admin, $blockContext->getSetting('query'), $blockContext->getSetting('page'), $blockContext->getSetting('per_page'));
     return $this->renderPrivateResponse($admin->getTemplate('search_result_block'), array('block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings(), 'admin_pool' => $this->pool, 'pager' => $pager, 'admin' => $admin), $response);
 }