class EventDispatcherCollectionTest in Payment 8.2
@coversDefaultClass \Drupal\payment\EventDispatcherCollection
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\EventDispatcherCollectionTest
Expanded class hierarchy of EventDispatcherCollectionTest
File
- tests/
src/ Unit/ EventDispatcherCollectionTest.php, line 29
Namespace
Drupal\Tests\payment\UnitView source
class EventDispatcherCollectionTest extends UnitTestCase {
/**
* The subject under test.
*
* @var \Drupal\payment\EventDispatcherCollection
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->sut = new EventDispatcherCollection();
}
/**
* @covers ::alterQueueLoadedPaymentIds
* @covers ::addEventDispatcher
*/
public function testAlterQueueLoadedPaymentIds() {
$queue_id = $this
->randomMachineName();
$category_id = $this
->randomMachineName();
$owner_id = mt_rand();
$payment_ids = [
mt_rand(),
mt_rand(),
mt_rand(),
];
$payment_ids_a = [
mt_rand(),
mt_rand(),
mt_rand(),
];
$payment_ids_b = [
mt_rand(),
mt_rand(),
mt_rand(),
];
$event_dispatcher_a = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_a
->expects($this
->atLeastOnce())
->method('alterQueueLoadedPaymentIds')
->with($queue_id, $category_id, $owner_id, $payment_ids)
->willReturn($payment_ids_a);
$event_dispatcher_b = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_b
->expects($this
->atLeastOnce())
->method('alterQueueLoadedPaymentIds')
->with($queue_id, $category_id, $owner_id, $payment_ids_a)
->willReturn($payment_ids_b);
$this->sut
->addEventDispatcher($event_dispatcher_a);
$this->sut
->addEventDispatcher($event_dispatcher_b);
$this
->assertSame($payment_ids_b, $this->sut
->alterQueueLoadedPaymentIds($queue_id, $category_id, $owner_id, $payment_ids));
}
/**
* @covers ::setPaymentStatus
*/
public function testSetPaymentStatus() {
$payment = $this
->createMock(PaymentInterface::class);
$previous_payment_status = $this
->createMock(PaymentStatusInterface::class);
$event_dispatcher_a = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_a
->expects($this
->atLeastOnce())
->method('setPaymentStatus')
->with($payment, $previous_payment_status);
$event_dispatcher_b = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_b
->expects($this
->atLeastOnce())
->method('setPaymentStatus')
->with($payment, $previous_payment_status);
$this->sut
->addEventDispatcher($event_dispatcher_a);
$this->sut
->addEventDispatcher($event_dispatcher_b);
$this->sut
->setPaymentStatus($payment, $previous_payment_status);
}
/**
* @covers ::preExecutePayment
*
*/
public function testPreExecutePayment() {
$payment = $this
->createMock(PaymentInterface::class);
$event_dispatcher_a = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_a
->expects($this
->atLeastOnce())
->method('preExecutePayment')
->with($payment);
$event_dispatcher_b = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_b
->expects($this
->atLeastOnce())
->method('preExecutePayment')
->with($payment);
$this->sut
->addEventDispatcher($event_dispatcher_a);
$this->sut
->addEventDispatcher($event_dispatcher_b);
$this->sut
->preExecutePayment($payment);
}
/**
* @covers ::executePaymentAccess
*
* @dataProvider providerExecutePaymentAccess
*
* @param bool|null $expected_access
* TRUE for allowed, NULL for neutral, FALSE for forbidden.
* @param \Drupal\Core\Access\AccessResult $event_dispatcher_access_a
* @param \Drupal\Core\Access\AccessResult $event_dispatcher_access_b
*/
public function testExecutePaymentAccess($expected_access, AccessResult $event_dispatcher_access_a, AccessResult $event_dispatcher_access_b) {
$payment = $this
->createMock(PaymentInterface::class);
$payment_method = $this
->createMock(PaymentMethodInterface::class);
$account = $this
->createMock(AccountInterface::class);
$event_dispatcher_a = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_a
->expects($this
->atLeastOnce())
->method('executePaymentAccess')
->with($payment, $payment_method, $account)
->willReturn($event_dispatcher_access_a);
$event_dispatcher_b = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_b
->expects($this
->atLeastOnce())
->method('executePaymentAccess')
->with($payment, $payment_method, $account)
->willReturn($event_dispatcher_access_b);
$this->sut
->addEventDispatcher($event_dispatcher_a);
$this->sut
->addEventDispatcher($event_dispatcher_b);
$access = $this->sut
->executePaymentAccess($payment, $payment_method, $account);
$this
->assertInstanceOf(AccessResultInterface::class, $access);
if ($expected_access === TRUE) {
$this
->assertTrue($access
->isAllowed());
}
elseif ($expected_access === FALSE) {
$this
->assertTrue($access
->isForbidden());
}
elseif ($expected_access === NULL) {
$this
->assertTrue($access
->isNeutral());
}
}
/**
* Provides data to self::testExecutePaymentAccess
*/
public function providerExecutePaymentAccess() {
return [
[
TRUE,
AccessResult::allowed(),
AccessResult::allowed(),
],
[
TRUE,
AccessResult::allowed(),
AccessResult::neutral(),
],
[
TRUE,
AccessResult::neutral(),
AccessResult::allowed(),
],
[
NULL,
AccessResult::neutral(),
AccessResult::neutral(),
],
[
FALSE,
AccessResult::allowed(),
AccessResult::forbidden(),
],
[
FALSE,
AccessResult::neutral(),
AccessResult::forbidden(),
],
[
FALSE,
AccessResult::forbidden(),
AccessResult::allowed(),
],
[
FALSE,
AccessResult::forbidden(),
AccessResult::neutral(),
],
[
FALSE,
AccessResult::forbidden(),
AccessResult::forbidden(),
],
];
}
/**
* @covers ::preCapturePayment
*/
public function testPreCapturePayment() {
$payment = $this
->createMock(PaymentInterface::class);
$event_dispatcher_a = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_a
->expects($this
->atLeastOnce())
->method('preCapturePayment')
->with($payment);
$event_dispatcher_b = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_b
->expects($this
->atLeastOnce())
->method('preCapturePayment')
->with($payment);
$this->sut
->addEventDispatcher($event_dispatcher_a);
$this->sut
->addEventDispatcher($event_dispatcher_b);
$this->sut
->preCapturePayment($payment);
}
/**
* @covers ::preRefundPayment
*/
public function testPreRefundPayment() {
$payment = $this
->createMock(PaymentInterface::class);
$event_dispatcher_a = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_a
->expects($this
->atLeastOnce())
->method('preRefundPayment')
->with($payment);
$event_dispatcher_b = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_b
->expects($this
->atLeastOnce())
->method('preRefundPayment')
->with($payment);
$this->sut
->addEventDispatcher($event_dispatcher_a);
$this->sut
->addEventDispatcher($event_dispatcher_b);
$this->sut
->preRefundPayment($payment);
}
/**
* @covers ::preResumeContext
*/
public function testPreResumeContext() {
$payment = $this
->createMock(PaymentInterface::class);
$event_dispatcher_a = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_a
->expects($this
->atLeastOnce())
->method('preResumeContext')
->with($payment);
$event_dispatcher_b = $this
->createMock(EventDispatcherInterface::class);
$event_dispatcher_b
->expects($this
->atLeastOnce())
->method('preResumeContext')
->with($payment);
$this->sut
->addEventDispatcher($event_dispatcher_a);
$this->sut
->addEventDispatcher($event_dispatcher_b);
$this->sut
->preResumeContext($payment);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EventDispatcherCollectionTest:: |
protected | property | The subject under test. | |
EventDispatcherCollectionTest:: |
public | function | Provides data to self::testExecutePaymentAccess | |
EventDispatcherCollectionTest:: |
public | function |
Overrides UnitTestCase:: |
|
EventDispatcherCollectionTest:: |
public | function | @covers ::alterQueueLoadedPaymentIds @covers ::addEventDispatcher | |
EventDispatcherCollectionTest:: |
public | function | @covers ::executePaymentAccess | |
EventDispatcherCollectionTest:: |
public | function | @covers ::preCapturePayment | |
EventDispatcherCollectionTest:: |
public | function | @covers ::preExecutePayment | |
EventDispatcherCollectionTest:: |
public | function | @covers ::preRefundPayment | |
EventDispatcherCollectionTest:: |
public | function | @covers ::preResumeContext | |
EventDispatcherCollectionTest:: |
public | function | @covers ::setPaymentStatus | |
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. |