class PaymentFormConfigurationFormTest in Payment 8.2
@coversDefaultClass \Drupal\payment_form\Plugin\Payment\Type\PaymentFormConfigurationForm
@group Payment Reference Field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment_form\Unit\Plugin\Payment\Type\PaymentFormConfigurationFormTest
Expanded class hierarchy of PaymentFormConfigurationFormTest
File
- modules/
payment_form/ tests/ src/ Unit/ Plugin/ Payment/ Type/ PaymentFormConfigurationFormTest.php, line 21
Namespace
Drupal\Tests\payment_form\Unit\Plugin\Payment\TypeView source
class PaymentFormConfigurationFormTest extends UnitTestCase {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactory|\PHPUnit\Framework\MockObject\MockObject
*/
protected $configFactory;
/**
* The configuration the config factory returns.
*
* @see self::__construct
*
* @var array
*/
protected $configFactoryConfiguration = [];
/**
* The payment method manager.
*
* @var \Drupal\payment\Plugin\Payment\Method\PaymentMethodManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paymentMethodManager;
/**
* The plugin selector.
*
* @var \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $pluginSelector;
/**
* The plugin selector manager.
*
* @var \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $pluginSelectorManager;
/**
* The plugin selector plugin type.
*
* @var \Drupal\plugin\PluginType\PluginTypeInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $pluginSelectorType;
/**
* The selected plugin selector.
*
* @var \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $selectedPluginSelector;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected $stringTranslation;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $messenger;
/**
* The class under test.
*
* @var \Drupal\payment_form\Plugin\Payment\Type\PaymentFormConfigurationForm
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->configFactoryConfiguration = [
'payment_form.payment_type' => [
'limit_allowed_plugins' => TRUE,
'allowed_plugin_ids' => [
$this
->randomMachineName(),
],
'plugin_selector_id' => $this
->randomMachineName(),
],
];
$this->configFactory = $this
->getConfigFactoryStub($this->configFactoryConfiguration);
$this->paymentMethodManager = $this
->createMock(PaymentMethodManagerInterface::class);
$this->pluginSelector = $this
->createMock(PluginSelectorInterface::class);
$this->pluginSelectorManager = $this
->createMock(PluginSelectorManagerInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->pluginSelectorType = $this
->prophesize(PluginTypeInterface::class);
$this->pluginSelectorType
->getPluginManager()
->willReturn($this->pluginSelectorManager);
$this->selectedPluginSelector = $this
->createMock(PluginSelectorInterface::class);
$this->messenger = $this
->createMock(MessengerInterface::class);
$this->sut = new PaymentFormConfigurationForm($this->configFactory, $this->stringTranslation, $this->paymentMethodManager, $this->pluginSelectorType
->reveal());
$this->sut
->setMessenger($this->messenger);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$plugin_type_manager = $this
->prophesize(PluginTypeManagerInterface::class);
$plugin_type_manager
->getPluginType('plugin_selector')
->willReturn($this->pluginSelectorType
->reveal());
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'config.factory',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->configFactory,
],
[
'plugin.manager.payment.method',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->paymentMethodManager,
],
[
'plugin.plugin_type_manager',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$plugin_type_manager
->reveal(),
],
[
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = PaymentFormConfigurationForm::create($container);
$this
->assertInstanceOf(PaymentFormConfigurationForm::class, $sut);
}
/**
* @covers ::getFormId
*/
public function testGetFormId() {
$this
->assertIsString($this->sut
->getFormId());
}
/**
* @covers ::buildForm
* @covers ::getPluginSelector
*/
public function testBuildForm() {
$form = [];
$form_state = new FormState();
$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('buildSelectorForm')
->with([], $form_state)
->willReturn($this->pluginSelector);
$this->paymentMethodManager
->expects($this
->atLeastOnce())
->method('getDefinitions')
->willReturn([]);
$build = $this->sut
->buildForm($form, $form_state);
$this
->assertIsArray($build);
}
/**
* @covers ::validateForm
* @covers ::getPluginSelector
*/
public function testValidateForm() {
$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('validateSelectorForm')
->with($form['plugin_selector'], $form_state);
$this->sut
->validateForm($form, $form_state);
}
/**
* @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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentFormConfigurationFormTest:: |
protected | property | The config factory. | |
PaymentFormConfigurationFormTest:: |
protected | property | The configuration the config factory returns. | |
PaymentFormConfigurationFormTest:: |
protected | property | The messenger. | |
PaymentFormConfigurationFormTest:: |
protected | property | The payment method manager. | |
PaymentFormConfigurationFormTest:: |
protected | property | The plugin selector. | |
PaymentFormConfigurationFormTest:: |
protected | property | The plugin selector manager. | |
PaymentFormConfigurationFormTest:: |
protected | property | The plugin selector plugin type. | |
PaymentFormConfigurationFormTest:: |
protected | property | The selected plugin selector. | |
PaymentFormConfigurationFormTest:: |
protected | property | The string translator. | |
PaymentFormConfigurationFormTest:: |
protected | property | The class under test. | |
PaymentFormConfigurationFormTest:: |
public | function |
Overrides UnitTestCase:: |
|
PaymentFormConfigurationFormTest:: |
public | function | @covers ::buildForm @covers ::getPluginSelector | |
PaymentFormConfigurationFormTest:: |
function | @covers ::create @covers ::__construct | ||
PaymentFormConfigurationFormTest:: |
public | function | @covers ::getFormId | |
PaymentFormConfigurationFormTest:: |
public | function | @covers ::submitForm @covers ::getPluginSelector | |
PaymentFormConfigurationFormTest:: |
public | function | @covers ::validateForm @covers ::getPluginSelector | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |