public function PaymentLineItemsInputTest::testProcess in Payment 8.2
@covers ::process
File
- tests/
src/ Unit/ Element/ PaymentLineItemsInputTest.php, line 150
Class
- PaymentLineItemsInputTest
- @coversDefaultClass \Drupal\payment\Element\PaymentLineItemsInput
Namespace
Drupal\Tests\payment\Unit\ElementCode
public function testProcess() {
$form_state = new FormState();
$form = [];
$line_item_name_a = $this
->randomMachineName();
$line_item_configuration_form_a = array(
'#foo' => $this
->randomMachineName(),
);
$line_item_a = $this
->createMock(PaymentLineItemInterface::class);
$line_item_a
->expects($this
->atLeastOnce())
->method('buildConfigurationForm')
->with([], $form_state)
->willReturn($line_item_configuration_form_a);
$line_item_a
->expects($this
->atLeastOnce())
->method('getName')
->willReturn($line_item_name_a);
$line_item_name_b = $this
->randomMachineName();
$line_item_configuration_form_b = array(
'#foo' => $this
->randomMachineName(),
);
$line_item_b = $this
->createMock(PaymentLineItemInterface::class);
$line_item_b
->expects($this
->atLeastOnce())
->method('buildConfigurationForm')
->with([], $form_state)
->willReturn($line_item_configuration_form_b);
$line_item_b
->expects($this
->atLeastOnce())
->method('getName')
->willReturn($line_item_name_b);
$line_items = array(
$line_item_a,
$line_item_b,
);
$line_item_id_a = $this
->randomMachineName();
$line_item_id_b = $this
->randomMachineName();
$line_item_definitions = [
$line_item_id_a => [
'id' => $line_item_id_a,
'label' => $this
->randomMachineName(),
],
$line_item_id_b => [
'id' => $line_item_id_b,
'label' => $this
->randomMachineName(),
],
];
$this->paymentLineItemManager
->expects($this
->atLeastOnce())
->method('getDefinitions')
->willReturn($line_item_definitions);
$line_item_a
->expects($this
->atLeastOnce())
->method('getPluginDefinition')
->willReturn($line_item_definitions[$line_item_id_a]);
$line_item_b
->expects($this
->atLeastOnce())
->method('getPluginDefinition')
->willReturn($line_item_definitions[$line_item_id_b]);
$element = array(
'#cardinality' => PaymentLineItemsInput::CARDINALITY_UNLIMITED,
'#default_value' => $line_items,
'#name' => $this
->randomMachineName(),
'#parents' => array(
$this
->randomMachineName(),
$this
->randomMachineName(),
),
);
$element = $this->sut
->process($element, $form_state, $form);
$this
->assertArrayHasKey($line_item_name_a, $element['line_items']);
$this
->assertSame($line_item_configuration_form_a, $element['line_items'][$line_item_name_a]['plugin_form']);
$this
->assertArrayHasKey('delete', $element['line_items'][$line_item_name_a]);
$this
->assertArrayHasKey($line_item_name_b, $element['line_items']);
$this
->assertSame($line_item_configuration_form_b, $element['line_items'][$line_item_name_b]['plugin_form']);
$this
->assertArrayHasKey('delete', $element['line_items'][$line_item_name_b]);
$this
->assertArrayHasKey('add_more', $element);
$this
->assertArrayHasKey('add', $element['add_more']);
$this
->assertArrayHasKey('type', $element['add_more']);
}