DuplicatePaymentMethodConfigurationTest.php in Payment 8.2
File
tests/src/Unit/Controller/DuplicatePaymentMethodConfigurationTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit\Controller;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Entity\EntityFormInterface;
use Drupal\payment\Controller\DuplicatePaymentMethodConfiguration;
use Drupal\payment\Entity\PaymentMethodConfigurationInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DuplicatePaymentMethodConfigurationTest extends UnitTestCase {
protected $entityFormBuilder;
protected $stringTranslation;
protected $sut;
protected function setUp() : void {
$this->entityFormBuilder = $this
->createMock(EntityFormBuilderInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->sut = new DuplicatePaymentMethodConfiguration($this->stringTranslation, $this->entityFormBuilder);
}
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'entity.form_builder',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->entityFormBuilder,
],
[
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = DuplicatePaymentMethodConfiguration::create($container);
$this
->assertInstanceOf(DuplicatePaymentMethodConfiguration::class, $sut);
}
public function testExecute() {
$payment_method_configuration = $this
->createMock(PaymentMethodConfigurationInterface::class);
$payment_method_configuration
->expects($this
->once())
->method('createDuplicate')
->willReturnSelf();
$payment_method_configuration
->expects($this
->once())
->method('setLabel')
->willReturnSelf();
$form = $this
->createMock(EntityFormInterface::class);
$this->entityFormBuilder
->expects($this
->once())
->method('getForm')
->with($payment_method_configuration, 'default')
->willReturn($form);
$this->sut
->execute($payment_method_configuration);
}
public function testTitle() {
$label = $this
->randomMachineName();
$payment_method_configuration = $this
->createMock(PaymentMethodConfigurationInterface::class);
$payment_method_configuration
->expects($this
->once())
->method('label')
->willReturn($label);
$this
->assertStringContainsString($label, (string) $this->sut
->title($payment_method_configuration));
}
}