public function PaymentStatusFormTest::testSubmitForm in Payment 8.2
@covers ::submitForm @covers ::getPluginSelector
File
- tests/
src/ Unit/ Entity/ Payment/ PaymentStatusFormTest.php, line 272
Class
- PaymentStatusFormTest
- @coversDefaultClass \Drupal\payment\Entity\Payment\PaymentStatusForm
Namespace
Drupal\Tests\payment\Unit\Entity\PaymentCode
public function testSubmitForm() {
$form = [
'payment_status' => [
'foo' => $this
->randomMachineName(),
],
];
$form_state = new FormState();
$form_display = $this
->prophesize(EntityFormDisplayInterface::class);
$form_display
->extractFormValues(Argument::any(), $form, $form_state);
$form_state
->set('form_display', $form_display
->reveal());
$entity_type = new EntityType([
'id' => 'payment',
]);
$this->payment
->expects($this
->any())
->method('getEntityType')
->willReturn($entity_type);
$payment_status = $this
->createMock(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('toUrl')
->with('canonical')
->willReturn($url);
$payment_status_manager = $this
->prophesize(PaymentStatusManagerInterface::class);
$this->paymentStatusPluginType
->getPluginManager()
->willReturn($payment_status_manager
->reveal());
$this->sut
->submitForm($form, $form_state);
$this
->assertSame($url, $form_state
->getRedirect());
}