class BasicTest in Payment 8.2
Same name in this branch
- 8.2 tests/src/Unit/Plugin/Payment/MethodConfiguration/BasicTest.php \Drupal\Tests\payment\Unit\Plugin\Payment\MethodConfiguration\BasicTest
- 8.2 tests/src/Unit/Plugin/Payment/Method/BasicTest.php \Drupal\Tests\payment\Unit\Plugin\Payment\Method\BasicTest
- 8.2 tests/src/Unit/Plugin/Payment/LineItem/BasicTest.php \Drupal\Tests\payment\Unit\Plugin\Payment\LineItem\BasicTest
@coversDefaultClass \Drupal\payment\Plugin\Payment\Method\Basic
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Plugin\Payment\Method\PaymentMethodBaseTestBase
- class \Drupal\Tests\payment\Unit\Plugin\Payment\Method\BasicTest
- class \Drupal\Tests\payment\Unit\Plugin\Payment\Method\PaymentMethodBaseTestBase
Expanded class hierarchy of BasicTest
File
- tests/
src/ Unit/ Plugin/ Payment/ Method/ BasicTest.php, line 18
Namespace
Drupal\Tests\payment\Unit\Plugin\Payment\MethodView source
class BasicTest extends PaymentMethodBaseTestBase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $moduleHandler;
/**
* The payment status manager.
*
* @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paymentStatusManager;
/**
* The class under test.
*
* @var \Drupal\payment\Plugin\Payment\Method\Basic
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
$this->pluginDefinition += array(
'entity_id' => $this
->randomMachineName(),
'execute_status_id' => $this
->randomMachineName(),
'capture' => TRUE,
'capture_status_id' => $this
->randomMachineName(),
'refund' => TRUE,
'refund_status_id' => $this
->randomMachineName(),
);
$this->moduleHandler = $this
->createMock(ModuleHandlerInterface::class);
$this->paymentStatusManager = $this
->createMock(PaymentStatusManagerInterface::class);
$this->sut = new Basic([], '', $this->pluginDefinition, $this->moduleHandler, $this->eventDispatcher, $this->token, $this->paymentStatusManager);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'payment.event_dispatcher',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->eventDispatcher,
),
array(
'module_handler',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->moduleHandler,
),
array(
'plugin.manager.payment.status',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->paymentStatusManager,
),
array(
'token',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->token,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = Basic::create($container, [], '', $this->pluginDefinition);
$this
->assertInstanceOf(Basic::class, $sut);
}
/**
* @covers ::defaultConfiguration
*/
public function testDefaultConfiguration() {
$this
->assertIsArray($this->sut
->defaultConfiguration());
}
/**
* @covers ::getExecuteStatusId
*/
public function testGetExecuteStatusId() {
$this
->assertSame($this->pluginDefinition['execute_status_id'], $this->sut
->getExecuteStatusId());
}
/**
* @covers ::getCaptureStatusId
*/
public function testGetCaptureStatusId() {
$this
->assertSame($this->pluginDefinition['capture_status_id'], $this->sut
->getCaptureStatusId());
}
/**
* @covers ::getCapture
*/
public function testGetCapture() {
$this
->assertSame($this->pluginDefinition['capture'], $this->sut
->getCapture());
}
/**
* @covers ::getRefundStatusId
*/
public function testGetRefundStatusId() {
$this
->assertSame($this->pluginDefinition['refund_status_id'], $this->sut
->getRefundStatusId());
}
/**
* @covers ::getRefund
*/
public function testGetRefund() {
$this
->assertSame($this->pluginDefinition['refund'], $this->sut
->getRefund());
}
/**
* @covers ::doExecutePayment
*/
public function testDoExecutePayment() {
$payment_status = $this
->createMock(PaymentStatusInterface::class);
$this->paymentStatusManager
->expects($this
->once())
->method('createInstance')
->with($this->pluginDefinition['execute_status_id'])
->willReturn($payment_status);
$payment = $this
->createMock(PaymentInterface::class);
$payment
->expects($this
->once())
->method('save');
$payment
->expects($this
->once())
->method('setPaymentStatus')
->with($payment_status);
$this->sut
->setPayment($payment);
$method = new \ReflectionMethod($this->sut, 'doExecutePayment');
$method
->setAccessible(TRUE);
$method
->invoke($this->sut, $payment);
}
/**
* @covers ::doCapturePayment
*/
public function testDoCapturePayment() {
$payment_status = $this
->createMock(PaymentStatusInterface::class);
$this->paymentStatusManager
->expects($this
->once())
->method('createInstance')
->with($this->pluginDefinition['capture_status_id'])
->willReturn($payment_status);
$payment = $this
->createMock(PaymentInterface::class);
$payment
->expects($this
->once())
->method('save');
$payment
->expects($this
->once())
->method('setPaymentStatus')
->with($payment_status);
$this->sut
->setPayment($payment);
$method = new \ReflectionMethod($this->sut, 'doCapturePayment');
$method
->setAccessible(TRUE);
$method
->invoke($this->sut, $payment);
}
/**
* @covers ::doCapturePaymentAccess
*
* @dataProvider providerDoCapturePaymentAccess
*/
public function testDoCapturePaymentAccess($expected, $capture, $current_status_id, $capture_status_id) {
$this->pluginDefinition['capture'] = $capture;
$this->pluginDefinition['capture_status_id'] = $capture_status_id;
$this->sut = new Basic([], '', $this->pluginDefinition, $this->moduleHandler, $this->eventDispatcher, $this->token, $this->paymentStatusManager);
$capture_payment_status = $this
->createMock(PaymentStatusInterface::class);
$capture_payment_status
->expects($this
->any())
->method('getPluginId')
->willReturn($current_status_id);
$capture_payment_status = $this
->createMock(PaymentStatusInterface::class);
$capture_payment_status
->expects($this
->any())
->method('getPluginId')
->willReturn($current_status_id);
$payment = $this
->createMock(PaymentInterface::class);
$payment
->expects($this
->any())
->method('getPaymentStatus')
->willReturn($capture_payment_status);
$this->sut
->setPayment($payment);
$account = $this
->createMock(AccountInterface::class);
$method = new \ReflectionMethod($this->sut, 'doCapturePaymentAccess');
$method
->setAccessible(TRUE);
$this
->assertSame($expected, $method
->invoke($this->sut, $account));
}
/**
* Provides data to self::testDoCapturePaymentAccess().
*/
public function providerDoCapturePaymentAccess() {
$status_id_a = $this
->randomMachineName();
$status_id_b = $this
->randomMachineName();
$status_id_c = $this
->randomMachineName();
return array(
array(
TRUE,
TRUE,
$status_id_a,
$status_id_b,
),
array(
TRUE,
TRUE,
$status_id_a,
$status_id_c,
),
array(
FALSE,
FALSE,
$status_id_a,
$status_id_b,
),
);
}
/**
* @covers ::doRefundPayment
*/
public function testDoRefundPayment() {
$payment_status = $this
->createMock(PaymentStatusInterface::class);
$this->paymentStatusManager
->expects($this
->once())
->method('createInstance')
->with($this->pluginDefinition['refund_status_id'])
->willReturn($payment_status);
$payment = $this
->createMock(PaymentInterface::class);
$payment
->expects($this
->once())
->method('save');
$payment
->expects($this
->once())
->method('setPaymentStatus')
->with($payment_status);
$this->sut
->setPayment($payment);
$method = new \ReflectionMethod($this->sut, 'doRefundPayment');
$method
->setAccessible(TRUE);
$method
->invoke($this->sut, $payment);
}
/**
* @covers ::doRefundPaymentAccess
*
* @dataProvider providerDoRefundPaymentAccess
*/
public function testDoRefundPaymentAccess($expected, $refund, $current_status_id, $refund_status_id) {
$this->pluginDefinition['refund'] = $refund;
$this->pluginDefinition['refund_status_id'] = $refund_status_id;
$this->sut = new Basic([], '', $this->pluginDefinition, $this->moduleHandler, $this->eventDispatcher, $this->token, $this->paymentStatusManager);
$payment_status = $this
->createMock(PaymentStatusInterface::class);
$payment_status
->expects($this
->any())
->method('getPluginId')
->willReturn($current_status_id);
$payment = $this
->createMock(PaymentInterface::class);
$payment
->expects($this
->any())
->method('getPaymentStatus')
->willReturn($payment_status);
$this->sut
->setPayment($payment);
$account = $this
->createMock(AccountInterface::class);
$method = new \ReflectionMethod($this->sut, 'doRefundPaymentAccess');
$method
->setAccessible(TRUE);
$this
->assertSame($expected, $method
->invoke($this->sut, $account));
}
/**
* Provides data to self::testDoRefundPaymentAccess().
*/
public function providerDoRefundPaymentAccess() {
$status_id_a = $this
->randomMachineName();
$status_id_b = $this
->randomMachineName();
$status_id_c = $this
->randomMachineName();
return array(
array(
TRUE,
TRUE,
$status_id_a,
$status_id_b,
),
array(
TRUE,
TRUE,
$status_id_a,
$status_id_c,
),
array(
FALSE,
FALSE,
$status_id_a,
$status_id_b,
),
);
}
/**
* @covers ::updatePaymentStatusAccess
*/
public function testUpdatePaymentStatusAccess() {
$account = $this
->createMock(AccountInterface::class);
$this
->assertFalse($this->sut
->updatePaymentStatusAccess($account)
->isAllowed());
}
/**
* @covers ::getSettablePaymentStatuses
*/
public function testGetSettablePaymentStatuses() {
$account = $this
->createMock(AccountInterface::class);
$payment = $this
->createMock(PaymentInterface::class);
$this
->assertSame([], $this->sut
->getSettablePaymentStatuses($account, $payment));
}
/**
* @covers ::getSupportedCurrencies
*/
public function testGetSupportedCurrencies() {
$this
->assertTrue($this->sut
->getSupportedCurrencies());
}
/**
* @covers ::getEntityId
*/
public function testGetEntityId() {
$this
->assertSame($this->pluginDefinition['entity_id'], $this->sut
->getEntityId());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BasicTest:: |
protected | property |
The module handler. Overrides PaymentMethodBaseTestBase:: |
|
BasicTest:: |
protected | property |
The payment status manager. Overrides PaymentMethodBaseTestBase:: |
|
BasicTest:: |
protected | property | The class under test. | |
BasicTest:: |
public | function | Provides data to self::testDoCapturePaymentAccess(). | |
BasicTest:: |
public | function | Provides data to self::testDoRefundPaymentAccess(). | |
BasicTest:: |
public | function |
Overrides PaymentMethodBaseTestBase:: |
|
BasicTest:: |
function | @covers ::create @covers ::__construct | ||
BasicTest:: |
public | function | @covers ::defaultConfiguration | |
BasicTest:: |
public | function | @covers ::doCapturePayment | |
BasicTest:: |
public | function | @covers ::doCapturePaymentAccess | |
BasicTest:: |
public | function | @covers ::doExecutePayment | |
BasicTest:: |
public | function | @covers ::doRefundPayment | |
BasicTest:: |
public | function | @covers ::doRefundPaymentAccess | |
BasicTest:: |
public | function | @covers ::getCapture | |
BasicTest:: |
public | function | @covers ::getCaptureStatusId | |
BasicTest:: |
public | function | @covers ::getEntityId | |
BasicTest:: |
public | function | @covers ::getExecuteStatusId | |
BasicTest:: |
public | function | @covers ::getRefund | |
BasicTest:: |
public | function | @covers ::getRefundStatusId | |
BasicTest:: |
public | function | @covers ::getSettablePaymentStatuses | |
BasicTest:: |
public | function | @covers ::getSupportedCurrencies | |
BasicTest:: |
public | function | @covers ::updatePaymentStatusAccess | |
PaymentMethodBaseTestBase:: |
protected | property | The cache context manager. | |
PaymentMethodBaseTestBase:: |
protected | property | The event dispatcher. | |
PaymentMethodBaseTestBase:: |
protected | property | The definition of the payment method plugin under test. | |
PaymentMethodBaseTestBase:: |
protected | property | The ID of the payment method plugin under test. | |
PaymentMethodBaseTestBase:: |
protected | property | The token API. | |
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. | |
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. |