public function ConfigurePaymentTypeTest::testExecute in Payment 8.2
@covers ::execute
File
- tests/
src/ Unit/ Controller/ ConfigurePaymentTypeTest.php, line 82
Class
- ConfigurePaymentTypeTest
- @coversDefaultClass \Drupal\payment\Controller\ConfigurePaymentType
Namespace
Drupal\Tests\payment\Unit\ControllerCode
public function testExecute() {
$bundle_exists = $this
->randomMachineName();
$bundle_exists_definition = [
'configuration_form' => $this
->randomMachineName(),
];
$bundle_exists_no_form = $this
->randomMachineName();
$bundle_exists_no_form_definition = [];
$bundle_no_exists = $this
->randomMachineName();
$bundle_no_exists_definition = NULL;
$form_build = [
'#type' => $this
->randomMachineName(),
];
$this->formBuilder
->expects($this
->once())
->method('getForm')
->with($bundle_exists_definition['configuration_form'])
->willReturn($form_build);
$map = [
[
$bundle_exists,
FALSE,
$bundle_exists_definition,
],
[
$bundle_exists_no_form,
FALSE,
$bundle_exists_no_form_definition,
],
[
$bundle_no_exists,
FALSE,
$bundle_no_exists_definition,
],
];
$this->paymentTypeManager
->expects($this
->any())
->method('getDefinition')
->willReturnMap($map);
// Test with a bundle of a plugin with a form.
$build = $this->sut
->execute($bundle_exists);
$this
->assertSame($form_build, $build);
// Test with a bundle of a plugin without a form.
$build = $this->sut
->execute($bundle_exists_no_form);
$this
->assertIsArray($build);
// Test with a non-existing bundle.
$this
->expectException(NotFoundHttpException::class);
$this->sut
->execute($bundle_no_exists);
}