/**
  * @param FormInterface $form
  * @param Product $entity
  * @param array|callable $saveAndStayRoute
  * @param array|callable $saveAndCloseRoute
  * @param string $saveMessage
  * @param null $resultCallback
  * @return array|RedirectResponse
  */
 protected function processSave(FormInterface $form, $entity, $saveAndStayRoute, $saveAndCloseRoute, $saveMessage, $resultCallback = null)
 {
     $result = parent::processSave($form, $entity, $saveAndStayRoute, $saveAndCloseRoute, $saveMessage, $resultCallback);
     if ($result instanceof RedirectResponse && $this->isSaveAndDuplicateAction()) {
         $saveMessage = $this->translator->trans('orob2b.product.controller.product.saved_and_duplicated.message');
         $this->session->getFlashBag()->set('success', $saveMessage);
         return new RedirectResponse($this->urlGenerator->generate('orob2b_product_duplicate', ['id' => $entity->getId()]));
     }
     return $result;
 }
예제 #2
0
 public function testHandleSaveNoWid()
 {
     $message = 'Saved';
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $entity = new \stdClass();
     $handler = $this->getMockBuilder('Oro\\Bundle\\FormBundle\\Tests\\Unit\\Form\\Stub\\HandlerStub')->getMock();
     $handler->expects($this->once())->method('process')->with($entity)->will($this->returnValue(true));
     $flashBag = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface')->getMock();
     $flashBag->expects($this->once())->method('add')->with('success', $message);
     $this->session->expects($this->once())->method('getFlashBag')->will($this->returnValue($flashBag));
     $saveAndStayRoute = array('route' => 'test_update');
     $saveAndCloseRoute = array('route' => 'test_view');
     $expected = array('redirect' => true);
     $this->router->expects($this->once())->method('redirectAfterSave')->with($saveAndStayRoute, $saveAndCloseRoute, $entity)->will($this->returnValue($expected));
     $result = $this->handler->handleUpdate($entity, $form, $saveAndStayRoute, $saveAndCloseRoute, $message, $handler);
     $this->assertEquals($expected, $result);
 }
예제 #3
0
 public function testHandleSaveNoWid()
 {
     $queryParameters = ['qwe' => 'rty'];
     $this->request->query = new ParameterBag($queryParameters);
     $message = 'Saved';
     /** @var \PHPUnit_Framework_MockObject_MockObject|Form $form */
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $entity = $this->getObject();
     $handler = $this->getMockBuilder('Oro\\Bundle\\FormBundle\\Tests\\Unit\\Form\\Stub\\HandlerStub')->getMock();
     $handler->expects($this->once())->method('process')->with($entity)->will($this->returnValue(true));
     $flashBag = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface')->getMock();
     $flashBag->expects($this->once())->method('add')->with('success', $message);
     $this->session->expects($this->once())->method('getFlashBag')->will($this->returnValue($flashBag));
     $saveAndStayRoute = ['route' => 'test_update'];
     $saveAndCloseRoute = ['route' => 'test_view'];
     $expected = ['redirect' => true];
     $this->router->expects($this->once())->method('redirectAfterSave')->with(array_merge($saveAndStayRoute, ['parameters' => $queryParameters]), array_merge($saveAndCloseRoute, ['parameters' => $queryParameters]), $entity)->will($this->returnValue($expected));
     $result = $this->handler->handleUpdate($entity, $form, $saveAndStayRoute, $saveAndCloseRoute, $message, $handler);
     $this->assertEquals($expected, $result);
 }