View source
<?php
namespace Drupal\Tests\payment\Unit\Plugin\Payment\LineItem;
use Drupal\Core\Form\FormStateInterface;
use Drupal\payment\Entity\PaymentInterface;
use Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemBase;
use Drupal\Tests\UnitTestCase;
class PaymentLineItemBaseTest extends UnitTestCase {
protected $sut;
public function setUp() : void {
$configuration = [];
$plugin_id = $this
->randomMachineName();
$plugin_definition = [];
$this->sut = $this
->getMockBuilder(PaymentLineItemBase::class)
->setConstructorArgs(array(
$configuration,
$plugin_id,
$plugin_definition,
))
->getMockForAbstractClass();
}
public function testGetConfiguration() {
$configuration = array(
$this
->randomMachineName() => mt_rand(),
) + $this->sut
->defaultConfiguration();
$return = $this->sut
->setConfiguration($configuration);
$this
->assertNull($return);
$this
->assertSame($configuration, $this->sut
->getConfiguration());
}
public function testGetQuantity() {
$quantity = 7.7;
$this
->assertSame($this->sut, $this->sut
->setQuantity($quantity));
$this
->assertSame($quantity, $this->sut
->getQuantity());
}
public function testGetTotalAmount() {
$amount = 7;
$quantity = 7;
$total_amount = bcmul($amount, $quantity, 6);
$configuration = [];
$plugin_id = $this
->randomMachineName();
$plugin_definition = [];
$line_item = $this
->getMockBuilder(PaymentLineItemBase::class)
->setMethods(array(
'formElements',
'getAmount',
'getConfigurationFromFormValues',
'getCurrencyCode',
'getDescription',
'getQuantity',
))
->setConstructorArgs(array(
$configuration,
$plugin_id,
$plugin_definition,
))
->getMock();
$line_item
->expects($this
->once())
->method('getAmount')
->willReturn($amount);
$line_item
->expects($this
->once())
->method('getQuantity')
->willReturn($quantity);
$this
->assertSame($total_amount, $line_item
->getTotalAmount());
}
public function testGetName() {
$name = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setName($name));
$this
->assertSame($name, $this->sut
->getName());
}
public function testGetPayment() {
$payment = $this
->createMock(PaymentInterface::class);
$this
->assertSame($this->sut, $this->sut
->setPayment($payment));
$this
->assertSame($payment, $this->sut
->getPayment());
}
public function testCalculateDependencies() {
$this
->assertSame([], $this->sut
->calculateDependencies());
}
public function testDefaultConfiguration() {
$default_configuration = array(
'name' => NULL,
'quantity' => 1,
);
$this
->assertSame($default_configuration, $this->sut
->defaultConfiguration());
}
public function testBuildConfigurationForm() {
$form = [];
$form_state = $this
->createMock(FormStateInterface::class);
$this
->assertSame([], $this->sut
->buildConfigurationForm($form, $form_state));
}
}