예제 #1
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');
 }
예제 #2
0
 /**
  * @test
  */
 public function shouldRenderFormWhenSubmitedAndValid()
 {
     $httpRequest = new Request();
     $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('isValid')->will($this->returnValue(true));
     $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));
     $action = new ObtainCreditCardAction($formFactoryMock, 'aTemplate');
     $action->setRequest($httpRequest);
     $obtainCreditCard = new ObtainCreditCard();
     $action->execute($obtainCreditCard);
     $this->assertSame($creditCard, $obtainCreditCard->obtain());
 }
예제 #3
0
 /**
  * @param ArrayObject $config
  *
  * @return ObtainCreditCardAction
  */
 public function build(ArrayObject $config)
 {
     $action = new ObtainCreditCardAction($this->formFactory, $config['payum.template.obtain_credit_card']);
     $action->setRequestStack($this->requestStack);
     return $action;
 }