class PaymentFormTest in Payment 8.2
Same name in this branch
- 8.2 modules/payment_form/tests/src/Unit/Entity/Payment/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Entity\Payment\PaymentFormTest
- 8.2 modules/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Plugin\Payment\Type\PaymentFormTest
- 8.2 modules/payment_form/tests/src/Unit/Plugin/Field/FieldFormatter/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Plugin\Field\FieldFormatter\PaymentFormTest
- 8.2 modules/payment_form/tests/src/Unit/Plugin/Field/FieldWidget/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Plugin\Field\FieldWidget\PaymentFormTest
- 8.2 modules/payment_form/tests/src/Unit/Plugin/Field/FieldType/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Plugin\Field\FieldType\PaymentFormTest
@coversDefaultClass \Drupal\payment_form\Plugin\Field\FieldWidget\PaymentForm
@group Payment Form Field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment_form\Unit\Plugin\Field\FieldWidget\PaymentFormTest
Expanded class hierarchy of PaymentFormTest
File
- modules/
payment_form/ tests/ src/ Unit/ Plugin/ Field/ FieldWidget/ PaymentFormTest.php, line 21
Namespace
Drupal\Tests\payment_form\Unit\Plugin\Field\FieldWidgetView source
class PaymentFormTest extends UnitTestCase {
/**
* The field definition.
*
* @var \Drupal\Core\Field\FieldDefinitionInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $fieldDefinition;
/**
* The payment line item manager.
*
* @var \Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paymentLineItemManager;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* The class under test.
*
* @var \Drupal\payment_form\Plugin\Field\FieldWidget\PaymentForm
*/
protected $sut;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$plugin_id = $this
->randomMachineName();
$plugin_definition = [];
$this->fieldDefinition = $this
->createMock(FieldDefinitionInterface::class);
$settings = [];
$third_party_settings = [];
$this->paymentLineItemManager = $this
->createMock(PaymentLineItemManagerInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->sut = new PaymentForm($plugin_id, $plugin_definition, $this->fieldDefinition, $settings, $third_party_settings, $this->stringTranslation, $this->paymentLineItemManager);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'plugin.manager.payment.line_item',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->paymentLineItemManager,
],
[
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$field_definition = $this
->createMock(FieldDefinitionInterface::class);
$configuration = [
'field_definition' => $field_definition,
'settings' => [],
'third_party_settings' => [],
];
$plugin_definition = [];
$plugin_id = $this
->randomMachineName();
$sut = PaymentForm::create($container, $configuration, $plugin_id, $plugin_definition);
$this
->assertInstanceOf(PaymentForm::class, $sut);
}
/**
* @covers ::settingsSummary
*/
public function testSettingsSummaryWithOneLineItem() {
$line_items_data = [
[
'plugin_id' => $this
->randomMachineName(),
'plugin_configuration' => [],
],
];
$this->sut
->setSetting('line_items', $line_items_data);
$this->stringTranslation
->expects($this
->any())
->method('formatPlural')
->with(1);
$this
->assertInstanceOf(PluralTranslatableMarkup::class, $this->sut
->settingsSummary()[0]);
}
/**
* @covers ::settingsSummary
*/
public function testSettingsSummaryWithMultipleLineItems() {
$line_items_data = [
[
'plugin_id' => $this
->randomMachineName(),
'plugin_configuration' => [],
],
[
'plugin_id' => $this
->randomMachineName(),
'plugin_configuration' => [],
],
];
$this->sut
->setSetting('line_items', $line_items_data);
$this->stringTranslation
->expects($this
->any())
->method('formatPlural')
->with(2);
$this
->assertInstanceOf(PluralTranslatableMarkup::class, $this->sut
->settingsSummary()[0]);
}
/**
* @covers ::formElement
*/
public function testFormElement() {
$items = $this
->getMockBuilder(FieldItemList::class)
->disableOriginalConstructor()
->getMock();
$delta = 0;
$element = [];
$form = [];
$form_state = $this
->createMock(FormStateInterface::class);
$this
->assertIsArray($this->sut
->formElement($items, $delta, $element, $form, $form_state));
}
/**
* @covers ::formElementProcess
*/
public function testFormElementProcess() {
$field_storage_definition = $this
->createMock(FieldStorageDefinitionInterface::class);
$this->fieldDefinition
->expects($this
->atLeastOnce())
->method('getFieldStorageDefinition')
->willReturn($field_storage_definition);
$iterator = new \ArrayIterator([
(object) [
'plugin_configuration' => [],
'plugin_id' => $this
->randomMachineName(),
],
]);
$items = $this
->getMockBuilder(FieldItemList::class)
->disableOriginalConstructor()
->setMethods([
'getIterator',
])
->getMock();
$items
->expects($this
->once())
->method('getIterator')
->willReturn($iterator);
$element = [
'#array_parents' => [
'line_items',
],
'#items' => $items,
];
$form = [];
$form_state = $this
->createMock(FormStateInterface::class);
$element = $this->sut
->formElementProcess($element, $form_state, $form);
$this
->assertIsArray($element);
$this
->arrayHasKey('array_parents', $element);
$this
->arrayHasKey('line_items', $element);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentFormTest:: |
protected | property | The field definition. | |
PaymentFormTest:: |
protected | property | The payment line item manager. | |
PaymentFormTest:: |
protected | property | The string translator. | |
PaymentFormTest:: |
protected | property | The class under test. | |
PaymentFormTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PaymentFormTest:: |
function | @covers ::create @covers ::__construct | ||
PaymentFormTest:: |
public | function | @covers ::formElement | |
PaymentFormTest:: |
public | function | @covers ::formElementProcess | |
PaymentFormTest:: |
public | function | @covers ::settingsSummary | |
PaymentFormTest:: |
public | function | @covers ::settingsSummary | |
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. |