class OrderPaymentGatewayTest in Commerce Core 8.2
@coversDefaultClass \Drupal\commerce_payment\Plugin\Commerce\Condition\OrderPaymentGateway @group commerce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce_payment\Unit\Plugin\Commerce\Condition\OrderPaymentGatewayTest
Expanded class hierarchy of OrderPaymentGatewayTest
File
- modules/
payment/ tests/ src/ Unit/ Plugin/ Commerce/ Condition/ OrderPaymentGatewayTest.php, line 15
Namespace
Drupal\Tests\commerce_payment\Unit\Plugin\Commerce\ConditionView source
class OrderPaymentGatewayTest extends UnitTestCase {
/**
* ::covers evaluate.
*/
public function testIncompleteOrder() {
$condition = new OrderPaymentGateway([
'payment_gateways' => [
'test',
],
], 'order_payment_gateway', [
'entity_type' => 'commerce_order',
]);
$order = $this
->prophesize(OrderInterface::class);
$entity_reference_item = $this
->prophesize(EntityReferenceItem::class);
$entity_reference_item
->isEmpty()
->willReturn(TRUE);
$entity_reference_item = $entity_reference_item
->reveal();
$order = $this
->prophesize(OrderInterface::class);
$order
->getEntityTypeId()
->willReturn('commerce_order');
$order
->get('payment_gateway')
->willReturn($entity_reference_item);
$order = $order
->reveal();
$this
->assertFalse($condition
->evaluate($order));
}
/**
* Covers evaluate.
*/
public function testOrderPaymentGateway() {
$entity_reference_item = $this
->prophesize(EntityReferenceItem::class);
$entity_reference_item
->getValue()
->willReturn([
'target_id' => 'test_payment',
]);
$entity_reference_item_list = $this
->prophesize(EntityReferenceFieldItemList::class);
$entity_reference_item_list
->isEmpty()
->willReturn(FALSE);
$entity_reference_item_list
->first()
->willReturn($entity_reference_item
->reveal());
$entity_reference_item_list = $entity_reference_item_list
->reveal();
$order = $this
->prophesize(OrderInterface::class);
$order
->getEntityTypeId()
->willReturn('commerce_order');
$order
->get('payment_gateway')
->willReturn($entity_reference_item_list);
$order = $order
->reveal();
$condition = new OrderPaymentGateway([
'payment_gateways' => [],
], 'order_payment_gateway', [
'entity_type' => 'commerce_order',
]);
$this
->assertFalse($condition
->evaluate($order));
$condition = new OrderPaymentGateway([
'payment_gateways' => [
'cash_on_delivery',
'bank_transfer',
],
], 'order_payment_gateway', [
'entity_type' => 'commerce_order',
]);
$this
->assertFalse($condition
->evaluate($order));
$condition = new OrderPaymentGateway([
'payment_gateways' => [
'cash_on_delivery',
'test_payment',
],
], 'order_payment_gateway', [
'entity_type' => 'commerce_order',
]);
$this
->assertTrue($condition
->evaluate($order));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrderPaymentGatewayTest:: |
public | function | ::covers evaluate. | |
OrderPaymentGatewayTest:: |
public | function | Covers evaluate. | |
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. | |
UnitTestCase:: |
protected | function | 340 |