public function testSaveAndDuplicate()
 {
     $entity = $this->getProductMock();
     $queryParameters = ['qwe' => 'rty'];
     $this->request->query = new ParameterBag($queryParameters);
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('POST'));
     $this->request->expects($this->at(1))->method('get')->with($this->anything())->will($this->returnValue(false));
     $this->request->expects($this->at(2))->method('get')->with(Router::ACTION_PARAMETER)->will($this->returnValue(ProductUpdateHandler::ACTION_SAVE_AND_DUPLICATE));
     $this->doctrineHelper->expects($this->once())->method('getEntityManager')->with($entity)->will($this->returnValue($this->entityManager));
     $message = 'Saved';
     $savedAndDuplicatedMessage = 'Saved and duplicated';
     /** @var \PHPUnit_Framework_MockObject_MockObject|Form $form */
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $flashBag = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface')->getMock();
     $flashBag->expects($this->once())->method('add')->with('success', $message);
     $flashBag->expects($this->once())->method('set')->with('success', $savedAndDuplicatedMessage);
     $this->session->expects($this->any())->method('getFlashBag')->will($this->returnValue($flashBag));
     $saveAndStayRoute = ['route' => 'test_update'];
     $saveAndCloseRoute = ['route' => 'test_view'];
     $this->router->expects($this->once())->method('redirectAfterSave')->with(array_merge($saveAndStayRoute, ['parameters' => $queryParameters]), array_merge($saveAndCloseRoute, ['parameters' => $queryParameters]), $entity)->will($this->returnValue(new RedirectResponse('test_url')));
     $this->translator->expects($this->once())->method('trans')->with('orob2b.product.controller.product.saved_and_duplicated.message')->will($this->returnValue($savedAndDuplicatedMessage));
     $this->urlGenerator->expects($this->once())->method('generate')->with('orob2b_product_duplicate', ['id' => self::PRODUCT_ID])->will($this->returnValue('generated_redirect_url'));
     $result = $this->handler->handleUpdate($entity, $form, $saveAndStayRoute, $saveAndCloseRoute, $message);
     $this->assertEquals('generated_redirect_url', $result->headers->get('location'));
     $this->assertEquals(302, $result->getStatusCode());
 }
Exemplo n.º 2
0
 /**
  * @param FormInterface $form
  * @param object $entity
  * @param array|callable $saveAndStayRoute
  * @param array|callable $saveAndCloseRoute
  * @param string $saveMessage
  * @param callback|null $resultCallback
  * @return array|RedirectResponse
  */
 protected function processSave(FormInterface $form, $entity, $saveAndStayRoute, $saveAndCloseRoute, $saveMessage, $resultCallback = null)
 {
     if ($this->request->get('_wid')) {
         $result = $this->getResult($entity, $form, $resultCallback);
         $result['savedId'] = $this->doctrineHelper->getSingleEntityIdentifier($entity);
         return $result;
     } else {
         $this->session->getFlashBag()->add('success', $saveMessage);
         if (is_callable($saveAndStayRoute)) {
             $saveAndStayRoute = call_user_func($saveAndStayRoute, $entity);
         }
         if (is_callable($saveAndCloseRoute)) {
             $saveAndCloseRoute = call_user_func($saveAndCloseRoute, $entity);
         }
         return $this->router->redirectAfterSave($saveAndStayRoute, $saveAndCloseRoute, $entity);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 4
0
 public function testWrongParametersActionRedirect()
 {
     $this->setExpectedException('\\LogicException');
     $this->router->actionRedirect(array(), array());
 }
Exemplo n.º 5
0
 public function testWrongParametersRedirectAfterSave()
 {
     $this->setExpectedException('\\InvalidArgumentException');
     $this->router->redirectAfterSave(array(), array());
 }