class SelectPaymentMethodConfigurationTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Controller\SelectPaymentMethodConfiguration
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Controller\SelectPaymentMethodConfigurationTest
Expanded class hierarchy of SelectPaymentMethodConfigurationTest
File
- tests/
src/ Unit/ Controller/ SelectPaymentMethodConfigurationTest.php, line 19
Namespace
Drupal\Tests\payment\Unit\ControllerView source
class SelectPaymentMethodConfigurationTest extends UnitTestCase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $currentUser;
/**
* The payment method configuration access control handler.
*
* @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paymentMethodConfigurationAccessControlHandler;
/**
* The payment method configuration manager.
*
* @var \Drupal\payment\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paymentMethodConfigurationManager;
/**
* The class under test.
*
* @var \Drupal\payment\Controller\SelectPaymentMethodConfiguration
*/
protected $sut;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->currentUser = $this
->createMock(AccountInterface::class);
$this->paymentMethodConfigurationAccessControlHandler = $this
->createMock(EntityAccessControlHandlerInterface::class);
$this->paymentMethodConfigurationManager = $this
->createMock(PaymentMethodConfigurationManagerInterface::class);
$this->sut = new SelectPaymentMethodConfiguration($this->paymentMethodConfigurationAccessControlHandler, $this->paymentMethodConfigurationManager, $this->currentUser);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_type_manager
->expects($this
->atLeastOnce())
->method('getAccessControlHandler')
->with('payment_method_configuration')
->willReturn($this->paymentMethodConfigurationAccessControlHandler);
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'current_user',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->currentUser,
],
[
'entity_type.manager',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$entity_type_manager,
],
[
'plugin.manager.payment.method_configuration',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->paymentMethodConfigurationManager,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = SelectPaymentMethodConfiguration::create($container);
$this
->assertInstanceOf(SelectPaymentMethodConfiguration::class, $sut);
}
/**
* @covers ::execute
*/
public function testExecute() {
$definitions = [
'payment_unavailable' => [],
'foo' => [
'description' => $this
->randomMachineName(),
'label' => $this
->randomMachineName(),
],
'bar' => [
'description' => $this
->randomMachineName(),
'label' => $this
->randomMachineName(),
],
];
$this->paymentMethodConfigurationManager
->expects($this
->once())
->method('getDefinitions')
->willReturn($definitions);
$this->paymentMethodConfigurationAccessControlHandler
->expects($this
->any())
->method('createAccess')
->willReturn(TRUE);
$this->sut
->execute();
}
/**
* @covers ::access
*/
public function testAccess() {
$definitions = [
'payment_unavailable' => [],
'foo' => [
'description' => $this
->randomMachineName(),
'label' => $this
->randomMachineName(),
],
'bar' => [
'description' => $this
->randomMachineName(),
'label' => $this
->randomMachineName(),
],
];
$this->paymentMethodConfigurationManager
->expects($this
->exactly(2))
->method('getDefinitions')
->willReturn($definitions);
$this->paymentMethodConfigurationAccessControlHandler
->expects($this
->at(0))
->method('createAccess')
->with('foo', $this->currentUser, [], TRUE)
->willReturn(AccessResult::allowed());
$this->paymentMethodConfigurationAccessControlHandler
->expects($this
->at(1))
->method('createAccess')
->with('foo', $this->currentUser, [], TRUE)
->willReturn(AccessResult::forbidden());
$this->paymentMethodConfigurationAccessControlHandler
->expects($this
->at(2))
->method('createAccess')
->with('bar', $this->currentUser, [], TRUE)
->willReturn(AccessResult::forbidden());
$this
->assertTrue($this->sut
->access()
->isAllowed());
$this
->assertFalse($this->sut
->access()
->isAllowed());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
SelectPaymentMethodConfigurationTest:: |
protected | property | The current user. | |
SelectPaymentMethodConfigurationTest:: |
protected | property | The payment method configuration access control handler. | |
SelectPaymentMethodConfigurationTest:: |
protected | property | The payment method configuration manager. | |
SelectPaymentMethodConfigurationTest:: |
protected | property | The class under test. | |
SelectPaymentMethodConfigurationTest:: |
protected | function |
Overrides UnitTestCase:: |
|
SelectPaymentMethodConfigurationTest:: |
public | function | @covers ::access | |
SelectPaymentMethodConfigurationTest:: |
function | @covers ::create @covers ::__construct | ||
SelectPaymentMethodConfigurationTest:: |
public | function | @covers ::execute | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |