public function PaymentLineItemsInputTest::testAddMoreSubmit in Payment 8.2
@covers ::addMoreSubmit
File
- tests/
src/ Unit/ Element/ PaymentLineItemsInputTest.php, line 386
Class
- PaymentLineItemsInputTest
- @coversDefaultClass \Drupal\payment\Element\PaymentLineItemsInput
Namespace
Drupal\Tests\payment\Unit\ElementCode
public function testAddMoreSubmit() {
$plugin_id = $this
->randomMachineName();
$values = array(
'add_more' => array(
'type' => $plugin_id,
),
);
$line_item = $this
->createMock(PaymentLineItemInterface::class);
$line_item
->expects($this
->once())
->method('setName')
->with($plugin_id);
$this->paymentLineItemManager
->expects($this
->once())
->method('createInstance')
->with($plugin_id)
->willReturn($line_item);
$form_build = array(
'foo' => array(
'#name' => $this
->randomMachineName(),
'#parents' => array(
$this
->randomMachineName(),
$this
->randomMachineName(),
),
'add_more' => array(
'add' => array(
'#array_parents' => array(
'foo',
'add_more',
'add',
),
'#parents' => [],
),
),
),
);
$form_state = new FormState();
$form_state
->setTriggeringElement($form_build['foo']['add_more']['add']);
$form_state
->setValues($values);
$this->sut
->addMoreSubmit($form_build, $form_state);
$this
->assertTrue($form_state
->isRebuilding());
$element = $this->sut;
$line_items = $element::getLineItems($form_build['foo'], $form_state);
$this
->assertTrue(in_array($line_item, $line_items, TRUE));
}