/** * @covers ::setLineItem * @covers ::getLineItem * @covers ::getLineItems */ public function testSetLineItem() { $line_item_name = $this->randomMachineName(); $line_item = $this->getMock(PaymentLineItemInterface::class); $line_item->expects($this->atLeastOnce())->method('getName')->willReturn($line_item_name); $this->assertSame($this->sut, $this->sut->setLineItem($line_item)); $this->assertSame($line_item, $this->sut->getLineItem($line_item_name)); $expected = $this->lineItems + [$line_item_name => $line_item]; $this->assertSame($expected, $this->sut->getLineItems()); }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $payment_line_items = new LineItemCollection(); /** @var \Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemInterface $item */ foreach ($items as $delta => $item) { $payment_line_items->setLineItem($item->getContainedPluginInstance()); } $entity = $items->getEntity(); if ($entity instanceof LineItemCollectionInterface) { $payment_line_items->setCurrencyCode($entity->getCurrencyCode()); } $build[0] = array('#payment_line_items' => $payment_line_items, '#type' => 'payment_line_items_display'); return $build; }