コード例 #1
0
 /**
  * @test
  */
 public function shouldRenderFormWhenSubmittedButNotValid()
 {
     $httpRequest = new Request();
     $formView = new FormView();
     $creditCard = new CreditCard();
     $formMock = $this->createFormMock();
     $formMock->expects($this->once())->method('handleRequest')->with($this->identicalTo($httpRequest));
     $formMock->expects($this->once())->method('isSubmitted')->will($this->returnValue(true));
     $formMock->expects($this->once())->method('createView')->will($this->returnValue($formView));
     $formMock->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $formMock->expects($this->once())->method('getData')->will($this->returnValue($creditCard));
     $formFactoryMock = $this->createFormFactoryMock();
     $formFactoryMock->expects($this->once())->method('create')->with('payum_credit_card')->will($this->returnValue($formMock));
     $testCase = $this;
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\RenderTemplate'))->will($this->returnCallback(function (RenderTemplate $request) use($testCase, $formView) {
         $testCase->assertEquals('theTemplateName', $request->getTemplateName());
         $testCase->assertEquals(array('form' => $formView), $request->getParameters());
         $request->setResult('theObtainCreditCardPageWithForm');
     }));
     $action = new ObtainCreditCardAction($formFactoryMock, 'theTemplateName');
     $action->setRequest($httpRequest);
     $action->setGateway($gatewayMock);
     try {
         $action->execute(new ObtainCreditCard());
     } catch (HttpResponse $e) {
         $this->assertEquals('theObtainCreditCardPageWithForm', $e->getResponse()->getContent());
         $this->assertEquals(200, $e->getResponse()->getStatusCode());
         $this->assertEquals('max-age=0, no-cache, no-store, post-check=0, pre-check=0, private', $e->getResponse()->headers->get('Cache-Control'));
         $this->assertEquals('no-cache', $e->getResponse()->headers->get('Pragma'));
         return;
     }
     $this->fail('Reply exception was expected to be thrown');
 }
コード例 #2
0
 /**
  * @test
  */
 public function shouldPassFirstAndCurrentModelsToTemplate()
 {
     $firstModel = new \stdClass();
     $currentModel = new \stdClass();
     $httpRequest = new Request();
     $formView = new FormView();
     $creditCard = new CreditCard();
     $formMock = $this->createFormMock();
     $formMock->expects($this->once())->method('handleRequest')->with($this->identicalTo($httpRequest));
     $formMock->expects($this->once())->method('isSubmitted')->will($this->returnValue(true));
     $formMock->expects($this->once())->method('createView')->will($this->returnValue($formView));
     $formMock->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $formMock->expects($this->once())->method('getData')->will($this->returnValue($creditCard));
     $formFactoryMock = $this->createFormFactoryMock();
     $formFactoryMock->expects($this->once())->method('create')->with('payum_credit_card')->will($this->returnValue($formMock));
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\RenderTemplate'))->will($this->returnCallback(function (RenderTemplate $request) use($formView, $firstModel, $currentModel) {
         $this->assertEquals('theTemplateName', $request->getTemplateName());
         $this->assertEquals(array('form' => $formView, 'model' => $currentModel, 'firstModel' => $firstModel, 'actionUrl' => null), $request->getParameters());
         $request->setResult('theObtainCreditCardPageWithForm');
     }));
     $action = new ObtainCreditCardAction($formFactoryMock, 'theTemplateName');
     $action->setRequest($httpRequest);
     $action->setGateway($gatewayMock);
     try {
         $action->execute(new ObtainCreditCard($firstModel, $currentModel));
     } catch (HttpResponse $e) {
         return;
     }
     $this->fail('Reply exception was expected to be thrown');
 }