Ejemplo n.º 1
0
 public function testDeleteUserId()
 {
     $this->session->expects($this->any())->method('get')->will($this->returnValueMap([[State::USER_KEY, null, 'bar']]));
     $this->state->saveUserId($this->state->getUserId());
     $this->assertEquals('bar', $this->storedValues[State::USER_KEY]);
     $this->state->deleteUserId();
     $this->assertNull($this->storedValues[State::USER_KEY]);
 }
 public function testOnPostSubmitWithInvalidForm()
 {
     $event = $this->createFormEventMock();
     $event->expects($this->once())->method('getForm')->will($this->returnValue($form = $this->createFormMock()));
     $form->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $this->session->expects($this->once())->method('getFlashBag')->will($this->returnValue($flashBag = $this->createFlashBagMock()));
     $this->translator->expects($this->once())->method('trans')->with($this->identicalTo('lug.resource.csrf.error'), $this->identicalTo([]), $this->identicalTo('flashes'))->will($this->returnValue($translation = 'translation'));
     $flashBag->expects($this->once())->method('add')->with($this->identicalTo('error'), $this->identicalTo($translation));
     $this->flashCsrfProtectionSubscriber->onPostSubmit($event);
 }
Ejemplo n.º 3
0
 public function testInvalidatesOnInvalidUserAgent()
 {
     $logger = $this->getMockBuilder('Monolog\\Logger')->setConstructorArgs(array(''))->enableArgumentCloning()->getMock();
     // Change client agent
     $this->request->server->set('HTTP_USER_AGENT', 'TESTING');
     // Set session agent to something different
     $this->session->set('CLIENT_HTTP_USER_AGENT', 'SOME OTHER USER AGENT');
     $this->validator->setLogger($logger);
     // Invalidate
     $logger->expects($this->once())->method('debug');
     $this->session->expects($this->once())->method('invalidate');
     $this->validator->handleSessionValidation($this->session);
 }
 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());
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
 public function testFlashWithApi()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $this->session->expects($this->never())->method('getFlashBag');
     $this->flashListener->addFlash($this->createDomainEventMock());
 }