public function testBatchActionDeleteWithModelManagerException() { $modelManager = $this->getMock('Sonata\\AdminBundle\\Model\\ModelManagerInterface'); $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete'); $this->admin->expects($this->once())->method('getModelManager')->will($this->returnValue($modelManager)); $this->admin->expects($this->once())->method('getFilterParameters')->will($this->returnValue(array('foo' => 'bar'))); $result = $this->controller->batchActionDelete($this->getMock('Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface')); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $result); $this->assertSame(array('flash_batch_delete_error'), $this->session->getFlashBag()->get('sonata_flash_error')); $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl()); }
public function testBatchActionDeleteWithModelManagerExceptionInDebugMode() { $modelManager = $this->getMock('Sonata\\AdminBundle\\Model\\ModelManagerInterface'); $this->setExpectedException('Sonata\\AdminBundle\\Exception\\ModelManagerException'); $modelManager->expects($this->once())->method('batchDelete')->will($this->returnCallback(function () { throw new ModelManagerException(); })); $this->admin->expects($this->once())->method('getModelManager')->will($this->returnValue($modelManager)); $this->kernel->expects($this->once())->method('isDebug')->will($this->returnValue(true)); $this->controller->batchActionDelete($this->getMock('Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface')); }
/** * Batch forms deletion * * @param ProxyQueryInterface $query * @param Request $request * @return RedirectResponse */ public function batchActionDelete(ProxyQueryInterface $query, Request $request = null) { /** @var FcForm $fc_form */ foreach ($query->find() as $fc_form) { if ($fc_form->isUsedAsWidget()) { $this->addFlash('sonata_flash_error', $this->admin->trans('fc.message.admin.form.is_used_as_widget', array(), 'FenrizbesFormConstructorBundle')); return new RedirectResponse($this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters()))); } } return parent::batchActionDelete($query); }
public function batchActionDelete(ProxyQueryInterface $query) { // status = Vérouillé cannot be deleted $query->andWhere('o.status = 2 OR o.status IS NULL'); return parent::batchActionDelete($query); }