public function testBatchActionNoItems()
 {
     $batchActions = array('delete' => array('label' => 'Foo Bar', 'ask_confirmation' => true));
     $this->admin->expects($this->once())->method('getBatchActions')->will($this->returnValue($batchActions));
     $datagrid = $this->getMock('\\Sonata\\AdminBundle\\Datagrid\\DatagridInterface');
     $this->admin->expects($this->once())->method('getDatagrid')->will($this->returnValue($datagrid));
     $this->request->setMethod('POST');
     $this->request->request->set('action', 'delete');
     $this->request->request->set('idx', array());
     $result = $this->controller->batchAction();
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $result);
     $this->assertSame(array('flash_batch_empty'), $this->session->getFlashBag()->get('sonata_flash_info'));
     $this->assertEquals('list?', $result->getTargetUrl());
 }
 public function testBatchActionWithRequesData()
 {
     $batchActions = array('delete' => array('label' => 'Foo Bar', 'ask_confirmation' => false));
     $this->admin->expects($this->once())->method('getBatchActions')->will($this->returnValue($batchActions));
     $datagrid = $this->getMock('\\Sonata\\AdminBundle\\Datagrid\\DatagridInterface');
     $query = $this->getMock('\\Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface');
     $datagrid->expects($this->once())->method('getQuery')->will($this->returnValue($query));
     $this->admin->expects($this->once())->method('getDatagrid')->will($this->returnValue($datagrid));
     $modelManager = $this->getMock('Sonata\\AdminBundle\\Model\\ModelManagerInterface');
     $this->admin->expects($this->once())->method('checkAccess')->with($this->equalTo('batchDelete'))->will($this->returnValue(true));
     $this->admin->expects($this->any())->method('getModelManager')->will($this->returnValue($modelManager));
     $this->admin->expects($this->any())->method('getClass')->will($this->returnValue('Foo'));
     $modelManager->expects($this->once())->method('addIdentifiersToQuery')->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(array('123', '456')))->will($this->returnValue(true));
     $this->request->setMethod('POST');
     $this->request->request->set('data', json_encode(array('action' => 'delete', 'idx' => array('123', '456'), 'all_elements' => false)));
     $this->request->request->set('foo', 'bar');
     $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
     $result = $this->controller->batchAction($this->request);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $result);
     $this->assertSame(array('flash_batch_delete_success'), $this->session->getFlashBag()->get('sonata_flash_success'));
     $this->assertSame('list?', $result->getTargetUrl());
     $this->assertSame('bar', $this->request->request->get('foo'));
 }
 /**
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function batchAction()
 {
     $date_piece = $this->getRequest()->query->get('date_piece');
     $this->_month = $date_piece['value']['month'];
     $this->getLocking();
     $this->getLockingAccessDenied();
     return parent::batchAction();
 }