UnavailableTest.php in Payment 8.2
File
tests/src/Unit/Plugin/Payment/Type/UnavailableTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit\Plugin\Payment\Type;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\payment\Entity\PaymentInterface;
use Drupal\payment\EventDispatcherInterface;
use Drupal\payment\Plugin\Payment\Type\Unavailable;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class UnavailableTest extends UnitTestCase {
protected $eventDispatcher;
protected $stringTranslation;
protected $sut;
public function setUp() : void {
$this->eventDispatcher = $this
->createMock(EventDispatcherInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$configuration = [];
$plugin_id = $this
->randomMachineName();
$plugin_definition = [];
$this->sut = new Unavailable($configuration, $plugin_id, $plugin_definition, $this->eventDispatcher, $this->stringTranslation);
}
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'payment.event_dispatcher',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->eventDispatcher,
),
array(
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$configuration = [];
$plugin_definition = [];
$plugin_id = $this
->randomMachineName();
$sut = Unavailable::create($container, $configuration, $plugin_id, $plugin_definition);
$this
->assertInstanceOf(Unavailable::class, $sut);
}
public function testResumeContextAccess() {
$account = $this
->createMock(AccountInterface::class);
$access = $this->sut
->resumeContextAccess($account);
$this
->assertInstanceOf(AccessResultInterface::class, $access);
$this
->assertTrue($access
->isForbidden());
}
public function testDoGetResumeContextResponse() {
$this
->expectException(NotFoundHttpException::class);
$payment = $this
->createMock(PaymentInterface::class);
$this->sut
->setPayment($payment);
$this->sut
->getResumeContextResponse();
}
public function testGetPaymentDescription() {
$this
->assertInstanceOf(TranslatableMarkup::class, $this->sut
->getPaymentDescription());
}
}