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()); }
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); }