Skip to content

Commit

Permalink
Fix missing flash message translations
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelVella authored and jlamur committed Sep 20, 2017
1 parent b2caac9 commit c39403f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,16 @@ public function batchActionDelete(ProxyQueryInterface $query)

try {
$modelManager->batchDelete($this->admin->getClass(), $query);
$this->addFlash('sonata_flash_success', 'flash_batch_delete_success');
$this->addFlash(
'sonata_flash_success',
$this->trans('flash_batch_delete_success', array(), 'SonataAdminBundle')
);
} catch (ModelManagerException $e) {
$this->handleModelManagerException($e);
$this->addFlash('sonata_flash_error', 'flash_batch_delete_error');
$this->addFlash(
'sonata_flash_error',
$this->trans('flash_batch_delete_error', array(), 'SonataAdminBundle')
);
}

return new RedirectResponse($this->admin->generateUrl(
Expand Down Expand Up @@ -406,7 +412,10 @@ public function batchAction()
$datagrid->buildPager();

if (true !== $nonRelevantMessage) {
$this->addFlash('sonata_flash_info', $nonRelevantMessage);
$this->addFlash(
'sonata_flash_info',
$this->trans($nonRelevantMessage, array(), 'SonataAdminBundle')
);

return new RedirectResponse(
$this->admin->generateUrl(
Expand Down Expand Up @@ -912,7 +921,10 @@ public function aclAction($id = null)

if ($form->isValid()) {
$adminObjectAclManipulator->$updateMethod($adminObjectAclData);
$this->addFlash('sonata_flash_success', 'flash_acl_edit_success');
$this->addFlash(
'sonata_flash_success',
$this->trans('flash_acl_edit_success', array(), 'SonataAdminBundle')
);

return new RedirectResponse($this->admin->generateObjectUrl('acl', $object));
}
Expand Down
18 changes: 18 additions & 0 deletions Tests/Controller/CRUDControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ public function testBatchActionDelete()
->method('getFilterParameters')
->will($this->returnValue(array('foo' => 'bar')));

$this->expectTranslate('flash_batch_delete_success', array(), 'SonataAdminBundle');

$result = $this->controller->batchActionDelete($this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
Expand All @@ -797,6 +799,8 @@ public function testBatchActionDeleteWithModelManagerException()
->method('getFilterParameters')
->will($this->returnValue(array('foo' => 'bar')));

$this->expectTranslate('flash_batch_delete_error', array(), 'SonataAdminBundle');

$result = $this->controller->batchActionDelete($this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
Expand Down Expand Up @@ -2885,6 +2889,8 @@ public function testAclActionSuccessfulUpdate()
->method('getSecurityHandler')
->will($this->returnValue($aclSecurityHandler));

$this->expectTranslate('flash_acl_edit_success', array(), 'SonataAdminBundle');

$this->request->setMethod('POST');

$response = $this->controller->aclAction(null, $this->request);
Expand Down Expand Up @@ -3394,6 +3400,8 @@ public function testBatchActionWithoutConfirmation()
->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(array('123', '456')))
->will($this->returnValue(true));

$this->expectTranslate('flash_batch_delete_success', array(), 'SonataAdminBundle');

$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('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
Expand Down Expand Up @@ -3449,6 +3457,8 @@ public function testBatchActionWithoutConfirmation2()
->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(array('123', '456')))
->will($this->returnValue(true));

$this->expectTranslate('flash_batch_delete_success', array(), 'SonataAdminBundle');

$this->request->setMethod('POST');
$this->request->request->set('action', 'delete');
$this->request->request->set('idx', array('123', '456'));
Expand Down Expand Up @@ -3537,6 +3547,8 @@ public function testBatchActionNonRelevantAction()
->method('getDatagrid')
->will($this->returnValue($datagrid));

$this->expectTranslate('flash_batch_empty', array(), 'SonataAdminBundle');

$this->request->setMethod('POST');
$this->request->request->set('action', 'foo');
$this->request->request->set('idx', array('789'));
Expand Down Expand Up @@ -3571,6 +3583,8 @@ public function testBatchActionNonRelevantAction2()
->method('getDatagrid')
->will($this->returnValue($datagrid));

$this->expectTranslate('flash_foo_error', array(), 'SonataAdminBundle');

$this->request->setMethod('POST');
$this->request->request->set('action', 'foo');
$this->request->request->set('idx', array('999'));
Expand Down Expand Up @@ -3602,6 +3616,8 @@ public function testBatchActionNoItems()
->method('getDatagrid')
->will($this->returnValue($datagrid));

$this->expectTranslate('flash_batch_empty', array(), 'SonataAdminBundle');

$this->request->setMethod('POST');
$this->request->request->set('action', 'delete');
$this->request->request->set('idx', array());
Expand Down Expand Up @@ -3706,6 +3722,8 @@ public function testBatchActionWithRequesData()
->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(array('123', '456')))
->will($this->returnValue(true));

$this->expectTranslate('flash_batch_delete_success', array(), 'SonataAdminBundle');

$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');
Expand Down

0 comments on commit c39403f

Please sign in to comment.