/** * @covers ::submitForm * @covers ::getPluginSelector */ public function testSubmitForm() { $form = ['plugin_selector' => ['foo' => $this->randomMachineName()]]; $form_state = new FormState(); $form_state->setValues(['plugin_selector_id' => $this->configFactoryConfiguration['payment_form.payment_type']['plugin_selector_id'], 'allowed_plugin_ids' => $this->configFactoryConfiguration['payment_form.payment_type']['allowed_plugin_ids'], 'limit_allowed_plugins' => $this->configFactoryConfiguration['payment_form.payment_type']['limit_allowed_plugins']]); $map = [['payment_radios', [], $this->pluginSelector], [$this->configFactoryConfiguration['payment_form.payment_type']['plugin_selector_id'], [], $this->selectedPluginSelector]]; $this->pluginSelectorManager->expects($this->atLeast(count($map)))->method('createInstance')->willReturnMap($map); $this->pluginSelector->expects($this->once())->method('submitSelectorForm')->with($form['plugin_selector'], $form_state); $this->pluginSelector->expects($this->once())->method('getSelectedPlugin')->willReturn($this->selectedPluginSelector); $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()); }