/** * @covers ::submitForm */ function testSubmitFormWithoutCompletionResponse() { $operation_result = $this->getMock(OperationResultInterface::class); $operation_result->expects($this->atLeastOnce())->method('isCompleted')->willReturn(TRUE); $payment_method = $this->getMock(PaymentMethodRefundPaymentInterface::class); $payment_method->expects($this->once())->method('refundPayment')->willReturn($operation_result); $url = new Url($this->randomMachineName()); $this->payment->expects($this->atLeastOnce())->method('getPaymentMethod')->willReturn($payment_method); $this->payment->expects($this->atLeastOnce())->method('urlInfo')->with('canonical')->willReturn($url); $form = []; $form_state = $this->getMock(FormStateInterface::class); $form_state->expects($this->atLeastOnce())->method('setRedirectUrl')->with($url); $this->sut->submitForm($form, $form_state); }
/** * @covers ::submitForm * @covers ::getPluginSelector */ public function testSubmitForm() { $form = ['payment_status' => ['foo' => $this->randomMachineName()]]; $form_state = new FormState(); $payment_status = $this->getMock(PaymentStatusInterface::class); $this->pluginSelectorManager->expects($this->once())->method('createInstance')->willReturn($this->pluginSelector); $this->pluginSelector->expects($this->atLeastOnce())->method('getSelectedPlugin')->willReturn($payment_status); $this->pluginSelector->expects($this->atLeastOnce())->method('submitSelectorForm')->with($form['payment_status'], $form_state); $url = new Url($this->randomMachineName()); $this->payment->expects($this->once())->method('setPaymentStatus')->with($payment_status); $this->payment->expects($this->once())->method('save'); $this->payment->expects($this->once())->method('urlInfo')->with('canonical')->willReturn($url); $this->sut->submitForm($form, $form_state); $this->assertSame($url, $form_state->getRedirect()); }
/** * @covers ::submitForm * @covers ::getPluginSelector * @covers ::getPaymentMethodManager */ public function testSubmitForm() { $redirect_url = new Url($this->randomMachineName()); $response = new Response($redirect_url); $result = $this->getMock(OperationResultInterface::class); $result->expects($this->atLeastOnce())->method('getCompletionResponse')->willReturn($response); $form = ['payment_method' => ['#type' => $this->randomMachineName()]]; $form_state = new FormState(); $payment_method = $this->getMock(PaymentMethodInterface::class); $this->pluginSelectorManager->expects($this->once())->method('createInstance')->with($this->configFactoryConfiguration['payment_form.payment_type']['plugin_selector_id'])->willReturn($this->pluginSelector); $this->pluginSelector->expects($this->atLeastOnce())->method('getSelectedPlugin')->willReturn($payment_method); $this->pluginSelector->expects($this->atLeastOnce())->method('submitSelectorForm')->with($form['payment_method'], $form_state); $this->payment->expects($this->atLeastOnce())->method('setPaymentMethod')->with($payment_method); $this->payment->expects($this->atLeastOnce())->method('save'); $this->payment->expects($this->atLeastOnce())->method('execute')->willReturn($result); $this->sut->submitForm($form, $form_state); $this->assertSame($redirect_url, $form_state->getRedirect()); }